Skip to content

Commit

Permalink
Fix settings options using config()
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Mar 13, 2016
1 parent 4c00429 commit a294dd4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
15 changes: 15 additions & 0 deletions src/gui/configurationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,21 @@ QString ConfigurationManager::optionValue(const QString &name) const
return m_options.value(name).value().toString();
}

bool ConfigurationManager::setOptionValue(const QString &name, const QString &value)
{
if ( !m_options.contains(name) )
return false;

const QString oldValue = optionValue(name);
m_options[name].setValue(value);
if ( optionValue(name) == oldValue )
return false;

AppConfig().setOption(name, m_options[name].value());
emit configurationChanged();
return true;
}

QString ConfigurationManager::optionToolTip(const QString &name) const
{
return m_options[name].tooltip();
Expand Down
5 changes: 5 additions & 0 deletions src/gui/configurationmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ class ConfigurationManager : public QDialog

/** Return list of options that can be set or view using command line. */
QStringList options() const;

/** Return value of an option. */
QString optionValue(const QString &name) const;

/** Set value of an option and returns true only if the value changes. */
bool setOptionValue(const QString &name, const QString &value);

/** Return tooltip text for option with given @a name. */
QString optionToolTip(const QString &name) const;

Expand Down
11 changes: 7 additions & 4 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ MainWindow::MainWindow(ItemFactory *itemFactory, QWidget *parent)
this, SLOT(updateIconSnip()) );
connect( qApp, SIGNAL(aboutToQuit()),
this, SLOT(onAboutToQuit()) );
connect( this, SIGNAL(configurationChanged()),
this, SLOT(loadSettings()) );

connect(&m_itemMenuCommandTester, SIGNAL(commandPassed(Command,bool)),
SLOT(addCommandsToItemMenu(Command,bool)));
Expand Down Expand Up @@ -1901,13 +1903,16 @@ QString MainWindow::getUserOptionsDescription() const
QString MainWindow::getUserOptionValue(const QString &name) const
{
ConfigurationManager configurationManager(m_sharedData->itemFactory);
configurationManager.loadSettings();
return configurationManager.optionValue(name);
}

void MainWindow::setUserOptionValue(const QString &name, const QString &value)
{
AppConfig().setOption(name, value);
emit configurationChanged();
ConfigurationManager configurationManager(m_sharedData->itemFactory);
configurationManager.loadSettings();
if ( configurationManager.setOptionValue(name, value) )
emit configurationChanged();
}

bool MainWindow::hasUserOption(const QString &name) const
Expand Down Expand Up @@ -2278,8 +2283,6 @@ void MainWindow::openPreferences()
// notify window if configuration changes
connect( &configurationManager, SIGNAL(configurationChanged()),
this, SIGNAL(configurationChanged()) );
connect( this, SIGNAL(configurationChanged()),
this, SLOT(loadSettings()) );
connect( &configurationManager, SIGNAL(error(QString)),
this, SLOT(showError(QString)) );
connect( &configurationManager, SIGNAL(openCommandDialogRequest()),
Expand Down
1 change: 0 additions & 1 deletion src/tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ Tests::Tests(const TestInterfacePtr &test, QObject *parent)

void Tests::initTestCase()
{
TEST(m_test->init());
}

void Tests::cleanupTestCase()
Expand Down

0 comments on commit a294dd4

Please sign in to comment.