0
0
mirror of https://github.com/fralx/LimeReport.git synced 2025-01-11 17:18:10 +03:00

Saving the designer state has been refactored

This commit is contained in:
Arin Alexander 2017-09-20 22:25:50 +03:00
parent fd4e8057a9
commit 2b708b38f5
3 changed files with 44 additions and 65 deletions

View File

@ -71,7 +71,8 @@ public:
Page, Page,
Dialog, Dialog,
Script, Script,
Translations Translations,
TabTypeCount
}; };
ReportDesignWidget(ReportEngine* report, QMainWindow *mainWindow, QWidget *parent = 0); ReportDesignWidget(ReportEngine* report, QMainWindow *mainWindow, QWidget *parent = 0);
~ReportDesignWidget(); ~ReportDesignWidget();

View File

@ -63,7 +63,8 @@ namespace LimeReport{
ReportDesignWindow* ReportDesignWindow::m_instance=0; ReportDesignWindow* ReportDesignWindow::m_instance=0;
ReportDesignWindow::ReportDesignWindow(ReportEngine *report, QWidget *parent, QSettings* settings) : 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); initReportEditor(report);
createActions(); createActions();
@ -92,8 +93,7 @@ ReportDesignWindow::ReportDesignWindow(ReportEngine *report, QWidget *parent, QS
showDefaultToolBars(); showDefaultToolBars();
restoreSetting(); restoreSetting();
m_hideLeftPanel->setChecked(isDockAreaVisible(Qt::LeftDockWidgetArea)); m_hideLeftPanel->setChecked(isDockAreaVisible(Qt::LeftDockWidgetArea));
m_hideRightPanel->setChecked(isDockAreaVisible(Qt::RightDockWidgetArea)); m_hideRightPanel->setChecked(isDockAreaVisible(Qt::RightDockWidgetArea));
m_editorTabType = ReportDesignWidget::Page;
} }
ReportDesignWindow::~ReportDesignWindow() ReportDesignWindow::~ReportDesignWindow()
@ -663,23 +663,12 @@ void ReportDesignWindow::writePosition()
void ReportDesignWindow::writeState() void ReportDesignWindow::writeState()
{ {
settings()->beginGroup("DesignerWindow"); settings()->beginGroup("DesignerWindow");
switch (m_editorTabType) {
case ReportDesignWidget::Page: m_editorsStates[m_editorTabType] = saveState();
settings()->setValue("PageEditorsState", saveState()); settings()->setValue("PageEditorsState", m_editorsStates[ReportDesignWidget::Page]);
settings()->setValue("DialogEditorsState", m_dialogEditorsState); settings()->setValue("DialogEditorsState", m_editorsStates[ReportDesignWidget::Dialog]);
settings()->setValue("ScriptEditorsState", m_scriptEditorState); settings()->setValue("ScriptEditorsState", m_editorsStates[ReportDesignWidget::Script]);
break; settings()->setValue("TranslationEditorsState", m_editorsStates[ReportDesignWidget::Translations]);
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()->setValue("InspectorFirsColumnWidth",m_objectInspector->columnWidth(0));
settings()->endGroup(); settings()->endGroup();
settings()->beginGroup("RecentFiles"); settings()->beginGroup("RecentFiles");
@ -774,18 +763,23 @@ void ReportDesignWindow::restoreSetting()
} }
v = settings()->value("PageEditorsState"); v = settings()->value("PageEditorsState");
if (v.isValid()){ if (v.isValid()){
m_pageEditorsState = v.toByteArray(); m_editorsStates[ReportDesignWidget::Page] = v.toByteArray();
restoreState(v.toByteArray());
m_editorTabType = ReportDesignWidget::Page; m_editorTabType = ReportDesignWidget::Page;
} }
v = settings()->value("DialogEditorsState"); v = settings()->value("DialogEditorsState");
if (v.isValid()){ if (v.isValid()){
m_dialogEditorsState = v.toByteArray(); m_editorsStates[ReportDesignWidget::Dialog] = v.toByteArray();
} }
v = settings()->value("ScriptEditorsState"); v = settings()->value("ScriptEditorsState");
if (v.isValid()){ 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"); v = settings()->value("InspectorFirsColumnWidth");
if (v.isValid()){ if (v.isValid()){
m_objectInspector->setColumnWidth(0,v.toInt()); m_objectInspector->setColumnWidth(0,v.toInt());
@ -1087,7 +1081,7 @@ void ReportDesignWindow::slotLoadReport()
setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer");
addRecentFile(fileName); addRecentFile(fileName);
m_editorTabType = ReportDesignWidget::Page; m_editorTabType = ReportDesignWidget::Page;
showDefaultToolBars(); //showDefaultToolBars();
showDefaultEditors(); showDefaultEditors();
} }
} }
@ -1287,48 +1281,20 @@ void ReportDesignWindow::slotActivePageChanged()
updateRedoUndo(); updateRedoUndo();
updateAvaibleBands(); updateAvaibleBands();
switch (m_editorTabType) { if (m_editorTabType == ReportDesignWidget::Dialog){
case ReportDesignWidget::Dialog:
m_dialogEditorsState = saveState();
#ifdef HAVE_UI_LOADER #ifdef HAVE_UI_LOADER
m_scriptBrowser->updateDialogsTree(); m_scriptBrowser->updateDialogsTree();
#endif #endif
break;
case ReportDesignWidget::Script:
m_scriptEditorState = saveState();
break;
default:
m_pageEditorsState = saveState();
break;
} }
m_editorsStates[m_editorTabType] = saveState();
m_editorTabType = m_reportDesignWidget->activeTabType(); m_editorTabType = m_reportDesignWidget->activeTabType();
switch (m_editorTabType) { if (!m_editorsStates[m_editorTabType].isEmpty()){
case ReportDesignWidget::Dialog: restoreState(m_editorsStates[m_editorTabType]);
if (!m_dialogEditorsState.isEmpty()){ } else {
restoreState(m_dialogEditorsState); showDefaultEditors();
} else { showDefaultToolBars();
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;
} }
} }
@ -1474,6 +1440,19 @@ void ReportDesignWindow::resizeEvent(QResizeEvent*)
#endif #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*) void ReportDesignWindow::moveEvent(QMoveEvent*)
{ {
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX

View File

@ -126,6 +126,7 @@ private slots:
protected: protected:
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
void resizeEvent(QResizeEvent *); void resizeEvent(QResizeEvent *);
void showEvent(QShowEvent* event);
void moveEvent(QMoveEvent *); void moveEvent(QMoveEvent *);
void hideDockWidgets(Qt::DockWidgetArea area, bool value); void hideDockWidgets(Qt::DockWidgetArea area, bool value);
bool isDockAreaVisible(Qt::DockWidgetArea area); bool isDockAreaVisible(Qt::DockWidgetArea area);
@ -262,9 +263,7 @@ private:
QVector<QDockWidget*> m_dialogEditors; QVector<QDockWidget*> m_dialogEditors;
QVector<QDockWidget*> m_docksToTabify; QVector<QDockWidget*> m_docksToTabify;
ReportDesignWidget::EditorTabType m_editorTabType; ReportDesignWidget::EditorTabType m_editorTabType;
QByteArray m_pageEditorsState; QByteArray m_editorsStates[ReportDesignWidget::TabTypeCount];
QByteArray m_dialogEditorsState;
QByteArray m_scriptEditorState;
QVector<QToolBar*> m_pageTools; QVector<QToolBar*> m_pageTools;
QVector<QToolBar*> m_dialogTools; QVector<QToolBar*> m_dialogTools;