Script editor has been finishes

This commit is contained in:
Arin Alexander 2017-09-20 00:51:17 +03:00
parent 219b4ad678
commit 4764334940
7 changed files with 191 additions and 129 deletions

View File

@ -184,6 +184,7 @@ void ReportDesignWidget::saveState(QSettings* settings)
settings->setValue("vGridStep",m_verticalGridStep); settings->setValue("vGridStep",m_verticalGridStep);
settings->setValue("defaultFont",m_defaultFont); settings->setValue("defaultFont",m_defaultFont);
settings->setValue("useGrid",m_useGrid); settings->setValue("useGrid",m_useGrid);
settings->setValue("ScriptEditorState", m_scriptEditor->saveState());
settings->endGroup(); settings->endGroup();
} }
@ -216,6 +217,12 @@ void ReportDesignWidget::loadState(QSettings* settings)
if (v.isValid()){ if (v.isValid()){
m_useGrid = v.toBool(); m_useGrid = v.toBool();
} }
v = settings->value("ScriptEditorState");
if (v.isValid()){
m_scriptEditor->restoreState(v.toByteArray());
}
settings->endGroup(); settings->endGroup();
applySettings(); applySettings();
} }
@ -242,17 +249,12 @@ void ReportDesignWidget::createTabs(){
this, SLOT(slotPagePropertyObjectNameChanged(QString,QString))); 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")); pageIndex = m_tabWidget->addTab(m_scriptEditor,QIcon(),tr("Script"));
m_tabWidget->setTabWhatsThis(pageIndex,"script"); m_tabWidget->setTabWhatsThis(pageIndex,"script");
m_tabWidget->setCurrentIndex(0); 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 #ifdef HAVE_QTDESIGNER_INTEGRATION
QWidget* dialogDesigner; QWidget* dialogDesigner;
foreach(DialogDescriber::Ptr dialogDesc, m_report->scriptContext()->dialogDescribers()){ foreach(DialogDescriber::Ptr dialogDesc, m_report->scriptContext()->dialogDescribers()){
@ -442,9 +444,11 @@ bool ReportDesignWidget::save()
bool ReportDesignWidget::loadFromFile(const QString &fileName) bool ReportDesignWidget::loadFromFile(const QString &fileName)
{ {
if (m_report->loadFromFile(fileName,false)){ if (m_report->loadFromFile(fileName,false)){
QByteArray editorState = m_scriptEditor->saveState();
createTabs(); createTabs();
//connectPage(m_report->pageAt(0)); //connectPage(m_report->pageAt(0));
m_scriptEditor->setPlainText(m_report->scriptContext()->initScript()); m_scriptEditor->setPlainText(m_report->scriptContext()->initScript());
m_scriptEditor->restoreState(editorState);
emit loaded(); emit loaded();
m_dialogChanged = false; m_dialogChanged = false;
return true; return true;
@ -796,7 +800,8 @@ void ReportDesignWidget::slotCurrentTabChanged(int index)
} }
if (activeTabType() == Script){ if (activeTabType() == Script){
m_newScriptEditor->initCompleter(); m_scriptEditor->initCompleter();
m_scriptEditor->setFocus();
} }
emit activePageChanged(); emit activePageChanged();

View File

@ -191,8 +191,7 @@ private:
private: private:
ReportEnginePrivate* m_report; ReportEnginePrivate* m_report;
QGraphicsView *m_view; QGraphicsView *m_view;
QTextEdit* m_scriptEditor; ScriptEditor* m_scriptEditor;
ScriptEditor* m_newScriptEditor;
TranslationEditor* m_traslationEditor; TranslationEditor* m_traslationEditor;
#ifdef HAVE_QTDESIGNER_INTEGRATION #ifdef HAVE_QTDESIGNER_INTEGRATION
DialogDesignerManager* m_dialogDesignerManager; DialogDesignerManager* m_dialogDesignerManager;

View File

@ -664,14 +664,21 @@ void ReportDesignWindow::writeState()
{ {
settings()->beginGroup("DesignerWindow"); settings()->beginGroup("DesignerWindow");
switch (m_editorTabType) { switch (m_editorTabType) {
case ReportDesignWidget::Page: case ReportDesignWidget::Page:
settings()->setValue("PageEditorsState", saveState()); settings()->setValue("PageEditorsState", saveState());
settings()->setValue("DialogEditorsState", m_dialogEditorsState); settings()->setValue("DialogEditorsState", m_dialogEditorsState);
break; settings()->setValue("ScriptEditorsState", m_scriptEditorState);
default: break;
settings()->setValue("DialogEditorsState", saveState()); case ReportDesignWidget::Script:
settings()->setValue("PageEditorsState", m_pageEditorsState); settings()->setValue("ScriptEditorsState", saveState());
break; 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()->setValue("InspectorFirsColumnWidth",m_objectInspector->columnWidth(0));
settings()->endGroup(); settings()->endGroup();
@ -775,6 +782,10 @@ void ReportDesignWindow::restoreSetting()
if (v.isValid()){ if (v.isValid()){
m_dialogEditorsState = v.toByteArray(); m_dialogEditorsState = v.toByteArray();
} }
v = settings()->value("ScriptEditorsState");
if (v.isValid()){
m_scriptEditorState = v.toByteArray();
}
v = settings()->value("InspectorFirsColumnWidth"); v = settings()->value("InspectorFirsColumnWidth");
if (v.isValid()){ if (v.isValid()){
m_objectInspector->setColumnWidth(0,v.toInt()); m_objectInspector->setColumnWidth(0,v.toInt());
@ -1277,12 +1288,15 @@ void ReportDesignWindow::slotActivePageChanged()
updateAvaibleBands(); updateAvaibleBands();
switch (m_editorTabType) { switch (m_editorTabType) {
case ReportDesignWidget::Dialog: case ReportDesignWidget::Dialog:
m_dialogEditorsState = saveState(); m_dialogEditorsState = saveState();
#ifdef HAVE_UI_LOADER #ifdef HAVE_UI_LOADER
m_scriptBrowser->updateDialogsTree(); m_scriptBrowser->updateDialogsTree();
#endif #endif
break; break;
case ReportDesignWidget::Script:
m_scriptEditorState = saveState();
break;
default: default:
m_pageEditorsState = saveState(); m_pageEditorsState = saveState();
break; break;
@ -1291,20 +1305,30 @@ void ReportDesignWindow::slotActivePageChanged()
m_editorTabType = m_reportDesignWidget->activeTabType(); m_editorTabType = m_reportDesignWidget->activeTabType();
switch (m_editorTabType) { switch (m_editorTabType) {
case ReportDesignWidget::Dialog: case ReportDesignWidget::Dialog:
if (!m_dialogEditorsState.isEmpty()) if (!m_dialogEditorsState.isEmpty()){
restoreState(m_dialogEditorsState); restoreState(m_dialogEditorsState);
else } else {
showDefaultEditors(); showDefaultEditors();
showDefaultToolBars(); showDefaultToolBars();
break; }
default: break;
if (!m_pageEditors.isEmpty()) case ReportDesignWidget::Script:
restoreState(m_pageEditorsState); if (!m_scriptEditorState.isEmpty()){
else restoreState(m_scriptEditorState);
showDefaultEditors(); } else {
showDefaultToolBars(); showDefaultEditors();
break; showDefaultToolBars();
}
break;
default:
if (!m_pageEditors.isEmpty()){
restoreState(m_pageEditorsState);
} else {
showDefaultEditors();
showDefaultToolBars();
}
break;
} }
} }

View File

@ -264,6 +264,7 @@ private:
ReportDesignWidget::EditorTabType m_editorTabType; ReportDesignWidget::EditorTabType m_editorTabType;
QByteArray m_pageEditorsState; QByteArray m_pageEditorsState;
QByteArray m_dialogEditorsState; QByteArray m_dialogEditorsState;
QByteArray m_scriptEditorState;
QVector<QToolBar*> m_pageTools; QVector<QToolBar*> m_pageTools;
QVector<QToolBar*> m_dialogTools; QVector<QToolBar*> m_dialogTools;

View File

@ -14,6 +14,7 @@ ScriptEditor::ScriptEditor(QWidget *parent) :
ui(new Ui::ScriptEditor) ui(new Ui::ScriptEditor)
{ {
ui->setupUi(this); ui->setupUi(this);
setFocusProxy(ui->textEdit);
m_completer = new QCompleter(this); m_completer = new QCompleter(this);
ui->textEdit->setCompleter(m_completer); ui->textEdit->setCompleter(m_completer);
} }
@ -78,6 +79,26 @@ void ScriptEditor::initCompleter()
m_completer->setModel(new QStringListModel(dataWords,m_completer)); 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) void ScriptEditor::addItemToCompleater(const QString& pageName, BaseDesignIntf* item, QStringList& dataWords)
{ {
BandDesignIntf* band = dynamic_cast<BandDesignIntf*>(item); BandDesignIntf* band = dynamic_cast<BandDesignIntf*>(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<LimeReport::DataNode*>(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<LimeReport::ScriptEngineNode*>(index.internalPointer());
if (node->type()==LimeReport::ScriptEngineNode::Function){
ui->textEdit->insertPlainText(node->name()+"()");
}
ui->textEdit->setFocus();
}
} // namespace LimeReport } // namespace LimeReport

View File

@ -24,6 +24,15 @@ public:
~ScriptEditor(); ~ScriptEditor();
void setReportEngine(ReportEnginePrivate* reportEngine); void setReportEngine(ReportEnginePrivate* reportEngine);
void initCompleter(); 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: private:
void addItemToCompleater(const QString& pageName, BaseDesignIntf* item, QStringList& dataWords); void addItemToCompleater(const QString& pageName, BaseDesignIntf* item, QStringList& dataWords);
private: private:

View File

@ -13,116 +13,92 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QSplitter" name="splitter">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="title"> <property name="orientation">
<string>Content</string> <enum>Qt::Horizontal</enum>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <widget class="LimeReport::CodeEditor" name="textEdit">
<property name="spacing"> <property name="sizePolicy">
<number>2</number> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="leftMargin"> <property name="font">
<number>2</number> <font>
<pointsize>12</pointsize>
</font>
</property> </property>
<property name="topMargin"> </widget>
<number>2</number> <widget class="QTabWidget" name="tabWidget">
<property name="tabPosition">
<enum>QTabWidget::South</enum>
</property> </property>
<property name="rightMargin"> <property name="currentIndex">
<number>2</number> <number>0</number>
</property> </property>
<property name="bottomMargin"> <widget class="QWidget" name="tab">
<number>2</number> <attribute name="title">
</property> <string>Data</string>
<item> </attribute>
<widget class="QSplitter" name="splitter"> <layout class="QVBoxLayout" name="verticalLayout_3">
<property name="sizePolicy"> <property name="spacing">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <number>3</number>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="orientation"> <property name="leftMargin">
<enum>Qt::Horizontal</enum> <number>3</number>
</property> </property>
<widget class="LimeReport::CodeEditor" name="textEdit"> <property name="topMargin">
<property name="font"> <number>3</number>
<font> </property>
<pointsize>12</pointsize> <property name="rightMargin">
</font> <number>3</number>
</property> </property>
</widget> <property name="bottomMargin">
<widget class="QTabWidget" name="tabWidget"> <number>3</number>
<property name="tabPosition"> </property>
<enum>QTabWidget::South</enum> <item>
</property> <widget class="QTreeView" name="twData">
<property name="currentIndex"> <attribute name="headerVisible">
<number>0</number> <bool>false</bool>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Data</string>
</attribute> </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>
<widget class="QWidget" name="tab_2"> </item>
<attribute name="title"> </layout>
<string>Functions</string> </widget>
</attribute> <widget class="QWidget" name="tab_2">
<layout class="QVBoxLayout" name="verticalLayout_4"> <attribute name="title">
<item> <string>Functions</string>
<widget class="QSplitter" name="splitter_2"> </attribute>
<property name="orientation"> <layout class="QVBoxLayout" name="verticalLayout_4">
<enum>Qt::Vertical</enum> <item>
</property> <widget class="QSplitter" name="splitter_2">
<widget class="QTreeView" name="twScriptEngine"> <property name="orientation">
<attribute name="headerVisible"> <enum>Qt::Vertical</enum>
<bool>false</bool> </property>
</attribute> <widget class="QTreeView" name="twScriptEngine">
</widget> <attribute name="headerVisible">
<widget class="QLabel" name="lblDescription"> <bool>false</bool>
<property name="text"> </attribute>
<string/> </widget>
</property> <widget class="QLabel" name="lblDescription">
</widget> <property name="text">
</widget> <string/>
</item> </property>
</layout> </widget>
</widget> </widget>
</widget> </item>
</widget> </layout>
</item> </widget>
</layout> </widget>
</widget> </widget>
</item> </item>
</layout> </layout>