Merge #15874: Resolve the qt/guiutil <-> qt/optionsmodel CD

fa1c8e297 Resolve the qt/guiutil <-> qt/optionsmodal CD (251)

Pull request description:

  This pull request attempts to resolve the `qt/guiutil` <-> `qt/optionsmodel` circular dependency.

  The `Intro` class in `qt/intro` has a static member function `getDefaultDataDirectory` which is used by `qt/optionsmodel` and creates the circular dependency
  `qt/guiutil -> qt/walletmodel -> qt/optionsmodel -> qt/intro -> qt/guiutil`.

  This circular dependency is resolved by moving `Intro::getDefaultDataDirectory` to `GUIUtil::getDefaultDataDirectory` without modifying the implementation.

ACKs for commit fa1c8e:
  MarcoFalke:
    utACK fa1c8e297825fbaeda049c8bf36f39de919a9989
  promag:
    utACK fa1c8e2.
  hebasto:
    utACK fa1c8e297825fbaeda049c8bf36f39de919a9989
  practicalswift:
    utACK fa1c8e297825fbaeda049c8bf36f39de919a9989
  jonasschnelli:
    utACK fa1c8e297825fbaeda049c8bf36f39de919a9989

Tree-SHA512: 58cc4aee937c943d8de9dc97ef1789decfddb0287308f44e7e3a3b497c19e51da184988e17207544fff410168ec98dd49a3e62c47e84ad1f0cf6ef7247a80fb5
This commit is contained in:
Jonas Schnelli 2019-04-23 18:10:45 +02:00 committed by Munkybooty
parent e12e018dcf
commit 4f03473dbd
5 changed files with 16 additions and 17 deletions

View File

@ -469,6 +469,11 @@ QList<QModelIndex> getEntryData(QAbstractItemView *view, int column)
return view->selectionModel()->selectedRows(column); return view->selectionModel()->selectedRows(column);
} }
QString getDefaultDataDirectory()
{
return boostPathToQString(GetDefaultDataDir());
}
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir,
const QString &filter, const QString &filter,
QString *selectedSuffixOut) QString *selectedSuffixOut)

View File

@ -145,6 +145,11 @@ namespace GUIUtil
void setClipboard(const QString& str); void setClipboard(const QString& str);
/**
* Determine default data directory for operating system.
*/
QString getDefaultDataDirectory();
/** Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix /** Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix
when no suffix is provided by the user. when no suffix is provided by the user.

View File

@ -170,7 +170,7 @@ QString Intro::getDataDirectory()
void Intro::setDataDirectory(const QString &dataDir) void Intro::setDataDirectory(const QString &dataDir)
{ {
ui->dataDirectory->setText(dataDir); ui->dataDirectory->setText(dataDir);
if(dataDir == getDefaultDataDirectory()) if(dataDir == GUIUtil::getDefaultDataDirectory())
{ {
ui->dataDirDefault->setChecked(true); ui->dataDirDefault->setChecked(true);
ui->dataDirectory->setEnabled(false); ui->dataDirectory->setEnabled(false);
@ -182,11 +182,6 @@ void Intro::setDataDirectory(const QString &dataDir)
} }
} }
QString Intro::getDefaultDataDirectory()
{
return GUIUtil::boostPathToQString(GetDefaultDataDir());
}
bool Intro::pickDataDirectory(interfaces::Node& node) bool Intro::pickDataDirectory(interfaces::Node& node)
{ {
QSettings settings; QSettings settings;
@ -195,7 +190,7 @@ bool Intro::pickDataDirectory(interfaces::Node& node)
if(!gArgs.GetArg("-datadir", "").empty()) if(!gArgs.GetArg("-datadir", "").empty())
return true; return true;
/* 1) Default data directory for operating system */ /* 1) Default data directory for operating system */
QString dataDirDefaultCurrent = getDefaultDataDirectory(); QString dataDirDefaultCurrent = GUIUtil::getDefaultDataDirectory();
/* 2) Allow QSettings to override default dir */ /* 2) Allow QSettings to override default dir */
QString dataDir = settings.value("strDataDir", dataDirDefaultCurrent).toString(); QString dataDir = settings.value("strDataDir", dataDirDefaultCurrent).toString();
/* 3) Check to see if default datadir is the one we expect */ /* 3) Check to see if default datadir is the one we expect */
@ -246,7 +241,7 @@ bool Intro::pickDataDirectory(interfaces::Node& node)
* override -datadir in the dash.conf file in the default data directory * override -datadir in the dash.conf file in the default data directory
* (to be consistent with dashd behavior) * (to be consistent with dashd behavior)
*/ */
if(dataDir != dataDirDefaultCurrent) { if(dataDir != GUIUtil::getDefaultDataDirectory()) {
node.softSetArg("-datadir", GUIUtil::qstringToBoostPath(dataDir).string()); // use OS locale for path setting node.softSetArg("-datadir", GUIUtil::qstringToBoostPath(dataDir).string()); // use OS locale for path setting
} }
return true; return true;
@ -300,7 +295,7 @@ void Intro::on_ellipsisButton_clicked()
void Intro::on_dataDirDefault_clicked() void Intro::on_dataDirDefault_clicked()
{ {
setDataDirectory(getDefaultDataDirectory()); setDataDirectory(GUIUtil::getDefaultDataDirectory());
} }
void Intro::on_dataDirCustom_clicked() void Intro::on_dataDirCustom_clicked()

View File

@ -48,11 +48,6 @@ public:
*/ */
static bool pickDataDirectory(interfaces::Node& node); static bool pickDataDirectory(interfaces::Node& node);
/**
* Determine default data directory for operating system.
*/
static QString getDefaultDataDirectory();
Q_SIGNALS: Q_SIGNALS:
void requestCheck(); void requestCheck();

View File

@ -12,7 +12,6 @@
#include <qt/bitcoinunits.h> #include <qt/bitcoinunits.h>
#include <qt/guiconstants.h> #include <qt/guiconstants.h>
#include <qt/guiutil.h> #include <qt/guiutil.h>
#include <qt/intro.h>
#include <interfaces/node.h> #include <interfaces/node.h>
#include <validation.h> // For DEFAULT_SCRIPTCHECK_THREADS #include <validation.h> // For DEFAULT_SCRIPTCHECK_THREADS
@ -210,7 +209,7 @@ void OptionsModel::Init(bool resetSettings)
addOverriddenOption("-par"); addOverriddenOption("-par");
if (!settings.contains("strDataDir")) if (!settings.contains("strDataDir"))
settings.setValue("strDataDir", Intro::getDefaultDataDirectory()); settings.setValue("strDataDir", GUIUtil::getDefaultDataDirectory());
// Wallet // Wallet
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
@ -311,7 +310,7 @@ void OptionsModel::Reset()
BackupSettings(GetDataDir(true) / "guisettings.ini.bak", settings); BackupSettings(GetDataDir(true) / "guisettings.ini.bak", settings);
// Save the strDataDir setting // Save the strDataDir setting
QString dataDir = Intro::getDefaultDataDirectory(); QString dataDir = GUIUtil::getDefaultDataDirectory();
dataDir = settings.value("strDataDir", dataDir).toString(); dataDir = settings.value("strDataDir", dataDir).toString();
// Remove all entries from our QSettings object // Remove all entries from our QSettings object