diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index 046cd3e..6dd6518 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -214,7 +214,7 @@ public: ReportSettings *reportSettings() const; void setReportSettings(ReportSettings *reportSettings); - bool isHasChanges(){ return m_hasChanges; } + bool hasChanges(){ return m_hasChanges; } void dropChanges(){ m_hasChanges = false; } signals: void loadCollectionFinished(const QString& collectionName); diff --git a/limereport/lrreportdesignwidget.cpp b/limereport/lrreportdesignwidget.cpp index 750ae0a..f13ed02 100644 --- a/limereport/lrreportdesignwidget.cpp +++ b/limereport/lrreportdesignwidget.cpp @@ -284,6 +284,7 @@ void ReportDesignWidget::createTabs(){ } m_scriptEditor = new ScriptEditor(this); + connect(m_scriptEditor, SIGNAL(textChanged()), this, SLOT(slotScriptTextChanged())); m_scriptEditor->setReportEngine(m_report); pageIndex = m_tabWidget->addTab(m_scriptEditor,QIcon(),tr("Script")); m_tabWidget->setTabWhatsThis(pageIndex,"script"); @@ -882,6 +883,11 @@ void ReportDesignWidget::slotReportLoaded() m_dialogChanged = false; } +void ReportDesignWidget::slotScriptTextChanged() +{ + m_report->scriptContext()->setInitScript(m_scriptEditor->toPlainText()); +} + #ifdef HAVE_QTDESIGNER_INTEGRATION void ReportDesignWidget::addNewDialog() diff --git a/limereport/lrreportdesignwidget.h b/limereport/lrreportdesignwidget.h index 0352158..f1b092c 100644 --- a/limereport/lrreportdesignwidget.h +++ b/limereport/lrreportdesignwidget.h @@ -173,6 +173,7 @@ private slots: void slotSceneRectChanged(QRectF); void slotCurrentTabChanged(int index); void slotReportLoaded(); + void slotScriptTextChanged(); #ifdef HAVE_QTDESIGNER_INTEGRATION void slotDialogChanged(QString); void slotDialogNameChanged(QString oldName, QString newName); diff --git a/limereport/lrreportdesignwindow.cpp b/limereport/lrreportdesignwindow.cpp index 685ac93..3aa1660 100644 --- a/limereport/lrreportdesignwindow.cpp +++ b/limereport/lrreportdesignwindow.cpp @@ -662,6 +662,8 @@ void ReportDesignWindow::startNewReport() m_editorTabType = ReportDesignWidget::Page; showDefaultToolBars(); m_reportDesignWidget->report()->dataManager()->dropChanges(); + m_reportDesignWidget->report()->scriptContext()->dropChanges(); + } void ReportDesignWindow::writePosition() diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 330d757..6c62d4a 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -717,7 +717,7 @@ bool ReportEnginePrivate::slotLoadFromFile(const QString &fileName) EASY_BLOCK("Connect auto connections") dataManager()->connectAutoConnections(); EASY_END_BLOCK; - dataManager()->dropChanges(); + dropChanges(); if ( hasActivePreview() ) { @@ -881,7 +881,7 @@ bool ReportEnginePrivate::saveToFile(const QString &fileName) page->setToSaved(); } } - m_datasources->dropChanges(); + dropChanges(); return saved; } @@ -896,7 +896,7 @@ QByteArray ReportEnginePrivate::saveToByteArray() page->setToSaved(); } } - m_datasources->dropChanges(); + dropChanges(); return result; } @@ -910,7 +910,7 @@ QString ReportEnginePrivate::saveToString(){ page->setToSaved(); } } - m_datasources->dropChanges(); + dropChanges(); return result; } @@ -919,9 +919,11 @@ bool ReportEnginePrivate::isNeedToSave() foreach(PageDesignIntf* page, m_pages){ if (page->isHasChanges()) return true; } - if (dataManager()->isHasChanges()){ + if (dataManager()->hasChanges()){ return true; } + if (scriptContext()->hasChanges()) + return true; return false; } diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index 9580cb6..461fd69 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -249,6 +249,7 @@ private: PageItemDesignIntf *createRenderingPage(PageItemDesignIntf *page); void initReport(); void paintByExternalPainter(const QString& objectName, QPainter* painter, const QStyleOptionGraphicsItem* options); + void dropChanges(){ m_datasources->dropChanges(); m_scriptEngineContext->dropChanges();} private: QList m_pages; QList m_renderingPages; diff --git a/limereport/lrscriptenginemanager.cpp b/limereport/lrscriptenginemanager.cpp index 4fe90e3..d69f3af 100644 --- a/limereport/lrscriptenginemanager.cpp +++ b/limereport/lrscriptenginemanager.cpp @@ -1390,7 +1390,10 @@ QString ScriptEngineContext::initScript() const void ScriptEngineContext::setInitScript(const QString& initScript) { - m_initScript = initScript; + if (m_initScript != initScript){ + m_initScript = initScript; + m_hasChanges = true; + } } DialogDescriber::Ptr DialogDescriber::create(const QString& name, const QByteArray& desc) { @@ -1884,7 +1887,7 @@ void TableBuilder::buildTable(const QString& datasourceName) fillInRowData(addRow()); m_dataManager->dataSource(datasourceName)->next(); } - m_horizontalLayout->setVisible(false); + m_horizontalLayout->setHeight(0); } void TableBuilder::checkBaseLayout() diff --git a/limereport/lrscriptenginemanager.h b/limereport/lrscriptenginemanager.h index b9a06c9..3e8db0c 100644 --- a/limereport/lrscriptenginemanager.h +++ b/limereport/lrscriptenginemanager.h @@ -174,7 +174,9 @@ public: #ifdef HAVE_UI_LOADER typedef QSharedPointer DialogPtr; #endif - explicit ScriptEngineContext(QObject* parent=0):QObject(parent), m_tableOfContents(new TableOfContents(this)){} + explicit ScriptEngineContext(QObject* parent=0): + QObject(parent), + m_tableOfContents(new TableOfContents(this)), m_hasChanges(false) {} #ifdef HAVE_UI_LOADER void addDialog(const QString& name, const QByteArray& description); bool changeDialog(const QString& name, const QByteArray &description); @@ -200,7 +202,8 @@ public: void setCurrentPage(PageItemDesignIntf* currentPage); TableOfContents* tableOfContents() const; void setTableOfContents(TableOfContents* tableOfContents); - + void dropChanges(){ m_hasChanges = false;} + bool hasChanges(){ return m_hasChanges;} #ifdef HAVE_UI_LOADER signals: void dialogNameChanged(QString dialogName); @@ -227,6 +230,7 @@ private: BandDesignIntf* m_currentBand; PageItemDesignIntf* m_currentPage; TableOfContents* m_tableOfContents; + bool m_hasChanges; }; class JSFunctionDesc{ diff --git a/limereport/scripteditor/lrcodeeditor.cpp b/limereport/scripteditor/lrcodeeditor.cpp index 97deeb5..308f376 100644 --- a/limereport/scripteditor/lrcodeeditor.cpp +++ b/limereport/scripteditor/lrcodeeditor.cpp @@ -282,8 +282,8 @@ void CodeEditor::insertCompletion(const QString &completion) return; QTextCursor tc = textCursor(); int extra = completion.length() - m_compleater->completionPrefix().length(); - tc.movePosition(QTextCursor::Left); - tc.movePosition(QTextCursor::EndOfWord); + //tc.movePosition(QTextCursor::Left); + //tc.movePosition(QTextCursor::EndOfWord); tc.insertText(completion.right(extra)); setTextCursor(tc); } diff --git a/limereport/scripteditor/lrscripteditor.cpp b/limereport/scripteditor/lrscripteditor.cpp index c5f8273..5f96a33 100644 --- a/limereport/scripteditor/lrscripteditor.cpp +++ b/limereport/scripteditor/lrscripteditor.cpp @@ -22,6 +22,7 @@ ScriptEditor::ScriptEditor(QWidget *parent) : ui->textEdit->setCompleter(m_completer); ui->textEdit->setTabStopWidth(ui->textEdit->fontMetrics().width("0")*m_tabIndention); connect(ui->splitter, SIGNAL(splitterMoved(int,int)), this, SIGNAL(splitterMoved(int,int))); + connect(ui->textEdit, SIGNAL(textChanged()), this, SIGNAL(textChanged())); } ScriptEditor::~ScriptEditor() @@ -361,3 +362,5 @@ void ReportStructureCompleater::addChildItem(BaseDesignIntf *item, const QString + + diff --git a/limereport/scripteditor/lrscripteditor.h b/limereport/scripteditor/lrscripteditor.h index 10a7ad1..10dcd5a 100644 --- a/limereport/scripteditor/lrscripteditor.h +++ b/limereport/scripteditor/lrscripteditor.h @@ -60,8 +60,11 @@ public: void setEditorFont(QFont font); QFont editorFont(); QString toPlainText(); + bool hasChanges() const; + void setHasChanges(bool hasChanges); signals: void splitterMoved(int, int); + void textChanged(); protected: void initEditor(DataSourceManager* dm); @@ -69,6 +72,7 @@ private slots: void on_twData_doubleClicked(const QModelIndex &index); void on_twScriptEngine_doubleClicked(const QModelIndex &index); void slotOnCurrentChanged(const QModelIndex& to, const QModelIndex&); + private: Ui::ScriptEditor *ui; ReportEnginePrivateInterface* m_reportEngine;