forked from qt-creator/qt-creator
Debugger: Remember sizes and order of the columns in the debugger views
Task-number: QTCREATORBUG-23341 Change-Id: I405be5361e732eccadebd1f51d90c7a3229a2e5e Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -52,6 +52,7 @@
|
||||
#include <QContextMenuEvent>
|
||||
#include <QDockWidget>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QLoggingCategory>
|
||||
#include <QMenu>
|
||||
#include <QScrollArea>
|
||||
@@ -59,6 +60,7 @@
|
||||
#include <QStandardItemModel>
|
||||
#include <QTimer>
|
||||
#include <QToolButton>
|
||||
#include <QTreeView>
|
||||
|
||||
using namespace Debugger;
|
||||
using namespace Core;
|
||||
@@ -73,7 +75,8 @@ const char LAST_PERSPECTIVE_KEY[] = "LastPerspective";
|
||||
const char MAINWINDOW_KEY[] = "Debugger.MainWindow";
|
||||
const char AUTOHIDE_TITLEBARS_KEY[] = "AutoHideTitleBars";
|
||||
const char SHOW_CENTRALWIDGET_KEY[] = "ShowCentralWidget";
|
||||
const char STATE_KEY[] = "State";
|
||||
const char STATE_KEY[] = "State"; // Up to 4.10
|
||||
const char STATE_KEY2[] = "State2"; // From 4.11 on
|
||||
const char CHANGED_DOCK_KEY[] = "ChangedDocks";
|
||||
|
||||
static DebuggerMainWindow *theMainWindow = nullptr;
|
||||
@@ -166,8 +169,8 @@ public:
|
||||
QList<QPointer<Perspective>> m_perspectives;
|
||||
QSet<QString> m_persistentChangedDocks; // Dock Ids of docks with non-default visibility.
|
||||
|
||||
QHash<QString, QByteArray> m_lastPerspectiveStates; // Perspective::id() -> MainWindow::state()
|
||||
QHash<QString, QByteArray> m_lastTypePerspectiveStates; // Perspective::settingsId() -> MainWindow::state()
|
||||
QHash<QString, PerspectiveState> m_lastPerspectiveStates; // Perspective::id() -> MainWindow::state()
|
||||
QHash<QString, PerspectiveState> m_lastTypePerspectiveStates; // Perspective::settingsId() -> MainWindow::state()
|
||||
};
|
||||
|
||||
DebuggerMainWindowPrivate::DebuggerMainWindowPrivate(DebuggerMainWindow *parent)
|
||||
@@ -265,6 +268,9 @@ DebuggerMainWindowPrivate::~DebuggerMainWindowPrivate()
|
||||
DebuggerMainWindow::DebuggerMainWindow()
|
||||
: d(new DebuggerMainWindowPrivate(this))
|
||||
{
|
||||
qRegisterMetaType<PerspectiveState>("PerspectiveState");
|
||||
qRegisterMetaTypeStreamOperators<PerspectiveState>("PerspectiveState");
|
||||
|
||||
setDockNestingEnabled(true);
|
||||
setDockActionsVisible(false);
|
||||
setDocumentMode(true);
|
||||
@@ -437,11 +443,17 @@ void DebuggerMainWindow::restorePersistentSettings()
|
||||
QSettings *settings = ICore::settings();
|
||||
settings->beginGroup(MAINWINDOW_KEY);
|
||||
|
||||
// state2 is current, state is kept for upgradeing from <=4.10
|
||||
const QHash<QString, QVariant> states2 = settings->value(STATE_KEY2).toHash();
|
||||
const QHash<QString, QVariant> states = settings->value(STATE_KEY).toHash();
|
||||
d->m_lastTypePerspectiveStates.clear();
|
||||
for (const QString &type : states.keys()) {
|
||||
const QByteArray state = states.value(type).toByteArray();
|
||||
QTC_ASSERT(!state.isEmpty(), continue);
|
||||
QSet<QString> keys = Utils::toSet(states2.keys());
|
||||
keys.unite(Utils::toSet(states.keys()));
|
||||
for (const QString &type : keys) {
|
||||
PerspectiveState state = states2.value(type).value<PerspectiveState>();
|
||||
if (state.mainWindowState.isEmpty())
|
||||
state.mainWindowState = states.value(type).toByteArray();
|
||||
QTC_ASSERT(!state.mainWindowState.isEmpty(), continue);
|
||||
d->m_lastTypePerspectiveStates.insert(type, state);
|
||||
}
|
||||
|
||||
@@ -467,16 +479,17 @@ void DebuggerMainWindow::savePersistentSettings() const
|
||||
QVariantHash states;
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE TYPES: " << d->m_lastTypePerspectiveStates.keys();
|
||||
for (const QString &type : d->m_lastTypePerspectiveStates.keys()) {
|
||||
const QByteArray state = d->m_lastTypePerspectiveStates.value(type);
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE TYPE " << type << " HAS STATE: " << !state.isEmpty();
|
||||
QTC_ASSERT(!state.isEmpty(), continue);
|
||||
states.insert(type, state);
|
||||
const PerspectiveState state = d->m_lastTypePerspectiveStates.value(type);
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE TYPE " << type
|
||||
<< " HAS STATE: " << !state.mainWindowState.isEmpty();
|
||||
QTC_ASSERT(!state.mainWindowState.isEmpty(), continue);
|
||||
states.insert(type, QVariant::fromValue(state));
|
||||
}
|
||||
|
||||
QSettings *settings = ICore::settings();
|
||||
settings->beginGroup(MAINWINDOW_KEY);
|
||||
settings->setValue(CHANGED_DOCK_KEY, QStringList(Utils::toList(d->m_persistentChangedDocks)));
|
||||
settings->setValue(STATE_KEY, states);
|
||||
settings->setValue(STATE_KEY2, states);
|
||||
settings->setValue(AUTOHIDE_TITLEBARS_KEY, autoHideTitleBars());
|
||||
settings->setValue(SHOW_CENTRALWIDGET_KEY, isCentralWidgetShown());
|
||||
settings->endGroup();
|
||||
@@ -931,11 +944,11 @@ void Perspective::select()
|
||||
void PerspectivePrivate::restoreLayout()
|
||||
{
|
||||
qCDebug(perspectivesLog) << "RESTORE LAYOUT FOR " << m_id << settingsId();
|
||||
QByteArray state = theMainWindow->d->m_lastPerspectiveStates.value(m_id);
|
||||
if (state.isEmpty()) {
|
||||
PerspectiveState state = theMainWindow->d->m_lastPerspectiveStates.value(m_id);
|
||||
if (state.mainWindowState.isEmpty()) {
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE STATE NOT AVAILABLE BY FULL ID.";
|
||||
state = theMainWindow->d->m_lastTypePerspectiveStates.value(settingsId());
|
||||
if (state.isEmpty()) {
|
||||
if (state.mainWindowState.isEmpty()) {
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE STATE NOT AVAILABLE BY PERSPECTIVE TYPE";
|
||||
} else {
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE STATE AVAILABLE BY PERSPECTIVE TYPE.";
|
||||
@@ -961,19 +974,43 @@ void PerspectivePrivate::restoreLayout()
|
||||
}
|
||||
}
|
||||
|
||||
if (state.isEmpty()) {
|
||||
if (state.mainWindowState.isEmpty()) {
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE " << m_id << "RESTORE NOT POSSIBLE, NO STORED STATE";
|
||||
} else {
|
||||
bool result = theMainWindow->restoreState(state);
|
||||
bool result = theMainWindow->restoreState(state.mainWindowState);
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE " << m_id << "RESTORED, SUCCESS: " << result;
|
||||
}
|
||||
|
||||
for (DockOperation &op : m_dockOperations) {
|
||||
if (op.operationType != Perspective::Raise) {
|
||||
QTC_ASSERT(op.dock, continue);
|
||||
for (QTreeView *tv : op.dock->findChildren<QTreeView *>()) {
|
||||
if (tv->property(PerspectiveState::savesHeaderKey()).toBool()) {
|
||||
const QByteArray s = state.headerViewStates.value(op.name()).toByteArray();
|
||||
if (!s.isEmpty())
|
||||
tv->header()->restoreState(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PerspectivePrivate::saveLayout()
|
||||
{
|
||||
qCDebug(perspectivesLog) << "PERSPECTIVE" << m_id << "SAVE LAYOUT TO " << settingsId();
|
||||
theMainWindow->d->m_lastPerspectiveStates.insert(m_id, theMainWindow->saveState());
|
||||
theMainWindow->d->m_lastTypePerspectiveStates.insert(settingsId(), theMainWindow->saveState());
|
||||
PerspectiveState state;
|
||||
state.mainWindowState = theMainWindow->saveState();
|
||||
for (DockOperation &op : m_dockOperations) {
|
||||
QTC_ASSERT(op.dock, continue);
|
||||
for (QTreeView *tv : op.dock->findChildren<QTreeView *>()) {
|
||||
if (tv->property(PerspectiveState::savesHeaderKey()).toBool()) {
|
||||
if (QHeaderView *hv = tv->header())
|
||||
state.headerViewStates.insert(op.name(), hv->saveState());
|
||||
}
|
||||
}
|
||||
}
|
||||
theMainWindow->d->m_lastPerspectiveStates.insert(m_id, state);
|
||||
theMainWindow->d->m_lastTypePerspectiveStates.insert(settingsId(), state);
|
||||
}
|
||||
|
||||
QString PerspectivePrivate::settingsId() const
|
||||
@@ -1006,4 +1043,9 @@ void OptionalAction::setToolButtonStyle(Qt::ToolButtonStyle style)
|
||||
m_toolButton->setToolButtonStyle(style);
|
||||
}
|
||||
|
||||
const char *PerspectiveState::savesHeaderKey()
|
||||
{
|
||||
return "SavesHeader";
|
||||
}
|
||||
|
||||
} // Utils
|
||||
|
||||
Reference in New Issue
Block a user