0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 16:44:39 +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,
Dialog,
Script,
Translations
Translations,
TabTypeCount
};
ReportDesignWidget(ReportEngine* report, QMainWindow *mainWindow, QWidget *parent = 0);
~ReportDesignWidget();

View File

@ -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();
@ -93,7 +94,6 @@ ReportDesignWindow::ReportDesignWindow(ReportEngine *report, QWidget *parent, QS
restoreSetting();
m_hideLeftPanel->setChecked(isDockAreaVisible(Qt::LeftDockWidgetArea));
m_hideRightPanel->setChecked(isDockAreaVisible(Qt::RightDockWidgetArea));
m_editorTabType = ReportDesignWidget::Page;
}
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

View File

@ -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<QDockWidget*> m_dialogEditors;
QVector<QDockWidget*> m_docksToTabify;
ReportDesignWidget::EditorTabType m_editorTabType;
QByteArray m_pageEditorsState;
QByteArray m_dialogEditorsState;
QByteArray m_scriptEditorState;
QByteArray m_editorsStates[ReportDesignWidget::TabTypeCount];
QVector<QToolBar*> m_pageTools;
QVector<QToolBar*> m_dialogTools;