From 47643349404d6a6d2f3b8b97462a89b0959961b2 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Wed, 20 Sep 2017 00:51:17 +0300 Subject: [PATCH] Script editor has been finishes --- limereport/lrreportdesignwidget.cpp | 21 ++- limereport/lrreportdesignwidget.h | 3 +- limereport/lrreportdesignwindow.cpp | 76 ++++++---- limereport/lrreportdesignwindow.h | 1 + limereport/scripteditor/lrscripteditor.cpp | 48 ++++++ limereport/scripteditor/lrscripteditor.h | 9 ++ limereport/scripteditor/lrscripteditor.ui | 162 +++++++++------------ 7 files changed, 191 insertions(+), 129 deletions(-) diff --git a/limereport/lrreportdesignwidget.cpp b/limereport/lrreportdesignwidget.cpp index 2b7f160..0145940 100644 --- a/limereport/lrreportdesignwidget.cpp +++ b/limereport/lrreportdesignwidget.cpp @@ -184,6 +184,7 @@ void ReportDesignWidget::saveState(QSettings* settings) settings->setValue("vGridStep",m_verticalGridStep); settings->setValue("defaultFont",m_defaultFont); settings->setValue("useGrid",m_useGrid); + settings->setValue("ScriptEditorState", m_scriptEditor->saveState()); settings->endGroup(); } @@ -216,6 +217,12 @@ void ReportDesignWidget::loadState(QSettings* settings) if (v.isValid()){ m_useGrid = v.toBool(); } + + v = settings->value("ScriptEditorState"); + if (v.isValid()){ + m_scriptEditor->restoreState(v.toByteArray()); + } + settings->endGroup(); applySettings(); } @@ -242,17 +249,12 @@ void ReportDesignWidget::createTabs(){ this, SLOT(slotPagePropertyObjectNameChanged(QString,QString))); } - m_scriptEditor = new QTextEdit(this); + m_scriptEditor = new ScriptEditor(this); + m_scriptEditor->setReportEngine(m_report); pageIndex = m_tabWidget->addTab(m_scriptEditor,QIcon(),tr("Script")); m_tabWidget->setTabWhatsThis(pageIndex,"script"); m_tabWidget->setCurrentIndex(0); - m_newScriptEditor = new ScriptEditor(this); - m_newScriptEditor->setReportEngine(m_report); - pageIndex = m_tabWidget->addTab(m_newScriptEditor,QIcon(),tr("New Script Editor")); - m_tabWidget->setTabWhatsThis(pageIndex,"script"); - m_tabWidget->setCurrentIndex(0); - #ifdef HAVE_QTDESIGNER_INTEGRATION QWidget* dialogDesigner; foreach(DialogDescriber::Ptr dialogDesc, m_report->scriptContext()->dialogDescribers()){ @@ -442,9 +444,11 @@ bool ReportDesignWidget::save() bool ReportDesignWidget::loadFromFile(const QString &fileName) { if (m_report->loadFromFile(fileName,false)){ + QByteArray editorState = m_scriptEditor->saveState(); createTabs(); //connectPage(m_report->pageAt(0)); m_scriptEditor->setPlainText(m_report->scriptContext()->initScript()); + m_scriptEditor->restoreState(editorState); emit loaded(); m_dialogChanged = false; return true; @@ -796,7 +800,8 @@ void ReportDesignWidget::slotCurrentTabChanged(int index) } if (activeTabType() == Script){ - m_newScriptEditor->initCompleter(); + m_scriptEditor->initCompleter(); + m_scriptEditor->setFocus(); } emit activePageChanged(); diff --git a/limereport/lrreportdesignwidget.h b/limereport/lrreportdesignwidget.h index d710537..b7e38b7 100644 --- a/limereport/lrreportdesignwidget.h +++ b/limereport/lrreportdesignwidget.h @@ -191,8 +191,7 @@ private: private: ReportEnginePrivate* m_report; QGraphicsView *m_view; - QTextEdit* m_scriptEditor; - ScriptEditor* m_newScriptEditor; + ScriptEditor* m_scriptEditor; TranslationEditor* m_traslationEditor; #ifdef HAVE_QTDESIGNER_INTEGRATION DialogDesignerManager* m_dialogDesignerManager; diff --git a/limereport/lrreportdesignwindow.cpp b/limereport/lrreportdesignwindow.cpp index 0bdae75..1ad41c7 100644 --- a/limereport/lrreportdesignwindow.cpp +++ b/limereport/lrreportdesignwindow.cpp @@ -664,14 +664,21 @@ void ReportDesignWindow::writeState() { settings()->beginGroup("DesignerWindow"); switch (m_editorTabType) { - case ReportDesignWidget::Page: - settings()->setValue("PageEditorsState", saveState()); - settings()->setValue("DialogEditorsState", m_dialogEditorsState); - break; - default: - settings()->setValue("DialogEditorsState", saveState()); - settings()->setValue("PageEditorsState", m_pageEditorsState); - break; + case ReportDesignWidget::Page: + settings()->setValue("PageEditorsState", saveState()); + settings()->setValue("DialogEditorsState", m_dialogEditorsState); + settings()->setValue("ScriptEditorsState", m_scriptEditorState); + break; + case ReportDesignWidget::Script: + settings()->setValue("ScriptEditorsState", saveState()); + settings()->setValue("DialogEditorsState", m_dialogEditorsState); + settings()->setValue("PageEditorsState", m_pageEditorsState); + break; + default: + settings()->setValue("DialogEditorsState", saveState()); + settings()->setValue("PageEditorsState", m_pageEditorsState); + settings()->setValue("ScriptEditorsState", m_scriptEditorState); + break; } settings()->setValue("InspectorFirsColumnWidth",m_objectInspector->columnWidth(0)); settings()->endGroup(); @@ -775,6 +782,10 @@ void ReportDesignWindow::restoreSetting() if (v.isValid()){ m_dialogEditorsState = v.toByteArray(); } + v = settings()->value("ScriptEditorsState"); + if (v.isValid()){ + m_scriptEditorState = v.toByteArray(); + } v = settings()->value("InspectorFirsColumnWidth"); if (v.isValid()){ m_objectInspector->setColumnWidth(0,v.toInt()); @@ -1277,12 +1288,15 @@ void ReportDesignWindow::slotActivePageChanged() updateAvaibleBands(); switch (m_editorTabType) { - case ReportDesignWidget::Dialog: - m_dialogEditorsState = saveState(); + case ReportDesignWidget::Dialog: + m_dialogEditorsState = saveState(); #ifdef HAVE_UI_LOADER - m_scriptBrowser->updateDialogsTree(); + m_scriptBrowser->updateDialogsTree(); #endif - break; + break; + case ReportDesignWidget::Script: + m_scriptEditorState = saveState(); + break; default: m_pageEditorsState = saveState(); break; @@ -1291,20 +1305,30 @@ void ReportDesignWindow::slotActivePageChanged() m_editorTabType = m_reportDesignWidget->activeTabType(); switch (m_editorTabType) { - case ReportDesignWidget::Dialog: - if (!m_dialogEditorsState.isEmpty()) - restoreState(m_dialogEditorsState); - else - showDefaultEditors(); - showDefaultToolBars(); - break; - default: - if (!m_pageEditors.isEmpty()) - restoreState(m_pageEditorsState); - else - showDefaultEditors(); - showDefaultToolBars(); - break; + case ReportDesignWidget::Dialog: + if (!m_dialogEditorsState.isEmpty()){ + restoreState(m_dialogEditorsState); + } else { + showDefaultEditors(); + showDefaultToolBars(); + } + break; + case ReportDesignWidget::Script: + if (!m_scriptEditorState.isEmpty()){ + restoreState(m_scriptEditorState); + } else { + showDefaultEditors(); + showDefaultToolBars(); + } + break; + default: + if (!m_pageEditors.isEmpty()){ + restoreState(m_pageEditorsState); + } else { + showDefaultEditors(); + showDefaultToolBars(); + } + break; } } diff --git a/limereport/lrreportdesignwindow.h b/limereport/lrreportdesignwindow.h index 94c4bd5..1779ed3 100644 --- a/limereport/lrreportdesignwindow.h +++ b/limereport/lrreportdesignwindow.h @@ -264,6 +264,7 @@ private: ReportDesignWidget::EditorTabType m_editorTabType; QByteArray m_pageEditorsState; QByteArray m_dialogEditorsState; + QByteArray m_scriptEditorState; QVector m_pageTools; QVector m_dialogTools; diff --git a/limereport/scripteditor/lrscripteditor.cpp b/limereport/scripteditor/lrscripteditor.cpp index 613926e..461a8f9 100644 --- a/limereport/scripteditor/lrscripteditor.cpp +++ b/limereport/scripteditor/lrscripteditor.cpp @@ -14,6 +14,7 @@ ScriptEditor::ScriptEditor(QWidget *parent) : ui(new Ui::ScriptEditor) { ui->setupUi(this); + setFocusProxy(ui->textEdit); m_completer = new QCompleter(this); ui->textEdit->setCompleter(m_completer); } @@ -78,6 +79,26 @@ void ScriptEditor::initCompleter() m_completer->setModel(new QStringListModel(dataWords,m_completer)); } +QByteArray ScriptEditor::saveState() +{ + return ui->splitter->saveState(); +} + +void ScriptEditor::restoreState(QByteArray state) +{ + ui->splitter->restoreState(state); +} + +void ScriptEditor::setPlainText(const QString& text) +{ + ui->textEdit->setPlainText(text); +} + +QString ScriptEditor::toPlainText() +{ + return ui->textEdit->toPlainText(); +} + void ScriptEditor::addItemToCompleater(const QString& pageName, BaseDesignIntf* item, QStringList& dataWords) { BandDesignIntf* band = dynamic_cast(item); @@ -99,4 +120,31 @@ void ScriptEditor::addItemToCompleater(const QString& pageName, BaseDesignIntf* } } +void ScriptEditor::on_twData_doubleClicked(const QModelIndex &index) +{ + if (!index.isValid()) return; + LimeReport::DataNode* node = static_cast(index.internalPointer()); + if (node->type()==LimeReport::DataNode::Field){ + ui->textEdit->insertPlainText(QString("$D{%1.%2}").arg(node->parent()->name()).arg(node->name())); + } + if (node->type()==LimeReport::DataNode::Variable){ + ui->textEdit->insertPlainText(QString("$V{%1}").arg(node->name())); + } + ui->textEdit->setFocus(); +} + +void ScriptEditor::on_twScriptEngine_doubleClicked(const QModelIndex &index) +{ + if (!index.isValid()) return; + LimeReport::ScriptEngineNode* node = static_cast(index.internalPointer()); + if (node->type()==LimeReport::ScriptEngineNode::Function){ + ui->textEdit->insertPlainText(node->name()+"()"); + } + ui->textEdit->setFocus(); +} + } // namespace LimeReport + + + + diff --git a/limereport/scripteditor/lrscripteditor.h b/limereport/scripteditor/lrscripteditor.h index 6943fcb..eedb66d 100644 --- a/limereport/scripteditor/lrscripteditor.h +++ b/limereport/scripteditor/lrscripteditor.h @@ -24,6 +24,15 @@ public: ~ScriptEditor(); void setReportEngine(ReportEnginePrivate* reportEngine); void initCompleter(); + QByteArray saveState(); + void restoreState(QByteArray state); + void setPlainText(const QString &text); + QString toPlainText(); +private slots: + void on_twData_doubleClicked(const QModelIndex &index); + + void on_twScriptEngine_doubleClicked(const QModelIndex &index); + private: void addItemToCompleater(const QString& pageName, BaseDesignIntf* item, QStringList& dataWords); private: diff --git a/limereport/scripteditor/lrscripteditor.ui b/limereport/scripteditor/lrscripteditor.ui index 49fcfb6..27f8e7f 100644 --- a/limereport/scripteditor/lrscripteditor.ui +++ b/limereport/scripteditor/lrscripteditor.ui @@ -13,116 +13,92 @@ Form - + - + 0 0 - - Content + + Qt::Horizontal - - - 2 + + + + 0 + 0 + - - 2 + + + 12 + - - 2 + + + + QTabWidget::South - - 2 + + 0 - - 2 - - - - - - 0 - 0 - + + + Data + + + + 3 - - Qt::Horizontal + + 3 - - - - 12 - - - - - - QTabWidget::South - - - 0 - - - - Data + + 3 + + + 3 + + + 3 + + + + + false - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - false - - - - - - - Functions - - - - - - Qt::Vertical - - - - false - - - - - - - - - - + + + + + + Functions + + + + + + Qt::Vertical + + + + false + + + + + + + - - - - + + + +