Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
modeltools.cpp File Reference

The model_read / model_locate tools: the data in item models, and where cells are shown. More...

#include <sonde/guiintegration.h>
#include <sonde/guitools.h>
#include <sonde/objecttree.h>
#include <sonde/schema.h>
#include <QtCore/QAbstractItemModel>
#include <QtCore/QJsonArray>
#include <QtCore/QJsonDocument>
#include <QtGui/QWindow>
#include <algorithm>
#include <array>

Classes

struct  Sonde::anonymous_namespace{modeltools.cpp}::Role
 A role (built-in or from the model's roleNames()), and its name. More...

Namespaces

namespace  Sonde
 Embeddable Model Context Protocol server for Qt applications.

Functions

const std::array< std::pair< QLatin1StringView, int >, 8 > & Sonde::anonymous_namespace{modeltools.cpp}::standardRoles ()
 The built-in roles, by the names the tool accepts.
int Sonde::anonymous_namespace{modeltools.cpp}::roleByName (const QString &name, const QHash< int, QByteArray > &names)
 The role called name (built-in or one of names), or -1.
QString Sonde::anonymous_namespace{modeltools.cpp}::knownRoles (const QHash< int, QByteArray > &names)
 Every role name the tool accepts for a model with names, for error messages.
std::optional< QList< Role > > Sonde::anonymous_namespace{modeltools.cpp}::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 Sonde::anonymous_namespace{modeltools.cpp}::cellJson (const QVariant &v, int role)
 A cell value as JSON; check states by name, decorations described rather than encoded.
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.
std::optional< QModelIndex > Sonde::anonymous_namespace{modeltools.cpp}::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 Sonde::anonymous_namespace{modeltools.cpp}::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 Sonde::anonymous_namespace{modeltools.cpp}::cellText (const QJsonObject &cell)
 One cell for the text form: its display text, or its roles as name=value.
bool Sonde::anonymous_namespace{modeltools.cpp}::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 > Sonde::anonymous_namespace{modeltools.cpp}::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 Sonde::anonymous_namespace{modeltools.cpp}::headerLabels (const QAbstractItemModel *model, int columns)
 The header labels of the first columns columns (empty if the model has none).
ToolResult Sonde::anonymous_namespace{modeltools.cpp}::modelRead (const QJsonObject &args)
 The model_read tool.
ToolResult Sonde::anonymous_namespace{modeltools.cpp}::modelLocate (const QJsonObject &args)
 The model_locate tool.
QJsonObject Sonde::anonymous_namespace{modeltools.cpp}::commonProperties ()
 The "object" and "parent" properties shared by both tools.
void Sonde::installModelTools (Server &server)
 Registers model_read and model_locate: the data in item models (through their views), and where a cell is on screen.

Variables

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

Detailed Description

The model_read / model_locate tools: the data in item models, and where cells are shown.