Commit 5a06efed authored by Frédéric Larue's avatar Frédéric Larue
Browse files

QSettings system revisited.

parent 857fec71
......@@ -39,7 +39,8 @@ UIMainWindow::UIMainWindow(QWidget *parent) :
QMainWindow( parent ),
ui( new Ui::MainWindow ),
m_CurrentViewer( NULL ),
m_CurrentProject( NULL )
m_CurrentProject( NULL ),
m_UserSettings( NULL )
{
}
......@@ -51,14 +52,21 @@ UIMainWindow::~UIMainWindow()
bool UIMainWindow::saveUISettings() const
{
QSettings settings( QSettings::IniFormat, QSettings::UserScope, "ExRealis", "Settings" );
settings.setValue( "geometry", saveGeometry() );
settings.setValue( "windowState", saveState() );
// Get user settings file.
QSettings *settings = getUserSettings();
// Store geometry and state of the main window and the dock widgets.
settings->setValue( "geometry", saveGeometry() );
settings->setValue( "windowState", saveState() );
// Store the list of recently used projects.
QStringList recents;
for( auto r : m_RecentProjects )
recents.push_back( r->text() );
settings.setValue( "recent", recents );
settings->setValue( "recent", recents );
return true;
}
......@@ -66,15 +74,22 @@ bool UIMainWindow::saveUISettings() const
bool UIMainWindow::loadUISettings()
{
QSettings settings( QSettings::IniFormat, QSettings::UserScope, "ExRealis", "Settings" );
// Get user settings file.
QSettings *settings = getUserSettings();
// Load geometry and state of the main window and the dock widgets.
if( settings.value("geometry").toByteArray().isEmpty() || settings.value("windowState").toByteArray().isEmpty() )
if( settings->value("geometry" ).toByteArray().isEmpty() ||
settings->value("windowState").toByteArray().isEmpty() )
return false;
restoreGeometry( settings.value("geometry").toByteArray() );
restoreState( settings.value("windowState").toByteArray() );
restoreGeometry( settings->value("geometry" ).toByteArray() );
restoreState ( settings->value("windowState").toByteArray() );
QStringList recents = settings.value( "recent" ).toStringList();
// Load the list of recently used projects.
QStringList recents = settings->value( "recent" ).toStringList();
for( auto r=recents.rbegin(); r!=recents.rend(); ++r )
updateRecentListEntry( *r );
......@@ -169,6 +184,11 @@ void UIMainWindow::declareCustomMenuAction( const QString& menuName, QAction* ac
void UIMainWindow::init()
{
QString compagnyName, applicationName, shortDescription;
applicationInfo( compagnyName, applicationName, shortDescription );
m_UserSettings = new QSettings( QSettings::IniFormat, QSettings::UserScope, compagnyName + "/" + applicationName, "Settings" );
onDeclaringToolCategories(); // must be called before setupUi(...) because tool categories are required for the AlgorithmSelector widget.
ui->setupUi(this);
......@@ -234,6 +254,8 @@ void UIMainWindow::release()
closeAllProjects();
delete m_UserSettings;
ui->toolSelector->releaseAllTools();
delete ui;
......@@ -243,7 +265,10 @@ void UIMainWindow::release()
void UIMainWindow::setMainWindowTitleInfos( const QString& str )
{
QString title = mainWindowTitle();
QString compagnyName, applicationName, shortDescription;
applicationInfo( compagnyName, applicationName, shortDescription );
QString title = applicationName + " / " + shortDescription;
if( str.length() )
{
......
......@@ -83,8 +83,10 @@ class GUIMAIN_API UIMainWindow : public QMainWindow
QList< WidgetStackItem > m_CentralWidgetStack;
QSettings *m_UserSettings;
public:
UIMainWindow(QWidget *parent = 0);
UIMainWindow( QWidget *parent = NULL );
~UIMainWindow();
void setViewerMode( DisplayDoF mode );
......@@ -96,8 +98,9 @@ public:
void init();
void release();
virtual QString mainWindowTitle() const = 0;
virtual void applicationInfo( QString &compagnyName, QString &applicationName, QString &shortDescription ) const = 0;
virtual QString projectFileExtension() const = 0;
inline QSettings* getUserSettings() const { return m_UserSettings; }
virtual void onInitializingApp() {}
virtual void onReleasingApp() {}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment