diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-03 21:07:03 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-04 12:54:21 +0200 |
| commit | 1e587846a255592e5aab022c4e6e134d4ff64ed2 (patch) | |
| tree | c3dd9bc24b3a7010a1edbed6cf56991619442e71 /src/querycompleter.h | |
| parent | a6f73f77890d801ecd7209e97ba948c06fdd35c2 (diff) | |
| download | qtmaildir-1e587846a255592e5aab022c4e6e134d4ff64ed2.tar.gz qtmaildir-1e587846a255592e5aab022c4e6e134d4ff64ed2.zip | |
feat(completion): render the popup with descriptions
The free-form date hint is a footer label rather than a model row: a row
would be filtered away by the first non-matching keystroke and could be
selected and inserted, producing a query that errors.
QCompleter::setPopup takes a QAbstractItemView, so the label cannot be laid
out beside the view in a container widget. The footer sits in space reserved
with setViewportMargins inside the list view instead.
setItemDelegate must run after setPopup, not before: setPopup installs a
plain QStyledItemDelegate of its own and discards whatever was already set,
which silently drops the description column.
Accepting replaces exactly the span the tokenizer identified rather than
QCompleter's own completion prefix, which is a different span once a prefix
or a range bound is involved. Four tests drive that path directly instead of
through synthetic key events, since whether a key needs Shift is a
keyboard-layout property and could not decide the question.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'src/querycompleter.h')
| -rw-r--r-- | src/querycompleter.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/querycompleter.h b/src/querycompleter.h index e9ffc64..374fe84 100644 --- a/src/querycompleter.h +++ b/src/querycompleter.h @@ -26,7 +26,12 @@ #include "completionentry.h" class Config; +class QCompleter; class QLineEdit; +class QStandardItemModel; + +/// The completion popup, defined in the .cpp: a list view with a footer strip. +class CompletionPopup; /// Where the cursor sits in a query, and therefore what should be offered. /// @@ -96,10 +101,25 @@ public: /// The candidate values for a context, in the order they are offered. QStringList candidatesFor(const CompletionContext &context) const; + /// Recomputes the context from the line edit and refills the popup model. + void updateContext(); + + /// Inserts `value` over the span the last updateContext() identified. + /// + /// Public so a test can drive the accept path directly. Going through + /// synthetic key events instead would test the keyboard layout, not this. + void acceptCompletion(const QString &value); + private: QList<CompletionEntry> entriesFor(const CompletionContext &context) const; + void rebuildModel(const CompletionContext &context); QLineEdit *m_edit = nullptr; const Config &m_config; QStringList m_tags; + + QCompleter *m_completer = nullptr; + QStandardItemModel *m_model = nullptr; + CompletionPopup *m_popup = nullptr; + CompletionContext m_context; }; |
