summary refs log tree commit diff
diff options
context:
space:
mode:
authorJussi Kuokkanen <jussi.kuokkanen@protonmail.com>2020-09-02 13:32:57 +0300
committerNicolas Werner <nicolas.werner@hotmail.de>2020-11-25 19:05:12 +0100
commit748bf0cd988c103e66919db753d40fe19a784022 (patch)
treeb062ee29e6e0e621987ab90c0af4888d8aca9cac
parentWIP Qml completer (diff)
downloadnheko-748bf0cd988c103e66919db753d40fe19a784022.tar.xz
rename CompletionModel to CompletionProxyModel
-rw-r--r--src/CompletionProxyModel.h20
-rw-r--r--src/TextInputWidget.cpp4
-rw-r--r--src/TextInputWidget.h4
3 files changed, 24 insertions, 4 deletions
diff --git a/src/CompletionProxyModel.h b/src/CompletionProxyModel.h
new file mode 100644
index 00000000..ee38075e
--- /dev/null
+++ b/src/CompletionProxyModel.h
@@ -0,0 +1,20 @@
+#pragma once
+
+// Class for showing a limited amount of completions at a time
+
+#include <QSortFilterProxyModel>
+
+class CompletionProxyModel : public QSortFilterProxyModel
+{
+public:
+        CompletionProxyModel(QAbstractItemModel *model, QObject *parent = nullptr)
+          : QSortFilterProxyModel(parent)
+        {
+                setSourceModel(model);
+        }
+        int rowCount(const QModelIndex &parent) const override
+        {
+                auto row_count = QSortFilterProxyModel::rowCount(parent);
+                return (row_count < 7) ? row_count : 7;
+        }
+};
diff --git a/src/TextInputWidget.cpp b/src/TextInputWidget.cpp
index 30589b61..b46f0e5a 100644
--- a/src/TextInputWidget.cpp
+++ b/src/TextInputWidget.cpp
@@ -30,7 +30,7 @@
 
 #include "Cache.h"
 #include "ChatPage.h"
-#include "CompletionModel.h"
+#include "CompletionProxyModel.h"
 #include "Logging.h"
 #include "TextInputWidget.h"
 #include "Utils.h"
@@ -70,7 +70,7 @@ FilteredTextEdit::FilteredTextEdit(QWidget *parent)
         completer_->setWidget(this);
         auto model = new emoji::EmojiSearchModel(this);
         model->sort(0, Qt::AscendingOrder);
-        completer_->setModel((emoji_completion_model_ = new CompletionModel(model, this)));
+        completer_->setModel((emoji_completion_model_ = new CompletionProxyModel(model, this)));
         completer_->setModelSorting(QCompleter::UnsortedModel);
         completer_->popup()->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
         completer_->popup()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
diff --git a/src/TextInputWidget.h b/src/TextInputWidget.h
index c62a98be..19462f70 100644
--- a/src/TextInputWidget.h
+++ b/src/TextInputWidget.h
@@ -31,7 +31,7 @@
 
 struct SearchResult;
 
-class CompletionModel;
+class CompletionProxyModel;
 class FlatButton;
 class LoadingIndicator;
 class QCompleter;
@@ -72,7 +72,7 @@ protected:
 
 private:
         bool emoji_popup_open_ = false;
-        CompletionModel *emoji_completion_model_;
+        CompletionProxyModel *emoji_completion_model_;
         std::deque<QString> true_history_, working_history_;
         int trigger_pos_; // Where emoji completer was triggered
         size_t history_index_;