Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
Sonde::anonymous_namespace{modeltools.cpp} Namespace Reference

Classes

struct  Role
 A role (built-in or from the model's roleNames()), and its name. More...

Functions

const std::array< std::pair< QLatin1StringView, int >, 8 > & standardRoles ()
 The built-in roles, by the names the tool accepts.
int roleByName (const QString &name, const QHash< int, QByteArray > &names)
 The role called name (built-in or one of names), or -1.
QString knownRoles (const QHash< int, QByteArray > &names)
 Every role name the tool accepts for a model with names, for error messages.
std::optional< QList< Role > > rolesFor (const QAbstractItemModel *model, const QJsonArray &requested, QString *error)
 The roles to read: those named in requested, or by default "display" plus the model's own roles (those at Qt::UserRole and above, as QML models use).
QJsonValue cellJson (const QVariant &v, int role)
 A cell value as JSON; check states by name, decorations described rather than encoded.
QAbstractItemModel * resolveModel (const QString &spec, QObject **view, QString *error)
 The model named by spec (a model, or a view or combo box showing one), with the object it was found through.
std::optional< QModelIndex > parentIndex (const QAbstractItemModel *model, const QJsonArray &path, QString *error)
 The index that "parent" (a list of row numbers from the top, column 0 each) names.
QJsonArray rowCells (const QAbstractItemModel *model, int row, int columns, const QModelIndex &parent, const QList< Role > &roles)
 The cells of one row as JSON objects {role: value}.
QString cellText (const QJsonObject &cell)
 One cell for the text form: its display text, or its roles as name=value.
bool rowContains (const QAbstractItemModel *model, int row, int columns, const QModelIndex &parent, const QString &text)
 Whether any column of row shows text (case-insensitive, display role).
QList< int > selectRows (const QAbstractItemModel *model, const QJsonObject &args, const QModelIndex &parent, int columns, bool *more)
 The rows to show: from 'row' on, or those matching 'find'.
QJsonArray headerLabels (const QAbstractItemModel *model, int columns)
 The header labels of the first columns columns (empty if the model has none).
ToolResult modelRead (const QJsonObject &args)
 The model_read tool.
ToolResult modelLocate (const QJsonObject &args)
 The model_locate tool.
QJsonObject commonProperties ()
 The "object" and "parent" properties shared by both tools.

Variables

constexpr int kDefaultRows = 50
 Default and largest number of rows model_read returns.
constexpr int kMaxRows = 500
 See kDefaultRows.
constexpr int kMaxColumns = 50
 Most columns model_read returns.
constexpr int kMaxSearchedRows = 100000
 Most rows a 'find' search looks at.
constexpr qsizetype kMaxCellText = 80
 Longest text shown for one cell in the text form (JSON has it all).

Function Documentation

◆ resolveModel()

QAbstractItemModel * Sonde::anonymous_namespace{modeltools.cpp}::resolveModel ( const QString & spec,
QObject ** view,
QString * error )

The model named by spec (a model, or a view or combo box showing one), with the object it was found through.

Returns
The model, or nullptr with error set.