summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2019-03-20 07:31:24 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-03-20 09:07:17 -0700
commitc69ca4df80c9c74aa842b7f1fb3c44b22ae3232e (patch)
treed502a697cb55f9837c390d4ba08f54ebbaa2e664
parent643f4a5726926b86693b442e318f40cf28fee04a (diff)
downloadsubsurface-c69ca4df80c9c74aa842b7f1fb3c44b22ae3232e.tar.gz
Core: simplify ConnectionListModel
The complicated setup with the AddressRole is unnecessary. All we want to be able to do is get the index of a specific text in the list. In hindsight I am puzzled why I implemented this in such a complex fashion. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--core/connectionlistmodel.cpp16
-rw-r--r--core/connectionlistmodel.h7
-rw-r--r--core/downloadfromdcthread.cpp8
3 files changed, 4 insertions, 27 deletions
diff --git a/core/connectionlistmodel.cpp b/core/connectionlistmodel.cpp
index 3cc9c24f9..8cd270347 100644
--- a/core/connectionlistmodel.cpp
+++ b/core/connectionlistmodel.cpp
@@ -7,29 +7,15 @@ ConnectionListModel::ConnectionListModel(QObject *parent) :
{
}
-QHash <int, QByteArray> ConnectionListModel::roleNames() const
-{
- QHash<int, QByteArray> roles;
- roles[AddressRole] = "address";
- return roles;
-}
-
QVariant ConnectionListModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= m_addresses.count())
return QVariant();
- if (role != AddressRole)
+ if (role != Qt::DisplayRole)
return QVariant();
return m_addresses[index.row()];
}
-QString ConnectionListModel::address(int idx) const
-{
- if (idx < 0 || idx >> m_addresses.count())
- return QString();
- return m_addresses[idx];
-}
-
int ConnectionListModel::rowCount(const QModelIndex&) const
{
return m_addresses.count();
diff --git a/core/connectionlistmodel.h b/core/connectionlistmodel.h
index 11a93bfbc..d6ffe831c 100644
--- a/core/connectionlistmodel.h
+++ b/core/connectionlistmodel.h
@@ -6,13 +6,8 @@
class ConnectionListModel : public QAbstractListModel {
Q_OBJECT
public:
- enum CLMRole {
- AddressRole = Qt::UserRole + 1
- };
ConnectionListModel(QObject *parent = 0);
- QHash<int, QByteArray> roleNames() const;
- QVariant data(const QModelIndex &index, int role = AddressRole) const;
- QString address(int idx) const;
+ QVariant data(const QModelIndex &index, int role) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
void addAddress(const QString address);
void removeAllAddresses();
diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp
index 214854342..e2db8b66e 100644
--- a/core/downloadfromdcthread.cpp
+++ b/core/downloadfromdcthread.cpp
@@ -287,12 +287,8 @@ QStringList DCDeviceData::getProductListFromVendor(const QString &vendor)
int DCDeviceData::getMatchingAddress(const QString &vendor, const QString &product)
{
- for (int i = 0; i < connectionListModel.rowCount(); i++) {
- QString address = connectionListModel.address(i);
- if (address.contains(product))
- return i;
- }
- return -1;
+ Q_UNUSED(vendor)
+ return connectionListModel.indexOf(product);
}
DCDeviceData *DownloadThread::data()