aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/pathchooser.h
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@theqtcompany.com>2015-02-27 16:24:29 +0100
committerChristian Kandeler <christian.kandeler@theqtcompany.com>2015-03-02 11:04:47 +0000
commitafa47e1048ad4cf219a6f06ee8ebd43e1a681b9c (patch)
tree9068b9b2e80e5110fbf5e283fc629705c4a7915c /src/libs/utils/pathchooser.h
parentd2892026c8eb979c046b14095f82f4f69218717f (diff)
PathChooser: Replace virtual function with function object.
This allows calling code to add its own path validation without creating a derived class. Some notes on API decisions: - Since all current users of this functionality call the base class implementation in their derived function, no functionality is provided to completely replace the path validation function (as opposed to merely add checks). In the unlikely case that this is ever needed, we can easily add it. - The member function is called "setAdditionalValidator" rather than the shorter "addValidator" because the latter might suggest that repeated calls will chain the provided functions. - There is also no functionality to conveniently remove the additional validator, because such dynamic behavior was not needed so far. This patch only does the minimum changes to the calling sites that are required for them to continue compiling and working. Removal of the derived classes that are no longer needed happens in a follow-up patch. Change-Id: I5282835b5dd227149748a7f567006beb288d8aa3 Reviewed-by: hjk <hjk@theqtcompany.com> Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Diffstat (limited to 'src/libs/utils/pathchooser.h')
-rw-r--r--src/libs/utils/pathchooser.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/libs/utils/pathchooser.h b/src/libs/utils/pathchooser.h
index 21eccba9357..ff4ea83bdca 100644
--- a/src/libs/utils/pathchooser.h
+++ b/src/libs/utils/pathchooser.h
@@ -35,6 +35,8 @@
#include <QWidget>
+#include <functional>
+
QT_BEGIN_NAMESPACE
class QAbstractButton;
class QLineEdit;
@@ -108,7 +110,7 @@ public:
/** Returns the suggested label title when used in a form layout. */
static QString label();
- virtual bool validatePath(const QString &path, QString *errorMessage = 0);
+ bool validatePath(const QString &path, QString *errorMessage = 0);
/** Return the home directory, which needs some fixing under Windows. */
static QString homePath();
@@ -137,6 +139,10 @@ public:
void setReadOnly(bool b);
void triggerChanged();
+
+ typedef std::function<bool(const QString &, QString *)> PathValidator;
+ void setAdditionalPathValidator(const PathValidator &pathValidator);
+
private:
// Returns overridden title or the one from <title>
QString makeDialogTitle(const QString &title);