Changed: #1193 Added reading and writing settings in core plugin.

This commit is contained in:
dnk-88 2011-02-13 16:02:28 +02:00
parent b0f6962f4c
commit 15db12add9
2 changed files with 49 additions and 11 deletions

View file

@ -37,6 +37,7 @@ CMainWindow::CMainWindow(CorePlugin *corePlugin, QWidget *parent)
{
_corePlugin = corePlugin;
_pluginManager = _corePlugin->pluginManager();
_settings = _pluginManager->settings();
setObjectName(Constants::MAIN_WINDOW);
@ -48,12 +49,7 @@ CMainWindow::CMainWindow(CorePlugin *corePlugin, QWidget *parent)
Q_FOREACH(IAppPage *appPage, listAppPages)
{
QWidget *tabWidget = new QWidget(_tabWidget);
_tabWidget->addTab(tabWidget, appPage->icon(), appPage->trName());
QGridLayout *gridLayout = new QGridLayout(tabWidget);
gridLayout->setObjectName(QString::fromUtf8("gridLayout_") + appPage->id());
gridLayout->setContentsMargins(0, 0, 0, 0);
gridLayout->addWidget(appPage->widget(), 0, 0, 1, 1);
addAppPage(appPage);
}
setDockNestingEnabled(true);
@ -65,8 +61,12 @@ CMainWindow::CMainWindow(CorePlugin *corePlugin, QWidget *parent)
createMenus();
createStatusBar();
readSettings();
setWindowIcon(QIcon(Constants::ICON_NEL));
setWindowTitle(tr("Object Viewer Qt"));
connect(_pluginManager, SIGNAL(objectAdded(QObject *)), this, SLOT(checkObject(QObject *)));
}
CMainWindow::~CMainWindow()
@ -74,6 +74,13 @@ CMainWindow::~CMainWindow()
delete _pluginView;
}
void CMainWindow::checkObject(QObject *obj)
{
IAppPage *appPage = qobject_cast<IAppPage *>(obj);
if (appPage)
addAppPage(appPage);
}
bool CMainWindow::showOptionsDialog(const QString &group,
const QString &page,
QWidget *parent)
@ -103,9 +110,22 @@ void CMainWindow::closeEvent(QCloseEvent *event)
return;
}
}
writeSettings();
QMainWindow::closeEvent(event);
}
void CMainWindow::addAppPage(IAppPage *appPage)
{
QWidget *tabWidget = new QWidget(_tabWidget);
_tabWidget->addTab(tabWidget, appPage->icon(), appPage->trName());
QGridLayout *gridLayout = new QGridLayout(tabWidget);
gridLayout->setObjectName(QString::fromUtf8("gridLayout_") + appPage->id());
gridLayout->setContentsMargins(0, 0, 0, 0);
gridLayout->addWidget(appPage->widget(), 0, 0, 1, 1);
}
void CMainWindow::createActions()
{
_openAction = new QAction(tr("&Open..."), this);
@ -177,6 +197,22 @@ void CMainWindow::createDialogs()
_pluginView = new ExtensionSystem::CPluginView(_pluginManager, this);
}
void CMainWindow::readSettings()
{
_settings->beginGroup("MainWindowSettings");
restoreState(_settings->value("QtWindowState").toByteArray());
restoreGeometry(_settings->value("QtWindowGeometry").toByteArray());
_settings->endGroup();
}
void CMainWindow::writeSettings()
{
_settings->beginGroup("MainWindowSettings");
_settings->setValue("QtWindowState", saveState());
_settings->setValue("QtWindowGeometry", saveGeometry());
_settings->endGroup();
}
} /* namespace Core */
/* end of file */

View file

@ -32,6 +32,7 @@ namespace Core
{
class CSettingsDialog;
class CorePlugin;
class IAppPage;
class CMainWindow : public QMainWindow
{
@ -41,12 +42,8 @@ public:
CMainWindow(CorePlugin *corePlugin, QWidget *parent = 0);
~CMainWindow();
inline QSettings *settings() const
{
return _settings;
}
private Q_SLOTS:
void checkObject(QObject *obj);
bool showOptionsDialog(const QString &group = QString(),
const QString &page = QString(),
QWidget *parent = 0);
@ -55,11 +52,16 @@ protected:
virtual void closeEvent(QCloseEvent *event);
private:
void addAppPage(IAppPage *appPage);
void createActions();
void createMenus();
void createStatusBar();
void createDialogs();
void readSettings();
void writeSettings();
ExtensionSystem::IPluginManager *_pluginManager;
ExtensionSystem::CPluginView *_pluginView;
CorePlugin *_corePlugin;