summaryrefslogtreecommitdiffstats
path: root/network/abstractnetworkmodel.cpp
diff options
context:
space:
mode:
authorRaquel Medina <raquel.medina@konsulko.com>2019-07-18 23:59:08 +0200
committerRaquel Medina <raquel.medina@konsulko.com>2019-07-19 01:39:38 +0200
commit61d01475342f6811458d1ae70c23aeaed5348143 (patch)
tree39a2d5a387cd311d75d43012ec1104374f4689fb /network/abstractnetworkmodel.cpp
parent9d2600f4b4dcbdd3820910967eb00a9b00cd8a17 (diff)
libqtappfw: network: improve error checks
- include extra checks for error conditions - remove some tabs and unused variable Bug-AGL: SPEC-2636 Signed-off-by: Raquel Medina <raquel.medina@konsulko.com> Change-Id: I28b38c77979175236a7b115a0f4263840c70eb94
Diffstat (limited to 'network/abstractnetworkmodel.cpp')
-rw-r--r--network/abstractnetworkmodel.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/network/abstractnetworkmodel.cpp b/network/abstractnetworkmodel.cpp
index 6eada6a..ad5a31a 100644
--- a/network/abstractnetworkmodel.cpp
+++ b/network/abstractnetworkmodel.cpp
@@ -11,12 +11,15 @@ AbstractNetworkModel::AbstractNetworkModel(QObject *parent)
void AbstractNetworkModel::addNetwork(ConnectionProfile *network)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
- m_networks << network;
+ m_networks.insert(rowCount(), network);
endInsertRows();
}
void AbstractNetworkModel::removeNetwork(ConnectionProfile *network)
{
+ if (m_networks.isEmpty() || (network == nullptr))
+ return;
+
int row = m_networks.indexOf(network);
beginRemoveRows(QModelIndex(), row, row);
m_networks.removeAt(row);
@@ -26,14 +29,20 @@ void AbstractNetworkModel::removeNetwork(ConnectionProfile *network)
void AbstractNetworkModel::removeAllNetworks()
{
+ if (m_networks.isEmpty())
+ return;
+
beginRemoveRows(QModelIndex(), 0, m_networks.count() - 1);
qDeleteAll(m_networks.begin(), m_networks.end());
- m_networks.clear();
endRemoveRows();
+ m_networks.clear();
}
ConnectionProfile *AbstractNetworkModel::getNetwork(QString service)
{
+ if (m_networks.isEmpty())
+ return nullptr;
+
for (auto network : m_networks) {
if (network->service() == service)
return network;