rename CompletionModel to CompletionProxyModel

This commit is contained in:
Jussi Kuokkanen 2020-09-02 13:32:57 +03:00 committed by Nicolas Werner
parent cabeb1464c
commit 748bf0cd98
3 changed files with 24 additions and 4 deletions

View file

@ -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;
}
};

View file

@ -30,7 +30,7 @@
#include "Cache.h" #include "Cache.h"
#include "ChatPage.h" #include "ChatPage.h"
#include "CompletionModel.h" #include "CompletionProxyModel.h"
#include "Logging.h" #include "Logging.h"
#include "TextInputWidget.h" #include "TextInputWidget.h"
#include "Utils.h" #include "Utils.h"
@ -70,7 +70,7 @@ FilteredTextEdit::FilteredTextEdit(QWidget *parent)
completer_->setWidget(this); completer_->setWidget(this);
auto model = new emoji::EmojiSearchModel(this); auto model = new emoji::EmojiSearchModel(this);
model->sort(0, Qt::AscendingOrder); 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_->setModelSorting(QCompleter::UnsortedModel);
completer_->popup()->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); completer_->popup()->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
completer_->popup()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); completer_->popup()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

View file

@ -31,7 +31,7 @@
struct SearchResult; struct SearchResult;
class CompletionModel; class CompletionProxyModel;
class FlatButton; class FlatButton;
class LoadingIndicator; class LoadingIndicator;
class QCompleter; class QCompleter;
@ -72,7 +72,7 @@ protected:
private: private:
bool emoji_popup_open_ = false; bool emoji_popup_open_ = false;
CompletionModel *emoji_completion_model_; CompletionProxyModel *emoji_completion_model_;
std::deque<QString> true_history_, working_history_; std::deque<QString> true_history_, working_history_;
int trigger_pos_; // Where emoji completer was triggered int trigger_pos_; // Where emoji completer was triggered
size_t history_index_; size_t history_index_;