diff options
Diffstat (limited to 'network/wirednetworkmodel.cpp')
-rw-r--r-- | network/wirednetworkmodel.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/network/wirednetworkmodel.cpp b/network/wirednetworkmodel.cpp index d14bce4..01a50fb 100644 --- a/network/wirednetworkmodel.cpp +++ b/network/wirednetworkmodel.cpp @@ -1,5 +1,6 @@ #include "wirednetworkmodel.h" #include "connectionprofile.h" +#include <QVector> #include <QDebug> WiredNetworkModel::WiredNetworkModel(QObject *parent) @@ -9,8 +10,13 @@ WiredNetworkModel::WiredNetworkModel(QObject *parent) QVariant WiredNetworkModel::data(const QModelIndex &index, int role) const { + QVariant ret; + + if (!index.isValid()) + return ret; + if (index.row() < 0 || index.row() >= m_networks.count()) - return QVariant(); + return ret; const ConnectionProfile *network = m_networks[index.row()]; @@ -25,7 +31,7 @@ QVariant WiredNetworkModel::data(const QModelIndex &index, int role) const return network->state(); } - return QVariant(); + return ret; } QHash<int, QByteArray> WiredNetworkModel::roleNames() const { @@ -41,17 +47,20 @@ QHash<int, QByteArray> WiredNetworkModel::roleNames() const { void WiredNetworkModel::updateProperties(QString service, QJsonObject properties) { ConnectionProfile *network; + QVector<int> vroles; - // FIXME: add role parameter to emits if ((network = getNetwork(service))) { if (properties.contains("ipv4")) { QString address = properties.value("ipv4").toObject().value("address").toString(); network->setAddress(address); - emit dataChanged(indexOf(network), indexOf(network)); + vroles.push_back(AddressRole); } if (properties.contains("state")) { network->setState(properties.value("state").toString()); - emit dataChanged(indexOf(network), indexOf(network)); + vroles.push_back(StateRole); } + if (!vroles.isEmpty()) + emit dataChanged(indexOf(network), indexOf(network), vroles); + } } |