aboutsummaryrefslogtreecommitdiff
path: root/src/completion/CommandsModel.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/completion/CommandsModel.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/completion/CommandsModel.cpp b/src/completion/CommandsModel.cpp
new file mode 100644
index 0000000..0f66233
--- /dev/null
+++ b/src/completion/CommandsModel.cpp
@@ -0,0 +1,42 @@
+#include <QAbstractListModel>
+#include <QWidget>
+#include <QtCore>
+
+#include "completion/CommandsModel.hpp"
+
+CommandsModel::CommandsModel(QObject *parent) : QAbstractListModel(parent) {
+ items = commands;
+}
+
+QVariant CommandsModel::data(const QModelIndex &index, int role) const {
+ if (!index.isValid() || index.row() >= items.size())
+ return QVariant();
+
+ const Command &item = items.at(index.row());
+
+ if (role == Qt::DisplayRole)
+ return item.name;
+ else if (role == Qt::ToolTipRole)
+ return item.description;
+ else if (role == Qt::UserRole)
+ return item.description;
+
+ return QVariant();
+}
+
+QHash<int, QByteArray> CommandsModel::roleNames() const {
+ QHash<int, QByteArray> roles;
+ roles[Qt::DisplayRole] = "name";
+ roles[Qt::UserRole] = "description";
+ return roles;
+}
+
+int CommandsModel::rowCount(const QModelIndex &parent) const {
+ Q_UNUSED(parent);
+ return items.size();
+}
+
+int CommandsModel::columnCount(const QModelIndex &parent) const {
+ Q_UNUSED(parent);
+ return 2; // name + description
+}