forked from qt-creator/qt-creator
IpAddressLineEdit has been refactored
This commit is contained in:
@@ -54,20 +54,16 @@ public:
|
|||||||
|
|
||||||
QValidator *m_ipAddressValidator;
|
QValidator *m_ipAddressValidator;
|
||||||
QColor m_validColor;
|
QColor m_validColor;
|
||||||
bool m_addressIsValid;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
IpAddressLineEditPrivate::IpAddressLineEditPrivate() :
|
IpAddressLineEditPrivate::IpAddressLineEditPrivate()
|
||||||
m_addressIsValid(true)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
IpAddressLineEdit::IpAddressLineEdit(QWidget* parent) :
|
IpAddressLineEdit::IpAddressLineEdit(QWidget* parent) :
|
||||||
QLineEdit(parent),
|
BaseValidatingLineEdit(parent),
|
||||||
m_d(new IpAddressLineEditPrivate())
|
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]?)\\."
|
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]?)\\."
|
||||||
"(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);
|
QRegExp ipAddressRegExp(ipAddressRegExpPattern);
|
||||||
m_d->m_ipAddressValidator = new QRegExpValidator(ipAddressRegExp, this);
|
m_d->m_ipAddressValidator = new QRegExpValidator(ipAddressRegExp, this);
|
||||||
|
|
||||||
connect(this, SIGNAL(textChanged(QString)), this, SLOT(validateAddress(QString)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IpAddressLineEdit::~IpAddressLineEdit()
|
IpAddressLineEdit::~IpAddressLineEdit()
|
||||||
@@ -85,36 +79,25 @@ IpAddressLineEdit::~IpAddressLineEdit()
|
|||||||
delete m_d;
|
delete m_d;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IpAddressLineEdit::isValid() const
|
bool IpAddressLineEdit::validate(const QString &value, QString *errorMessage) const
|
||||||
{
|
{
|
||||||
return m_d->m_addressIsValid;
|
QString copy = value;
|
||||||
}
|
|
||||||
|
|
||||||
void IpAddressLineEdit::validateAddress(const QString &string)
|
|
||||||
{
|
|
||||||
QString copy = string;
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
bool isValid = m_d->m_ipAddressValidator->validate(copy, offset) == QValidator::Acceptable;
|
bool isValid = m_d->m_ipAddressValidator->validate(copy, offset) == QValidator::Acceptable;
|
||||||
|
if (!isValid) {
|
||||||
if (isValid != m_d->m_addressIsValid) {
|
*errorMessage = tr("The IP address is not valid.");
|
||||||
if (isValid) {
|
return false;
|
||||||
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;
|
return true;
|
||||||
} else {
|
}
|
||||||
if (isValid)
|
|
||||||
emit validAddressChanged(copy);
|
void IpAddressLineEdit::slotChanged(const QString &t)
|
||||||
|
{
|
||||||
|
Utils::BaseValidatingLineEdit::slotChanged(t);
|
||||||
|
if (isValid())
|
||||||
|
emit validAddressChanged(t);
|
||||||
else
|
else
|
||||||
emit invalidAddressChanged();
|
emit invalidAddressChanged();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
@@ -35,28 +35,28 @@
|
|||||||
#define IPADDRESSLINEEDIT_H
|
#define IPADDRESSLINEEDIT_H
|
||||||
|
|
||||||
#include "utils_global.h"
|
#include "utils_global.h"
|
||||||
|
#include "basevalidatinglineedit.h"
|
||||||
#include <QtGui/QLineEdit>
|
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
class IpAddressLineEditPrivate;
|
class IpAddressLineEditPrivate;
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT IpAddressLineEdit : public QLineEdit
|
class QTCREATOR_UTILS_EXPORT IpAddressLineEdit : public Utils::BaseValidatingLineEdit
|
||||||
{
|
{
|
||||||
|
Q_DISABLE_COPY(IpAddressLineEdit)
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit IpAddressLineEdit(QWidget* parent = 0);
|
explicit IpAddressLineEdit(QWidget* parent = 0);
|
||||||
virtual ~IpAddressLineEdit();
|
virtual ~IpAddressLineEdit();
|
||||||
|
|
||||||
bool isValid() const;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void validAddressChanged(const QString& address);
|
void validAddressChanged(const QString& address);
|
||||||
void invalidAddressChanged();
|
void invalidAddressChanged();
|
||||||
|
|
||||||
private slots:
|
protected:
|
||||||
void validateAddress(const QString &string);
|
virtual bool validate(const QString &value, QString *errorMessage) const;
|
||||||
|
virtual void slotChanged(const QString &t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IpAddressLineEditPrivate *m_d;
|
IpAddressLineEditPrivate *m_d;
|
||||||
|
@@ -381,6 +381,7 @@ QString S60DeployConfiguration::deviceAddress() const
|
|||||||
void S60DeployConfiguration::setDeviceAddress(const QString &address)
|
void S60DeployConfiguration::setDeviceAddress(const QString &address)
|
||||||
{
|
{
|
||||||
if (m_deviceAddress != address) {
|
if (m_deviceAddress != address) {
|
||||||
|
qDebug() << __FUNCTION__ << address;
|
||||||
m_deviceAddress = address;
|
m_deviceAddress = address;
|
||||||
emit deviceAddressChanged();
|
emit deviceAddressChanged();
|
||||||
}
|
}
|
||||||
@@ -394,6 +395,7 @@ QString S60DeployConfiguration::devicePort() const
|
|||||||
void S60DeployConfiguration::setDevicePort(const QString &port)
|
void S60DeployConfiguration::setDevicePort(const QString &port)
|
||||||
{
|
{
|
||||||
if (m_devicePort != port) {
|
if (m_devicePort != port) {
|
||||||
|
qDebug() << __FUNCTION__ << port;
|
||||||
if (port.isEmpty()) //setup the default CODA's port
|
if (port.isEmpty()) //setup the default CODA's port
|
||||||
m_devicePort = QLatin1String(DEFAULT_TCF_TRK_TCP_PORT);
|
m_devicePort = QLatin1String(DEFAULT_TCF_TRK_TCP_PORT);
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user