forked from qt-creator/qt-creator
Support view/hide right side bar in Debug mode
Like it is now supported in Widget Designer, the view/hide action toggles the corresponding dock widget area. We cannot do that for the left dock widget area yet, because that action still needs to toggle the navigation side bar. To support this, we need to save not only the QMainWindow state for the debugger perspectives, but the whole FancyMainWindow state including the information about hidden dock widget areas. Unfortunately the PerspectiveState was serialized to QVariant without versioning, so keeping it that way is difficult. Switch saving&restoring of PerspectiveState to Utils::Store (and keep some compatibility code). Change-Id: I0035841930c6a574aeb31650a28be9989e2b5741 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -590,11 +590,13 @@ Store FancyMainWindow::saveSettings() const
|
||||
return settings;
|
||||
}
|
||||
|
||||
void FancyMainWindow::restoreSettings(const Store &settings)
|
||||
bool FancyMainWindow::restoreSettings(const Store &settings)
|
||||
{
|
||||
bool success = true;
|
||||
QByteArray ba = settings.value(StateKey, QByteArray()).toByteArray();
|
||||
if (!ba.isEmpty()) {
|
||||
if (!restoreFancyState(ba, settingsVersion))
|
||||
success = restoreFancyState(ba, settingsVersion);
|
||||
if (!success)
|
||||
qWarning() << "Restoring the state of dock widgets failed.";
|
||||
}
|
||||
d->m_showCentralWidget.setChecked(settings.value(ShowCentralWidgetKey, true).toBool());
|
||||
@@ -603,6 +605,8 @@ void FancyMainWindow::restoreSettings(const Store &settings)
|
||||
settings.value(keyFromString(widget->objectName()), false));
|
||||
}
|
||||
d->restoreHiddenDockAreasFromHash(settings.value(HiddenDockAreasKey).toHash());
|
||||
emit dockWidgetsChanged();
|
||||
return success;
|
||||
}
|
||||
|
||||
bool FancyMainWindow::restoreFancyState(const QByteArray &state, int version)
|
||||
|
@@ -33,7 +33,7 @@ public:
|
||||
void saveSettings(QtcSettings *settings) const;
|
||||
void restoreSettings(const QtcSettings *settings);
|
||||
Store saveSettings() const;
|
||||
void restoreSettings(const Store &settings);
|
||||
bool restoreSettings(const Store &settings);
|
||||
bool restoreFancyState(const QByteArray &state, int version = 0);
|
||||
|
||||
// Additional context menu actions
|
||||
|
@@ -437,8 +437,14 @@ void DebuggerMainWindow::restorePersistentSettings()
|
||||
d->m_lastTypePerspectiveStates.clear();
|
||||
QSet<QString> keys = Utils::toSet(states2.keys());
|
||||
for (const QString &type : keys) {
|
||||
PerspectiveState state = states2.value(type).value<PerspectiveState>();
|
||||
QTC_ASSERT(!state.mainWindowState.isEmpty(), continue);
|
||||
PerspectiveState state;
|
||||
if (states2.value(type).canConvert<QVariantMap>()) {
|
||||
state = PerspectiveState::fromSettings(storeFromMap(states2.value(type).toMap()));
|
||||
} else {
|
||||
// legacy for up to QtC 12
|
||||
state = states2.value(type).value<PerspectiveState>();
|
||||
}
|
||||
QTC_ASSERT(state.hasWindowState(), continue);
|
||||
d->m_lastTypePerspectiveStates.insert(type, state);
|
||||
}
|
||||
|
||||
@@ -469,7 +475,7 @@ void DebuggerMainWindow::savePersistentSettings() const
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE TYPE " << type
|
||||
<< " HAS STATE: " << !state.mainWindowState.isEmpty();
|
||||
QTC_ASSERT(!state.mainWindowState.isEmpty(), continue);
|
||||
states.insert(type, QVariant::fromValue(state));
|
||||
states.insert(type, mapFromStore(state.toSettings()));
|
||||
}
|
||||
|
||||
QtcSettings *settings = ICore::settings();
|
||||
@@ -965,10 +971,10 @@ void PerspectivePrivate::restoreLayout()
|
||||
{
|
||||
qCDebug(perspectivesLog) << "RESTORE LAYOUT FOR " << m_id << settingsId();
|
||||
PerspectiveState state = theMainWindow->d->m_lastPerspectiveStates.value(m_id);
|
||||
if (state.mainWindowState.isEmpty()) {
|
||||
if (!state.hasWindowState()) {
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE STATE NOT AVAILABLE BY FULL ID.";
|
||||
state = theMainWindow->d->m_lastTypePerspectiveStates.value(settingsId());
|
||||
if (state.mainWindowState.isEmpty()) {
|
||||
if (state.hasWindowState()) {
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE STATE NOT AVAILABLE BY PERSPECTIVE TYPE";
|
||||
} else {
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE STATE AVAILABLE BY PERSPECTIVE TYPE.";
|
||||
@@ -994,10 +1000,10 @@ void PerspectivePrivate::restoreLayout()
|
||||
}
|
||||
}
|
||||
|
||||
if (state.mainWindowState.isEmpty()) {
|
||||
if (!state.hasWindowState()) {
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE " << m_id << "RESTORE NOT POSSIBLE, NO STORED STATE";
|
||||
} else {
|
||||
bool result = theMainWindow->restoreFancyState(state.mainWindowState);
|
||||
const bool result = state.restoreWindowState(theMainWindow);
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE " << m_id << "RESTORED, SUCCESS: " << result;
|
||||
}
|
||||
|
||||
@@ -1019,7 +1025,7 @@ void PerspectivePrivate::saveLayout()
|
||||
{
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE" << m_id << "SAVE LAYOUT TO " << settingsId();
|
||||
PerspectiveState state;
|
||||
state.mainWindowState = theMainWindow->saveState();
|
||||
state.mainWindowState = theMainWindow->saveSettings();
|
||||
for (DockOperation &op : m_dockOperations) {
|
||||
if (op.operationType != Perspective::Raise) {
|
||||
QTC_ASSERT(op.dock, continue);
|
||||
@@ -1070,4 +1076,36 @@ const char *PerspectiveState::savesHeaderKey()
|
||||
return "SavesHeader";
|
||||
}
|
||||
|
||||
bool PerspectiveState::hasWindowState() const
|
||||
{
|
||||
return !mainWindowState.isEmpty() || !mainWindowStateLegacy.isEmpty();
|
||||
}
|
||||
|
||||
bool PerspectiveState::restoreWindowState(FancyMainWindow * mainWindow)
|
||||
{
|
||||
if (!mainWindowState.isEmpty())
|
||||
return mainWindow->restoreSettings(mainWindowState);
|
||||
if (!mainWindowStateLegacy.isEmpty())
|
||||
return mainWindow->restoreFancyState(mainWindowStateLegacy);
|
||||
return false;
|
||||
}
|
||||
|
||||
const char kMainWindowStateKey[] = "MainWindow";
|
||||
const char kHeaderViewStatesKey[] = "HeaderViewStates";
|
||||
|
||||
Store PerspectiveState::toSettings() const
|
||||
{
|
||||
Store result;
|
||||
result.insert(kMainWindowStateKey, QVariant::fromValue(mainWindowState));
|
||||
result.insert(kHeaderViewStatesKey, QVariant::fromValue(headerViewStates));
|
||||
return result;
|
||||
}
|
||||
PerspectiveState PerspectiveState::fromSettings(const Store &settings)
|
||||
{
|
||||
PerspectiveState state;
|
||||
state.mainWindowState = settings.value(kMainWindowStateKey).value<Store>();
|
||||
state.headerViewStates = settings.value(kHeaderViewStatesKey).value<QVariantHash>();
|
||||
return state;
|
||||
}
|
||||
|
||||
} // Utils
|
||||
|
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <utils/fancymainwindow.h>
|
||||
#include <utils/statuslabel.h>
|
||||
#include <utils/storekey.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QPointer>
|
||||
@@ -37,13 +38,27 @@ class PerspectiveState
|
||||
public:
|
||||
static const char *savesHeaderKey();
|
||||
|
||||
QByteArray mainWindowState;
|
||||
bool hasWindowState() const;
|
||||
|
||||
bool restoreWindowState(FancyMainWindow *mainWindow);
|
||||
|
||||
Store mainWindowState;
|
||||
QVariantHash headerViewStates;
|
||||
|
||||
QByteArray mainWindowStateLegacy; // legacy for up to QtC 12
|
||||
|
||||
Store toSettings() const;
|
||||
static PerspectiveState fromSettings(const Store &settings);
|
||||
|
||||
// legacy for up to QtC 12, operators for direct QVariant conversion
|
||||
friend QDataStream &operator>>(QDataStream &ds, PerspectiveState &state)
|
||||
{ return ds >> state.mainWindowState >> state.headerViewStates; }
|
||||
{
|
||||
return ds >> state.mainWindowStateLegacy >> state.headerViewStates;
|
||||
}
|
||||
friend QDataStream &operator<<(QDataStream &ds, const PerspectiveState &state)
|
||||
{ return ds << state.mainWindowState << state.headerViewStates; }
|
||||
{
|
||||
return ds << state.mainWindowStateLegacy << state.headerViewStates;
|
||||
}
|
||||
};
|
||||
|
||||
class DEBUGGER_EXPORT Perspective : public QObject
|
||||
|
@@ -512,6 +512,7 @@ public:
|
||||
mainWindow->addSubPerspectiveSwitcher(EngineManager::dapEngineChooser());
|
||||
|
||||
setWidget(splitter);
|
||||
setMainWindow(mainWindow);
|
||||
|
||||
setMenu(DebuggerMainWindow::perspectiveMenu());
|
||||
}
|
||||
|
Reference in New Issue
Block a user