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>
This commit is contained in:
Dirk Hohndel 2019-03-20 07:31:24 -07:00
parent 643f4a5726
commit c69ca4df80
3 changed files with 4 additions and 27 deletions

View file

@ -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 QVariant ConnectionListModel::data(const QModelIndex &index, int role) const
{ {
if (index.row() < 0 || index.row() >= m_addresses.count()) if (index.row() < 0 || index.row() >= m_addresses.count())
return QVariant(); return QVariant();
if (role != AddressRole) if (role != Qt::DisplayRole)
return QVariant(); return QVariant();
return m_addresses[index.row()]; 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 int ConnectionListModel::rowCount(const QModelIndex&) const
{ {
return m_addresses.count(); return m_addresses.count();

View file

@ -6,13 +6,8 @@
class ConnectionListModel : public QAbstractListModel { class ConnectionListModel : public QAbstractListModel {
Q_OBJECT Q_OBJECT
public: public:
enum CLMRole {
AddressRole = Qt::UserRole + 1
};
ConnectionListModel(QObject *parent = 0); ConnectionListModel(QObject *parent = 0);
QHash<int, QByteArray> roleNames() const; QVariant data(const QModelIndex &index, int role) const;
QVariant data(const QModelIndex &index, int role = AddressRole) const;
QString address(int idx) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const;
void addAddress(const QString address); void addAddress(const QString address);
void removeAllAddresses(); void removeAllAddresses();

View file

@ -287,12 +287,8 @@ QStringList DCDeviceData::getProductListFromVendor(const QString &vendor)
int DCDeviceData::getMatchingAddress(const QString &vendor, const QString &product) int DCDeviceData::getMatchingAddress(const QString &vendor, const QString &product)
{ {
for (int i = 0; i < connectionListModel.rowCount(); i++) { Q_UNUSED(vendor)
QString address = connectionListModel.address(i); return connectionListModel.indexOf(product);
if (address.contains(product))
return i;
}
return -1;
} }
DCDeviceData *DownloadThread::data() DCDeviceData *DownloadThread::data()