forked from qt-creator/qt-creator
FancyLineEdit: Refactor class
Rename the code that evaluates the text and make it a public slot. Change-Id: I843bf505fa6e33661fc840a1fd2ec13ceb210037 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -169,7 +169,7 @@ FancyLineEdit::FancyLineEdit(QWidget *parent) :
|
|||||||
|
|
||||||
connect(d->m_iconbutton[Left], &QAbstractButton::clicked, this, &FancyLineEdit::iconClicked);
|
connect(d->m_iconbutton[Left], &QAbstractButton::clicked, this, &FancyLineEdit::iconClicked);
|
||||||
connect(d->m_iconbutton[Right], &QAbstractButton::clicked, this, &FancyLineEdit::iconClicked);
|
connect(d->m_iconbutton[Right], &QAbstractButton::clicked, this, &FancyLineEdit::iconClicked);
|
||||||
connect(this, &QLineEdit::textChanged, this, &FancyLineEdit::onTextChanged);
|
connect(this, &QLineEdit::textChanged, this, &FancyLineEdit::validate);
|
||||||
}
|
}
|
||||||
|
|
||||||
FancyLineEdit::~FancyLineEdit()
|
FancyLineEdit::~FancyLineEdit()
|
||||||
@@ -451,8 +451,10 @@ QString FancyLineEdit::errorMessage() const
|
|||||||
return d->m_errorMessage;
|
return d->m_errorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyLineEdit::onTextChanged(const QString &t)
|
void FancyLineEdit::validate()
|
||||||
{
|
{
|
||||||
|
const QString t = text();
|
||||||
|
|
||||||
if (d->m_isFiltering){
|
if (d->m_isFiltering){
|
||||||
if (t != d->m_lastFilterText) {
|
if (t != d->m_lastFilterText) {
|
||||||
d->m_lastFilterText = t;
|
d->m_lastFilterText = t;
|
||||||
@@ -498,17 +500,11 @@ void FancyLineEdit::onTextChanged(const QString &t)
|
|||||||
handleChanged(t);
|
handleChanged(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyLineEdit::triggerChanged()
|
|
||||||
{
|
|
||||||
onTextChanged(text());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString FancyLineEdit::fixInputString(const QString &string)
|
QString FancyLineEdit::fixInputString(const QString &string)
|
||||||
{
|
{
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// IconButton - helper class to represent a clickable icon
|
// IconButton - helper class to represent a clickable icon
|
||||||
//
|
//
|
||||||
|
@@ -143,16 +143,14 @@ public:
|
|||||||
QColor errorColor() const;
|
QColor errorColor() const;
|
||||||
void setErrorColor(const QColor &);
|
void setErrorColor(const QColor &);
|
||||||
|
|
||||||
// Trigger an update (after changing settings)
|
|
||||||
void triggerChanged();
|
|
||||||
|
|
||||||
static QColor textColor(const QWidget *w);
|
static QColor textColor(const QWidget *w);
|
||||||
static void setTextColor(QWidget *w, const QColor &c);
|
static void setTextColor(QWidget *w, const QColor &c);
|
||||||
|
|
||||||
void setValidationFunction(const ValidationFunction &fn);
|
void setValidationFunction(const ValidationFunction &fn);
|
||||||
static ValidationFunction defaultValidationFunction();
|
static ValidationFunction defaultValidationFunction();
|
||||||
|
void validate();
|
||||||
|
|
||||||
protected slots:
|
protected:
|
||||||
// Custom behaviour can be added here.
|
// Custom behaviour can be added here.
|
||||||
virtual void handleChanged(const QString &) {}
|
virtual void handleChanged(const QString &) {}
|
||||||
|
|
||||||
@@ -166,17 +164,15 @@ signals:
|
|||||||
void validChanged(bool validState);
|
void validChanged(bool validState);
|
||||||
void validReturnPressed();
|
void validReturnPressed();
|
||||||
|
|
||||||
private slots:
|
|
||||||
void iconClicked();
|
|
||||||
void onTextChanged(const QString &);
|
|
||||||
void onEditingFinished();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *e);
|
void resizeEvent(QResizeEvent *e);
|
||||||
|
|
||||||
virtual QString fixInputString(const QString &string);
|
virtual QString fixInputString(const QString &string);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void iconClicked();
|
||||||
|
void onEditingFinished();
|
||||||
|
|
||||||
static bool validateWithValidator(FancyLineEdit *edit, QString *errorMessage);
|
static bool validateWithValidator(FancyLineEdit *edit, QString *errorMessage);
|
||||||
// Unimplemented, to force the user to make a decision on
|
// Unimplemented, to force the user to make a decision on
|
||||||
// whether to use setHistoryCompleter() or setSpecialCompleter().
|
// whether to use setHistoryCompleter() or setSpecialCompleter().
|
||||||
|
@@ -533,11 +533,6 @@ bool NewClassWidget::isValid(QString *error) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewClassWidget::triggerUpdateFileNames()
|
|
||||||
{
|
|
||||||
d->m_ui.classLineEdit->triggerChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NewClassWidget::slotUpdateFileNames(const QString &baseName)
|
void NewClassWidget::slotUpdateFileNames(const QString &baseName)
|
||||||
{
|
{
|
||||||
if (debugNewClassWidget)
|
if (debugNewClassWidget)
|
||||||
|
@@ -155,10 +155,6 @@ public slots:
|
|||||||
*/
|
*/
|
||||||
void suggestClassNameFromBase();
|
void suggestClassNameFromBase();
|
||||||
|
|
||||||
public slots:
|
|
||||||
/** Trigger an update (after changing settings) */
|
|
||||||
void triggerUpdateFileNames();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotUpdateFileNames(const QString &t);
|
void slotUpdateFileNames(const QString &t);
|
||||||
void slotValidChanged();
|
void slotValidChanged();
|
||||||
|
@@ -453,7 +453,7 @@ QString PathChooser::errorMessage() const
|
|||||||
|
|
||||||
void PathChooser::triggerChanged()
|
void PathChooser::triggerChanged()
|
||||||
{
|
{
|
||||||
d->m_lineEdit->triggerChanged();
|
d->m_lineEdit->validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PathChooser::setAboutToShowContextMenuHandler(PathChooser::AboutToShowContextMenuHandler handler)
|
void PathChooser::setAboutToShowContextMenuHandler(PathChooser::AboutToShowContextMenuHandler handler)
|
||||||
@@ -616,7 +616,7 @@ void PathChooser::setExpectedKind(Kind expected)
|
|||||||
if (d->m_acceptingKind == expected)
|
if (d->m_acceptingKind == expected)
|
||||||
return;
|
return;
|
||||||
d->m_acceptingKind = expected;
|
d->m_acceptingKind = expected;
|
||||||
d->m_lineEdit->triggerChanged();
|
d->m_lineEdit->validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
PathChooser::Kind PathChooser::expectedKind() const
|
PathChooser::Kind PathChooser::expectedKind() const
|
||||||
|
Reference in New Issue
Block a user