FancyLineEdit: Remove property initialText

The same can be easily achieved by placeholderText nowadays.

Change-Id: Icfe0652ae8536c8077cf45a03844275aa1eddad6
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Andre Hartmann
2017-10-21 21:04:51 +02:00
committed by André Hartmann
parent 310a2bf96f
commit 8d1a592d16
3 changed files with 9 additions and 28 deletions

View File

@@ -105,7 +105,6 @@ public:
QColor m_okTextColor; QColor m_okTextColor;
QColor m_errorTextColor = Qt::red; QColor m_errorTextColor = Qt::red;
QString m_errorMessage; QString m_errorMessage;
QString m_initialText;
}; };
FancyLineEditPrivate::FancyLineEditPrivate(FancyLineEdit *parent) : FancyLineEditPrivate::FancyLineEditPrivate(FancyLineEdit *parent) :
@@ -373,20 +372,6 @@ void FancyLineEdit::setFiltering(bool on)
} }
} }
QString FancyLineEdit::initialText() const
{
return d->m_initialText;
}
void FancyLineEdit::setInitialText(const QString &t)
{
if (d->m_initialText != t) {
d->m_initialText = t;
d->m_firstChange = true;
setText(t);
}
}
QColor FancyLineEdit::errorColor() const QColor FancyLineEdit::errorColor() const
{ {
return d->m_errorTextColor; return d->m_errorTextColor;
@@ -458,13 +443,13 @@ void FancyLineEdit::validate()
} }
d->m_errorMessage.clear(); d->m_errorMessage.clear();
// Are we displaying the initial text? // Are we displaying the placeholder text?
const bool isDisplayingInitialText = !d->m_initialText.isEmpty() && t == d->m_initialText; const bool isDisplayingPlaceholderText = !placeholderText().isEmpty() && t.isEmpty();
const State newState = isDisplayingInitialText ? const State newState = isDisplayingPlaceholderText ?
DisplayingInitialText : DisplayingPlaceholderText :
(d->m_validationFunction(this, &d->m_errorMessage) ? Valid : Invalid); (d->m_validationFunction(this, &d->m_errorMessage) ? Valid : Invalid);
setToolTip(d->m_errorMessage); setToolTip(d->m_errorMessage);
// Changed..figure out if valid changed. DisplayingInitialText is not valid, // Changed..figure out if valid changed. DisplayingPlaceholderText is not valid,
// but should not show error color. Also trigger on the first change. // but should not show error color. Also trigger on the first change.
if (newState != d->m_state || d->m_firstChange) { if (newState != d->m_state || d->m_firstChange) {
const bool validHasChanged = (d->m_state == Valid) != (newState == Valid); const bool validHasChanged = (d->m_state == Valid) != (newState == Valid);

View File

@@ -73,7 +73,6 @@ class QTCREATOR_UTILS_EXPORT FancyLineEdit : public CompletingLineEdit
Q_ENUMS(Side) Q_ENUMS(Side)
// Validation. // Validation.
Q_PROPERTY(QString initialText READ initialText WRITE setInitialText DESIGNABLE true)
Q_PROPERTY(QColor errorColor READ errorColor WRITE setErrorColor DESIGNABLE true) Q_PROPERTY(QColor errorColor READ errorColor WRITE setErrorColor DESIGNABLE true)
Q_PROPERTY(QColor okColor READ okColor WRITE setOkColor DESIGNABLE true) Q_PROPERTY(QColor okColor READ okColor WRITE setOkColor DESIGNABLE true)
@@ -123,15 +122,12 @@ public:
// line edit, (out)errorMessage -> valid? // line edit, (out)errorMessage -> valid?
typedef std::function<bool(FancyLineEdit *, QString *)> ValidationFunction; typedef std::function<bool(FancyLineEdit *, QString *)> ValidationFunction;
enum State { Invalid, DisplayingInitialText, Valid }; enum State { Invalid, DisplayingPlaceholderText, Valid };
State state() const; State state() const;
bool isValid() const; bool isValid() const;
QString errorMessage() const; QString errorMessage() const;
QString initialText() const;
void setInitialText(const QString &);
QColor errorColor() const; QColor errorColor() const;
void setErrorColor(const QColor &c); void setErrorColor(const QColor &c);

View File

@@ -85,7 +85,7 @@ ProjectIntroPage::ProjectIntroPage(QWidget *parent) :
{ {
d->m_ui.setupUi(this); d->m_ui.setupUi(this);
hideStatusLabel(); hideStatusLabel();
d->m_ui.nameLineEdit->setInitialText(tr("<Enter_Name>")); d->m_ui.nameLineEdit->setPlaceholderText(tr("Enter project name"));
d->m_ui.nameLineEdit->setFocus(); d->m_ui.nameLineEdit->setFocus();
d->m_ui.nameLineEdit->setValidationFunction([this](FancyLineEdit *edit, QString *errorString) { d->m_ui.nameLineEdit->setValidationFunction([this](FancyLineEdit *edit, QString *errorString) {
return validateProjectName(edit->text(), errorString); return validateProjectName(edit->text(), errorString);
@@ -178,13 +178,13 @@ bool ProjectIntroPage::validate()
return false; return false;
} }
// Name valid? Ignore 'DisplayingInitialText' state. // Name valid? Ignore 'DisplayingPlaceholderText' state.
bool nameValid = false; bool nameValid = false;
switch (d->m_ui.nameLineEdit->state()) { switch (d->m_ui.nameLineEdit->state()) {
case FancyLineEdit::Invalid: case FancyLineEdit::Invalid:
displayStatusMessage(Error, d->m_ui.nameLineEdit->errorMessage()); displayStatusMessage(Error, d->m_ui.nameLineEdit->errorMessage());
return false; return false;
case FancyLineEdit::DisplayingInitialText: case FancyLineEdit::DisplayingPlaceholderText:
break; break;
case FancyLineEdit::Valid: case FancyLineEdit::Valid:
nameValid = true; nameValid = true;