Add setter functions for model itemproperties
parent
3388f68de5
commit
6576cf69e5
|
@ -177,6 +177,7 @@ Qt::ItemFlags FibonacciList::flags(const QModelIndex &i) const
|
||||||
auto flags = QAbstractItemModel::flags(i);
|
auto flags = QAbstractItemModel::flags(i);
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant FibonacciList::result(int row) const
|
QVariant FibonacciList::result(int row) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
|
@ -197,6 +198,7 @@ QVariant FibonacciList::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> FibonacciList::roleNames() const {
|
QHash<int, QByteArray> FibonacciList::roleNames() const {
|
||||||
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
||||||
names.insert(Qt::UserRole + 0, "result");
|
names.insert(Qt::UserRole + 0, "result");
|
||||||
|
@ -221,12 +223,9 @@ bool FibonacciList::setHeaderData(int section, Qt::Orientation orientation, cons
|
||||||
|
|
||||||
bool FibonacciList::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool FibonacciList::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
bool set = false;
|
return false;
|
||||||
if (set) {
|
|
||||||
emit dataChanged(index, index, QVector<int>() << role);
|
|
||||||
}
|
|
||||||
return set;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
FibonacciList::Private* fibonacci_list_new(FibonacciList*,
|
FibonacciList::Private* fibonacci_list_new(FibonacciList*,
|
||||||
void (*)(const FibonacciList*),
|
void (*)(const FibonacciList*),
|
||||||
|
@ -320,6 +319,7 @@ Qt::ItemFlags FileSystemTree::flags(const QModelIndex &i) const
|
||||||
auto flags = QAbstractItemModel::flags(i);
|
auto flags = QAbstractItemModel::flags(i);
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant FileSystemTree::fileIcon(const QModelIndex& index) const
|
QVariant FileSystemTree::fileIcon(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
|
@ -328,6 +328,7 @@ QVariant FileSystemTree::fileIcon(const QModelIndex& index) const
|
||||||
if (!b.isNull()) v.setValue<QByteArray>(b);
|
if (!b.isNull()) v.setValue<QByteArray>(b);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant FileSystemTree::fileName(const QModelIndex& index) const
|
QVariant FileSystemTree::fileName(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
|
@ -336,6 +337,7 @@ QVariant FileSystemTree::fileName(const QModelIndex& index) const
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant FileSystemTree::filePath(const QModelIndex& index) const
|
QVariant FileSystemTree::filePath(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
|
@ -344,18 +346,21 @@ QVariant FileSystemTree::filePath(const QModelIndex& index) const
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant FileSystemTree::filePermissions(const QModelIndex& index) const
|
QVariant FileSystemTree::filePermissions(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
v = file_system_tree_data_file_permissions(m_d, index.internalId());
|
v = file_system_tree_data_file_permissions(m_d, index.internalId());
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant FileSystemTree::fileSize(const QModelIndex& index) const
|
QVariant FileSystemTree::fileSize(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
v = file_system_tree_data_file_size(m_d, index.internalId());
|
v = file_system_tree_data_file_size(m_d, index.internalId());
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant FileSystemTree::fileType(const QModelIndex& index) const
|
QVariant FileSystemTree::fileType(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
|
@ -411,6 +416,7 @@ QVariant FileSystemTree::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> FileSystemTree::roleNames() const {
|
QHash<int, QByteArray> FileSystemTree::roleNames() const {
|
||||||
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
||||||
names.insert(Qt::UserRole + 0, "fileIcon");
|
names.insert(Qt::UserRole + 0, "fileIcon");
|
||||||
|
@ -440,12 +446,9 @@ bool FileSystemTree::setHeaderData(int section, Qt::Orientation orientation, con
|
||||||
|
|
||||||
bool FileSystemTree::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool FileSystemTree::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
bool set = false;
|
return false;
|
||||||
if (set) {
|
|
||||||
emit dataChanged(index, index, QVector<int>() << role);
|
|
||||||
}
|
|
||||||
return set;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
FileSystemTree::Private* file_system_tree_new(FileSystemTree*, void (*)(FileSystemTree*),
|
FileSystemTree::Private* file_system_tree_new(FileSystemTree*, void (*)(FileSystemTree*),
|
||||||
void (*)(const FileSystemTree*, quintptr, bool),
|
void (*)(const FileSystemTree*, quintptr, bool),
|
||||||
|
@ -543,6 +546,7 @@ Qt::ItemFlags Processes::flags(const QModelIndex &i) const
|
||||||
auto flags = QAbstractItemModel::flags(i);
|
auto flags = QAbstractItemModel::flags(i);
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Processes::cmd(const QModelIndex& index) const
|
QVariant Processes::cmd(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
|
@ -551,24 +555,28 @@ QVariant Processes::cmd(const QModelIndex& index) const
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Processes::cpuPercentage(const QModelIndex& index) const
|
QVariant Processes::cpuPercentage(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
v = processes_data_cpu_percentage(m_d, index.internalId());
|
v = processes_data_cpu_percentage(m_d, index.internalId());
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Processes::cpuUsage(const QModelIndex& index) const
|
QVariant Processes::cpuUsage(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
v = processes_data_cpu_usage(m_d, index.internalId());
|
v = processes_data_cpu_usage(m_d, index.internalId());
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Processes::memory(const QModelIndex& index) const
|
QVariant Processes::memory(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
v = processes_data_memory(m_d, index.internalId());
|
v = processes_data_memory(m_d, index.internalId());
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Processes::name(const QModelIndex& index) const
|
QVariant Processes::name(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
|
@ -577,12 +585,14 @@ QVariant Processes::name(const QModelIndex& index) const
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Processes::pid(const QModelIndex& index) const
|
QVariant Processes::pid(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
v = processes_data_pid(m_d, index.internalId());
|
v = processes_data_pid(m_d, index.internalId());
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Processes::uid(const QModelIndex& index) const
|
QVariant Processes::uid(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
|
@ -628,6 +638,7 @@ QVariant Processes::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> Processes::roleNames() const {
|
QHash<int, QByteArray> Processes::roleNames() const {
|
||||||
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
||||||
names.insert(Qt::UserRole + 0, "cmd");
|
names.insert(Qt::UserRole + 0, "cmd");
|
||||||
|
@ -658,12 +669,9 @@ bool Processes::setHeaderData(int section, Qt::Orientation orientation, const QV
|
||||||
|
|
||||||
bool Processes::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool Processes::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
bool set = false;
|
return false;
|
||||||
if (set) {
|
|
||||||
emit dataChanged(index, index, QVector<int>() << role);
|
|
||||||
}
|
|
||||||
return set;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
Processes::Private* processes_new(Processes*, void (*)(Processes*),
|
Processes::Private* processes_new(Processes*, void (*)(Processes*),
|
||||||
void (*)(const Processes*, quintptr, bool),
|
void (*)(const Processes*, quintptr, bool),
|
||||||
|
@ -745,12 +753,25 @@ Qt::ItemFlags TimeSeries::flags(const QModelIndex &i) const
|
||||||
}
|
}
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant TimeSeries::input(int row) const
|
QVariant TimeSeries::input(int row) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
v = time_series_data_input(m_d, row);
|
v = time_series_data_input(m_d, row);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TimeSeries::setInput(int row, const QVariant& value)
|
||||||
|
{
|
||||||
|
bool set = false;
|
||||||
|
set = time_series_set_data_input(m_d, row, value.value<quint32>());
|
||||||
|
if (set) {
|
||||||
|
QModelIndex index = createIndex(row, 0, row);
|
||||||
|
emit dataChanged(index, index);
|
||||||
|
}
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
QVariant TimeSeries::result(int row) const
|
QVariant TimeSeries::result(int row) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
|
@ -758,6 +779,17 @@ QVariant TimeSeries::result(int row) const
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TimeSeries::setResult(int row, const QVariant& value)
|
||||||
|
{
|
||||||
|
bool set = false;
|
||||||
|
set = time_series_set_data_result(m_d, row, value.value<quint32>());
|
||||||
|
if (set) {
|
||||||
|
QModelIndex index = createIndex(row, 0, row);
|
||||||
|
emit dataChanged(index, index);
|
||||||
|
}
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
QVariant TimeSeries::data(const QModelIndex &index, int role) const
|
QVariant TimeSeries::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(rowCount(index.parent()) > index.row());
|
Q_ASSERT(rowCount(index.parent()) > index.row());
|
||||||
|
@ -781,6 +813,7 @@ QVariant TimeSeries::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> TimeSeries::roleNames() const {
|
QHash<int, QByteArray> TimeSeries::roleNames() const {
|
||||||
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
||||||
names.insert(Qt::UserRole + 0, "input");
|
names.insert(Qt::UserRole + 0, "input");
|
||||||
|
@ -806,25 +839,22 @@ bool TimeSeries::setHeaderData(int section, Qt::Orientation orientation, const Q
|
||||||
|
|
||||||
bool TimeSeries::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool TimeSeries::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
bool set = false;
|
|
||||||
if (index.column() == 0) {
|
if (index.column() == 0) {
|
||||||
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 0) {
|
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 0) {
|
||||||
set = time_series_set_data_input(m_d, index.row(), value.value<quint32>());
|
return setInput(index.row(), value);
|
||||||
}
|
}
|
||||||
if (role == Qt::UserRole + 1) {
|
if (role == Qt::UserRole + 1) {
|
||||||
set = time_series_set_data_result(m_d, index.row(), value.value<quint32>());
|
return setResult(index.row(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (index.column() == 1) {
|
if (index.column() == 1) {
|
||||||
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 1) {
|
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 1) {
|
||||||
set = time_series_set_data_result(m_d, index.row(), value.value<quint32>());
|
return setResult(index.row(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (set) {
|
return false;
|
||||||
emit dataChanged(index, index, QVector<int>() << role);
|
|
||||||
}
|
|
||||||
return set;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
TimeSeries::Private* time_series_new(TimeSeries*,
|
TimeSeries::Private* time_series_new(TimeSeries*,
|
||||||
void (*)(const TimeSeries*),
|
void (*)(const TimeSeries*),
|
||||||
|
@ -1150,7 +1180,7 @@ FibonacciList::~FibonacciList() {
|
||||||
}
|
}
|
||||||
void FibonacciList::initHeaderData() {
|
void FibonacciList::initHeaderData() {
|
||||||
m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("result"));
|
m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("result"));
|
||||||
}
|
}
|
||||||
FileSystemTree::FileSystemTree(bool /*owned*/, QObject *parent):
|
FileSystemTree::FileSystemTree(bool /*owned*/, QObject *parent):
|
||||||
QAbstractItemModel(parent),
|
QAbstractItemModel(parent),
|
||||||
m_d(0),
|
m_d(0),
|
||||||
|
@ -1225,7 +1255,7 @@ void FileSystemTree::initHeaderData() {
|
||||||
m_headerData.insert(qMakePair(2, Qt::DisplayRole), QVariant("filePath"));
|
m_headerData.insert(qMakePair(2, Qt::DisplayRole), QVariant("filePath"));
|
||||||
m_headerData.insert(qMakePair(3, Qt::DisplayRole), QVariant("filePermissions"));
|
m_headerData.insert(qMakePair(3, Qt::DisplayRole), QVariant("filePermissions"));
|
||||||
m_headerData.insert(qMakePair(4, Qt::DisplayRole), QVariant("fileType"));
|
m_headerData.insert(qMakePair(4, Qt::DisplayRole), QVariant("fileType"));
|
||||||
}
|
}
|
||||||
QString FileSystemTree::path() const
|
QString FileSystemTree::path() const
|
||||||
{
|
{
|
||||||
QString v;
|
QString v;
|
||||||
|
@ -1311,7 +1341,7 @@ void Processes::initHeaderData() {
|
||||||
m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("name"));
|
m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("name"));
|
||||||
m_headerData.insert(qMakePair(1, Qt::DisplayRole), QVariant("cpuUsage"));
|
m_headerData.insert(qMakePair(1, Qt::DisplayRole), QVariant("cpuUsage"));
|
||||||
m_headerData.insert(qMakePair(2, Qt::DisplayRole), QVariant("memory"));
|
m_headerData.insert(qMakePair(2, Qt::DisplayRole), QVariant("memory"));
|
||||||
}
|
}
|
||||||
bool Processes::active() const
|
bool Processes::active() const
|
||||||
{
|
{
|
||||||
return processes_active_get(m_d);
|
return processes_active_get(m_d);
|
||||||
|
@ -1372,4 +1402,4 @@ TimeSeries::~TimeSeries() {
|
||||||
void TimeSeries::initHeaderData() {
|
void TimeSeries::initHeaderData() {
|
||||||
m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("input"));
|
m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("input"));
|
||||||
m_headerData.insert(qMakePair(1, Qt::DisplayRole), QVariant("result"));
|
m_headerData.insert(qMakePair(1, Qt::DisplayRole), QVariant("result"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,13 +103,14 @@ public:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
||||||
|
Q_INVOKABLE QVariant result(int row) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
void newDataReady(const QModelIndex &parent) const;
|
void newDataReady(const QModelIndex &parent) const;
|
||||||
private:
|
private:
|
||||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||||
void initHeaderData();
|
void initHeaderData();
|
||||||
QVariant result(int row) const;
|
|
||||||
signals:
|
signals:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -144,18 +145,19 @@ public:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
||||||
|
Q_INVOKABLE QVariant fileIcon(const QModelIndex& index) const;
|
||||||
|
Q_INVOKABLE QVariant fileName(const QModelIndex& index) const;
|
||||||
|
Q_INVOKABLE QVariant filePath(const QModelIndex& index) const;
|
||||||
|
Q_INVOKABLE QVariant filePermissions(const QModelIndex& index) const;
|
||||||
|
Q_INVOKABLE QVariant fileSize(const QModelIndex& index) const;
|
||||||
|
Q_INVOKABLE QVariant fileType(const QModelIndex& index) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
void newDataReady(const QModelIndex &parent) const;
|
void newDataReady(const QModelIndex &parent) const;
|
||||||
private:
|
private:
|
||||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||||
void initHeaderData();
|
void initHeaderData();
|
||||||
QVariant fileIcon(const QModelIndex& index) const;
|
|
||||||
QVariant fileName(const QModelIndex& index) const;
|
|
||||||
QVariant filePath(const QModelIndex& index) const;
|
|
||||||
QVariant filePermissions(const QModelIndex& index) const;
|
|
||||||
QVariant fileSize(const QModelIndex& index) const;
|
|
||||||
QVariant fileType(const QModelIndex& index) const;
|
|
||||||
signals:
|
signals:
|
||||||
void pathChanged();
|
void pathChanged();
|
||||||
};
|
};
|
||||||
|
@ -191,19 +193,20 @@ public:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
||||||
|
Q_INVOKABLE QVariant cmd(const QModelIndex& index) const;
|
||||||
|
Q_INVOKABLE QVariant cpuPercentage(const QModelIndex& index) const;
|
||||||
|
Q_INVOKABLE QVariant cpuUsage(const QModelIndex& index) const;
|
||||||
|
Q_INVOKABLE QVariant memory(const QModelIndex& index) const;
|
||||||
|
Q_INVOKABLE QVariant name(const QModelIndex& index) const;
|
||||||
|
Q_INVOKABLE QVariant pid(const QModelIndex& index) const;
|
||||||
|
Q_INVOKABLE QVariant uid(const QModelIndex& index) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
void newDataReady(const QModelIndex &parent) const;
|
void newDataReady(const QModelIndex &parent) const;
|
||||||
private:
|
private:
|
||||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||||
void initHeaderData();
|
void initHeaderData();
|
||||||
QVariant cmd(const QModelIndex& index) const;
|
|
||||||
QVariant cpuPercentage(const QModelIndex& index) const;
|
|
||||||
QVariant cpuUsage(const QModelIndex& index) const;
|
|
||||||
QVariant memory(const QModelIndex& index) const;
|
|
||||||
QVariant name(const QModelIndex& index) const;
|
|
||||||
QVariant pid(const QModelIndex& index) const;
|
|
||||||
QVariant uid(const QModelIndex& index) const;
|
|
||||||
signals:
|
signals:
|
||||||
void activeChanged();
|
void activeChanged();
|
||||||
};
|
};
|
||||||
|
@ -236,14 +239,17 @@ public:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
||||||
|
Q_INVOKABLE QVariant input(int row) const;
|
||||||
|
Q_INVOKABLE bool setInput(int row, const QVariant& value);
|
||||||
|
Q_INVOKABLE QVariant result(int row) const;
|
||||||
|
Q_INVOKABLE bool setResult(int row, const QVariant& value);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
void newDataReady(const QModelIndex &parent) const;
|
void newDataReady(const QModelIndex &parent) const;
|
||||||
private:
|
private:
|
||||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||||
void initHeaderData();
|
void initHeaderData();
|
||||||
QVariant input(int row) const;
|
|
||||||
QVariant result(int row) const;
|
|
||||||
signals:
|
signals:
|
||||||
};
|
};
|
||||||
#endif // BINDINGS_H
|
#endif // BINDINGS_H
|
||||||
|
|
171
src/cpp.cpp
171
src/cpp.cpp
|
@ -51,26 +51,28 @@ void writeHeaderItemModel(QTextStream& h, const Object& o) {
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
||||||
|
)");
|
||||||
|
for (auto ip: o.itemProperties) {
|
||||||
|
if (o.type == ObjectType::List) {
|
||||||
|
h << QString(" Q_INVOKABLE QVariant %1(int row) const;\n").arg(ip.name);
|
||||||
|
if (ip.write) {
|
||||||
|
h << QString(" Q_INVOKABLE bool set%1(int row, const QVariant& value);\n").arg(upperInitial(ip.name));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
h << QString(" Q_INVOKABLE QVariant %1(const QModelIndex& index) const;\n").arg(ip.name);
|
||||||
|
if (ip.write) {
|
||||||
|
h << QString(" Q_INVOKABLE bool set%1(const QModelIndex& index, const QVariant& value);\n").arg(upperInitial(ip.name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
h << R"(
|
||||||
signals:
|
signals:
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
void newDataReady(const QModelIndex &parent) const;
|
void newDataReady(const QModelIndex &parent) const;
|
||||||
private:
|
private:
|
||||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||||
void initHeaderData();
|
void initHeaderData();
|
||||||
)");
|
)";
|
||||||
for (auto ip: o.itemProperties) {
|
|
||||||
if (o.type == ObjectType::List) {
|
|
||||||
h << QString(" QVariant %1(int row) const;\n").arg(ip.name);
|
|
||||||
} else {
|
|
||||||
h << QString(" QVariant %1(const QModelIndex& index) const;\n").arg(ip.name);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
if (ip.write) {
|
|
||||||
r << QString(" fn set_%1(&mut self, item: usize, %2) -> bool;\n")
|
|
||||||
.arg(snakeCase(ip.name), rustType(ip));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isColumnWrite(const Object& o, int col) {
|
bool isColumnWrite(const Object& o, int col) {
|
||||||
|
@ -82,6 +84,85 @@ bool isColumnWrite(const Object& o, int col) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void writeModelGetterSetter(QTextStream& cpp, const QString& index,
|
||||||
|
const ItemProperty& ip, const Object& o) {
|
||||||
|
const QString lcname(snakeCase(o.name));
|
||||||
|
QString idx = index;
|
||||||
|
|
||||||
|
// getter
|
||||||
|
if (o.type == ObjectType::List) {
|
||||||
|
idx = ", row";
|
||||||
|
cpp << QString("QVariant %1::%2(int row) const\n{\n")
|
||||||
|
.arg(o.name, ip.name);
|
||||||
|
} else {
|
||||||
|
cpp << QString("QVariant %1::%2(const QModelIndex& index) const\n{\n")
|
||||||
|
.arg(o.name, ip.name);
|
||||||
|
}
|
||||||
|
cpp << " QVariant v;\n";
|
||||||
|
if (ip.type.name == "QString") {
|
||||||
|
cpp << " QString s;\n";
|
||||||
|
cpp << QString(" %1_data_%2(m_d%4, &s, set_%3);\n")
|
||||||
|
.arg(lcname, snakeCase(ip.name), ip.type.name.toLower(), idx);
|
||||||
|
cpp << " if (!s.isNull()) v.setValue<QString>(s);\n";
|
||||||
|
} else if (ip.type.name == "QByteArray") {
|
||||||
|
cpp << " QByteArray b;\n";
|
||||||
|
cpp << QString(" %1_data_%2(m_d%4, &b, set_%3);\n")
|
||||||
|
.arg(lcname, snakeCase(ip.name), ip.type.name.toLower(), idx);
|
||||||
|
cpp << " if (!b.isNull()) v.setValue<QByteArray>(b);\n";
|
||||||
|
} else {
|
||||||
|
cpp << QString(" v = %1_data_%2(m_d%3);\n")
|
||||||
|
.arg(lcname, snakeCase(ip.name), idx);
|
||||||
|
}
|
||||||
|
cpp << " return v;\n";
|
||||||
|
cpp << "}\n\n";
|
||||||
|
|
||||||
|
if (!ip.write) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// setter
|
||||||
|
if (o.type == ObjectType::List) {
|
||||||
|
idx = ", row";
|
||||||
|
cpp << QString("bool %1::set%2(int row, const QVariant& value)\n{\n")
|
||||||
|
.arg(o.name, upperInitial(ip.name));
|
||||||
|
} else {
|
||||||
|
cpp << QString("bool %1::set%2(const QModelIndex& index, const QVariant& value)\n{\n")
|
||||||
|
.arg(o.name, upperInitial(ip.name));
|
||||||
|
}
|
||||||
|
cpp << " bool set = false;\n";
|
||||||
|
if (ip.optional) {
|
||||||
|
QString test = "!value.isValid()";
|
||||||
|
if (ip.type.isComplex()) {
|
||||||
|
test += " || value.isNull()";
|
||||||
|
}
|
||||||
|
cpp << " if (" << test << ") {\n";
|
||||||
|
cpp << QString(" set = %1_set_data_%2_none(m_d%3);")
|
||||||
|
.arg(lcname, snakeCase(ip.name), idx) << endl;
|
||||||
|
cpp << " } else\n";
|
||||||
|
}
|
||||||
|
QString val = QString("value.value<%1>()").arg(ip.type.name);
|
||||||
|
cpp << QString(" set = %1_set_data_%2(m_d%3, %4);")
|
||||||
|
.arg(lcname, snakeCase(ip.name), idx, val) << endl;
|
||||||
|
if (o.type == ObjectType::List) {
|
||||||
|
cpp << R"( if (set) {
|
||||||
|
QModelIndex index = createIndex(row, 0, row);
|
||||||
|
emit dataChanged(index, index);
|
||||||
|
}
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
)";
|
||||||
|
} else {
|
||||||
|
cpp << R"( if (set) {
|
||||||
|
emit dataChanged(index, index);
|
||||||
|
}
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void writeCppModel(QTextStream& cpp, const Object& o) {
|
void writeCppModel(QTextStream& cpp, const Object& o) {
|
||||||
const QString lcname(snakeCase(o.name));
|
const QString lcname(snakeCase(o.name));
|
||||||
QString indexDecl = ", int";
|
QString indexDecl = ", int";
|
||||||
|
@ -237,37 +318,11 @@ Qt::ItemFlags %1::flags(const QModelIndex &i) const
|
||||||
cpp << " flags |= Qt::ItemIsEditable;\n }\n";
|
cpp << " flags |= Qt::ItemIsEditable;\n }\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cpp << " return flags;\n}\n";
|
cpp << " return flags;\n}\n\n";
|
||||||
for (auto ip: o.itemProperties) {
|
for (auto ip: o.itemProperties) {
|
||||||
QString idx = index;
|
writeModelGetterSetter(cpp, index, ip, o);
|
||||||
if (o.type == ObjectType::List) {
|
|
||||||
idx = ", row";
|
|
||||||
cpp << QString("QVariant %1::%2(int row) const\n{\n")
|
|
||||||
.arg(o.name, ip.name);
|
|
||||||
} else {
|
|
||||||
cpp << QString("QVariant %1::%2(const QModelIndex& index) const\n{\n")
|
|
||||||
.arg(o.name, ip.name);
|
|
||||||
}
|
|
||||||
cpp << " QVariant v;\n";
|
|
||||||
if (ip.type.name == "QString") {
|
|
||||||
cpp << " QString s;\n";
|
|
||||||
cpp << QString(" %1_data_%2(m_d%4, &s, set_%3);\n")
|
|
||||||
.arg(lcname, snakeCase(ip.name), ip.type.name.toLower(), idx);
|
|
||||||
cpp << " if (!s.isNull()) v.setValue<QString>(s);\n";
|
|
||||||
} else if (ip.type.name == "QByteArray") {
|
|
||||||
cpp << " QByteArray b;\n";
|
|
||||||
cpp << QString(" %1_data_%2(m_d%4, &b, set_%3);\n")
|
|
||||||
.arg(lcname, snakeCase(ip.name), ip.type.name.toLower(), idx);
|
|
||||||
cpp << " if (!b.isNull()) v.setValue<QByteArray>(b);\n";
|
|
||||||
} else {
|
|
||||||
cpp << QString(" v = %1_data_%2(m_d%3);\n")
|
|
||||||
.arg(lcname, snakeCase(ip.name), idx);
|
|
||||||
}
|
|
||||||
cpp << " return v;\n";
|
|
||||||
cpp << "}\n";
|
|
||||||
}
|
}
|
||||||
cpp << QString(R"(
|
cpp << QString(R"(QVariant %1::data(const QModelIndex &index, int role) const
|
||||||
QVariant %1::data(const QModelIndex &index, int role) const
|
|
||||||
{
|
{
|
||||||
Q_ASSERT(rowCount(index.parent()) > index.row());
|
Q_ASSERT(rowCount(index.parent()) > index.row());
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
|
@ -295,7 +350,7 @@ QVariant %1::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
cpp << " }\n";
|
cpp << " }\n";
|
||||||
}
|
}
|
||||||
cpp << " }\n return QVariant();\n}\n";
|
cpp << " }\n return QVariant();\n}\n\n";
|
||||||
cpp << "QHash<int, QByteArray> " << o.name << "::roleNames() const {\n";
|
cpp << "QHash<int, QByteArray> " << o.name << "::roleNames() const {\n";
|
||||||
cpp << " QHash<int, QByteArray> names = QAbstractItemModel::roleNames();\n";
|
cpp << " QHash<int, QByteArray> names = QAbstractItemModel::roleNames();\n";
|
||||||
for (int i = 0; i < o.itemProperties.size(); ++i) {
|
for (int i = 0; i < o.itemProperties.size(); ++i) {
|
||||||
|
@ -324,7 +379,6 @@ bool %1::setHeaderData(int section, Qt::Orientation orientation, const QVariant
|
||||||
bool %1::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool %1::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
)").arg(o.name);
|
)").arg(o.name);
|
||||||
cpp << " bool set = false;\n";
|
|
||||||
for (int col = 0; col < o.columnCount; ++col) {
|
for (int col = 0; col < o.columnCount; ++col) {
|
||||||
if (!isColumnWrite(o, col)) {
|
if (!isColumnWrite(o, col)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -344,29 +398,18 @@ bool %1::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
cpp << QString("role == Qt::%1 || ").arg(metaRoles.valueToKey(role));
|
cpp << QString("role == Qt::%1 || ").arg(metaRoles.valueToKey(role));
|
||||||
}
|
}
|
||||||
cpp << "role == Qt::UserRole + " << i << ") {\n";
|
cpp << "role == Qt::UserRole + " << i << ") {\n";
|
||||||
if (ip.optional) {
|
if (o.type == ObjectType::List) {
|
||||||
QString test = "!value.isValid()";
|
cpp << QString(" return set%1(index.row(), value);\n")
|
||||||
if (ip.type.isComplex()) {
|
.arg(upperInitial(ip.name));
|
||||||
test += " || value.isNull()";
|
} else {
|
||||||
}
|
cpp << QString(" return set%1(index, value);\n")
|
||||||
cpp << " if (" << test << ") {\n";
|
.arg(upperInitial(ip.name));
|
||||||
cpp << QString(" set = %1_set_data_%2_none(m_d%3);")
|
|
||||||
.arg(lcname, snakeCase(ip.name), index) << endl;
|
|
||||||
cpp << " } else\n";
|
|
||||||
}
|
}
|
||||||
QString val = QString("value.value<%1>()").arg(ip.type.name);
|
|
||||||
cpp << QString(" set = %1_set_data_%2(m_d%3, %4);")
|
|
||||||
.arg(lcname, snakeCase(ip.name), index, val) << endl;
|
|
||||||
cpp << " }\n";
|
cpp << " }\n";
|
||||||
}
|
}
|
||||||
cpp << " }\n";
|
cpp << " }\n";
|
||||||
}
|
}
|
||||||
cpp << R"( if (set) {
|
cpp << " return false;\n}\n\n";
|
||||||
emit dataChanged(index, index, QVector<int>() << role);
|
|
||||||
}
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeHeaderObject(QTextStream& h, const Object& o, const Configuration& conf) {
|
void writeHeaderObject(QTextStream& h, const Object& o, const Configuration& conf) {
|
||||||
|
@ -674,7 +717,7 @@ void writeCppObject(QTextStream& cpp, const Object& o, const Configuration& conf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cpp << " }\n";
|
cpp << "}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const Property& p: o.properties) {
|
for (const Property& p: o.properties) {
|
||||||
|
|
|
@ -115,6 +115,7 @@ Qt::ItemFlags Persons::flags(const QModelIndex &i) const
|
||||||
}
|
}
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Persons::userName(int row) const
|
QVariant Persons::userName(int row) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
|
@ -124,6 +125,17 @@ QVariant Persons::userName(int row) const
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Persons::setUserName(int row, const QVariant& value)
|
||||||
|
{
|
||||||
|
bool set = false;
|
||||||
|
set = persons_set_data_user_name(m_d, row, value.value<QString>());
|
||||||
|
if (set) {
|
||||||
|
QModelIndex index = createIndex(row, 0, row);
|
||||||
|
emit dataChanged(index, index);
|
||||||
|
}
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
QVariant Persons::data(const QModelIndex &index, int role) const
|
QVariant Persons::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(rowCount(index.parent()) > index.row());
|
Q_ASSERT(rowCount(index.parent()) > index.row());
|
||||||
|
@ -138,6 +150,7 @@ QVariant Persons::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> Persons::roleNames() const {
|
QHash<int, QByteArray> Persons::roleNames() const {
|
||||||
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
||||||
names.insert(Qt::UserRole + 0, "userName");
|
names.insert(Qt::UserRole + 0, "userName");
|
||||||
|
@ -162,17 +175,14 @@ bool Persons::setHeaderData(int section, Qt::Orientation orientation, const QVar
|
||||||
|
|
||||||
bool Persons::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool Persons::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
bool set = false;
|
|
||||||
if (index.column() == 0) {
|
if (index.column() == 0) {
|
||||||
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 0) {
|
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 0) {
|
||||||
set = persons_set_data_user_name(m_d, index.row(), value.value<QString>());
|
return setUserName(index.row(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (set) {
|
return false;
|
||||||
emit dataChanged(index, index, QVector<int>() << role);
|
|
||||||
}
|
|
||||||
return set;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
Persons::Private* persons_new(Persons*,
|
Persons::Private* persons_new(Persons*,
|
||||||
void (*)(const Persons*),
|
void (*)(const Persons*),
|
||||||
|
@ -238,4 +248,4 @@ Persons::~Persons() {
|
||||||
}
|
}
|
||||||
void Persons::initHeaderData() {
|
void Persons::initHeaderData() {
|
||||||
m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("userName"));
|
m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("userName"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,13 +34,15 @@ public:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
||||||
|
Q_INVOKABLE QVariant userName(int row) const;
|
||||||
|
Q_INVOKABLE bool setUserName(int row, const QVariant& value);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
void newDataReady(const QModelIndex &parent) const;
|
void newDataReady(const QModelIndex &parent) const;
|
||||||
private:
|
private:
|
||||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||||
void initHeaderData();
|
void initHeaderData();
|
||||||
QVariant userName(int row) const;
|
|
||||||
signals:
|
signals:
|
||||||
};
|
};
|
||||||
#endif // TEST_LIST_RUST_H
|
#endif // TEST_LIST_RUST_H
|
||||||
|
|
|
@ -133,6 +133,7 @@ Qt::ItemFlags Persons::flags(const QModelIndex &i) const
|
||||||
}
|
}
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Persons::userName(const QModelIndex& index) const
|
QVariant Persons::userName(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
|
@ -142,6 +143,16 @@ QVariant Persons::userName(const QModelIndex& index) const
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Persons::setUserName(const QModelIndex& index, const QVariant& value)
|
||||||
|
{
|
||||||
|
bool set = false;
|
||||||
|
set = persons_set_data_user_name(m_d, index.internalId(), value.value<QString>());
|
||||||
|
if (set) {
|
||||||
|
emit dataChanged(index, index);
|
||||||
|
}
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
QVariant Persons::data(const QModelIndex &index, int role) const
|
QVariant Persons::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(rowCount(index.parent()) > index.row());
|
Q_ASSERT(rowCount(index.parent()) > index.row());
|
||||||
|
@ -156,6 +167,7 @@ QVariant Persons::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> Persons::roleNames() const {
|
QHash<int, QByteArray> Persons::roleNames() const {
|
||||||
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
||||||
names.insert(Qt::UserRole + 0, "userName");
|
names.insert(Qt::UserRole + 0, "userName");
|
||||||
|
@ -180,17 +192,14 @@ bool Persons::setHeaderData(int section, Qt::Orientation orientation, const QVar
|
||||||
|
|
||||||
bool Persons::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool Persons::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
bool set = false;
|
|
||||||
if (index.column() == 0) {
|
if (index.column() == 0) {
|
||||||
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 0) {
|
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 0) {
|
||||||
set = persons_set_data_user_name(m_d, index.internalId(), value.value<QString>());
|
return setUserName(index, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (set) {
|
return false;
|
||||||
emit dataChanged(index, index, QVector<int>() << role);
|
|
||||||
}
|
|
||||||
return set;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
Persons::Private* persons_new(Persons*,
|
Persons::Private* persons_new(Persons*,
|
||||||
void (*)(const Persons*, quintptr, bool),
|
void (*)(const Persons*, quintptr, bool),
|
||||||
|
@ -273,4 +282,4 @@ Persons::~Persons() {
|
||||||
}
|
}
|
||||||
void Persons::initHeaderData() {
|
void Persons::initHeaderData() {
|
||||||
m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("userName"));
|
m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("userName"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,13 +34,15 @@ public:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
||||||
|
Q_INVOKABLE QVariant userName(const QModelIndex& index) const;
|
||||||
|
Q_INVOKABLE bool setUserName(const QModelIndex& index, const QVariant& value);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
void newDataReady(const QModelIndex &parent) const;
|
void newDataReady(const QModelIndex &parent) const;
|
||||||
private:
|
private:
|
||||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||||
void initHeaderData();
|
void initHeaderData();
|
||||||
QVariant userName(const QModelIndex& index) const;
|
|
||||||
signals:
|
signals:
|
||||||
};
|
};
|
||||||
#endif // TEST_TREE_RUST_H
|
#endif // TEST_TREE_RUST_H
|
||||||
|
|
Loading…
Reference in New Issue