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; _corePlugin = corePlugin;
_pluginManager = _corePlugin->pluginManager(); _pluginManager = _corePlugin->pluginManager();
_settings = _pluginManager->settings();
setObjectName(Constants::MAIN_WINDOW); setObjectName(Constants::MAIN_WINDOW);
@ -48,12 +49,7 @@ CMainWindow::CMainWindow(CorePlugin *corePlugin, QWidget *parent)
Q_FOREACH(IAppPage *appPage, listAppPages) Q_FOREACH(IAppPage *appPage, listAppPages)
{ {
QWidget *tabWidget = new QWidget(_tabWidget); addAppPage(appPage);
_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);
} }
setDockNestingEnabled(true); setDockNestingEnabled(true);
@ -65,8 +61,12 @@ CMainWindow::CMainWindow(CorePlugin *corePlugin, QWidget *parent)
createMenus(); createMenus();
createStatusBar(); createStatusBar();
readSettings();
setWindowIcon(QIcon(Constants::ICON_NEL)); setWindowIcon(QIcon(Constants::ICON_NEL));
setWindowTitle(tr("Object Viewer Qt")); setWindowTitle(tr("Object Viewer Qt"));
connect(_pluginManager, SIGNAL(objectAdded(QObject *)), this, SLOT(checkObject(QObject *)));
} }
CMainWindow::~CMainWindow() CMainWindow::~CMainWindow()
@ -74,6 +74,13 @@ CMainWindow::~CMainWindow()
delete _pluginView; delete _pluginView;
} }
void CMainWindow::checkObject(QObject *obj)
{
IAppPage *appPage = qobject_cast<IAppPage *>(obj);
if (appPage)
addAppPage(appPage);
}
bool CMainWindow::showOptionsDialog(const QString &group, bool CMainWindow::showOptionsDialog(const QString &group,
const QString &page, const QString &page,
QWidget *parent) QWidget *parent)
@ -103,9 +110,22 @@ void CMainWindow::closeEvent(QCloseEvent *event)
return; return;
} }
} }
writeSettings();
QMainWindow::closeEvent(event); 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() void CMainWindow::createActions()
{ {
_openAction = new QAction(tr("&Open..."), this); _openAction = new QAction(tr("&Open..."), this);
@ -177,6 +197,22 @@ void CMainWindow::createDialogs()
_pluginView = new ExtensionSystem::CPluginView(_pluginManager, this); _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 */ } /* namespace Core */
/* end of file */ /* end of file */

View file

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