Document actionsmodel and cleanup includes
This commit is contained in:
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "neochatroom.h"
|
#include "neochatroom.h"
|
||||||
#include "neochatuser.h"
|
|
||||||
#include "roommanager.h"
|
#include "roommanager.h"
|
||||||
#include <events/roommemberevent.h>
|
#include <events/roommemberevent.h>
|
||||||
#include <events/roompowerlevelsevent.h>
|
#include <events/roompowerlevelsevent.h>
|
||||||
|
|||||||
@@ -9,20 +9,42 @@
|
|||||||
|
|
||||||
class NeoChatRoom;
|
class NeoChatRoom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class ActionsModel
|
||||||
|
*
|
||||||
|
* This class defines a model for chat actions.
|
||||||
|
*
|
||||||
|
* @note A chat action is a message starting with /, resulting in something other
|
||||||
|
* than a normal message being sent (e.g. /me, /join).
|
||||||
|
*/
|
||||||
class ActionsModel : public QAbstractListModel
|
class ActionsModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Definition of an action.
|
||||||
|
*/
|
||||||
struct Action {
|
struct Action {
|
||||||
// The prefix, without '/' and space after the word
|
QString prefix; /**< The prefix, without '/' and space after the word. */
|
||||||
QString prefix;
|
/**
|
||||||
|
* @brief The function to execute when the action is triggered.
|
||||||
|
*/
|
||||||
std::function<QString(const QString &, NeoChatRoom *)> handle;
|
std::function<QString(const QString &, NeoChatRoom *)> handle;
|
||||||
// If this is true, this action transforms a message to a different message and it will be sent.
|
/**
|
||||||
// If this is false, this message does some action on the client and should not be sent as a message.
|
* @brief Whether the action is a message type action.
|
||||||
|
*
|
||||||
|
* If this is true, a message action will be sent. If this is false, this
|
||||||
|
* message does some action on the client and should not be sent as a message.
|
||||||
|
*/
|
||||||
bool messageAction;
|
bool messageAction;
|
||||||
// If this action changes the message type, this is the new message type. Otherwise it's nullopt
|
/**
|
||||||
|
* @brief The new message type of a message being sent.
|
||||||
|
*
|
||||||
|
* For a non-message action or a message action that outputs the same type
|
||||||
|
* as its input, it's nullopt.
|
||||||
|
*/
|
||||||
std::optional<Quotient::RoomMessageEvent::MsgType> messageType = std::nullopt;
|
std::optional<Quotient::RoomMessageEvent::MsgType> messageType = std::nullopt;
|
||||||
KLazyLocalizedString parameters;
|
KLazyLocalizedString parameters; /**< The input parameters expected by the action. */
|
||||||
KLazyLocalizedString description;
|
KLazyLocalizedString description; /**< The description of the action. */
|
||||||
};
|
};
|
||||||
static ActionsModel &instance()
|
static ActionsModel &instance()
|
||||||
{
|
{
|
||||||
@@ -30,18 +52,41 @@ public:
|
|||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Defines the model roles.
|
||||||
|
*/
|
||||||
enum Roles {
|
enum Roles {
|
||||||
Prefix = Qt::DisplayRole,
|
Prefix = Qt::DisplayRole, /**< The prefix, without '/' and space after the word. */
|
||||||
Description,
|
Description, /**< The description of the action. */
|
||||||
CompletionType,
|
CompletionType, /**< The completion type (always "action" for this model). */
|
||||||
Parameters,
|
Parameters, /**< The input parameters expected by the action. */
|
||||||
};
|
};
|
||||||
Q_ENUM(Roles);
|
Q_ENUM(Roles);
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
/**
|
||||||
|
* @brief Get the given role value at the given index.
|
||||||
|
*
|
||||||
|
* @sa QAbstractItemModel::data
|
||||||
|
*/
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Number of rows in the model.
|
||||||
|
*
|
||||||
|
* @sa QAbstractItemModel::rowCount
|
||||||
|
*/
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a mapping from Role enum values to role names.
|
||||||
|
*
|
||||||
|
* @sa EventRoles, QAbstractItemModel::roleNames()
|
||||||
|
*/
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return a vector with all supported actions.
|
||||||
|
*/
|
||||||
QVector<Action> &allActions() const;
|
QVector<Action> &allActions() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user