mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2025-01-11 20:31:04 +03:00
TextItem editor has been refactored
This commit is contained in:
parent
2b708b38f5
commit
fcf165df66
@ -33,6 +33,7 @@
|
|||||||
#include "lrdatasourcemanager.h"
|
#include "lrdatasourcemanager.h"
|
||||||
#include "lrscriptenginemanager.h"
|
#include "lrscriptenginemanager.h"
|
||||||
#include "lrdatadesignintf.h"
|
#include "lrdatadesignintf.h"
|
||||||
|
#include "lrscripteditor.h"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
@ -45,10 +46,9 @@ TextItemEditor::TextItemEditor(LimeReport::TextItem *item, LimeReport::PageDesig
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
initUI();
|
initUI();
|
||||||
m_teContent->setPlainText(item->content());
|
|
||||||
m_teContent->setFocus();
|
|
||||||
setWindowIcon(QIcon(":/items/images/TextItem"));
|
setWindowIcon(QIcon(":/items/images/TextItem"));
|
||||||
readSetting();
|
readSetting();
|
||||||
|
connect(ui->codeEditor, SIGNAL(splitterMoved(int,int)), this, SLOT(slotSplitterMoved(int,int)) );
|
||||||
}
|
}
|
||||||
|
|
||||||
TextItemEditor::~TextItemEditor()
|
TextItemEditor::~TextItemEditor()
|
||||||
@ -96,10 +96,20 @@ void TextItemEditor::moveEvent(QMoveEvent*)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextItemEditor::closeEvent(QCloseEvent* event)
|
||||||
|
{
|
||||||
|
if (settings()!=0){
|
||||||
|
settings()->beginGroup("TextItemEditor");
|
||||||
|
settings()->setValue("CodeEditorState",ui->codeEditor->saveState());
|
||||||
|
settings()->endGroup();
|
||||||
|
}
|
||||||
|
QWidget::closeEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
void TextItemEditor::on_pbOk_clicked()
|
void TextItemEditor::on_pbOk_clicked()
|
||||||
{
|
{
|
||||||
if (m_textItem->content()!=m_teContent->toPlainText()){
|
if (m_textItem->content()!= ui->codeEditor->toPlainText()){
|
||||||
m_textItem->setContent(m_teContent->toPlainText());
|
m_textItem->setContent(ui->codeEditor->toPlainText());
|
||||||
}
|
}
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
@ -107,84 +117,19 @@ void TextItemEditor::on_pbOk_clicked()
|
|||||||
void TextItemEditor::initUI()
|
void TextItemEditor::initUI()
|
||||||
{
|
{
|
||||||
QStringList dataWords;
|
QStringList dataWords;
|
||||||
m_teContent = ui->textEdit;
|
|
||||||
m_completer = new QCompleter(this);
|
|
||||||
m_teContent->setCompleter(m_completer);
|
|
||||||
|
|
||||||
m_datasourcesMenu = new QMenu(this);
|
|
||||||
|
|
||||||
|
ui->toolButton->setChecked(false);
|
||||||
|
ui->gbSettings->setVisible(false);
|
||||||
LimeReport::DataSourceManager* dm = m_page->datasourceManager();
|
LimeReport::DataSourceManager* dm = m_page->datasourceManager();
|
||||||
LimeReport::ScriptEngineManager& se = LimeReport::ScriptEngineManager::instance();
|
LimeReport::ScriptEngineManager& se = LimeReport::ScriptEngineManager::instance();
|
||||||
se.setDataManager(dm);
|
se.setDataManager(dm);
|
||||||
|
|
||||||
if (dm){
|
ScriptEditor* scriptEditor = dynamic_cast<ScriptEditor*>(ui->codeEditor);
|
||||||
if (dm->isNeedUpdateDatasourceModel())
|
if (scriptEditor){
|
||||||
dm->updateDatasourceModel();
|
scriptEditor->setReportPage(m_page);
|
||||||
ui->twData->setModel(dm->datasourcesModel());
|
scriptEditor->setPageBand(findParentBand());
|
||||||
ui->twScriptEngine->setModel(se.model());
|
scriptEditor->setPlainText(m_textItem->content());
|
||||||
|
|
||||||
foreach(const QString &dsName,dm->dataSourceNames()){
|
|
||||||
foreach(const QString &field, dm->fieldNames(dsName)){
|
|
||||||
dataWords<<dsName+"."+field;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ui->tabWidget->setVisible(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (LimeReport::ScriptFunctionDesc functionDesc, se.functionsDescribers()) {
|
|
||||||
dataWords<<functionDesc.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_completer->setModel(new QStringListModel(dataWords,m_completer));
|
|
||||||
ui->gbSettings->setVisible(false);
|
|
||||||
|
|
||||||
if (ui->twScriptEngine->selectionModel()){
|
|
||||||
connect(ui->twScriptEngine->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
|
||||||
this, SLOT(slotScriptItemsSelectionChanged(QModelIndex,QModelIndex)));
|
|
||||||
}
|
|
||||||
|
|
||||||
BandDesignIntf* band = findParentBand();
|
|
||||||
if (band && ui->twData->model() && !band->datasourceName().isEmpty()){
|
|
||||||
QModelIndexList nodes = ui->twData->model()->match(
|
|
||||||
ui->twData->model()->index(0,0),
|
|
||||||
Qt::DisplayRole,
|
|
||||||
band->datasourceName(),
|
|
||||||
2,
|
|
||||||
Qt::MatchRecursive
|
|
||||||
);
|
|
||||||
if (!nodes.isEmpty()){
|
|
||||||
ui->twData->expand(nodes.at(0).parent());
|
|
||||||
ui->twData->expand(nodes.at(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringListModel *TextItemEditor::getDataSources()
|
|
||||||
{
|
|
||||||
LimeReport::DataSourceManager* dm = m_page->datasourceManager();
|
|
||||||
QStringList dataSources;
|
|
||||||
foreach(QString dsName,dm->dataSourceNames()){
|
|
||||||
dataSources<<dsName;
|
|
||||||
}
|
|
||||||
return new QStringListModel(dataSources, m_completer);
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringListModel *TextItemEditor::getPrefixes()
|
|
||||||
{
|
|
||||||
QStringList prefixes;
|
|
||||||
prefixes<<"D{"<<"S{";
|
|
||||||
return new QStringListModel(prefixes, m_completer);
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringListModel *TextItemEditor::getColumns(QString datasource)
|
|
||||||
{
|
|
||||||
QStringList fields;
|
|
||||||
LimeReport::DataSourceManager* dm = m_page->datasourceManager();
|
|
||||||
foreach(QString field, dm->fieldNames(datasource)){
|
|
||||||
fields<<field;
|
|
||||||
}
|
|
||||||
return new QStringListModel(fields, m_completer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextItemEditor::on_pbCancel_clicked()
|
void TextItemEditor::on_pbCancel_clicked()
|
||||||
@ -192,12 +137,6 @@ void TextItemEditor::on_pbCancel_clicked()
|
|||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextItemEditor::slotFieldSelected()
|
|
||||||
{
|
|
||||||
QAction* action = dynamic_cast<QAction*>(sender());
|
|
||||||
m_teContent->insertPlainText(action->whatsThis());
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextItemEditor::readSetting()
|
void TextItemEditor::readSetting()
|
||||||
{
|
{
|
||||||
if (settings()==0) return;
|
if (settings()==0) return;
|
||||||
@ -209,16 +148,16 @@ void TextItemEditor::readSetting()
|
|||||||
if (v.isValid()){
|
if (v.isValid()){
|
||||||
restoreGeometry(v.toByteArray());
|
restoreGeometry(v.toByteArray());
|
||||||
}
|
}
|
||||||
v = settings()->value("State");
|
v = settings()->value("CodeEditorState");
|
||||||
if (v.isValid()){
|
if (v.isValid()){
|
||||||
ui->splitter->restoreState(v.toByteArray());
|
ui->codeEditor->restoreState(v.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant fontName = settings()->value("FontName");
|
QVariant fontName = settings()->value("FontName");
|
||||||
if (fontName.isValid()){
|
if (fontName.isValid()){
|
||||||
QVariant fontSize = settings()->value("FontSize");
|
QVariant fontSize = settings()->value("FontSize");
|
||||||
ui->textEdit->setFont(QFont(fontName.toString(),fontSize.toInt()));
|
ui->codeEditor->setEditorFont(QFont(fontName.toString(),fontSize.toInt()));
|
||||||
ui->editorFont->setCurrentFont(ui->textEdit->font());
|
ui->editorFont->setCurrentFont(ui->codeEditor->editorFont());
|
||||||
ui->editorFontSize->setValue(fontSize.toInt());
|
ui->editorFontSize->setValue(fontSize.toInt());
|
||||||
}
|
}
|
||||||
settings()->endGroup();
|
settings()->endGroup();
|
||||||
@ -231,136 +170,19 @@ void TextItemEditor::writeSetting()
|
|||||||
if (settings()!=0){
|
if (settings()!=0){
|
||||||
settings()->beginGroup("TextItemEditor");
|
settings()->beginGroup("TextItemEditor");
|
||||||
settings()->setValue("Geometry",saveGeometry());
|
settings()->setValue("Geometry",saveGeometry());
|
||||||
settings()->setValue("State",ui->splitter->saveState());
|
settings()->setValue("CodeEditorState",ui->codeEditor->saveState());
|
||||||
settings()->endGroup();
|
settings()->endGroup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CompleaterTextEditor::CompleaterTextEditor(QWidget *parent)
|
|
||||||
: QTextEdit(parent),m_compleater(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CompleaterTextEditor::setCompleter(QCompleter *value)
|
|
||||||
{
|
|
||||||
if (value) disconnect(value,0,this,0);
|
|
||||||
m_compleater = value;
|
|
||||||
if (!m_compleater) return;
|
|
||||||
m_compleater->setWidget(this);
|
|
||||||
m_compleater->setCompletionMode(QCompleter::PopupCompletion);
|
|
||||||
m_compleater->setCaseSensitivity(Qt::CaseInsensitive);
|
|
||||||
connect(m_compleater,SIGNAL(activated(QString)),this,SLOT(insertCompletion(QString)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CompleaterTextEditor::keyPressEvent(QKeyEvent *e)
|
|
||||||
{
|
|
||||||
if (m_compleater && m_compleater->popup()->isVisible()) {
|
|
||||||
switch (e->key()) {
|
|
||||||
case Qt::Key_Enter:
|
|
||||||
case Qt::Key_Return:
|
|
||||||
case Qt::Key_Escape:
|
|
||||||
case Qt::Key_Tab:
|
|
||||||
case Qt::Key_Backtab:
|
|
||||||
e->ignore();
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E);
|
|
||||||
if (!m_compleater || !isShortcut) QTextEdit::keyPressEvent(e);
|
|
||||||
|
|
||||||
const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
|
|
||||||
if (!m_compleater || (ctrlOrShift && e->text().isEmpty()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
static QString eow("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-="); // end of word
|
|
||||||
bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
|
|
||||||
|
|
||||||
QString completionPrefix = textUnderCursor();
|
|
||||||
|
|
||||||
if (!isShortcut && (hasModifier || e->text().isEmpty()|| completionPrefix.length() < 3
|
|
||||||
|| eow.contains(e->text().right(1)))) {
|
|
||||||
m_compleater->popup()->hide();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (completionPrefix != m_compleater->completionPrefix()) {
|
|
||||||
m_compleater->setCompletionPrefix(completionPrefix);
|
|
||||||
m_compleater->popup()->setCurrentIndex(m_compleater->completionModel()->index(0, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
QRect cr = cursorRect();
|
|
||||||
cr.setWidth(m_compleater->popup()->sizeHintForColumn(0)
|
|
||||||
+ m_compleater->popup()->verticalScrollBar()->sizeHint().width());
|
|
||||||
m_compleater->complete(cr);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void CompleaterTextEditor::focusInEvent(QFocusEvent *e)
|
|
||||||
{
|
|
||||||
if (m_compleater) m_compleater->setWidget(this);
|
|
||||||
QTextEdit::focusInEvent(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CompleaterTextEditor::textUnderCursor() const
|
|
||||||
{
|
|
||||||
QTextCursor tc = textCursor();
|
|
||||||
tc.select(QTextCursor::WordUnderCursor);
|
|
||||||
return tc.selectedText();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CompleaterTextEditor::insertCompletion(const QString &completion)
|
|
||||||
{
|
|
||||||
if (m_compleater->widget() != this)
|
|
||||||
return;
|
|
||||||
QTextCursor tc = textCursor();
|
|
||||||
int extra = completion.length() - m_compleater->completionPrefix().length();
|
|
||||||
tc.movePosition(QTextCursor::Left);
|
|
||||||
tc.movePosition(QTextCursor::EndOfWord);
|
|
||||||
tc.insertText(completion.right(extra));
|
|
||||||
setTextCursor(tc);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextItemEditor::on_twData_doubleClicked(const QModelIndex &index)
|
|
||||||
{
|
|
||||||
if (!index.isValid()) return;
|
|
||||||
LimeReport::DataNode* node = static_cast<LimeReport::DataNode*>(index.internalPointer());
|
|
||||||
if (node->type()==LimeReport::DataNode::Field){
|
|
||||||
m_teContent->insertPlainText(QString("$D{%1.%2}").arg(node->parent()->name()).arg(node->name()));
|
|
||||||
}
|
|
||||||
if (node->type()==LimeReport::DataNode::Variable){
|
|
||||||
m_teContent->insertPlainText(QString("$V{%1}").arg(node->name()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextItemEditor::on_twScriptEngine_doubleClicked(const QModelIndex &index)
|
|
||||||
{
|
|
||||||
if (!index.isValid()) return;
|
|
||||||
LimeReport::ScriptEngineNode* node = static_cast<LimeReport::ScriptEngineNode*>(index.internalPointer());
|
|
||||||
if (node->type()==LimeReport::ScriptEngineNode::Function){
|
|
||||||
m_teContent->insertPlainText(node->name()+"()");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextItemEditor::on_splitter_splitterMoved(int , int )
|
|
||||||
{
|
|
||||||
#ifdef unix
|
|
||||||
writeSetting();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextItemEditor::on_editorFont_currentFontChanged(const QFont &f)
|
void TextItemEditor::on_editorFont_currentFontChanged(const QFont &f)
|
||||||
{
|
{
|
||||||
if (m_isReadingSetting) return;
|
if (m_isReadingSetting) return;
|
||||||
QFont tmp = f;
|
QFont tmp = f;
|
||||||
tmp.setPointSize(ui->editorFontSize->value());
|
tmp.setPointSize(ui->editorFontSize->value());
|
||||||
ui->textEdit->setFont(tmp);
|
ui->codeEditor->setEditorFont(tmp);
|
||||||
settings()->beginGroup("TextItemEditor");
|
settings()->beginGroup("TextItemEditor");
|
||||||
settings()->setValue("FontName",ui->textEdit->font().family());
|
settings()->setValue("FontName",ui->codeEditor->editorFont().family());
|
||||||
settings()->setValue("FontSize",ui->editorFontSize->value());
|
settings()->setValue("FontSize",ui->editorFontSize->value());
|
||||||
settings()->endGroup();
|
settings()->endGroup();
|
||||||
}
|
}
|
||||||
@ -368,9 +190,9 @@ void TextItemEditor::on_editorFont_currentFontChanged(const QFont &f)
|
|||||||
void TextItemEditor::on_editorFontSize_valueChanged(int arg1)
|
void TextItemEditor::on_editorFontSize_valueChanged(int arg1)
|
||||||
{
|
{
|
||||||
if (m_isReadingSetting) return;
|
if (m_isReadingSetting) return;
|
||||||
ui->textEdit->setFont(QFont(ui->textEdit->font().family(),arg1));
|
ui->codeEditor->setEditorFont(QFont(ui->codeEditor->editorFont().family(),arg1));
|
||||||
settings()->beginGroup("TextItemEditor");
|
settings()->beginGroup("TextItemEditor");
|
||||||
settings()->setValue("FontName",ui->textEdit->font().family());
|
settings()->setValue("FontName",ui->codeEditor->editorFont().family());
|
||||||
settings()->setValue("FontSize",ui->editorFontSize->value());
|
settings()->setValue("FontSize",ui->editorFontSize->value());
|
||||||
settings()->endGroup();
|
settings()->endGroup();
|
||||||
}
|
}
|
||||||
@ -380,21 +202,9 @@ void TextItemEditor::on_toolButton_clicked(bool checked)
|
|||||||
ui->gbSettings->setVisible(checked);
|
ui->gbSettings->setVisible(checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextItemEditor::slotSplitterMoved(int, int)
|
||||||
void TextItemEditor::on_twScriptEngine_activated(const QModelIndex &index)
|
|
||||||
{
|
{
|
||||||
LimeReport::ScriptEngineNode* node = static_cast<LimeReport::ScriptEngineNode*>(index.internalPointer());
|
writeSetting();
|
||||||
if (node->type()==LimeReport::ScriptEngineNode::Function){
|
|
||||||
ui->lblDescription->setText(node->name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextItemEditor::slotScriptItemsSelectionChanged(const QModelIndex &to, const QModelIndex)
|
|
||||||
{
|
|
||||||
LimeReport::ScriptEngineNode* node = static_cast<LimeReport::ScriptEngineNode*>(to.internalPointer());
|
|
||||||
if (node->type()==LimeReport::ScriptEngineNode::Function){
|
|
||||||
ui->lblDescription->setText(node->description());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BandDesignIntf *TextItemEditor::findParentBand()
|
BandDesignIntf *TextItemEditor::findParentBand()
|
||||||
|
@ -43,23 +43,23 @@ namespace Ui {
|
|||||||
class TextItemEditor;
|
class TextItemEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
class CompleaterTextEditor :public QTextEdit
|
//class CompleaterTextEditor :public QTextEdit
|
||||||
{
|
//{
|
||||||
Q_OBJECT
|
// Q_OBJECT
|
||||||
public:
|
//public:
|
||||||
CompleaterTextEditor(QWidget* parent=0);
|
// CompleaterTextEditor(QWidget* parent=0);
|
||||||
void setCompleter(QCompleter* value);
|
// void setCompleter(QCompleter* value);
|
||||||
QCompleter* compleater() const{ return m_compleater;}
|
// QCompleter* compleater() const{ return m_compleater;}
|
||||||
protected:
|
//protected:
|
||||||
virtual void keyPressEvent(QKeyEvent *e);
|
// virtual void keyPressEvent(QKeyEvent *e);
|
||||||
virtual void focusInEvent(QFocusEvent *e);
|
// virtual void focusInEvent(QFocusEvent *e);
|
||||||
private:
|
//private:
|
||||||
QString textUnderCursor() const;
|
// QString textUnderCursor() const;
|
||||||
private slots:
|
//private slots:
|
||||||
void insertCompletion(const QString& completion);
|
// void insertCompletion(const QString& completion);
|
||||||
private:
|
//private:
|
||||||
QCompleter* m_compleater;
|
// QCompleter* m_compleater;
|
||||||
};
|
//};
|
||||||
|
|
||||||
class TextItemEditor : public QWidget
|
class TextItemEditor : public QWidget
|
||||||
{
|
{
|
||||||
@ -73,33 +73,23 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *);
|
void resizeEvent(QResizeEvent *);
|
||||||
void moveEvent(QMoveEvent *);
|
void moveEvent(QMoveEvent *);
|
||||||
|
void closeEvent(QCloseEvent *event);
|
||||||
BandDesignIntf* findParentBand();
|
BandDesignIntf* findParentBand();
|
||||||
private slots:
|
private slots:
|
||||||
void on_pbOk_clicked();
|
void on_pbOk_clicked();
|
||||||
void on_pbCancel_clicked();
|
void on_pbCancel_clicked();
|
||||||
void slotFieldSelected();
|
|
||||||
void on_twData_doubleClicked(const QModelIndex &index);
|
|
||||||
void on_twScriptEngine_doubleClicked(const QModelIndex &index);
|
|
||||||
void on_splitter_splitterMoved(int, int);
|
|
||||||
void on_editorFont_currentFontChanged(const QFont &f);
|
void on_editorFont_currentFontChanged(const QFont &f);
|
||||||
void on_editorFontSize_valueChanged(int arg1);
|
void on_editorFontSize_valueChanged(int arg1);
|
||||||
void on_toolButton_clicked(bool checked);
|
void on_toolButton_clicked(bool checked);
|
||||||
void on_twScriptEngine_activated(const QModelIndex &index);
|
void slotSplitterMoved(int, int);
|
||||||
void slotScriptItemsSelectionChanged(const QModelIndex &to, const QModelIndex);
|
|
||||||
private:
|
private:
|
||||||
void initUI();
|
void initUI();
|
||||||
void readSetting();
|
void readSetting();
|
||||||
void writeSetting();
|
void writeSetting();
|
||||||
QStringListModel* getDataSources();
|
|
||||||
QStringListModel* getPrefixes();
|
|
||||||
QStringListModel* getColumns(QString datasource);
|
|
||||||
private:
|
private:
|
||||||
Ui::TextItemEditor *ui;
|
Ui::TextItemEditor *ui;
|
||||||
LimeReport::TextItem* m_textItem;
|
LimeReport::TextItem* m_textItem;
|
||||||
LimeReport::PageDesignIntf* m_page;
|
LimeReport::PageDesignIntf* m_page;
|
||||||
QMenu* m_datasourcesMenu;
|
|
||||||
CompleaterTextEditor* m_teContent;
|
|
||||||
QCompleter* m_completer;
|
|
||||||
QSettings* m_settings;
|
QSettings* m_settings;
|
||||||
bool m_ownedSettings;
|
bool m_ownedSettings;
|
||||||
bool m_isReadingSetting;
|
bool m_isReadingSetting;
|
||||||
|
@ -9,15 +9,15 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>539</width>
|
<width>457</width>
|
||||||
<height>436</height>
|
<height>366</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Text Item Editor</string>
|
<string>Text Item Editor</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowIcon">
|
<property name="windowIcon">
|
||||||
<iconset resource="items.qrc">
|
<iconset>
|
||||||
<normaloff>:/items/images/insert-text_3.png</normaloff>:/items/images/insert-text_3.png</iconset>
|
<normaloff>:/items/images/insert-text_3.png</normaloff>:/items/images/insert-text_3.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
@ -33,9 +33,6 @@
|
|||||||
<string>Content</string>
|
<string>Content</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<property name="spacing">
|
|
||||||
<number>2</number>
|
|
||||||
</property>
|
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>2</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
@ -49,84 +46,13 @@
|
|||||||
<number>2</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSplitter" name="splitter">
|
<widget class="LimeReport::ScriptEditor" name="codeEditor" native="true">
|
||||||
<property name="sizePolicy">
|
<property name="minimumSize">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
<size>
|
||||||
<horstretch>0</horstretch>
|
<width>0</width>
|
||||||
<verstretch>0</verstretch>
|
<height>0</height>
|
||||||
</sizepolicy>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<widget class="CompleaterTextEditor" name="textEdit">
|
|
||||||
<property name="font">
|
|
||||||
<font>
|
|
||||||
<pointsize>12</pointsize>
|
|
||||||
</font>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QTabWidget" name="tabWidget">
|
|
||||||
<property name="tabPosition">
|
|
||||||
<enum>QTabWidget::South</enum>
|
|
||||||
</property>
|
|
||||||
<property name="currentIndex">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<widget class="QWidget" name="tab">
|
|
||||||
<attribute name="title">
|
|
||||||
<string>Data</string>
|
|
||||||
</attribute>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
|
||||||
<property name="spacing">
|
|
||||||
<number>3</number>
|
|
||||||
</property>
|
|
||||||
<property name="leftMargin">
|
|
||||||
<number>3</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>3</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>3</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>3</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<widget class="QTreeView" name="twData">
|
|
||||||
<attribute name="headerVisible">
|
|
||||||
<bool>false</bool>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<widget class="QWidget" name="tab_2">
|
|
||||||
<attribute name="title">
|
|
||||||
<string>Functions</string>
|
|
||||||
</attribute>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
|
||||||
<item>
|
|
||||||
<widget class="QSplitter" name="splitter_2">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<widget class="QTreeView" name="twScriptEngine">
|
|
||||||
<attribute name="headerVisible">
|
|
||||||
<bool>false</bool>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
|
||||||
<widget class="QLabel" name="lblDescription">
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@ -183,7 +109,7 @@
|
|||||||
<string>...</string>
|
<string>...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="items.qrc">
|
<iconset>
|
||||||
<normaloff>:/items/images/settings.png</normaloff>:/items/images/settings.png</iconset>
|
<normaloff>:/items/images/settings.png</normaloff>:/items/images/settings.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="checkable">
|
<property name="checkable">
|
||||||
@ -233,17 +159,16 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>CompleaterTextEditor</class>
|
<class>LimeReport::ScriptEditor</class>
|
||||||
<extends>QTextEdit</extends>
|
<extends>QWidget</extends>
|
||||||
<header>lrtextitemeditor.h</header>
|
<header>lrscripteditor.h</header>
|
||||||
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>pbOk</tabstop>
|
<tabstop>pbOk</tabstop>
|
||||||
<tabstop>pbCancel</tabstop>
|
<tabstop>pbCancel</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources>
|
<resources/>
|
||||||
<include location="items.qrc"/>
|
|
||||||
</resources>
|
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -11,12 +11,13 @@ namespace LimeReport{
|
|||||||
|
|
||||||
ScriptEditor::ScriptEditor(QWidget *parent) :
|
ScriptEditor::ScriptEditor(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::ScriptEditor)
|
ui(new Ui::ScriptEditor), m_reportEngine(0), m_page(0)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setFocusProxy(ui->textEdit);
|
setFocusProxy(ui->textEdit);
|
||||||
m_completer = new QCompleter(this);
|
m_completer = new QCompleter(this);
|
||||||
ui->textEdit->setCompleter(m_completer);
|
ui->textEdit->setCompleter(m_completer);
|
||||||
|
connect(ui->splitter, SIGNAL(splitterMoved(int,int)), this, SIGNAL(splitterMoved(int,int)));
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptEditor::~ScriptEditor()
|
ScriptEditor::~ScriptEditor()
|
||||||
@ -42,10 +43,50 @@ void ScriptEditor::setReportEngine(ReportEnginePrivate* reportEngine)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptEditor::setReportPage(PageDesignIntf* page)
|
||||||
|
{
|
||||||
|
m_page = page;
|
||||||
|
DataSourceManager* dm = page->datasourceManager();
|
||||||
|
ScriptEngineManager& se = LimeReport::ScriptEngineManager::instance();
|
||||||
|
se.setDataManager(dm);
|
||||||
|
|
||||||
|
initCompleter();
|
||||||
|
|
||||||
|
if (dm){
|
||||||
|
if (dm->isNeedUpdateDatasourceModel())
|
||||||
|
dm->updateDatasourceModel();
|
||||||
|
ui->twData->setModel(dm->datasourcesModel());
|
||||||
|
ui->twScriptEngine->setModel(se.model());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptEditor::setPageBand(BandDesignIntf* band)
|
||||||
|
{
|
||||||
|
if (band && ui->twData->model() && !band->datasourceName().isEmpty()){
|
||||||
|
QModelIndexList nodes = ui->twData->model()->match(
|
||||||
|
ui->twData->model()->index(0,0),
|
||||||
|
Qt::DisplayRole,
|
||||||
|
band->datasourceName(),
|
||||||
|
2,
|
||||||
|
Qt::MatchRecursive
|
||||||
|
);
|
||||||
|
if (!nodes.isEmpty()){
|
||||||
|
ui->twData->expand(nodes.at(0).parent());
|
||||||
|
ui->twData->expand(nodes.at(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptEditor::initCompleter()
|
void ScriptEditor::initCompleter()
|
||||||
{
|
{
|
||||||
QStringList dataWords;
|
QStringList dataWords;
|
||||||
DataSourceManager* dm = m_reportEngine->dataManager();
|
|
||||||
|
DataSourceManager* dm = 0;
|
||||||
|
if (m_reportEngine)
|
||||||
|
dm = m_reportEngine->dataManager();
|
||||||
|
if (m_page)
|
||||||
|
dm = m_page->datasourceManager();
|
||||||
|
|
||||||
ScriptEngineManager& se = LimeReport::ScriptEngineManager::instance();
|
ScriptEngineManager& se = LimeReport::ScriptEngineManager::instance();
|
||||||
|
|
||||||
QJSValue globalObject = se.scriptEngine()->globalObject();
|
QJSValue globalObject = se.scriptEngine()->globalObject();
|
||||||
@ -68,11 +109,13 @@ void ScriptEditor::initCompleter()
|
|||||||
dataWords << varName.remove("#");
|
dataWords << varName.remove("#");
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( int i = 0; i < m_reportEngine->pageCount(); ++i){
|
if (m_reportEngine){
|
||||||
PageDesignIntf* page = m_reportEngine->pageAt(i);
|
for ( int i = 0; i < m_reportEngine->pageCount(); ++i){
|
||||||
dataWords << page->pageItem()->objectName();
|
PageDesignIntf* page = m_reportEngine->pageAt(i);
|
||||||
foreach (BaseDesignIntf* item, page->pageItem()->childBaseItems()){
|
dataWords << page->pageItem()->objectName();
|
||||||
addItemToCompleater(page->pageItem()->objectName(), item, dataWords);
|
foreach (BaseDesignIntf* item, page->pageItem()->childBaseItems()){
|
||||||
|
addItemToCompleater(page->pageItem()->objectName(), item, dataWords);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,6 +137,16 @@ void ScriptEditor::setPlainText(const QString& text)
|
|||||||
ui->textEdit->setPlainText(text);
|
ui->textEdit->setPlainText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptEditor::setEditorFont(QFont font)
|
||||||
|
{
|
||||||
|
ui->textEdit->setFont(font);
|
||||||
|
}
|
||||||
|
|
||||||
|
QFont ScriptEditor::editorFont()
|
||||||
|
{
|
||||||
|
return ui->textEdit->font();
|
||||||
|
}
|
||||||
|
|
||||||
QString ScriptEditor::toPlainText()
|
QString ScriptEditor::toPlainText()
|
||||||
{
|
{
|
||||||
return ui->textEdit->toPlainText();
|
return ui->textEdit->toPlainText();
|
||||||
|
@ -11,6 +11,8 @@ namespace LimeReport{
|
|||||||
|
|
||||||
class ReportEnginePrivate;
|
class ReportEnginePrivate;
|
||||||
class BaseDesignIntf;
|
class BaseDesignIntf;
|
||||||
|
class PageDesignIntf;
|
||||||
|
class BandDesignIntf;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ScriptEditor;
|
class ScriptEditor;
|
||||||
@ -23,21 +25,26 @@ public:
|
|||||||
explicit ScriptEditor(QWidget *parent = 0);
|
explicit ScriptEditor(QWidget *parent = 0);
|
||||||
~ScriptEditor();
|
~ScriptEditor();
|
||||||
void setReportEngine(ReportEnginePrivate* reportEngine);
|
void setReportEngine(ReportEnginePrivate* reportEngine);
|
||||||
|
void setReportPage(PageDesignIntf* page);
|
||||||
|
void setPageBand(BandDesignIntf* band);
|
||||||
void initCompleter();
|
void initCompleter();
|
||||||
QByteArray saveState();
|
QByteArray saveState();
|
||||||
void restoreState(QByteArray state);
|
void restoreState(QByteArray state);
|
||||||
void setPlainText(const QString &text);
|
void setPlainText(const QString &text);
|
||||||
|
void setEditorFont(QFont font);
|
||||||
|
QFont editorFont();
|
||||||
QString toPlainText();
|
QString toPlainText();
|
||||||
|
signals:
|
||||||
|
void splitterMoved(int, int);
|
||||||
private slots:
|
private slots:
|
||||||
void on_twData_doubleClicked(const QModelIndex &index);
|
void on_twData_doubleClicked(const QModelIndex &index);
|
||||||
|
|
||||||
void on_twScriptEngine_doubleClicked(const QModelIndex &index);
|
void on_twScriptEngine_doubleClicked(const QModelIndex &index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addItemToCompleater(const QString& pageName, BaseDesignIntf* item, QStringList& dataWords);
|
void addItemToCompleater(const QString& pageName, BaseDesignIntf* item, QStringList& dataWords);
|
||||||
private:
|
private:
|
||||||
Ui::ScriptEditor *ui;
|
Ui::ScriptEditor *ui;
|
||||||
ReportEnginePrivate* m_reportEngine;
|
ReportEnginePrivate* m_reportEngine;
|
||||||
|
PageDesignIntf* m_page;
|
||||||
QCompleter* m_completer;
|
QCompleter* m_completer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user