Skip to content

Commit

Permalink
Merge bitcoin#15874: Resolve the qt/guiutil <-> qt/optionsmodel CD
Browse files Browse the repository at this point in the history
fa1c8e2 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 fa1c8e2
  promag:
    utACK fa1c8e2.
  hebasto:
    utACK fa1c8e2
  practicalswift:
    utACK fa1c8e2
  jonasschnelli:
    utACK fa1c8e2

Tree-SHA512: 58cc4aee937c943d8de9dc97ef1789decfddb0287308f44e7e3a3b497c19e51da184988e17207544fff410168ec98dd49a3e62c47e84ad1f0cf6ef7247a80fb5
  • Loading branch information
jonasschnelli committed Apr 23, 2019
2 parents cd14d21 + fa1c8e2 commit e9e777e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ QList<QModelIndex> getEntryData(QAbstractItemView *view, int column)
return view->selectionModel()->selectedRows(column);
}

QString getDefaultDataDirectory()
{
return boostPathToQString(GetDefaultDataDir());
}

QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir,
const QString &filter,
QString *selectedSuffixOut)
Expand Down
5 changes: 5 additions & 0 deletions src/qt/guiutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ namespace GUIUtil

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
when no suffix is provided by the user.
Expand Down
13 changes: 4 additions & 9 deletions src/qt/intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ QString Intro::getDataDirectory()
void Intro::setDataDirectory(const QString &dataDir)
{
ui->dataDirectory->setText(dataDir);
if(dataDir == getDefaultDataDirectory())
if(dataDir == GUIUtil::getDefaultDataDirectory())
{
ui->dataDirDefault->setChecked(true);
ui->dataDirectory->setEnabled(false);
Expand All @@ -180,11 +180,6 @@ void Intro::setDataDirectory(const QString &dataDir)
}
}

QString Intro::getDefaultDataDirectory()
{
return GUIUtil::boostPathToQString(GetDefaultDataDir());
}

bool Intro::pickDataDirectory(interfaces::Node& node)
{
QSettings settings;
Expand All @@ -193,7 +188,7 @@ bool Intro::pickDataDirectory(interfaces::Node& node)
if(!gArgs.GetArg("-datadir", "").empty())
return true;
/* 1) Default data directory for operating system */
QString dataDir = getDefaultDataDirectory();
QString dataDir = GUIUtil::getDefaultDataDirectory();
/* 2) Allow QSettings to override default dir */
dataDir = settings.value("strDataDir", dataDir).toString();

Expand Down Expand Up @@ -239,7 +234,7 @@ bool Intro::pickDataDirectory(interfaces::Node& node)
* override -datadir in the bitcoin.conf file in the default data directory
* (to be consistent with bitcoind behavior)
*/
if(dataDir != getDefaultDataDirectory()) {
if(dataDir != GUIUtil::getDefaultDataDirectory()) {
node.softSetArg("-datadir", GUIUtil::qstringToBoostPath(dataDir).string()); // use OS locale for path setting
}
return true;
Expand Down Expand Up @@ -293,7 +288,7 @@ void Intro::on_ellipsisButton_clicked()

void Intro::on_dataDirDefault_clicked()
{
setDataDirectory(getDefaultDataDirectory());
setDataDirectory(GUIUtil::getDefaultDataDirectory());
}

void Intro::on_dataDirCustom_clicked()
Expand Down
5 changes: 0 additions & 5 deletions src/qt/intro.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ class Intro : public QDialog
*/
static bool pickDataDirectory(interfaces::Node& node);

/**
* Determine default data directory for operating system.
*/
static QString getDefaultDataDirectory();

Q_SIGNALS:
void requestCheck();

Expand Down
5 changes: 2 additions & 3 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <net.h>
#include <netbase.h>
#include <txdb.h> // for -dbcache defaults
#include <qt/intro.h>

#include <QNetworkProxy>
#include <QSettings>
Expand Down Expand Up @@ -110,7 +109,7 @@ void OptionsModel::Init(bool resetSettings)
addOverriddenOption("-par");

if (!settings.contains("strDataDir"))
settings.setValue("strDataDir", Intro::getDefaultDataDirectory());
settings.setValue("strDataDir", GUIUtil::getDefaultDataDirectory());

// Wallet
#ifdef ENABLE_WALLET
Expand Down Expand Up @@ -187,7 +186,7 @@ void OptionsModel::Reset()
BackupSettings(GetDataDir(true) / "guisettings.ini.bak", settings);

// Save the strDataDir setting
QString dataDir = Intro::getDefaultDataDirectory();
QString dataDir = GUIUtil::getDefaultDataDirectory();
dataDir = settings.value("strDataDir", dataDir).toString();

// Remove all entries from our QSettings object
Expand Down
1 change: 0 additions & 1 deletion test/lint/lint-circular-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"txmempool -> validation -> validationinterface -> txmempool"
"qt/addressbookpage -> qt/bitcoingui -> qt/walletview -> qt/receivecoinsdialog -> qt/addressbookpage"
"qt/addressbookpage -> qt/bitcoingui -> qt/walletview -> qt/signverifymessagedialog -> qt/addressbookpage"
"qt/guiutil -> qt/walletmodel -> qt/optionsmodel -> qt/intro -> qt/guiutil"
"qt/addressbookpage -> qt/bitcoingui -> qt/walletview -> qt/sendcoinsdialog -> qt/sendcoinsentry -> qt/addressbookpage"
)

Expand Down

0 comments on commit e9e777e

Please sign in to comment.