From 2b708b38f58f1ac7c6145010a33bc4fc830a4fdc Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Wed, 20 Sep 2017 22:25:50 +0300 Subject: [PATCH] Saving the designer state has been refactored --- limereport/lrreportdesignwidget.h | 3 +- limereport/lrreportdesignwindow.cpp | 101 +++++++++++----------------- limereport/lrreportdesignwindow.h | 5 +- 3 files changed, 44 insertions(+), 65 deletions(-) diff --git a/limereport/lrreportdesignwidget.h b/limereport/lrreportdesignwidget.h index b7e38b7..37aed74 100644 --- a/limereport/lrreportdesignwidget.h +++ b/limereport/lrreportdesignwidget.h @@ -71,7 +71,8 @@ public: Page, Dialog, Script, - Translations + Translations, + TabTypeCount }; ReportDesignWidget(ReportEngine* report, QMainWindow *mainWindow, QWidget *parent = 0); ~ReportDesignWidget(); diff --git a/limereport/lrreportdesignwindow.cpp b/limereport/lrreportdesignwindow.cpp index 1ad41c7..657f289 100644 --- a/limereport/lrreportdesignwindow.cpp +++ b/limereport/lrreportdesignwindow.cpp @@ -63,7 +63,8 @@ namespace LimeReport{ ReportDesignWindow* ReportDesignWindow::m_instance=0; ReportDesignWindow::ReportDesignWindow(ReportEngine *report, QWidget *parent, QSettings* settings) : - QMainWindow(parent), m_textAttibutesIsChanging(false), m_settings(settings), m_ownedSettings(false), m_progressDialog(0), m_showProgressDialog(true) + QMainWindow(parent), m_textAttibutesIsChanging(false), m_settings(settings), m_ownedSettings(false), + m_progressDialog(0), m_showProgressDialog(true), m_editorTabType(ReportDesignWidget::Page) { initReportEditor(report); createActions(); @@ -92,8 +93,7 @@ ReportDesignWindow::ReportDesignWindow(ReportEngine *report, QWidget *parent, QS showDefaultToolBars(); restoreSetting(); m_hideLeftPanel->setChecked(isDockAreaVisible(Qt::LeftDockWidgetArea)); - m_hideRightPanel->setChecked(isDockAreaVisible(Qt::RightDockWidgetArea)); - m_editorTabType = ReportDesignWidget::Page; + m_hideRightPanel->setChecked(isDockAreaVisible(Qt::RightDockWidgetArea)); } ReportDesignWindow::~ReportDesignWindow() @@ -663,23 +663,12 @@ void ReportDesignWindow::writePosition() void ReportDesignWindow::writeState() { settings()->beginGroup("DesignerWindow"); - switch (m_editorTabType) { - 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; - } + + m_editorsStates[m_editorTabType] = saveState(); + settings()->setValue("PageEditorsState", m_editorsStates[ReportDesignWidget::Page]); + settings()->setValue("DialogEditorsState", m_editorsStates[ReportDesignWidget::Dialog]); + settings()->setValue("ScriptEditorsState", m_editorsStates[ReportDesignWidget::Script]); + settings()->setValue("TranslationEditorsState", m_editorsStates[ReportDesignWidget::Translations]); settings()->setValue("InspectorFirsColumnWidth",m_objectInspector->columnWidth(0)); settings()->endGroup(); settings()->beginGroup("RecentFiles"); @@ -774,18 +763,23 @@ void ReportDesignWindow::restoreSetting() } v = settings()->value("PageEditorsState"); if (v.isValid()){ - m_pageEditorsState = v.toByteArray(); - restoreState(v.toByteArray()); + m_editorsStates[ReportDesignWidget::Page] = v.toByteArray(); m_editorTabType = ReportDesignWidget::Page; } v = settings()->value("DialogEditorsState"); if (v.isValid()){ - m_dialogEditorsState = v.toByteArray(); + m_editorsStates[ReportDesignWidget::Dialog] = v.toByteArray(); } v = settings()->value("ScriptEditorsState"); if (v.isValid()){ - m_scriptEditorState = v.toByteArray(); + m_editorsStates[ReportDesignWidget::Script] = v.toByteArray(); } + + v = settings()->value("TranslationEditorsState"); + if (v.isValid()){ + m_editorsStates[ReportDesignWidget::Translations] = v.toByteArray(); + } + v = settings()->value("InspectorFirsColumnWidth"); if (v.isValid()){ m_objectInspector->setColumnWidth(0,v.toInt()); @@ -1087,7 +1081,7 @@ void ReportDesignWindow::slotLoadReport() setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); addRecentFile(fileName); m_editorTabType = ReportDesignWidget::Page; - showDefaultToolBars(); + //showDefaultToolBars(); showDefaultEditors(); } } @@ -1287,48 +1281,20 @@ void ReportDesignWindow::slotActivePageChanged() updateRedoUndo(); updateAvaibleBands(); - switch (m_editorTabType) { - case ReportDesignWidget::Dialog: - m_dialogEditorsState = saveState(); + if (m_editorTabType == ReportDesignWidget::Dialog){ #ifdef HAVE_UI_LOADER - m_scriptBrowser->updateDialogsTree(); + m_scriptBrowser->updateDialogsTree(); #endif - break; - case ReportDesignWidget::Script: - m_scriptEditorState = saveState(); - break; - default: - m_pageEditorsState = saveState(); - break; } + m_editorsStates[m_editorTabType] = saveState(); m_editorTabType = m_reportDesignWidget->activeTabType(); - switch (m_editorTabType) { - 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; + if (!m_editorsStates[m_editorTabType].isEmpty()){ + restoreState(m_editorsStates[m_editorTabType]); + } else { + showDefaultEditors(); + showDefaultToolBars(); } } @@ -1474,6 +1440,19 @@ void ReportDesignWindow::resizeEvent(QResizeEvent*) #endif } +void ReportDesignWindow::showEvent(QShowEvent* event) +{ + QMainWindow::showEvent(event); + + if (!m_editorsStates[m_editorTabType].isEmpty()){ + restoreState(m_editorsStates[m_editorTabType]); + } else { + showDefaultEditors(); + showDefaultToolBars(); + } + +} + void ReportDesignWindow::moveEvent(QMoveEvent*) { #ifdef Q_OS_UNIX diff --git a/limereport/lrreportdesignwindow.h b/limereport/lrreportdesignwindow.h index 1779ed3..9a96845 100644 --- a/limereport/lrreportdesignwindow.h +++ b/limereport/lrreportdesignwindow.h @@ -126,6 +126,7 @@ private slots: protected: void closeEvent(QCloseEvent *event); void resizeEvent(QResizeEvent *); + void showEvent(QShowEvent* event); void moveEvent(QMoveEvent *); void hideDockWidgets(Qt::DockWidgetArea area, bool value); bool isDockAreaVisible(Qt::DockWidgetArea area); @@ -262,9 +263,7 @@ private: QVector m_dialogEditors; QVector m_docksToTabify; ReportDesignWidget::EditorTabType m_editorTabType; - QByteArray m_pageEditorsState; - QByteArray m_dialogEditorsState; - QByteArray m_scriptEditorState; + QByteArray m_editorsStates[ReportDesignWidget::TabTypeCount]; QVector m_pageTools; QVector m_dialogTools;