0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 00:33:02 +03:00

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("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();

View File

@ -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;

View File

@ -667,10 +667,17 @@ void ReportDesignWindow::writeState()
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));
@ -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());
@ -1283,6 +1294,9 @@ void ReportDesignWindow::slotActivePageChanged()
m_scriptBrowser->updateDialogsTree();
#endif
break;
case ReportDesignWidget::Script:
m_scriptEditorState = saveState();
break;
default:
m_pageEditorsState = saveState();
break;
@ -1292,18 +1306,28 @@ void ReportDesignWindow::slotActivePageChanged()
switch (m_editorTabType) {
case ReportDesignWidget::Dialog:
if (!m_dialogEditorsState.isEmpty())
if (!m_dialogEditorsState.isEmpty()){
restoreState(m_dialogEditorsState);
else
} else {
showDefaultEditors();
showDefaultToolBars();
}
break;
case ReportDesignWidget::Script:
if (!m_scriptEditorState.isEmpty()){
restoreState(m_scriptEditorState);
} else {
showDefaultEditors();
showDefaultToolBars();
}
break;
default:
if (!m_pageEditors.isEmpty())
if (!m_pageEditors.isEmpty()){
restoreState(m_pageEditorsState);
else
} else {
showDefaultEditors();
showDefaultToolBars();
}
break;
}

View File

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

View File

@ -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<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

View File

@ -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:

View File

@ -13,34 +13,7 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Content</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
@ -53,6 +26,12 @@
<enum>Qt::Horizontal</enum>
</property>
<widget class="LimeReport::CodeEditor" name="textEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
@ -124,9 +103,6 @@
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LimeReport::CodeEditor</class>