Improve accountlistmodel.
This commit is contained in:
parent
647a2cdbf2
commit
20113fb47f
|
@ -28,7 +28,8 @@ Page {
|
|||
|
||||
id: accountSettingsListView
|
||||
|
||||
delegate: SwipeDelegate {
|
||||
delegate: Column {
|
||||
SwipeDelegate {
|
||||
width: accountSettingsListView.width
|
||||
height: 64
|
||||
|
||||
|
@ -44,17 +45,17 @@ Page {
|
|||
width: parent.height
|
||||
height: parent.height
|
||||
|
||||
hint: name
|
||||
defaultColor: Util.stringToColor(name)
|
||||
image: avatar
|
||||
hint: user.displayName
|
||||
defaultColor: Util.stringToColor(user.displayName)
|
||||
image: user.avatar
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
Label {
|
||||
text: name
|
||||
text: user.displayName
|
||||
}
|
||||
Label {
|
||||
text: accountID
|
||||
text: user.id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,6 +76,65 @@ Page {
|
|||
|
||||
SwipeDelegate.onClicked: matriqueController.logout(connection)
|
||||
}
|
||||
|
||||
onClicked: accountSettingsListView.currentIndex == index ? accountSettingsListView.currentIndex = -1 : accountSettingsListView.currentIndex = index
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
width: parent.width
|
||||
height: 2
|
||||
visible: accountSettingsListView.currentIndex == index
|
||||
|
||||
color: Material.accent
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
visible: accountSettingsListView.currentIndex == index
|
||||
width: parent.width - 32
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
|
||||
spacing: 16
|
||||
|
||||
Label { text: "Homeserver:" }
|
||||
TextField {
|
||||
Layout.fillWidth: true
|
||||
|
||||
text: connection.homeserver
|
||||
selectByMouse: true
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
|
||||
spacing: 16
|
||||
|
||||
Label { text: "Device ID:" }
|
||||
TextField {
|
||||
Layout.fillWidth: true
|
||||
|
||||
text: connection.deviceId
|
||||
selectByMouse: true
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
|
||||
spacing: 16
|
||||
|
||||
Label { text: "Access Token:" }
|
||||
TextField {
|
||||
Layout.fillWidth: true
|
||||
|
||||
text: connection.accessToken
|
||||
selectByMouse: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -123,8 +123,8 @@ ApplicationWindow {
|
|||
anchors.fill: parent
|
||||
anchors.margins: 12
|
||||
|
||||
hint: name
|
||||
image: avatar
|
||||
hint: user.displayName
|
||||
image: user.avatar
|
||||
defaultColor: Material.accent
|
||||
}
|
||||
|
||||
|
|
|
@ -12,10 +12,7 @@ void AccountListModel::setController(Controller* value) {
|
|||
|
||||
m_controller = value;
|
||||
|
||||
for (auto c : m_controller->connections()) {
|
||||
connectConnectionSignals(c);
|
||||
m_connections.append(c);
|
||||
};
|
||||
for (auto c : m_controller->connections()) m_connections.append(c);
|
||||
|
||||
connect(m_controller, &Controller::connectionAdded, this,
|
||||
[=](Connection* conn) {
|
||||
|
@ -23,7 +20,6 @@ void AccountListModel::setController(Controller* value) {
|
|||
}
|
||||
beginInsertRows(QModelIndex(), m_connections.count(),
|
||||
m_connections.count());
|
||||
connectConnectionSignals(conn);
|
||||
m_connections.append(conn);
|
||||
endInsertRows();
|
||||
});
|
||||
|
@ -57,16 +53,8 @@ QVariant AccountListModel::data(const QModelIndex& index, int role) const {
|
|||
return QVariant();
|
||||
}
|
||||
auto m_connection = m_connections.at(index.row());
|
||||
if (role == NameRole) {
|
||||
return m_connection->user()->displayname();
|
||||
}
|
||||
if (role == AccountIDRole) {
|
||||
return m_connection->user()->id();
|
||||
}
|
||||
if (role == AvatarRole) {
|
||||
if (!m_connection->user()->avatarUrl().isEmpty())
|
||||
return m_connection->user()->avatar(64);
|
||||
return QImage();
|
||||
if (role == UserRole) {
|
||||
return QVariant::fromValue(m_connection->user());
|
||||
}
|
||||
if (role == ConnectionRole) {
|
||||
return QVariant::fromValue(m_connection);
|
||||
|
@ -81,22 +69,9 @@ int AccountListModel::rowCount(const QModelIndex& parent) const {
|
|||
return m_connections.count();
|
||||
}
|
||||
|
||||
void AccountListModel::connectConnectionSignals(Connection* conn) {
|
||||
connect(conn->user(), &User::avatarChanged, this, [=] {
|
||||
const auto it = std::find(m_connections.begin(), m_connections.end(), conn);
|
||||
if (it == m_connections.end()) {
|
||||
return;
|
||||
}
|
||||
const auto idx = index(it - m_connections.begin());
|
||||
emit dataChanged(idx, idx, {AvatarRole});
|
||||
});
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> AccountListModel::roleNames() const {
|
||||
QHash<int, QByteArray> roles;
|
||||
roles[NameRole] = "name";
|
||||
roles[AccountIDRole] = "accountID";
|
||||
roles[AvatarRole] = "avatar";
|
||||
roles[UserRole] = "user";
|
||||
roles[ConnectionRole] = "connection";
|
||||
return roles;
|
||||
}
|
||||
|
|
|
@ -11,16 +11,11 @@ class AccountListModel : public QAbstractListModel {
|
|||
Q_PROPERTY(Controller* controller READ controller WRITE setController NOTIFY
|
||||
controllerChanged)
|
||||
public:
|
||||
enum EventRoles {
|
||||
NameRole = Qt::UserRole + 1,
|
||||
AccountIDRole,
|
||||
AvatarRole,
|
||||
ConnectionRole
|
||||
};
|
||||
enum EventRoles { UserRole = Qt::UserRole + 1, ConnectionRole };
|
||||
|
||||
AccountListModel(QObject* parent = nullptr);
|
||||
|
||||
QVariant data(const QModelIndex& index, int role = NameRole) const override;
|
||||
QVariant data(const QModelIndex& index, int role = UserRole) const override;
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
@ -32,7 +27,6 @@ class AccountListModel : public QAbstractListModel {
|
|||
Controller* m_controller;
|
||||
QVector<Connection*> m_connections;
|
||||
|
||||
void connectConnectionSignals(Connection* conn);
|
||||
signals:
|
||||
void controllerChanged();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue