diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp index b460c0ea57b..b3916630a1a 100644 --- a/src/libs/utils/pathchooser.cpp +++ b/src/libs/utils/pathchooser.cpp @@ -189,6 +189,7 @@ public: QString m_dialogTitleOverride; QString m_dialogFilter; QString m_initialBrowsePathOverride; + QString m_defaultValue; FilePath m_baseDirectory; Environment m_environment; BinaryVersionToolTipEventFilter *m_binaryVersionToolTipEventFilter = nullptr; @@ -521,6 +522,12 @@ void PathChooser::setAboutToShowContextMenuHandler(PathChooser::AboutToShowConte s_aboutToShowContextMenuHandler = handler; } +void PathChooser::setDefaultValue(const QString &defaultValue) +{ + d->m_defaultValue = defaultValue; + d->m_lineEdit->setPlaceholderText(defaultValue); +} + FancyLineEdit::ValidationFunction PathChooser::defaultValidationFunction() const { return std::bind(&PathChooser::validatePath, this, std::placeholders::_1, std::placeholders::_2); @@ -528,15 +535,19 @@ FancyLineEdit::ValidationFunction PathChooser::defaultValidationFunction() const bool PathChooser::validatePath(FancyLineEdit *edit, QString *errorMessage) const { - const QString path = edit->text(); - QString expandedPath = d->expandedPath(path); + QString path = edit->text(); if (path.isEmpty()) { - if (errorMessage) - *errorMessage = tr("The path must not be empty."); - return false; + if (!d->m_defaultValue.isEmpty()) { + path = d->m_defaultValue; + } else { + if (errorMessage) + *errorMessage = tr("The path must not be empty."); + return false; + } } + const QString expandedPath = d->expandedPath(path); if (expandedPath.isEmpty()) { if (errorMessage) *errorMessage = tr("The path \"%1\" expanded to an empty string.").arg(QDir::toNativeSeparators(path)); diff --git a/src/libs/utils/pathchooser.h b/src/libs/utils/pathchooser.h index cc864b48be1..b7320d6c5d3 100644 --- a/src/libs/utils/pathchooser.h +++ b/src/libs/utils/pathchooser.h @@ -153,6 +153,10 @@ public: // Deprecated. Use filePath() FilePath fileName() const { return filePath(); } + // this sets the placeHolderText to defaultValue and enables to use this as + // input value during validation if the real value is empty + // setting an empty QString will disable this and clear the placeHolderText + void setDefaultValue(const QString &defaultValue); private: bool validatePath(FancyLineEdit *edit, QString *errorMessage) const; // Returns overridden title or the one from