forked from qt-creator/qt-creator
Utils: Simplify pathchooser validation
Allow to set a default value for the PathChooser which will be used on the one hand as placeHolderText and on the other hand for the default validation if the underlying line edit has no text set. Change-Id: I49d2f773cf3933cb30b54ee6de82290b480e743d Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -49,24 +49,10 @@ static void setupPathChooser(Utils::PathChooser *const chooser,
|
||||
const QString &historyCompleterId)
|
||||
{
|
||||
chooser->setPromptDialogTitle(promptDiaglogTitle);
|
||||
chooser->lineEdit()->setPlaceholderText(placeHolderText);
|
||||
chooser->setDefaultValue(placeHolderText);
|
||||
chooser->setPath(pathFromSettings);
|
||||
chooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
||||
chooser->setHistoryCompleter(historyCompleterId);
|
||||
chooser->setValidationFunction([chooser](Utils::FancyLineEdit *edit, QString *errorMessage) {
|
||||
const QString currentFilePath = chooser->filePath().toString();
|
||||
Utils::PathChooser pc;
|
||||
Utils::PathChooser *helperPathChooser;
|
||||
if (currentFilePath.isEmpty()) {
|
||||
pc.setExpectedKind(chooser->expectedKind());
|
||||
pc.setPath(edit->placeholderText());
|
||||
helperPathChooser = &pc;
|
||||
} else {
|
||||
helperPathChooser = chooser;
|
||||
}
|
||||
|
||||
return chooser->defaultValidationFunction()(helperPathChooser->lineEdit(), errorMessage);
|
||||
});
|
||||
}
|
||||
|
||||
SettingsWidget *SettingsWidget::instance()
|
||||
|
||||
Reference in New Issue
Block a user