From 971854bfefad4c644ac3d5f5d6003f24d551bf1d Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Mon, 10 Mar 2025 22:04:24 +0530 Subject: Add completer + simplify command parsing + class generator --- src/completion/CommandsModel.cpp | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/completion/CommandsModel.cpp (limited to 'src/completion/CommandsModel.cpp') 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 +#include +#include + +#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 CommandsModel::roleNames() const { + QHash 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 +} -- cgit v1.3.1