-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e25fc14
commit 208d89b
Showing
9 changed files
with
176 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "UserProfileModel.h" | ||
#include "UserProfile.h" | ||
#include <QModelIndex> | ||
|
||
UserProfileModel::UserProfileModel(QObject *parent) | ||
: QAbstractListModel(parent) | ||
, deviceList(nullptr) | ||
{} | ||
|
||
int | ||
UserProfileModel::rowCount(const QModelIndex &parent) const | ||
{ | ||
if (parent.isValid() || !this->deviceList) | ||
return 0; | ||
return this->deviceList->getDeviceList().size(); | ||
} | ||
|
||
QVariant | ||
UserProfileModel::data(const QModelIndex &index, int role) const | ||
{ | ||
if (!index.isValid() || !this->deviceList) | ||
return QVariant(); | ||
|
||
const DeviceInfo device = this->deviceList->getDeviceList().at(index.row()); | ||
switch (role) { | ||
case DEVICEID: | ||
return QVariant(device.device_id); | ||
case DISPLAYNAME: | ||
return QVariant(device.display_name); | ||
} | ||
return QVariant(); | ||
} | ||
|
||
QHash<int, QByteArray> | ||
UserProfileModel::roleNames() const | ||
{ | ||
QHash<int, QByteArray> names; | ||
names[DEVICEID] = "deviceID"; | ||
names[DISPLAYNAME] = "displayName"; | ||
return names; | ||
} | ||
|
||
UserProfile * | ||
UserProfileModel::getList() const | ||
{ | ||
return (this->deviceList); | ||
} | ||
|
||
void | ||
UserProfileModel::setList(UserProfile *devices) | ||
{ | ||
beginResetModel(); | ||
|
||
if (devices) | ||
devices->disconnect(this); | ||
|
||
if (this->deviceList) { | ||
const int index = this->deviceList->getDeviceList().size(); | ||
beginInsertRows(QModelIndex(), index, index); | ||
endInsertRows(); | ||
} | ||
|
||
this->deviceList = devices; | ||
|
||
endResetModel(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <QAbstractListModel> | ||
|
||
class UserProfile; // forward declaration of the class UserProfile | ||
|
||
class UserProfileModel : public QAbstractListModel | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(UserProfile *deviceList READ getList WRITE setList) | ||
|
||
public: | ||
explicit UserProfileModel(QObject *parent = nullptr); | ||
|
||
enum | ||
{ | ||
DEVICEID, | ||
DISPLAYNAME | ||
}; | ||
UserProfile *getList() const; | ||
void setList(UserProfile *devices); | ||
|
||
int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||
QVariant data(const QModelIndex &index, int role) const override; | ||
virtual QHash<int, QByteArray> roleNames() const override; | ||
|
||
private: | ||
UserProfile *deviceList; | ||
}; |