Use ComboBox as AccountRegistry view
Replace the RowLayout with a ComboBox. This permits a higher number of accounts to be used in the application without reducing the usability. BUG: 460601
This commit is contained in:
committed by
Tobias Fella
parent
10667f98ef
commit
ef255243ec
@@ -369,27 +369,17 @@ Kirigami.ScrollablePage {
|
||||
}
|
||||
|
||||
footer: QQC2.ToolBar {
|
||||
visible: accountList.count > 1 && !collapsedMode
|
||||
visible: AccountRegistry.accountCount > 1 && !collapsedMode
|
||||
height: visible ? implicitHeight : 0
|
||||
leftPadding: 0
|
||||
rightPadding: 0
|
||||
topPadding: 0
|
||||
bottomPadding: 0
|
||||
contentItem: RowLayout {
|
||||
spacing: 0
|
||||
Repeater {
|
||||
id: accountList
|
||||
model: AccountRegistry
|
||||
delegate: Kirigami.BasicListItem {
|
||||
checkable: true
|
||||
checked: Controller.activeConnection && Controller.activeConnection.localUserId === model.connection.localUserId
|
||||
onClicked: Controller.activeConnection = model.connection
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
text: model.connection.localUserId
|
||||
subtitle: model.connection.localUser.accountLabel
|
||||
}
|
||||
}
|
||||
|
||||
contentItem: QQC2.ComboBox {
|
||||
id: accountList
|
||||
|
||||
model: AccountRegistry
|
||||
textRole: "userId"
|
||||
valueRole: "connection"
|
||||
onActivated: Controller.activeConnection = currentValue
|
||||
Component.onCompleted: currentIndex = indexOfValue(Controller.activeConnection)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ void AccountRegistry::add(Connection *c)
|
||||
beginInsertRows(QModelIndex(), m_accounts.size(), m_accounts.size());
|
||||
m_accounts += c;
|
||||
endInsertRows();
|
||||
emit accountCountChanged();
|
||||
}
|
||||
|
||||
void AccountRegistry::drop(Connection *c)
|
||||
@@ -23,6 +24,7 @@ void AccountRegistry::drop(Connection *c)
|
||||
m_accounts.removeOne(c);
|
||||
endRemoveRows();
|
||||
Q_ASSERT(!m_accounts.contains(c));
|
||||
emit accountCountChanged();
|
||||
}
|
||||
|
||||
bool AccountRegistry::isLoggedIn(const QString &userId) const
|
||||
@@ -51,8 +53,13 @@ QVariant AccountRegistry::data(const QModelIndex &index, int role) const
|
||||
|
||||
const auto account = m_accounts[index.row()];
|
||||
|
||||
if (role == ConnectionRole) {
|
||||
return QVariant::fromValue(account);
|
||||
switch (role) {
|
||||
case ConnectionRole:
|
||||
return QVariant::fromValue(account);
|
||||
case UserIdRole:
|
||||
return QVariant::fromValue(account->userId());
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
|
||||
return {};
|
||||
@@ -69,7 +76,7 @@ int AccountRegistry::rowCount(const QModelIndex &parent) const
|
||||
|
||||
QHash<int, QByteArray> AccountRegistry::roleNames() const
|
||||
{
|
||||
return {{ConnectionRole, "connection"}};
|
||||
return {{ConnectionRole, "connection"}, {UserIdRole, "userId"}};
|
||||
}
|
||||
|
||||
bool AccountRegistry::isEmpty() const
|
||||
|
||||
@@ -15,9 +15,12 @@ class Connection;
|
||||
class AccountRegistry : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int accountCount READ count NOTIFY accountCountChanged);
|
||||
|
||||
public:
|
||||
enum EventRoles {
|
||||
ConnectionRole = Qt::UserRole + 1,
|
||||
UserIdRole = Qt::DisplayRole,
|
||||
};
|
||||
|
||||
static AccountRegistry &instance()
|
||||
@@ -40,6 +43,9 @@ public:
|
||||
|
||||
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void accountCountChanged();
|
||||
|
||||
private:
|
||||
AccountRegistry();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user