Commit ef89e5a5 authored by Tobias Fella's avatar Tobias Fella
Browse files

Try choosing default ticket by user's FullName

When opening a Connection that has multiple tickets, this checks if one of the ticket's names matches the user's full name
and selects it if it does. If no ticket matches, the first ticket is chosen as before.
parent 5fcec148
Pipeline #201713 passed with stage
in 2 minutes and 27 seconds
......@@ -39,6 +39,7 @@ ColumnLayout {
model: ticketModel
textRole: "display"
Layout.fillWidth: true
currentIndex: ticketModel.initialIndex
// ugly, but rowCount does not trigger binding changes
Component.onCompleted: visible = ticketModel.rowCount() >= 1 && root.resIds.length > 1
......
......@@ -13,6 +13,8 @@
#include <KLocalizedString>
#include <KUser>
using namespace KItinerary;
TicketTokenModel::TicketTokenModel(QObject* parent)
......@@ -76,6 +78,7 @@ void TicketTokenModel::setReservationIds(const QStringList& resIds)
}
}
endResetModel();
Q_EMIT initialIndexChanged();
}
QVariant TicketTokenModel::reservationAt(int row) const
......@@ -127,3 +130,15 @@ QHash<int, QByteArray> TicketTokenModel::roleNames() const
names.insert(ReservationRole, "reservation");
return names;
}
int TicketTokenModel::initialIndex() const
{
auto fullName = KUser().property(KUser::FullName).toString();
auto it = std::find_if(m_personNames.begin(), m_personNames.end(), [fullName](const auto &name) {
return !name.compare(fullName, Qt::CaseInsensitive);
});
if (it == m_personNames.end()) {
return 0;
}
return it - m_personNames.begin();
}
\ No newline at end of file
......@@ -19,6 +19,8 @@ class TicketTokenModel : public QAbstractListModel
Q_OBJECT
Q_PROPERTY(QObject* reservationManager READ reservationManager WRITE setReservationManager)
Q_PROPERTY(QStringList reservationIds READ reservationIds WRITE setReservationIds)
Q_PROPERTY(int initialIndex READ initialIndex NOTIFY initialIndexChanged)
public:
enum Roles {
ReservationRole = Qt::UserRole
......@@ -39,6 +41,11 @@ public:
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
int initialIndex() const;
Q_SIGNALS:
void initialIndexChanged();
private:
ReservationManager *m_resMgr = nullptr;
QStringList m_pendingResIds;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment