[SCM] ktp-accounts-kcm packaging branch, master, updated. debian/15.12.1-1-1157-gc4589c5
Maximiliano Curia
maxy at moszumanska.debian.org
Fri May 27 23:58:08 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-accounts-kcm.git;a=commitdiff;h=476dd96
The following commit has been merged in the master branch:
commit 476dd966e5c744abb50dc3ebfabb624315a5c520
Author: George Goldberg <grundleborg at googlemail.com>
Date: Mon Sep 14 08:51:40 2009 +0000
Reduce the amount of NIH (by using QValidators for int/uint types, rather than some crappy broken homebrew (yeah, it was my fault) validation code. Also make the validation results available through the model.
svn path=/trunk/playground/network/telepathy-accounts-kcm/; revision=1023212
---
src/KCMTelepathyAccounts/integer-edit.cpp | 70 +++++++++-------------
src/KCMTelepathyAccounts/integer-edit.h | 14 +++--
.../parameter-edit-delegate.cpp | 16 +++++
src/KCMTelepathyAccounts/parameter-edit-model.cpp | 28 +++++++--
src/KCMTelepathyAccounts/parameter-edit-model.h | 5 +-
src/KCMTelepathyAccounts/parameter-item.cpp | 13 ++++
src/KCMTelepathyAccounts/parameter-item.h | 8 ++-
src/KCMTelepathyAccounts/unsigned-integer-edit.cpp | 57 +++++++++---------
src/KCMTelepathyAccounts/unsigned-integer-edit.h | 14 +++--
9 files changed, 135 insertions(+), 90 deletions(-)
diff --git a/src/KCMTelepathyAccounts/integer-edit.cpp b/src/KCMTelepathyAccounts/integer-edit.cpp
index c052032..c2b541a 100644
--- a/src/KCMTelepathyAccounts/integer-edit.cpp
+++ b/src/KCMTelepathyAccounts/integer-edit.cpp
@@ -22,12 +22,15 @@
#include <KDebug>
-#include <QtGui/QKeyEvent>
+#include <QtGui/QIntValidator>
IntegerEdit::IntegerEdit(QWidget *parent)
: QLineEdit(parent)
{
connect(this, SIGNAL(textChanged(QString)), SLOT(onTextChanged(QString)));
+
+ // Set the validator range to the range of values in a 32 bit integer (dbus-type 'i').
+ setValidator(new QIntValidator(-2147483648, 2147483647, this));
}
IntegerEdit::~IntegerEdit()
@@ -35,62 +38,45 @@ IntegerEdit::~IntegerEdit()
}
-int IntegerEdit::value() const
+qint32 IntegerEdit::value() const
{
return text().toInt();
}
-void IntegerEdit::setValue(int integer)
+void IntegerEdit::setValue(qint32 integer)
{
setText(QString::number(integer));
}
-void IntegerEdit::keyPressEvent(QKeyEvent *event)
+QValidator::State IntegerEdit::validity() const
{
- kDebug() << "Key:" << event->key() << "Text:" << event->text();
+ int cursorPos = cursorPosition();
+ QString txt = text();
+ return validator()->validate(txt, cursorPos);
+}
- // If the text is empty or a modifier, allow the keypress
- if ((event->text().isEmpty()) || (event->key() < Qt::Key_Space)) {
- event->ignore();
- QLineEdit::keyPressEvent(event);
- return;
- }
+QPair<qint32, qint32> IntegerEdit::validRange() const
+{
+ QPair<qint32, qint32> ret;
+ ret.first = 0;
+ ret.second = 0;
- // If the key is backspace or delete, allow it
- if ((event->key() == Qt::Key_Delete) || (event->key() == Qt::Key_Backspace)) {
- event->ignore();
- QLineEdit::keyPressEvent(event);
- return;
- }
+ const QIntValidator *intValidator = qobject_cast<const QIntValidator*>(validator());
- // Check for numbers (and ensure maximum input length is not expended
- // FIXME: Have a better check to make sure the user doesn't enter a number too large.
- QString validKeys("0123456789");
- if (validKeys.contains(event->text())) {
- if (((text().contains(QString("-"))) && ((text().length() + 1) <= 5)) ||
- ((text().length() + 1) <= 4))
- {
- kDebug() << "Key is a number.";
- event->ignore();
- QLineEdit::keyPressEvent(event);
- return;
- }
+ if (!intValidator) {
+ kWarning() << "Somehow this is not an int validator :/";
+ return ret;
}
- // Check for minus sign as the first character
- if (event->text() == QString("-")) {
- if (cursorPosition() == 0) {
- if (!text().contains(QString("-"))) {
- kDebug() << "Key is a minus-sign at the start.";
- event->ignore();
- QLineEdit::keyPressEvent(event);
- return;
- }
- }
- }
+ ret.first = intValidator->bottom();
+ ret.second = intValidator->top();
+
+ return ret;
+}
- // Anything else, reject the keypress.
- event->accept();
+void IntegerEdit::setValidRange(qint32 minimum, qint32 maximum)
+{
+ setValidator(new QIntValidator(static_cast<int>(minimum), static_cast<int>(maximum), this));
}
void IntegerEdit::onTextChanged(const QString &text)
diff --git a/src/KCMTelepathyAccounts/integer-edit.h b/src/KCMTelepathyAccounts/integer-edit.h
index 4836208..7d4c0d9 100644
--- a/src/KCMTelepathyAccounts/integer-edit.h
+++ b/src/KCMTelepathyAccounts/integer-edit.h
@@ -23,7 +23,9 @@
#include <kdemacros.h>
+#include <QtCore/QPair>
#include <QtGui/QLineEdit>
+#include <QtGui/QValidator>
class KDE_EXPORT IntegerEdit : public QLineEdit
{
@@ -33,14 +35,16 @@ public:
explicit IntegerEdit(QWidget *parent = 0);
virtual ~IntegerEdit();
- int value() const;
- void setValue(int integer);
+ qint32 value() const;
+ void setValue(qint32 integer);
-protected:
- void keyPressEvent(QKeyEvent *event);
+ QValidator::State validity() const;
+
+ QPair<qint32, qint32> validRange() const;
+ void setValidRange(qint32 minimum, qint32 maximum);
Q_SIGNALS:
- void integerChanged(int integer);
+ void integerChanged(qint32 integer);
private Q_SLOTS:
void onTextChanged(const QString &text);
diff --git a/src/KCMTelepathyAccounts/parameter-edit-delegate.cpp b/src/KCMTelepathyAccounts/parameter-edit-delegate.cpp
index 0ff5e22..edbf14e 100644
--- a/src/KCMTelepathyAccounts/parameter-edit-delegate.cpp
+++ b/src/KCMTelepathyAccounts/parameter-edit-delegate.cpp
@@ -247,18 +247,34 @@ void ParameterEditDelegate::onIntegerEditTextChanged(const QString &text)
{
kDebug();
+ IntegerEdit *widget = qobject_cast<IntegerEdit*>(sender());
+
+ if (!widget) {
+ kWarning() << "Slot called by object of the wrong type.";
+ return;
+ }
+
QModelIndex index = focusedIndex();
Q_EMIT dataChanged(index, QVariant(text), ParameterEditModel::ValueRole);
+ Q_EMIT dataChanged(index, QVariant(widget->validity()), ParameterEditModel::ValidityRole);
}
void ParameterEditDelegate::onUnsignedIntegerEditTextChanged(const QString &text)
{
kDebug();
+ UnsignedIntegerEdit *widget = qobject_cast<UnsignedIntegerEdit*>(sender());
+
+ if (!widget) {
+ kWarning() << "Slot called by object of the wrong type.";
+ return;
+ }
+
QModelIndex index = focusedIndex();
Q_EMIT dataChanged(index, QVariant(text), ParameterEditModel::ValueRole);
+ Q_EMIT dataChanged(index, QVariant(widget->validity()), ParameterEditModel::ValidityRole);
}
diff --git a/src/KCMTelepathyAccounts/parameter-edit-model.cpp b/src/KCMTelepathyAccounts/parameter-edit-model.cpp
index acf9013..53e01bd 100644
--- a/src/KCMTelepathyAccounts/parameter-edit-model.cpp
+++ b/src/KCMTelepathyAccounts/parameter-edit-model.cpp
@@ -24,6 +24,8 @@
#include <KDebug>
+#include <QtGui/QValidator>
+
#include <TelepathyQt4/ConnectionManager>
ParameterEditModel::ParameterEditModel(QObject *parent)
@@ -82,6 +84,9 @@ QVariant ParameterEditModel::data(const QModelIndex &index, int role) const
case ParameterEditModel::RequiredForRegistrationRole:
data = QVariant(m_items.at(index.row())->isRequiredForRegistration());
break;
+ case ParameterEditModel::ValidityRole:
+ data = QVariant(m_items.at(index.row())->validity());
+ break;
default:
break;
}
@@ -101,16 +106,27 @@ bool ParameterEditModel::setData(const QModelIndex &index, const QVariant &value
return false;
}
- switch(role)
- {
- case ParameterEditModel::ValueRole:
+ if (role == ParameterEditModel::ValueRole) {
+
m_items.at(index.row())->setValue(value);
Q_EMIT dataChanged(index, index);
return true;
- break;
- default:
+
+ } else if (ParameterEditModel::ValidityRole) {
+
+ if (value.toInt() == QValidator::Acceptable) {
+ m_items.at(index.row())->setValidity(QValidator::Acceptable);
+ } else if (value.toInt() == QValidator::Intermediate) {
+ m_items.at(index.row())->setValidity(QValidator::Intermediate);
+ } else {
+ m_items.at(index.row())->setValidity(QValidator::Invalid);
+ }
+
+ Q_EMIT dataChanged(index, index);
+ return true;
+
+ } else {
return false;
- break;
}
}
diff --git a/src/KCMTelepathyAccounts/parameter-edit-model.h b/src/KCMTelepathyAccounts/parameter-edit-model.h
index 870527f..25bc2e3 100644
--- a/src/KCMTelepathyAccounts/parameter-edit-model.h
+++ b/src/KCMTelepathyAccounts/parameter-edit-model.h
@@ -18,8 +18,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef TELEPATHY_ACCOUNTS_KCM_PARAMETER_EDIT_MODEL_H
-#define TELEPATHY_ACCOUNTS_KCM_PARAMETER_EDIT_MODEL_H
+#ifndef LIB_KCM_TELEPATHY_ACCOUNTS_PARAMETER_EDIT_MODEL_H
+#define LIB_KCM_TELEPATHY_ACCOUNTS_PARAMETER_EDIT_MODEL_H
#include <QtCore/QAbstractListModel>
@@ -43,6 +43,7 @@ public:
SecretRole,
RequiredRole,
RequiredForRegistrationRole,
+ ValidityRole,
UserRole = Qt::UserRole + 42
};
diff --git a/src/KCMTelepathyAccounts/parameter-item.cpp b/src/KCMTelepathyAccounts/parameter-item.cpp
index 89c3f1d..318f175 100644
--- a/src/KCMTelepathyAccounts/parameter-item.cpp
+++ b/src/KCMTelepathyAccounts/parameter-item.cpp
@@ -42,6 +42,9 @@ ParameterItem::ParameterItem(Tp::ProtocolParameter *parameter,
if (m_localizedName.isEmpty()) {
m_localizedName = parameter->name();
}
+
+ // Assume the default/un-altered value is valid.
+ m_validity = QValidator::Acceptable;
}
ParameterItem::~ParameterItem()
@@ -89,6 +92,16 @@ Tp::ProtocolParameter *ParameterItem::parameter()
return m_parameter;
}
+QValidator::State ParameterItem::validity() const
+{
+ return m_validity;
+}
+
+void ParameterItem::setValidity(QValidator::State validity)
+{
+ m_validity = validity;
+}
+
void ParameterItem::setValue(const QVariant &value)
{
m_currentValue = value;
diff --git a/src/KCMTelepathyAccounts/parameter-item.h b/src/KCMTelepathyAccounts/parameter-item.h
index f47bb6c..14b1116 100644
--- a/src/KCMTelepathyAccounts/parameter-item.h
+++ b/src/KCMTelepathyAccounts/parameter-item.h
@@ -18,11 +18,12 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef TELEPATHY_ACCOUNTS_KCM_PARAMETER_ITEM_H
-#define TELEPATHY_ACCOUNTS_KCM_PARAMETER_ITEM_H
+#ifndef LIB_KCM_TELEPATHY_ACCOUNTS_PARAMETER_ITEM_H
+#define LIB_KCM_TELEPATHY_ACCOUNTS_PARAMETER_ITEM_H
#include <QtCore/QObject>
#include <QtCore/QVariant>
+#include <QtGui/QValidator>
#include <TelepathyQt4/ConnectionManager>
@@ -45,14 +46,17 @@ public:
bool isRequired() const;
bool isRequiredForRegistration() const;
Tp::ProtocolParameter *parameter();
+ QValidator::State validity() const;
void setValue(const QVariant &value);
+ void setValidity(QValidator::State validity);
private:
Tp::ProtocolParameter *m_parameter;
const QVariant m_originalValue;
QVariant m_currentValue;
QString m_localizedName;
+ QValidator::State m_validity;
};
diff --git a/src/KCMTelepathyAccounts/unsigned-integer-edit.cpp b/src/KCMTelepathyAccounts/unsigned-integer-edit.cpp
index e8e21e3..bf2b8b4 100644
--- a/src/KCMTelepathyAccounts/unsigned-integer-edit.cpp
+++ b/src/KCMTelepathyAccounts/unsigned-integer-edit.cpp
@@ -22,12 +22,16 @@
#include <KDebug>
-#include <QtGui/QKeyEvent>
+#include <QtGui/QIntValidator>
UnsignedIntegerEdit::UnsignedIntegerEdit(QWidget *parent)
: QLineEdit(parent)
{
connect(this, SIGNAL(textChanged(QString)), SLOT(onTextChanged(QString)));
+
+ // Set the validator range to the range of values in a 32 bit unsigned integer (dbus-type 'u').
+ // FIXME: Maximum value must be a valid type "int" for the validator to work. What a POS
+ setValidator(new QIntValidator(0, 2147483647, this));
}
UnsignedIntegerEdit::~UnsignedIntegerEdit()
@@ -45,39 +49,36 @@ void UnsignedIntegerEdit::setValue(uint unsignedInteger)
setText(QString::number(unsignedInteger));
}
-void UnsignedIntegerEdit::keyPressEvent(QKeyEvent *event)
+QValidator::State UnsignedIntegerEdit::validity() const
{
- kDebug() << "Key:" << event->key() << "Text:" << event->text();
+ int cursorPos = cursorPosition();
+ QString txt = text();
+ return validator()->validate(txt, cursorPos);
+}
- // If the text is empty or a modifier, allow the keypress
- if ((event->text().isEmpty()) || (event->key() < Qt::Key_Space)) {
- event->ignore();
- QLineEdit::keyPressEvent(event);
- return;
- }
+QPair<quint32, quint32> UnsignedIntegerEdit::validRange() const
+{
+ QPair<quint32, quint32> ret;
+ ret.first = 0;
+ ret.second = 0;
- // If the key is backspace or delete, allow it
- if ((event->key() == Qt::Key_Delete) || (event->key() == Qt::Key_Backspace)) {
- event->ignore();
- QLineEdit::keyPressEvent(event);
- return;
- }
+ QIntValidator const *intValidator = qobject_cast<const QIntValidator*>(validator());
- // Check for numbers (and ensure maximum input length is not expended
- // FIXME: Have a better check to make sure the user doesn't enter a number too large.
- QString validKeys("0123456789");
- if (validKeys.contains(event->text())) {
- if ((text().length() + 1) <= 4)
- {
- kDebug() << "Key is a number.";
- event->ignore();
- QLineEdit::keyPressEvent(event);
- return;
- }
+ if (!intValidator) {
+ kWarning() << "Somehow this is not an int validator :/";
+ return ret;
}
- // Anything else, reject the keypress.
- event->accept();
+ ret.first = intValidator->bottom();
+ ret.second = intValidator->top();
+
+ return ret;
+}
+
+// WARNING: Don't set a range outside of that supported by "int"!!!
+void UnsignedIntegerEdit::setValidRange(quint32 minimum, quint32 maximum)
+{
+ setValidator(new QIntValidator(static_cast<int>(minimum), static_cast<int>(maximum), this));
}
void UnsignedIntegerEdit::onTextChanged(const QString &text)
diff --git a/src/KCMTelepathyAccounts/unsigned-integer-edit.h b/src/KCMTelepathyAccounts/unsigned-integer-edit.h
index 35fe6f8..6ccf16c 100644
--- a/src/KCMTelepathyAccounts/unsigned-integer-edit.h
+++ b/src/KCMTelepathyAccounts/unsigned-integer-edit.h
@@ -23,7 +23,9 @@
#include <kdemacros.h>
+#include <QtCore/QPair>
#include <QtGui/QLineEdit>
+#include <QtGui/QValidator>
class KDE_EXPORT UnsignedIntegerEdit : public QLineEdit
{
@@ -33,14 +35,16 @@ public:
explicit UnsignedIntegerEdit(QWidget *parent = 0);
virtual ~UnsignedIntegerEdit();
- uint value() const;
- void setValue(uint unsignedInteger);
+ quint32 value() const;
+ void setValue(quint32 unsignedInteger);
-protected:
- void keyPressEvent(QKeyEvent *event);
+ QValidator::State validity() const;
+
+ QPair<quint32, quint32> validRange() const;
+ void setValidRange(quint32 minimum, quint32 maximum);
Q_SIGNALS:
- void unsignedIntegerChanged(uint unsignedInteger);
+ void unsignedIntegerChanged(quint32 unsignedInteger);
private Q_SLOTS:
void onTextChanged(const QString &text);
--
ktp-accounts-kcm packaging
More information about the pkg-kde-commits
mailing list