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 {
|
footer: QQC2.ToolBar {
|
||||||
visible: accountList.count > 1 && !collapsedMode
|
visible: AccountRegistry.accountCount > 1 && !collapsedMode
|
||||||
height: visible ? implicitHeight : 0
|
height: visible ? implicitHeight : 0
|
||||||
leftPadding: 0
|
|
||||||
rightPadding: 0
|
contentItem: QQC2.ComboBox {
|
||||||
topPadding: 0
|
id: accountList
|
||||||
bottomPadding: 0
|
|
||||||
contentItem: RowLayout {
|
model: AccountRegistry
|
||||||
spacing: 0
|
textRole: "userId"
|
||||||
Repeater {
|
valueRole: "connection"
|
||||||
id: accountList
|
onActivated: Controller.activeConnection = currentValue
|
||||||
model: AccountRegistry
|
Component.onCompleted: currentIndex = indexOfValue(Controller.activeConnection)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ void AccountRegistry::add(Connection *c)
|
|||||||
beginInsertRows(QModelIndex(), m_accounts.size(), m_accounts.size());
|
beginInsertRows(QModelIndex(), m_accounts.size(), m_accounts.size());
|
||||||
m_accounts += c;
|
m_accounts += c;
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
emit accountCountChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountRegistry::drop(Connection *c)
|
void AccountRegistry::drop(Connection *c)
|
||||||
@@ -23,6 +24,7 @@ void AccountRegistry::drop(Connection *c)
|
|||||||
m_accounts.removeOne(c);
|
m_accounts.removeOne(c);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
Q_ASSERT(!m_accounts.contains(c));
|
Q_ASSERT(!m_accounts.contains(c));
|
||||||
|
emit accountCountChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AccountRegistry::isLoggedIn(const QString &userId) const
|
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()];
|
const auto account = m_accounts[index.row()];
|
||||||
|
|
||||||
if (role == ConnectionRole) {
|
switch (role) {
|
||||||
return QVariant::fromValue(account);
|
case ConnectionRole:
|
||||||
|
return QVariant::fromValue(account);
|
||||||
|
case UserIdRole:
|
||||||
|
return QVariant::fromValue(account->userId());
|
||||||
|
default:
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
@@ -69,7 +76,7 @@ int AccountRegistry::rowCount(const QModelIndex &parent) const
|
|||||||
|
|
||||||
QHash<int, QByteArray> AccountRegistry::roleNames() const
|
QHash<int, QByteArray> AccountRegistry::roleNames() const
|
||||||
{
|
{
|
||||||
return {{ConnectionRole, "connection"}};
|
return {{ConnectionRole, "connection"}, {UserIdRole, "userId"}};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AccountRegistry::isEmpty() const
|
bool AccountRegistry::isEmpty() const
|
||||||
|
|||||||
@@ -15,9 +15,12 @@ class Connection;
|
|||||||
class AccountRegistry : public QAbstractListModel
|
class AccountRegistry : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int accountCount READ count NOTIFY accountCountChanged);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum EventRoles {
|
enum EventRoles {
|
||||||
ConnectionRole = Qt::UserRole + 1,
|
ConnectionRole = Qt::UserRole + 1,
|
||||||
|
UserIdRole = Qt::DisplayRole,
|
||||||
};
|
};
|
||||||
|
|
||||||
static AccountRegistry &instance()
|
static AccountRegistry &instance()
|
||||||
@@ -40,6 +43,9 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void accountCountChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AccountRegistry();
|
AccountRegistry();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user