Commit 079fc759 authored by Pawel Polanski's avatar Pawel Polanski
Browse files

IpAddressLineEdit has been refactored

parent 10e640db
......@@ -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
{
return m_d->m_addressIsValid;
}
void IpAddressLineEdit::validateAddress(const QString &string)
bool IpAddressLineEdit::validate(const QString &value, QString *errorMessage) const
{
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
......@@ -35,28 +35,28 @@
#define IPADDRESSLINEEDIT_H
#include "utils_global.h"
#include <QtGui/QLineEdit>
#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;
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment