diff options
author | laanwj <126646+laanwj@users.noreply.github.com> | 2022-06-22 06:53:03 +0200 |
---|---|---|
committer | laanwj <126646+laanwj@users.noreply.github.com> | 2022-06-22 07:12:10 +0200 |
commit | 58b9d6cf9e9b801be9c677a3ae121e5d2950ce66 (patch) | |
tree | 064394d628f8c882131bab6fa272a4e1a6a6daf0 /src | |
parent | 174b821e64d61d7cd9466c7b73f71b2eb8508f92 (diff) | |
parent | 67364ebe4c499eb8effe8dac11a5e3648f30c6c7 (diff) | |
download | bitcoin-58b9d6cf9e9b801be9c677a3ae121e5d2950ce66.tar.xz |
Merge bitcoin-core/gui#620: Replace `QRegExp` with `QRegularExpression`
67364ebe4c499eb8effe8dac11a5e3648f30c6c7 test, qt: Add tests for `GUIUtil::extractFirstSuffixFromFilter` (w0xlt)
ace9af5688662a56d855bd26f36bc5c145b909e3 qt: Replace `QRegExp` with `QRegularExpression` (w0xlt)
c378535e28e0c54353fde9c4a66cb3134a3ee742 qt: Add a function that extracts the suffix from a filter (w0xlt)
Pull request description:
Picking up https://github.com/bitcoin-core/gui/pull/606 (labeled "Up for grabs") and applying https://github.com/bitcoin-core/gui/pull/606#pullrequestreview-984607067 and https://github.com/bitcoin-core/gui/pull/606#issuecomment-1137149907.
Replaces occurrences of `QRegExp` usage with `QRegularExpression` as part of the roadmap for Qt6 integration.
Fixes https://github.com/bitcoin-core/gui/issues/578
ACKs for top commit:
laanwj:
Code review and lightly tested ACK 67364ebe4c499eb8effe8dac11a5e3648f30c6c7
hebasto:
ACK 67364ebe4c499eb8effe8dac11a5e3648f30c6c7
Tree-SHA512: 4a17d83e557bc635cbd1a15776856e9edb7162b23a369ccbd2ac59c68b8a1ea663baaa7d5ad98e419dc03b91ef3315c768eeadc01c0b29162de109493161e814
Diffstat (limited to 'src')
-rw-r--r-- | src/qt/guiutil.cpp | 30 | ||||
-rw-r--r-- | src/qt/guiutil.h | 8 | ||||
-rw-r--r-- | src/qt/test/optiontests.cpp | 10 | ||||
-rw-r--r-- | src/qt/test/optiontests.h | 1 | ||||
-rw-r--r-- | src/qt/utilitydialog.cpp | 8 |
5 files changed, 38 insertions, 19 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 186ed4f644..2551be0af3 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -53,6 +53,7 @@ #include <QMouseEvent> #include <QPluginLoader> #include <QProgressDialog> +#include <QRegularExpression> #include <QScreen> #include <QSettings> #include <QShortcut> @@ -289,6 +290,17 @@ QString getDefaultDataDirectory() return PathToQString(GetDefaultDataDir()); } +QString ExtractFirstSuffixFromFilter(const QString& filter) +{ + QRegularExpression filter_re(QStringLiteral(".* \\(\\*\\.(.*)[ \\)]"), QRegularExpression::InvertedGreedinessOption); + QString suffix; + QRegularExpressionMatch m = filter_re.match(filter); + if (m.hasMatch()) { + suffix = m.captured(1); + } + return suffix; +} + QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut) @@ -306,13 +318,7 @@ QString getSaveFileName(QWidget *parent, const QString &caption, const QString & /* Directly convert path to native OS path separators */ QString result = QDir::toNativeSeparators(QFileDialog::getSaveFileName(parent, caption, myDir, filter, &selectedFilter)); - /* Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...) */ - QRegExp filter_re(".* \\(\\*\\.(.*)[ \\)]"); - QString selectedSuffix; - if(filter_re.exactMatch(selectedFilter)) - { - selectedSuffix = filter_re.cap(1); - } + QString selectedSuffix = ExtractFirstSuffixFromFilter(selectedFilter); /* Add suffix if needed */ QFileInfo info(result); @@ -354,14 +360,8 @@ QString getOpenFileName(QWidget *parent, const QString &caption, const QString & if(selectedSuffixOut) { - /* Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...) */ - QRegExp filter_re(".* \\(\\*\\.(.*)[ \\)]"); - QString selectedSuffix; - if(filter_re.exactMatch(selectedFilter)) - { - selectedSuffix = filter_re.cap(1); - } - *selectedSuffixOut = selectedSuffix; + *selectedSuffixOut = ExtractFirstSuffixFromFilter(selectedFilter); + ; } return result; } diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index e38ac6026a..acbe415a91 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -123,6 +123,14 @@ namespace GUIUtil */ QString getDefaultDataDirectory(); + /** + * Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...). + * + * @param[in] filter Filter specification such as "Comma Separated Files (*.csv)" + * @return QString + */ + QString ExtractFirstSuffixFromFilter(const QString& filter); + /** Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when no suffix is provided by the user. diff --git a/src/qt/test/optiontests.cpp b/src/qt/test/optiontests.cpp index 3bd0af19ad..17ffeb220b 100644 --- a/src/qt/test/optiontests.cpp +++ b/src/qt/test/optiontests.cpp @@ -4,6 +4,7 @@ #include <init.h> #include <qt/bitcoin.h> +#include <qt/guiutil.h> #include <qt/test/optiontests.h> #include <test/util/setup_common.h> #include <util/system.h> @@ -122,3 +123,12 @@ void OptionTests::parametersInteraction() QVERIFY(!settings.contains("fListen")); gArgs.ClearPathCache(); } + +void OptionTests::extractFilter() +{ + QString filter = QString("Partially Signed Transaction (Binary) (*.psbt)"); + QCOMPARE(GUIUtil::ExtractFirstSuffixFromFilter(filter), "psbt"); + + filter = QString("Image (*.png *.jpg)"); + QCOMPARE(GUIUtil::ExtractFirstSuffixFromFilter(filter), "png"); +} diff --git a/src/qt/test/optiontests.h b/src/qt/test/optiontests.h index 286d785572..57ec8bd0f2 100644 --- a/src/qt/test/optiontests.h +++ b/src/qt/test/optiontests.h @@ -22,6 +22,7 @@ private Q_SLOTS: void migrateSettings(); void integerGetArgBug(); void parametersInteraction(); + void extractFilter(); private: interfaces::Node& m_node; diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index e68095f8e5..4894cac905 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -22,7 +22,8 @@ #include <QCloseEvent> #include <QLabel> #include <QMainWindow> -#include <QRegExp> +#include <QRegularExpression> +#include <QString> #include <QTextCursor> #include <QTextTable> #include <QVBoxLayout> @@ -44,9 +45,8 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : /// HTML-format the license message from the core QString licenseInfoHTML = QString::fromStdString(LicenseInfo()); // Make URLs clickable - QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2); - uri.setMinimal(true); // use non-greedy matching - licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>"); + QRegularExpression uri(QStringLiteral("<(.*)>"), QRegularExpression::InvertedGreedinessOption); + licenseInfoHTML.replace(uri, QStringLiteral("<a href=\"\\1\">\\1</a>")); // Replace newlines with HTML breaks licenseInfoHTML.replace("\n", "<br>"); |