Commit edd799c2 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Improve quickopen performance

parent 7cb6078b
......@@ -67,13 +67,10 @@ protected:
return true;
}
const auto idx = sourceModel()->index(sourceRow, 0, sourceParent);
const QString fileName = idx.data().toString();
const auto nameAndPath = fileName.splitRef(QStringLiteral("{[split]}"));
const QString name = idx.data(KateQuickOpenModel::FileName).toString();
const QString path = idx.data(KateQuickOpenModel::FilePath).toString();
const auto &name = nameAndPath.at(0);
const auto &path = nameAndPath.at(1);
int score = 0;
bool res = false;
if (mode == FilterMode::FilterByName) {
res = filterByName(name, score);
......@@ -103,12 +100,12 @@ public Q_SLOTS:
}
private:
inline bool filterByPath(const QStringRef &path, int &score) const
inline bool filterByPath(const QString &path, int &score) const
{
return kfts::fuzzy_match(pattern, path, score);
}
inline bool filterByName(const QStringRef &name, int &score) const
inline bool filterByName(const QString &name, int &score) const
{
return kfts::fuzzy_match(pattern, name, score);
}
......@@ -133,11 +130,8 @@ public:
QTextDocument doc;
QString str = index.data().toString();
auto namePath = str.split(QStringLiteral("{[split]}"));
QString name = namePath.at(0);
QString path = namePath.at(1);
QString name = index.data(KateQuickOpenModel::FileName).toString();
QString path = index.data(KateQuickOpenModel::FilePath).toString();
path.remove(QStringLiteral("/") + name);
......
......@@ -44,11 +44,14 @@ QVariant KateQuickOpenModel::data(const QModelIndex &idx, int role) const
}
const ModelEntry &entry = m_modelEntries.at(idx.row());
if (role == Qt::DisplayRole) {
switch (idx.column()) {
case Columns::FileName:
return QString(entry.fileName + QStringLiteral("{[split]}") + entry.filePath);
}
if (role == Role::FileName) {
return entry.fileName;
} else if (role == Role::FilePath) {
return entry.filePath;
} else if (role == Qt::DisplayRole) {
// Shouldn't ask for displayrole
Q_ASSERT(false);
return {};
} else if (role == Qt::FontRole) {
if (entry.bold) {
QFont font;
......
......@@ -32,8 +32,7 @@ class KateQuickOpenModel : public QAbstractTableModel
{
Q_OBJECT
public:
enum Columns : int { FileName, FilePath, Bold };
enum Role { Score = Qt::UserRole + 1 };
enum Role { FileName = Qt::UserRole + 1, FilePath, Score };
explicit KateQuickOpenModel(KateMainWindow *mainWindow, QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent) const override;
......
Markdown is supported
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