mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-20 15:24:14 +02:00
Fix restoreState() for QETElementEditor and QETTitleBlockTemplateEditor on Qt6
Apply the same split readSettings()/readSettingsState() pattern from QETDiagramEditor to the other two main windows: - QETElementEditor: split in constructor, call readSettingsState() after show() - QETTitleBlockTemplateEditor: split readSettings(), callers call readSettingsState() after show() (newTemplate + 2x openTitleBlockTemplate) - Remove destructive settings.remove() guards that would delete saved state on every Qt6 launch when restoreState() fails before show() Co-authored-by: ispyisail
This commit is contained in:
@@ -77,8 +77,9 @@ QETElementEditor::QETElementEditor(QWidget *parent) :
|
||||
//ui->m_display_menu->insertMenu(ui->m_zoom_in_action, menu);
|
||||
|
||||
setWindowState(Qt::WindowMaximized);
|
||||
readSettings();
|
||||
readSettings(); // restoreGeometry before show()
|
||||
show();
|
||||
readSettingsState(); // restoreState() must be called after show() in Qt6
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -950,20 +951,28 @@ void QETElementEditor::readSettings()
|
||||
restoreGeometry(geometry.toByteArray());
|
||||
}
|
||||
|
||||
auto data = m_elmt_scene->elementData();
|
||||
data.m_drawing_information = settings.value("elementeditor/default-informations", "").toString();
|
||||
m_elmt_scene->setElementData(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETElementEditor::readSettingsState
|
||||
* Restore the window state (docks, toolbars).
|
||||
* Must be called AFTER show() in Qt6 for restoreState() to work correctly.
|
||||
*/
|
||||
void QETElementEditor::readSettingsState()
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
QVariant state = settings.value("elementeditor/state");
|
||||
if (state.isValid()) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
if (!restoreState(state.toByteArray())) {
|
||||
settings.remove("elementeditor/state");
|
||||
}
|
||||
restoreState(state.toByteArray());
|
||||
#else
|
||||
restoreState(state.toByteArray());
|
||||
#endif
|
||||
}
|
||||
|
||||
auto data = m_elmt_scene->elementData();
|
||||
data.m_drawing_information = settings.value("elementeditor/default-informations", "").toString();
|
||||
m_elmt_scene->setElementData(data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -116,6 +116,7 @@ class QETElementEditor : public QMainWindow
|
||||
private:
|
||||
bool canClose();
|
||||
void readSettings();
|
||||
void readSettingsState();
|
||||
void writeSettings() const;
|
||||
void setupActions();
|
||||
void updateAction();
|
||||
|
||||
@@ -1975,6 +1975,7 @@ void QETApp::openTitleBlockTemplate(const TitleBlockTemplateLocation &location,
|
||||
qet_template_editor -> setOpenForDuplication(duplicate);
|
||||
qet_template_editor -> edit(location);
|
||||
qet_template_editor -> show();
|
||||
qet_template_editor -> readSettingsState(); // must run after show() in Qt6
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1986,6 +1987,7 @@ void QETApp::openTitleBlockTemplate(const QString &filepath) {
|
||||
QETTitleBlockTemplateEditor *qet_template_editor = new QETTitleBlockTemplateEditor();
|
||||
qet_template_editor -> edit(filepath);
|
||||
qet_template_editor -> show();
|
||||
qet_template_editor -> readSettingsState(); // must run after show() in Qt6
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -358,6 +358,7 @@ void QETTitleBlockTemplateEditor::newTemplate()
|
||||
QETTitleBlockTemplateEditor *qet_template_editor = new QETTitleBlockTemplateEditor();
|
||||
qet_template_editor -> edit(TitleBlockTemplateLocation());
|
||||
qet_template_editor -> show();
|
||||
qet_template_editor -> readSettingsState(); // must run after show() in Qt6
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -645,14 +646,23 @@ void QETTitleBlockTemplateEditor::readSettings()
|
||||
// window size and position
|
||||
QVariant geometry = settings.value("titleblocktemplateeditor/geometry");
|
||||
if (geometry.isValid()) restoreGeometry(geometry.toByteArray());
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETTitleBlockTemplateEditor::readSettingsState
|
||||
Restore the window state (docks, toolbars).
|
||||
Must be called AFTER show() in Qt6 for restoreState() to work correctly
|
||||
-- callers are responsible for calling this after show(), since this
|
||||
window isn't shown by its own constructor.
|
||||
*/
|
||||
void QETTitleBlockTemplateEditor::readSettingsState()
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
// window state (toolbars, docks...)
|
||||
QVariant state = settings.value("titleblocktemplateeditor/state");
|
||||
if (state.isValid()) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
if (!restoreState(state.toByteArray())) {
|
||||
settings.remove("titleblocktemplateeditor/state");
|
||||
}
|
||||
restoreState(state.toByteArray());
|
||||
#else
|
||||
restoreState(state.toByteArray());
|
||||
#endif
|
||||
|
||||
@@ -108,6 +108,7 @@ class QETTitleBlockTemplateEditor : public QETMainWindow {
|
||||
|
||||
public slots:
|
||||
void readSettings();
|
||||
void readSettingsState();
|
||||
void writeSettings();
|
||||
void selectedCellsChanged(const QList<TitleBlockCell *>&);
|
||||
void duplicateCurrentLocation();
|
||||
|
||||
Reference in New Issue
Block a user