[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    =?utf-8?q?=5Bnetworkmanagement/nm09=5D_libs/ui=3A_fix_some_issue?=
From:       Ilia Kats <ilia-kats () gmx ! net>
Date:       2011-05-31 19:19:40
Message-ID: 20110531191940.9F62FA60AE () git ! kde ! org
[Download RAW message or body]

Git commit 977a7ff2f633ab04236d1be3910fb9779e62d773 by Ilia Kats.
Committed on 31/05/2011 at 20:51.
Pushed by iliakats into branch 'nm09'.

fix some issues when entering wireless channel manually instead of
using the spinbox buttons

M  +25   -6    libs/ui/802_11_wirelesswidget.cpp     
M  +4    -2    libs/ui/802_11_wirelesswidget.h     

http://commits.kde.org/networkmanagement/977a7ff2f633ab04236d1be3910fb9779e62d773

diff --git a/libs/ui/802_11_wirelesswidget.cpp b/libs/ui/802_11_wirelesswidget.cpp
index 2ad9fcb..9e0f236 100644
--- a/libs/ui/802_11_wirelesswidget.cpp
+++ b/libs/ui/802_11_wirelesswidget.cpp
@@ -300,17 +300,36 @@ QString Wireless80211WidgetBand::textFromValue(int value) const
     return text;
 }
 
-uint Wireless80211WidgetBand::channelFromPos(int pos) const
+int Wireless80211WidgetBand::valueFromText(const QString &text) const
 {
-    QString text = QString::number(channels.at(selectedBand).at(pos),10);
-    bool ok;
-    return text.toUInt(&ok,10);
+    int channel = text.toInt();
+    int pos = posFromChannel(channel);
+    return (pos < 0) ? 0 : pos;
 }
 
-uint Wireless80211WidgetBand::posFromChannel(int channel) const
+QValidator::State Wireless80211WidgetBand::validate(QString &text, int &pos) const
+{
+    int channel = text.toInt();
+    int position = posFromChannel(channel);
+    int maxsize = QString::number(channels.at(selectedBand).last(),10).size();
+    if (position < 0 && pos < maxsize) {
+        return QValidator::Intermediate;
+    } else if (position < 0 ) {
+        return QValidator::Invalid;
+    } else {
+        return QValidator::Acceptable;
+    }
+}
+
+int Wireless80211WidgetBand::channelFromPos(int pos) const
+{
+    return channels.at(selectedBand).at(pos);
+}
+
+int Wireless80211WidgetBand::posFromChannel(int channel) const
 {
     int pos = channels.at(selectedBand).indexOf(channel);
-    return (pos < 0) ? 0 : static_cast<uint>(pos);
+    return pos;
 }
 
 void Wireless80211WidgetBand::setBand(int band)
diff --git a/libs/ui/802_11_wirelesswidget.h b/libs/ui/802_11_wirelesswidget.h
index aab1398..cad2abf 100644
--- a/libs/ui/802_11_wirelesswidget.h
+++ b/libs/ui/802_11_wirelesswidget.h
@@ -60,8 +60,10 @@ Q_OBJECT
 public:
     Wireless80211WidgetBand(QWidget * parent = 0);
     QString textFromValue(int) const;
-    uint channelFromPos(int) const;
-    uint posFromChannel(int) const;
+    int valueFromText(const QString&) const;
+    QValidator::State validate(QString&, int&) const;
+    int channelFromPos(int) const;
+    int posFromChannel(int) const;
     void setBand(int);
 private:
     QList< QList<int> > channels;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic