Utils: Make FancyLineEdit placeholder validation optional

Validation makes only sense if the placeholder is similar to
the actual contents, like a file path, not for explanatory text.

Amends 3dcdbe9.

Change-Id: I81ff7a3cf72f28c0fe49824b574b0997ada2d09b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2023-06-09 11:57:29 +02:00
parent d0cf49db47
commit f19481e6c7
5 changed files with 23 additions and 2 deletions

View File

@@ -671,6 +671,7 @@ public:
// the validation changes focus by opening a dialog
bool m_blockAutoApply = false;
bool m_allowPathFromDevice = true;
bool m_validatePlaceHolder = false;
template<class Widget> void updateWidgetFromCheckStatus(StringAspect *aspect, Widget *w)
{
@@ -985,6 +986,13 @@ void StringAspect::setAllowPathFromDevice(bool allowPathFromDevice)
d->m_pathChooserDisplay->setAllowPathFromDevice(allowPathFromDevice);
}
void StringAspect::setValidatePlaceHolder(bool validatePlaceHolder)
{
d->m_validatePlaceHolder = validatePlaceHolder;
if (d->m_pathChooserDisplay)
d->m_pathChooserDisplay->lineEdit()->setValidatePlaceHolder(validatePlaceHolder);
}
/*!
Sets \a elideMode as label elide mode.
*/
@@ -1131,6 +1139,7 @@ void StringAspect::addToLayout(LayoutItem &parent)
d->m_pathChooserDisplay->setPromptDialogTitle(d->m_prompDialogTitle);
d->m_pathChooserDisplay->setCommandVersionArguments(d->m_commandVersionArguments);
d->m_pathChooserDisplay->setAllowPathFromDevice(d->m_allowPathFromDevice);
d->m_pathChooserDisplay->lineEdit()->setValidatePlaceHolder(d->m_validatePlaceHolder);
if (defaultValue() == value())
d->m_pathChooserDisplay->setDefaultValue(defaultValue());
else
@@ -1169,6 +1178,7 @@ void StringAspect::addToLayout(LayoutItem &parent)
d->m_lineEditDisplay->setValidationFunction(d->m_validator);
d->m_lineEditDisplay->setTextKeepingActiveCursor(displayedString);
d->m_lineEditDisplay->setReadOnly(isReadOnly());
d->m_lineEditDisplay->setValidatePlaceHolder(d->m_validatePlaceHolder);
d->updateWidgetFromCheckStatus(this, d->m_lineEditDisplay.data());
addLabeledItem(parent, d->m_lineEditDisplay);
useMacroExpander(d->m_lineEditDisplay);

View File

@@ -407,6 +407,7 @@ public:
void setAutoApplyOnEditingFinished(bool applyOnEditingFinished);
void setElideMode(Qt::TextElideMode elideMode);
void setAllowPathFromDevice(bool allowPathFromDevice);
void setValidatePlaceHolder(bool validatePlaceHolder);
void validateInput();

View File

@@ -112,6 +112,7 @@ public:
bool m_isFiltering = false;
bool m_firstChange = true;
bool m_toolTipSet = false;
bool m_validatePlaceHolder = false;
QString m_lastFilterText;
@@ -469,6 +470,11 @@ QString FancyLineEdit::errorMessage() const
return d->m_errorMessage;
}
void FancyLineEdit::setValidatePlaceHolder(bool on)
{
d->m_validatePlaceHolder = on;
}
void FancyLineEdit::validate()
{
const QString t = text();
@@ -501,7 +507,8 @@ void FancyLineEdit::validate()
p.setColor(QPalette::Active, QPalette::Text,
newState == Invalid ? d->m_errorTextColor : d->m_okTextColor);
p.setColor(QPalette::Active, QPalette::PlaceholderText,
validates ? d->m_placeholderTextColor : d->m_errorTextColor);
validates || !d->m_validatePlaceHolder
? d->m_placeholderTextColor : d->m_errorTextColor);
setPalette(p);
if (validHasChanged)

View File

@@ -105,6 +105,8 @@ public:
bool isValid() const;
QString errorMessage() const;
void setValidatePlaceHolder(bool on);
void setValidationFunction(const ValidationFunction &fn);
static ValidationFunction defaultValidationFunction();
void validate();

View File

@@ -88,9 +88,10 @@ AbstractSettings::AbstractSettings(const QString &name, const QString &ending)
setSettingsGroups(Utils::Constants::BEAUTIFIER_SETTINGS_GROUP, name);
command.setSettingsKey("command");
command.setExpectedKind(Utils::PathChooser::ExistingCommand);
command.setExpectedKind(PathChooser::ExistingCommand);
command.setCommandVersionArguments({"--version"});
command.setPromptDialogTitle(BeautifierPlugin::msgCommandPromptDialogTitle("Clang Format"));
command.setValidatePlaceHolder(true);
supportedMimeTypes.setDisplayStyle(StringAspect::LineEditDisplay);
supportedMimeTypes.setSettingsKey("supportedMime");