diff --git a/src/libs/utils/ipaddresslineedit.cpp b/src/libs/utils/ipaddresslineedit.cpp index ebc255b9cbb..e85d59d9e2a 100644 --- a/src/libs/utils/ipaddresslineedit.cpp +++ b/src/libs/utils/ipaddresslineedit.cpp @@ -54,20 +54,16 @@ public: QValidator *m_ipAddressValidator; QColor m_validColor; - bool m_addressIsValid; }; -IpAddressLineEditPrivate::IpAddressLineEditPrivate() : - m_addressIsValid(true) +IpAddressLineEditPrivate::IpAddressLineEditPrivate() { } IpAddressLineEdit::IpAddressLineEdit(QWidget* parent) : - QLineEdit(parent), + BaseValidatingLineEdit(parent), m_d(new IpAddressLineEditPrivate()) { - m_d->m_validColor = palette().color(QPalette::Text); - const char * ipAddressRegExpPattern = "^\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." @@ -76,8 +72,6 @@ IpAddressLineEdit::IpAddressLineEdit(QWidget* parent) : QRegExp ipAddressRegExp(ipAddressRegExpPattern); m_d->m_ipAddressValidator = new QRegExpValidator(ipAddressRegExp, this); - - connect(this, SIGNAL(textChanged(QString)), this, SLOT(validateAddress(QString))); } IpAddressLineEdit::~IpAddressLineEdit() @@ -85,36 +79,25 @@ IpAddressLineEdit::~IpAddressLineEdit() delete m_d; } -bool IpAddressLineEdit::isValid() const +bool IpAddressLineEdit::validate(const QString &value, QString *errorMessage) const { - return m_d->m_addressIsValid; -} - -void IpAddressLineEdit::validateAddress(const QString &string) -{ - QString copy = string; + QString copy = value; int offset = 0; bool isValid = m_d->m_ipAddressValidator->validate(copy, offset) == QValidator::Acceptable; - - if (isValid != m_d->m_addressIsValid) { - if (isValid) { - QPalette pal(palette()); - pal.setColor(QPalette::Text, m_d->m_validColor); - setPalette(pal); - emit validAddressChanged(copy); - } else { - QPalette pal(palette()); - pal.setColor(QPalette::Text, Qt::red); - setPalette(pal); - setToolTip(tr("The IP address is not valid.")); - } - m_d->m_addressIsValid = isValid; - } else { - if (isValid) - emit validAddressChanged(copy); - else - emit invalidAddressChanged(); + if (!isValid) { + *errorMessage = tr("The IP address is not valid."); + return false; } + return true; +} + +void IpAddressLineEdit::slotChanged(const QString &t) +{ + Utils::BaseValidatingLineEdit::slotChanged(t); + if (isValid()) + emit validAddressChanged(t); + else + emit invalidAddressChanged(); } } // namespace Utils diff --git a/src/libs/utils/ipaddresslineedit.h b/src/libs/utils/ipaddresslineedit.h index 00decc74922..97119da9a95 100644 --- a/src/libs/utils/ipaddresslineedit.h +++ b/src/libs/utils/ipaddresslineedit.h @@ -35,28 +35,28 @@ #define IPADDRESSLINEEDIT_H #include "utils_global.h" - -#include +#include "basevalidatinglineedit.h" namespace Utils { class IpAddressLineEditPrivate; -class QTCREATOR_UTILS_EXPORT IpAddressLineEdit : public QLineEdit +class QTCREATOR_UTILS_EXPORT IpAddressLineEdit : public Utils::BaseValidatingLineEdit { + Q_DISABLE_COPY(IpAddressLineEdit) Q_OBJECT + public: explicit IpAddressLineEdit(QWidget* parent = 0); virtual ~IpAddressLineEdit(); - bool isValid() const; - signals: void validAddressChanged(const QString& address); void invalidAddressChanged(); -private slots: - void validateAddress(const QString &string); +protected: + virtual bool validate(const QString &value, QString *errorMessage) const; + virtual void slotChanged(const QString &t); private: IpAddressLineEditPrivate *m_d; diff --git a/src/plugins/qt4projectmanager/qt-s60/s60deployconfiguration.cpp b/src/plugins/qt4projectmanager/qt-s60/s60deployconfiguration.cpp index 3b52bf6e088..c850de22b01 100644 --- a/src/plugins/qt4projectmanager/qt-s60/s60deployconfiguration.cpp +++ b/src/plugins/qt4projectmanager/qt-s60/s60deployconfiguration.cpp @@ -381,6 +381,7 @@ QString S60DeployConfiguration::deviceAddress() const void S60DeployConfiguration::setDeviceAddress(const QString &address) { if (m_deviceAddress != address) { + qDebug() << __FUNCTION__ << address; m_deviceAddress = address; emit deviceAddressChanged(); } @@ -394,6 +395,7 @@ QString S60DeployConfiguration::devicePort() const void S60DeployConfiguration::setDevicePort(const QString &port) { if (m_devicePort != port) { + qDebug() << __FUNCTION__ << port; if (port.isEmpty()) //setup the default CODA's port m_devicePort = QLatin1String(DEFAULT_TCF_TRK_TCP_PORT); else