feat: add autocompletion for commands

partially copied code from emojimodel.h
This commit is contained in:
Srevin Saju
2021-05-01 13:27:54 +03:00
parent 57684aa454
commit ee595ed374
2 changed files with 90 additions and 0 deletions

58
src/commandmodel.h Normal file
View File

@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: 2021 Srevin Saju <srevinsaju@sugarlabs.org>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <QObject>
#include <QSettings>
#include <QVariant>
#include <QVector>
#include <utility>
struct Command {
Command(QString u, QString s)
: command(std::move(std::move(u)))
, help(std::move(std::move(s)))
{
}
Command() = default;
friend QDataStream &operator<<(QDataStream &arch, const Command &object)
{
arch << object.command;
arch << object.help;
return arch;
}
friend QDataStream &operator>>(QDataStream &arch, Command &object)
{
arch >> object.command;
arch >> object.help;
return arch;
}
QString command;
QString help;
Q_GADGET
Q_PROPERTY(QString command MEMBER command)
Q_PROPERTY(QString help MEMBER help)
};
Q_DECLARE_METATYPE(Command)
class CommandModel : public QObject
{
Q_OBJECT
public:
explicit CommandModel(QObject *parent = nullptr)
: QObject(parent)
{
}
Q_INVOKABLE static QVariantList filterModel(const QString &filter);
private:
static const QVariantList matrix;
};