From cfa0c9c7354849e484b7e7caa55f62e342d810da Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 14 Aug 2022 09:43:58 +0200 Subject: [PATCH] desktop: make DiveLocationModel entries "editable" If the entries in the DiveLocationModel don't have their entries set as editable, the auto-completion popup turns of composition if such an item is highlighted (see Qt code in /src/widgets/itemviews/qabstractitemview.cpp), thus disabling composition of multi-key characters. Therefore, set this flag. Seems weird, but what should we do!? Signed-off-by: Berthold Stoeger --- desktop-widgets/locationinformation.cpp | 10 ++++++++++ desktop-widgets/locationinformation.h | 9 +++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index 3c97360fd..76afaee79 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -421,6 +421,16 @@ int DiveLocationModel::rowCount(const QModelIndex&) const return dive_site_table.nr + 2; } +Qt::ItemFlags DiveLocationModel::flags(const QModelIndex &index) const +{ + // This is crazy: If an entry is not marked as editable, the QListView + // (or rather the QAbstractItemView base class) clears the WA_InputMethod + // flag, which means that key-composition events are disabled. This + // breaks composition as long as the popup is openen. Therefore, + // make all items editable. + return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; +} + bool DiveLocationModel::setData(const QModelIndex &index, const QVariant &value, int) { if (!index.isValid()) diff --git a/desktop-widgets/locationinformation.h b/desktop-widgets/locationinformation.h index c94623e23..ec8554feb 100644 --- a/desktop-widgets/locationinformation.h +++ b/desktop-widgets/locationinformation.h @@ -67,12 +67,13 @@ class DiveLocationModel : public QAbstractTableModel { public: DiveLocationModel(QObject *o = 0); void resetModel(); - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; - int rowCount(const QModelIndex& parent = QModelIndex()) const; - int columnCount(const QModelIndex& parent = QModelIndex()) const; - bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); + bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; private: QString new_ds_value[2]; + Qt::ItemFlags flags(const QModelIndex &index) const override; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + int rowCount(const QModelIndex& parent = QModelIndex()) const override; + int columnCount(const QModelIndex& parent = QModelIndex()) const override; }; class DiveLocationListView : public QListView {