forked from qt-creator/qt-creator
Fixes: Saving and restoring of ProjectTreeWidget states
Task: Reported on the ML multiple times. Details: Add a few methods to make it possible to save and restore settings. Save those settings to the .ini file. (I'm not sure whether seesion would be better, let's see what feedback we get.)
This commit is contained in:
@@ -48,3 +48,13 @@ QKeySequence INavigationWidgetFactory::activationSequence()
|
|||||||
return QKeySequence();
|
return QKeySequence();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void INavigationWidgetFactory::saveSettings(int position, QWidget *widget)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void INavigationWidgetFactory::restoreSettings(int position, QWidget *widget)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ public:
|
|||||||
// and the docktoolbar widgets
|
// and the docktoolbar widgets
|
||||||
// Similar to how IView
|
// Similar to how IView
|
||||||
virtual NavigationView createWidget() = 0;
|
virtual NavigationView createWidget() = 0;
|
||||||
|
|
||||||
|
// Read and store settings for the widget, created by this factory
|
||||||
|
// and beeing at position position. (The position is important since
|
||||||
|
// a certain type of widget could exist multiple times.)
|
||||||
|
virtual void saveSettings(int position, QWidget *widget);
|
||||||
|
virtual void restoreSettings(int position, QWidget *widget);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|||||||
@@ -997,7 +997,7 @@ void MainWindow::readSettings()
|
|||||||
|
|
||||||
m_settings->endGroup();
|
m_settings->endGroup();
|
||||||
m_editorManager->readSettings(m_settings);
|
m_editorManager->readSettings(m_settings);
|
||||||
m_navigationWidget->readSettings(m_settings);
|
m_navigationWidget->restoreSettings(m_settings);
|
||||||
m_rightPaneWidget->readSettings(m_settings);
|
m_rightPaneWidget->readSettings(m_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -220,6 +220,8 @@ void NavigationWidget::close()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void NavigationWidget::saveSettings(QSettings *settings)
|
void NavigationWidget::saveSettings(QSettings *settings)
|
||||||
{
|
{
|
||||||
QStringList views;
|
QStringList views;
|
||||||
@@ -230,9 +232,12 @@ void NavigationWidget::saveSettings(QSettings *settings)
|
|||||||
settings->setValue("Navigation/Visible", isShown());
|
settings->setValue("Navigation/Visible", isShown());
|
||||||
settings->setValue("Navigation/VerticalPosition", saveState());
|
settings->setValue("Navigation/VerticalPosition", saveState());
|
||||||
settings->setValue("Navigation/Width", m_width);
|
settings->setValue("Navigation/Width", m_width);
|
||||||
|
|
||||||
|
for (int i=0; i<m_subWidgets.count(); ++i)
|
||||||
|
m_subWidgets.at(i)->saveSettings(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationWidget::readSettings(QSettings *settings)
|
void NavigationWidget::restoreSettings(QSettings *settings)
|
||||||
{
|
{
|
||||||
if (settings->contains("Navigation/Views")) {
|
if (settings->contains("Navigation/Views")) {
|
||||||
QStringList views = settings->value("Navigation/Views").toStringList();
|
QStringList views = settings->value("Navigation/Views").toStringList();
|
||||||
@@ -266,6 +271,9 @@ void NavigationWidget::readSettings(QSettings *settings)
|
|||||||
if (NavigationWidgetPlaceHolder::m_current) {
|
if (NavigationWidgetPlaceHolder::m_current) {
|
||||||
NavigationWidgetPlaceHolder::m_current->applyStoredSize(m_width);
|
NavigationWidgetPlaceHolder::m_current->applyStoredSize(m_width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<m_subWidgets.count(); ++i)
|
||||||
|
m_subWidgets.at(i)->restoreSettings(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationWidget::setShown(bool b)
|
void NavigationWidget::setShown(bool b)
|
||||||
@@ -465,6 +473,16 @@ INavigationWidgetFactory *NavigationSubWidget::factory()
|
|||||||
return m_navigationComboBox->itemData(index).value<INavigationWidgetFactory *>();
|
return m_navigationComboBox->itemData(index).value<INavigationWidgetFactory *>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NavigationSubWidget::saveSettings(int position)
|
||||||
|
{
|
||||||
|
factory()->saveSettings(position, m_navigationWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavigationSubWidget::restoreSettings(int position)
|
||||||
|
{
|
||||||
|
factory()->restoreSettings(position, m_navigationWidget);
|
||||||
|
}
|
||||||
|
|
||||||
Core::ICommand *NavigationSubWidget::command(const QString &title) const
|
Core::ICommand *NavigationSubWidget::command(const QString &title) const
|
||||||
{
|
{
|
||||||
const QHash<QString, Core::ICommand*> commandMap = m_parentWidget->commandMap();
|
const QHash<QString, Core::ICommand*> commandMap = m_parentWidget->commandMap();
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public:
|
|||||||
~NavigationWidget();
|
~NavigationWidget();
|
||||||
|
|
||||||
void saveSettings(QSettings *settings);
|
void saveSettings(QSettings *settings);
|
||||||
void readSettings(QSettings *settings);
|
void restoreSettings(QSettings *settings);
|
||||||
|
|
||||||
bool isShown() const;
|
bool isShown() const;
|
||||||
void setShown(bool b);
|
void setShown(bool b);
|
||||||
@@ -133,6 +133,9 @@ public:
|
|||||||
void setFactory(const QString &name);
|
void setFactory(const QString &name);
|
||||||
void setFocusWidget();
|
void setFocusWidget();
|
||||||
|
|
||||||
|
void saveSettings(int position);
|
||||||
|
void restoreSettings(int position);
|
||||||
|
|
||||||
Core::ICommand *command(const QString &title) const;
|
Core::ICommand *command(const QString &title) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
@@ -926,6 +926,16 @@ void FlatModel::setGeneratedFilesFilterEnabled(bool filter)
|
|||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FlatModel::projectFilterEnabled()
|
||||||
|
{
|
||||||
|
return m_filterProjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FlatModel::generatedFilesFilterEnabled()
|
||||||
|
{
|
||||||
|
return m_filterGeneratedFiles;
|
||||||
|
}
|
||||||
|
|
||||||
Node *FlatModel::nodeForIndex(const QModelIndex &index) const
|
Node *FlatModel::nodeForIndex(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (index.isValid())
|
if (index.isValid())
|
||||||
|
|||||||
@@ -136,6 +136,9 @@ public:
|
|||||||
ProjectExplorer::Node *nodeForIndex(const QModelIndex &index) const;
|
ProjectExplorer::Node *nodeForIndex(const QModelIndex &index) const;
|
||||||
QModelIndex indexForNode(const Node *node);
|
QModelIndex indexForNode(const Node *node);
|
||||||
|
|
||||||
|
bool projectFilterEnabled();
|
||||||
|
bool generatedFilesFilterEnabled();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setProjectFilterEnabled(bool filter);
|
void setProjectFilterEnabled(bool filter);
|
||||||
void setGeneratedFilesFilterEnabled(bool filter);
|
void setGeneratedFilesFilterEnabled(bool filter);
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
#include <QtCore/QSettings>
|
||||||
|
|
||||||
#include <QtGui/QHeaderView>
|
#include <QtGui/QHeaderView>
|
||||||
#include <QtGui/QVBoxLayout>
|
#include <QtGui/QVBoxLayout>
|
||||||
@@ -156,7 +157,20 @@ ProjectTreeWidget::ProjectTreeWidget(Core::ICore *core, QWidget *parent)
|
|||||||
connect(m_explorer->session(), SIGNAL(startupProjectChanged(ProjectExplorer::Project *)),
|
connect(m_explorer->session(), SIGNAL(startupProjectChanged(ProjectExplorer::Project *)),
|
||||||
this, SLOT(startupProjectChanged(ProjectExplorer::Project *)));
|
this, SLOT(startupProjectChanged(ProjectExplorer::Project *)));
|
||||||
|
|
||||||
setAutoSynchronization(true);
|
m_toggleSync = new QToolButton;
|
||||||
|
m_toggleSync->setProperty("type", "dockbutton");
|
||||||
|
m_toggleSync->setIcon(QIcon(":/qworkbench/images/linkicon.png"));
|
||||||
|
m_toggleSync->setCheckable(true);
|
||||||
|
m_toggleSync->setChecked(autoSynchronization());
|
||||||
|
m_toggleSync->setToolTip(tr("Synchronize with Editor"));
|
||||||
|
connect(m_toggleSync, SIGNAL(clicked(bool)), this, SLOT(toggleAutoSynchronization()));
|
||||||
|
|
||||||
|
//setAutoSynchronization(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
QToolButton *ProjectTreeWidget::toggleSync()
|
||||||
|
{
|
||||||
|
return m_toggleSync;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectTreeWidget::toggleAutoSynchronization()
|
void ProjectTreeWidget::toggleAutoSynchronization()
|
||||||
@@ -171,6 +185,7 @@ bool ProjectTreeWidget::autoSynchronization() const
|
|||||||
|
|
||||||
void ProjectTreeWidget::setAutoSynchronization(bool sync, bool syncNow)
|
void ProjectTreeWidget::setAutoSynchronization(bool sync, bool syncNow)
|
||||||
{
|
{
|
||||||
|
m_toggleSync->setChecked(sync);
|
||||||
if (sync == m_autoSync)
|
if (sync == m_autoSync)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -296,6 +311,17 @@ void ProjectTreeWidget::setGeneratedFilesFilter(bool filter)
|
|||||||
m_filterGeneratedFilesAction->setChecked(filter);
|
m_filterGeneratedFilesAction->setChecked(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProjectTreeWidget::generatedFilesFilter()
|
||||||
|
{
|
||||||
|
return m_model->generatedFilesFilterEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProjectTreeWidget::projectFilter()
|
||||||
|
{
|
||||||
|
return m_model->projectFilterEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ProjectTreeWidgetFactory::ProjectTreeWidgetFactory(Core::ICore *core)
|
ProjectTreeWidgetFactory::ProjectTreeWidgetFactory(Core::ICore *core)
|
||||||
: m_core(core)
|
: m_core(core)
|
||||||
{
|
{
|
||||||
@@ -331,15 +357,24 @@ Core::NavigationView ProjectTreeWidgetFactory::createWidget()
|
|||||||
filterMenu->addAction(ptw->m_filterGeneratedFilesAction);
|
filterMenu->addAction(ptw->m_filterGeneratedFilesAction);
|
||||||
filter->setMenu(filterMenu);
|
filter->setMenu(filterMenu);
|
||||||
|
|
||||||
QToolButton *toggleSync = new QToolButton;
|
n.doockToolBarWidgets << filter << ptw->toggleSync();
|
||||||
toggleSync->setProperty("type", "dockbutton");
|
|
||||||
toggleSync->setIcon(QIcon(":/qworkbench/images/linkicon.png"));
|
|
||||||
toggleSync->setCheckable(true);
|
|
||||||
toggleSync->setChecked(ptw->autoSynchronization());
|
|
||||||
toggleSync->setToolTip(tr("Synchronize with Editor"));
|
|
||||||
connect(toggleSync, SIGNAL(clicked(bool)), ptw, SLOT(toggleAutoSynchronization()));
|
|
||||||
|
|
||||||
n.doockToolBarWidgets << filter << toggleSync;
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProjectTreeWidgetFactory::saveSettings(int position, QWidget *widget)
|
||||||
|
{
|
||||||
|
ProjectTreeWidget *ptw = qobject_cast<ProjectTreeWidget *>(widget);
|
||||||
|
Q_ASSERT(ptw);
|
||||||
|
m_core->settings()->setValue("ProjectTreeWidget."+QString::number(position)+".ProjectFilter", ptw->projectFilter());
|
||||||
|
m_core->settings()->setValue("ProjectTreeWidget."+QString::number(position)+".GeneratedFilter", ptw->generatedFilesFilter());
|
||||||
|
m_core->settings()->setValue("ProjectTreeWidget."+QString::number(position)+".SyncWithEditor", ptw->autoSynchronization());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProjectTreeWidgetFactory::restoreSettings(int position, QWidget *widget)
|
||||||
|
{
|
||||||
|
ProjectTreeWidget *ptw = qobject_cast<ProjectTreeWidget *>(widget);
|
||||||
|
Q_ASSERT(ptw);
|
||||||
|
ptw->setProjectFilter(m_core->settings()->value("ProjectTreeWidget."+QString::number(position)+".ProjectFilter", false).toBool());
|
||||||
|
ptw->setGeneratedFilesFilter(m_core->settings()->value("ProjectTreeWidget."+QString::number(position)+".GeneratedFilter", true).toBool());
|
||||||
|
ptw->setAutoSynchronization(m_core->settings()->value("ProjectTreeWidget."+QString::number(position)+".SyncWithEditor", true).toBool());
|
||||||
|
}
|
||||||
|
|||||||
@@ -60,6 +60,9 @@ public:
|
|||||||
|
|
||||||
bool autoSynchronization() const;
|
bool autoSynchronization() const;
|
||||||
void setAutoSynchronization(bool sync, bool syncNow = true);
|
void setAutoSynchronization(bool sync, bool syncNow = true);
|
||||||
|
bool projectFilter();
|
||||||
|
bool generatedFilesFilter();
|
||||||
|
QToolButton *toggleSync();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void toggleAutoSynchronization();
|
void toggleAutoSynchronization();
|
||||||
@@ -84,6 +87,7 @@ private:
|
|||||||
FlatModel *m_model;
|
FlatModel *m_model;
|
||||||
QAction *m_filterProjectsAction;
|
QAction *m_filterProjectsAction;
|
||||||
QAction *m_filterGeneratedFilesAction;
|
QAction *m_filterGeneratedFilesAction;
|
||||||
|
QToolButton *m_toggleSync;
|
||||||
|
|
||||||
QModelIndex m_subIndex;
|
QModelIndex m_subIndex;
|
||||||
QString m_modelId;
|
QString m_modelId;
|
||||||
@@ -100,6 +104,8 @@ public:
|
|||||||
virtual QString displayName();
|
virtual QString displayName();
|
||||||
virtual QKeySequence activationSequence();
|
virtual QKeySequence activationSequence();
|
||||||
virtual Core::NavigationView createWidget();
|
virtual Core::NavigationView createWidget();
|
||||||
|
void restoreSettings(int position, QWidget *widget);
|
||||||
|
void saveSettings(int position, QWidget *widget);
|
||||||
private:
|
private:
|
||||||
Core::ICore *m_core;
|
Core::ICore *m_core;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user