More precise types
parent
392153f9a9
commit
e636d82da5
|
@ -1,7 +1,7 @@
|
|||
/* generated by rust_qt_binding_generator */
|
||||
#![allow(unknown_lints)]
|
||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||
use libc::{c_char, c_ushort, c_int, c_void};
|
||||
use libc::{c_char, c_ushort, c_int};
|
||||
use std::slice;
|
||||
use std::char::decode_utf16;
|
||||
|
||||
|
@ -601,8 +601,8 @@ pub unsafe extern "C" fn file_system_tree_free(ptr: *mut FileSystemTree) {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn file_system_tree_path_get(
|
||||
ptr: *const FileSystemTree,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, *const c_char, c_int),
|
||||
p: *mut QString,
|
||||
set: fn(*mut QString, *const c_char, c_int),
|
||||
) {
|
||||
let o = unsafe { &*ptr };
|
||||
let v = o.path();
|
||||
|
@ -701,8 +701,8 @@ pub unsafe extern "C" fn file_system_tree_row(ptr: *const FileSystemTree, item:
|
|||
#[no_mangle]
|
||||
pub extern "C" fn file_system_tree_data_file_icon(
|
||||
ptr: *const FileSystemTree, item: usize,
|
||||
d: *mut QString,
|
||||
set: fn(*mut QString, *const c_char, len: c_int),
|
||||
d: *mut QByteArray,
|
||||
set: fn(*mut QByteArray, *const c_char, len: c_int),
|
||||
) {
|
||||
let o = unsafe { &*ptr };
|
||||
let data = o.file_icon(item);
|
||||
|
|
|
@ -48,6 +48,9 @@ namespace {
|
|||
int row;
|
||||
quintptr id;
|
||||
};
|
||||
inline QVariant cleanNullQVariant(const QVariant& v) {
|
||||
return (v.isNull()) ?QVariant() :v;
|
||||
}
|
||||
inline void fibonacciInputChanged(Fibonacci* o)
|
||||
{
|
||||
emit o->inputChanged();
|
||||
|
@ -186,18 +189,14 @@ Qt::ItemFlags FibonacciList::flags(const QModelIndex &i) const
|
|||
return flags;
|
||||
}
|
||||
|
||||
QVariant FibonacciList::fibonacciNumber(int row) const
|
||||
quint64 FibonacciList::fibonacciNumber(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(fibonacci_list_data_fibonacci_number(m_d, row));
|
||||
return v;
|
||||
return fibonacci_list_data_fibonacci_number(m_d, row);
|
||||
}
|
||||
|
||||
QVariant FibonacciList::row(int row) const
|
||||
quint64 FibonacciList::row(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(fibonacci_list_data_row(m_d, row));
|
||||
return v;
|
||||
return fibonacci_list_data_row(m_d, row);
|
||||
}
|
||||
|
||||
QVariant FibonacciList::data(const QModelIndex &index, int role) const
|
||||
|
@ -207,16 +206,16 @@ QVariant FibonacciList::data(const QModelIndex &index, int role) const
|
|||
case 0:
|
||||
switch (role) {
|
||||
case Qt::UserRole + 0:
|
||||
return fibonacciNumber(index.row());
|
||||
return QVariant::fromValue(fibonacciNumber(index.row()));
|
||||
case Qt::DisplayRole:
|
||||
case Qt::UserRole + 1:
|
||||
return row(index.row());
|
||||
return QVariant::fromValue(row(index.row()));
|
||||
}
|
||||
case 1:
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Qt::UserRole + 0:
|
||||
return fibonacciNumber(index.row());
|
||||
return QVariant::fromValue(fibonacciNumber(index.row()));
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
|
@ -349,38 +348,30 @@ Qt::ItemFlags FileSystemTree::flags(const QModelIndex &i) const
|
|||
return flags;
|
||||
}
|
||||
|
||||
QVariant FileSystemTree::fileIcon(const QModelIndex& index) const
|
||||
QByteArray FileSystemTree::fileIcon(const QModelIndex& index) const
|
||||
{
|
||||
QVariant v;
|
||||
QByteArray b;
|
||||
file_system_tree_data_file_icon(m_d, index.internalId(), &b, set_qbytearray);
|
||||
if (!b.isNull()) v.setValue<QByteArray>(b);
|
||||
return v;
|
||||
return b;
|
||||
}
|
||||
|
||||
QVariant FileSystemTree::fileName(const QModelIndex& index) const
|
||||
QString FileSystemTree::fileName(const QModelIndex& index) const
|
||||
{
|
||||
QVariant v;
|
||||
QString s;
|
||||
file_system_tree_data_file_name(m_d, index.internalId(), &s, set_qstring);
|
||||
if (!s.isNull()) v.setValue<QString>(s);
|
||||
return v;
|
||||
return s;
|
||||
}
|
||||
|
||||
QVariant FileSystemTree::filePath(const QModelIndex& index) const
|
||||
QString FileSystemTree::filePath(const QModelIndex& index) const
|
||||
{
|
||||
QVariant v;
|
||||
QString s;
|
||||
file_system_tree_data_file_path(m_d, index.internalId(), &s, set_qstring);
|
||||
if (!s.isNull()) v.setValue<QString>(s);
|
||||
return v;
|
||||
return s;
|
||||
}
|
||||
|
||||
QVariant FileSystemTree::filePermissions(const QModelIndex& index) const
|
||||
qint32 FileSystemTree::filePermissions(const QModelIndex& index) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(file_system_tree_data_file_permissions(m_d, index.internalId()));
|
||||
return v;
|
||||
return file_system_tree_data_file_permissions(m_d, index.internalId());
|
||||
}
|
||||
|
||||
QVariant FileSystemTree::fileSize(const QModelIndex& index) const
|
||||
|
@ -390,11 +381,9 @@ QVariant FileSystemTree::fileSize(const QModelIndex& index) const
|
|||
return v;
|
||||
}
|
||||
|
||||
QVariant FileSystemTree::fileType(const QModelIndex& index) const
|
||||
qint32 FileSystemTree::fileType(const QModelIndex& index) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(file_system_tree_data_file_type(m_d, index.internalId()));
|
||||
return v;
|
||||
return file_system_tree_data_file_type(m_d, index.internalId());
|
||||
}
|
||||
|
||||
QVariant FileSystemTree::data(const QModelIndex &index, int role) const
|
||||
|
@ -405,18 +394,18 @@ QVariant FileSystemTree::data(const QModelIndex &index, int role) const
|
|||
switch (role) {
|
||||
case Qt::DecorationRole:
|
||||
case Qt::UserRole + 0:
|
||||
return fileIcon(index);
|
||||
return QVariant::fromValue(fileIcon(index));
|
||||
case Qt::DisplayRole:
|
||||
case Qt::UserRole + 1:
|
||||
return fileName(index);
|
||||
return QVariant::fromValue(fileName(index));
|
||||
case Qt::UserRole + 2:
|
||||
return filePath(index);
|
||||
return cleanNullQVariant(QVariant::fromValue(filePath(index)));
|
||||
case Qt::UserRole + 3:
|
||||
return filePermissions(index);
|
||||
return QVariant::fromValue(filePermissions(index));
|
||||
case Qt::UserRole + 4:
|
||||
return fileSize(index);
|
||||
case Qt::UserRole + 5:
|
||||
return fileType(index);
|
||||
return QVariant::fromValue(fileType(index));
|
||||
}
|
||||
case 1:
|
||||
switch (role) {
|
||||
|
@ -428,19 +417,19 @@ QVariant FileSystemTree::data(const QModelIndex &index, int role) const
|
|||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Qt::UserRole + 2:
|
||||
return filePath(index);
|
||||
return cleanNullQVariant(QVariant::fromValue(filePath(index)));
|
||||
}
|
||||
case 3:
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Qt::UserRole + 3:
|
||||
return filePermissions(index);
|
||||
return QVariant::fromValue(filePermissions(index));
|
||||
}
|
||||
case 4:
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Qt::UserRole + 5:
|
||||
return fileType(index);
|
||||
return QVariant::fromValue(fileType(index));
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
|
@ -581,57 +570,43 @@ Qt::ItemFlags Processes::flags(const QModelIndex &i) const
|
|||
return flags;
|
||||
}
|
||||
|
||||
QVariant Processes::cmd(const QModelIndex& index) const
|
||||
QString Processes::cmd(const QModelIndex& index) const
|
||||
{
|
||||
QVariant v;
|
||||
QString s;
|
||||
processes_data_cmd(m_d, index.internalId(), &s, set_qstring);
|
||||
if (!s.isNull()) v.setValue<QString>(s);
|
||||
return v;
|
||||
return s;
|
||||
}
|
||||
|
||||
QVariant Processes::cpuPercentage(const QModelIndex& index) const
|
||||
quint8 Processes::cpuPercentage(const QModelIndex& index) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(processes_data_cpu_percentage(m_d, index.internalId()));
|
||||
return v;
|
||||
return processes_data_cpu_percentage(m_d, index.internalId());
|
||||
}
|
||||
|
||||
QVariant Processes::cpuUsage(const QModelIndex& index) const
|
||||
float Processes::cpuUsage(const QModelIndex& index) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(processes_data_cpu_usage(m_d, index.internalId()));
|
||||
return v;
|
||||
return processes_data_cpu_usage(m_d, index.internalId());
|
||||
}
|
||||
|
||||
QVariant Processes::memory(const QModelIndex& index) const
|
||||
quint64 Processes::memory(const QModelIndex& index) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(processes_data_memory(m_d, index.internalId()));
|
||||
return v;
|
||||
return processes_data_memory(m_d, index.internalId());
|
||||
}
|
||||
|
||||
QVariant Processes::name(const QModelIndex& index) const
|
||||
QString Processes::name(const QModelIndex& index) const
|
||||
{
|
||||
QVariant v;
|
||||
QString s;
|
||||
processes_data_name(m_d, index.internalId(), &s, set_qstring);
|
||||
if (!s.isNull()) v.setValue<QString>(s);
|
||||
return v;
|
||||
return s;
|
||||
}
|
||||
|
||||
QVariant Processes::pid(const QModelIndex& index) const
|
||||
quint32 Processes::pid(const QModelIndex& index) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(processes_data_pid(m_d, index.internalId()));
|
||||
return v;
|
||||
return processes_data_pid(m_d, index.internalId());
|
||||
}
|
||||
|
||||
QVariant Processes::uid(const QModelIndex& index) const
|
||||
quint32 Processes::uid(const QModelIndex& index) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(processes_data_uid(m_d, index.internalId()));
|
||||
return v;
|
||||
return processes_data_uid(m_d, index.internalId());
|
||||
}
|
||||
|
||||
QVariant Processes::data(const QModelIndex &index, int role) const
|
||||
|
@ -641,33 +616,33 @@ QVariant Processes::data(const QModelIndex &index, int role) const
|
|||
case 0:
|
||||
switch (role) {
|
||||
case Qt::UserRole + 0:
|
||||
return cmd(index);
|
||||
return QVariant::fromValue(cmd(index));
|
||||
case Qt::UserRole + 1:
|
||||
return cpuPercentage(index);
|
||||
return QVariant::fromValue(cpuPercentage(index));
|
||||
case Qt::UserRole + 2:
|
||||
return cpuUsage(index);
|
||||
return QVariant::fromValue(cpuUsage(index));
|
||||
case Qt::UserRole + 3:
|
||||
return memory(index);
|
||||
return QVariant::fromValue(memory(index));
|
||||
case Qt::DisplayRole:
|
||||
case Qt::UserRole + 4:
|
||||
return name(index);
|
||||
return QVariant::fromValue(name(index));
|
||||
case Qt::ToolTipRole:
|
||||
case Qt::UserRole + 5:
|
||||
return pid(index);
|
||||
return QVariant::fromValue(pid(index));
|
||||
case Qt::UserRole + 6:
|
||||
return uid(index);
|
||||
return QVariant::fromValue(uid(index));
|
||||
}
|
||||
case 1:
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Qt::UserRole + 2:
|
||||
return cpuUsage(index);
|
||||
return QVariant::fromValue(cpuUsage(index));
|
||||
}
|
||||
case 2:
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Qt::UserRole + 3:
|
||||
return memory(index);
|
||||
return QVariant::fromValue(memory(index));
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
|
@ -800,20 +775,15 @@ Qt::ItemFlags TimeSeries::flags(const QModelIndex &i) const
|
|||
return flags;
|
||||
}
|
||||
|
||||
QVariant TimeSeries::cos(int row) const
|
||||
float TimeSeries::cos(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(time_series_data_cos(m_d, row));
|
||||
return v;
|
||||
return time_series_data_cos(m_d, row);
|
||||
}
|
||||
|
||||
bool TimeSeries::setCos(int row, const QVariant& value)
|
||||
bool TimeSeries::setCos(int row, float value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<float>())) {
|
||||
return false;
|
||||
}
|
||||
set = time_series_set_data_cos(m_d, row, value.value<float>());
|
||||
set = time_series_set_data_cos(m_d, row, value);
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -821,20 +791,15 @@ bool TimeSeries::setCos(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant TimeSeries::sin(int row) const
|
||||
float TimeSeries::sin(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(time_series_data_sin(m_d, row));
|
||||
return v;
|
||||
return time_series_data_sin(m_d, row);
|
||||
}
|
||||
|
||||
bool TimeSeries::setSin(int row, const QVariant& value)
|
||||
bool TimeSeries::setSin(int row, float value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<float>())) {
|
||||
return false;
|
||||
}
|
||||
set = time_series_set_data_sin(m_d, row, value.value<float>());
|
||||
set = time_series_set_data_sin(m_d, row, value);
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -842,20 +807,15 @@ bool TimeSeries::setSin(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant TimeSeries::time(int row) const
|
||||
float TimeSeries::time(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(time_series_data_time(m_d, row));
|
||||
return v;
|
||||
return time_series_data_time(m_d, row);
|
||||
}
|
||||
|
||||
bool TimeSeries::setTime(int row, const QVariant& value)
|
||||
bool TimeSeries::setTime(int row, float value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<float>())) {
|
||||
return false;
|
||||
}
|
||||
set = time_series_set_data_time(m_d, row, value.value<float>());
|
||||
set = time_series_set_data_time(m_d, row, value);
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -870,27 +830,27 @@ QVariant TimeSeries::data(const QModelIndex &index, int role) const
|
|||
case 0:
|
||||
switch (role) {
|
||||
case Qt::UserRole + 0:
|
||||
return cos(index.row());
|
||||
return QVariant::fromValue(cos(index.row()));
|
||||
case Qt::UserRole + 1:
|
||||
return sin(index.row());
|
||||
return QVariant::fromValue(sin(index.row()));
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
case Qt::UserRole + 2:
|
||||
return time(index.row());
|
||||
return QVariant::fromValue(time(index.row()));
|
||||
}
|
||||
case 1:
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
case Qt::UserRole + 1:
|
||||
return sin(index.row());
|
||||
return QVariant::fromValue(sin(index.row()));
|
||||
}
|
||||
case 2:
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
case Qt::UserRole + 0:
|
||||
return cos(index.row());
|
||||
return QVariant::fromValue(cos(index.row()));
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
|
@ -924,23 +884,33 @@ bool TimeSeries::setData(const QModelIndex &index, const QVariant &value, int ro
|
|||
{
|
||||
if (index.column() == 0) {
|
||||
if (role == Qt::UserRole + 0) {
|
||||
return setCos(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<float>())) {
|
||||
return setCos(index.row(), value.value<float>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::UserRole + 1) {
|
||||
return setSin(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<float>())) {
|
||||
return setSin(index.row(), value.value<float>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 2) {
|
||||
return setTime(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<float>())) {
|
||||
return setTime(index.row(), value.value<float>());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (index.column() == 1) {
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 1) {
|
||||
return setSin(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<float>())) {
|
||||
return setSin(index.row(), value.value<float>());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (index.column() == 2) {
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 0) {
|
||||
return setCos(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<float>())) {
|
||||
return setCos(index.row(), value.value<float>());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -104,8 +104,8 @@ public:
|
|||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
|
||||
Q_INVOKABLE bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
Q_INVOKABLE QVariant fibonacciNumber(int row) const;
|
||||
Q_INVOKABLE QVariant row(int row) const;
|
||||
Q_INVOKABLE quint64 fibonacciNumber(int row) const;
|
||||
Q_INVOKABLE quint64 row(int row) const;
|
||||
|
||||
signals:
|
||||
// new data is ready to be made available to the model with fetchMore()
|
||||
|
@ -148,12 +148,12 @@ public:
|
|||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
|
||||
Q_INVOKABLE bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
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 QByteArray fileIcon(const QModelIndex& index) const;
|
||||
Q_INVOKABLE QString fileName(const QModelIndex& index) const;
|
||||
Q_INVOKABLE QString filePath(const QModelIndex& index) const;
|
||||
Q_INVOKABLE qint32 filePermissions(const QModelIndex& index) const;
|
||||
Q_INVOKABLE QVariant fileSize(const QModelIndex& index) const;
|
||||
Q_INVOKABLE QVariant fileType(const QModelIndex& index) const;
|
||||
Q_INVOKABLE qint32 fileType(const QModelIndex& index) const;
|
||||
|
||||
signals:
|
||||
// new data is ready to be made available to the model with fetchMore()
|
||||
|
@ -197,13 +197,13 @@ public:
|
|||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
|
||||
Q_INVOKABLE bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
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;
|
||||
Q_INVOKABLE QString cmd(const QModelIndex& index) const;
|
||||
Q_INVOKABLE quint8 cpuPercentage(const QModelIndex& index) const;
|
||||
Q_INVOKABLE float cpuUsage(const QModelIndex& index) const;
|
||||
Q_INVOKABLE quint64 memory(const QModelIndex& index) const;
|
||||
Q_INVOKABLE QString name(const QModelIndex& index) const;
|
||||
Q_INVOKABLE quint32 pid(const QModelIndex& index) const;
|
||||
Q_INVOKABLE quint32 uid(const QModelIndex& index) const;
|
||||
|
||||
signals:
|
||||
// new data is ready to be made available to the model with fetchMore()
|
||||
|
@ -245,12 +245,12 @@ public:
|
|||
Q_INVOKABLE bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
Q_INVOKABLE QVariant cos(int row) const;
|
||||
Q_INVOKABLE bool setCos(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant sin(int row) const;
|
||||
Q_INVOKABLE bool setSin(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant time(int row) const;
|
||||
Q_INVOKABLE bool setTime(int row, const QVariant& value);
|
||||
Q_INVOKABLE float cos(int row) const;
|
||||
Q_INVOKABLE bool setCos(int row, float value);
|
||||
Q_INVOKABLE float sin(int row) const;
|
||||
Q_INVOKABLE bool setSin(int row, float value);
|
||||
Q_INVOKABLE float time(int row) const;
|
||||
Q_INVOKABLE bool setTime(int row, float value);
|
||||
|
||||
signals:
|
||||
// new data is ready to be made available to the model with fetchMore()
|
||||
|
|
113
src/cpp.cpp
113
src/cpp.cpp
|
@ -33,6 +33,12 @@ QString cppSetType(const T& p)
|
|||
return p.type.cppSetType;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QString propertyType(const T& p)
|
||||
{
|
||||
return (p.optional && !p.type.isComplex()) ?"QVariant" :p.type.name;
|
||||
}
|
||||
|
||||
QString upperInitial(const QString& name) {
|
||||
return name.left(1).toUpper() + name.mid(1);
|
||||
}
|
||||
|
@ -86,15 +92,20 @@ void writeHeaderItemModel(QTextStream& h, const Object& o) {
|
|||
h << " bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;\n";
|
||||
}
|
||||
for (auto ip: o.itemProperties) {
|
||||
auto r = propertyType(ip);
|
||||
auto rw = r;
|
||||
if (r == "QVariant" || ip.type.isComplex()) {
|
||||
rw = "const " + r + "&";
|
||||
}
|
||||
if (o.type == ObjectType::List) {
|
||||
h << QString(" Q_INVOKABLE QVariant %1(int row) const;\n").arg(ip.name);
|
||||
h << QString(" Q_INVOKABLE %2 %1(int row) const;\n").arg(ip.name, r);
|
||||
if (ip.write) {
|
||||
h << QString(" Q_INVOKABLE bool set%1(int row, const QVariant& value);\n").arg(upperInitial(ip.name));
|
||||
h << QString(" Q_INVOKABLE bool set%1(int row, %2 value);\n").arg(upperInitial(ip.name), rw);
|
||||
}
|
||||
} else {
|
||||
h << QString(" Q_INVOKABLE QVariant %1(const QModelIndex& index) const;\n").arg(ip.name);
|
||||
h << QString(" Q_INVOKABLE %2 %1(const QModelIndex& index) const;\n").arg(ip.name, r);
|
||||
if (ip.write) {
|
||||
h << QString(" Q_INVOKABLE bool set%1(const QModelIndex& index, const QVariant& value);\n").arg(upperInitial(ip.name));
|
||||
h << QString(" Q_INVOKABLE bool set%1(const QModelIndex& index, %2 value);\n").arg(upperInitial(ip.name), rw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -123,33 +134,34 @@ void writeModelGetterSetter(QTextStream& cpp, const QString& index,
|
|||
QString idx = index;
|
||||
|
||||
// getter
|
||||
auto r = propertyType(ip);
|
||||
if (o.type == ObjectType::List) {
|
||||
idx = ", row";
|
||||
cpp << QString("QVariant %1::%2(int row) const\n{\n")
|
||||
.arg(o.name, ip.name);
|
||||
cpp << QString("%3 %1::%2(int row) const\n{\n")
|
||||
.arg(o.name, ip.name, r);
|
||||
} else {
|
||||
cpp << QString("QVariant %1::%2(const QModelIndex& index) const\n{\n")
|
||||
.arg(o.name, ip.name);
|
||||
cpp << QString("%3 %1::%2(const QModelIndex& index) const\n{\n")
|
||||
.arg(o.name, ip.name, r);
|
||||
}
|
||||
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";
|
||||
cpp << " return 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 if (!ip.optional) {
|
||||
cpp << QString(" v.setValue(%1_data_%2(m_d%3));\n")
|
||||
.arg(lcname, snakeCase(ip.name), idx);
|
||||
} else {
|
||||
cpp << " return b;\n";
|
||||
} else if (ip.optional) {
|
||||
cpp << " QVariant v;\n";
|
||||
cpp << QString(" v = %1_data_%2(m_d%3);\n")
|
||||
.arg(lcname, snakeCase(ip.name), idx);
|
||||
cpp << " return v;\n";
|
||||
} else {
|
||||
cpp << QString(" return %1_data_%2(m_d%3);\n")
|
||||
.arg(lcname, snakeCase(ip.name), idx);
|
||||
}
|
||||
cpp << " return v;\n";
|
||||
cpp << "}\n\n";
|
||||
|
||||
if (!ip.write) {
|
||||
|
@ -157,37 +169,44 @@ void writeModelGetterSetter(QTextStream& cpp, const QString& index,
|
|||
}
|
||||
|
||||
// setter
|
||||
if (r == "QVariant" || ip.type.isComplex()) {
|
||||
r = "const " + r + "&";
|
||||
}
|
||||
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));
|
||||
cpp << QString("bool %1::set%2(int row, %3 value)\n{\n")
|
||||
.arg(o.name, upperInitial(ip.name), r);
|
||||
} else {
|
||||
cpp << QString("bool %1::set%2(const QModelIndex& index, const QVariant& value)\n{\n")
|
||||
.arg(o.name, upperInitial(ip.name));
|
||||
cpp << QString("bool %1::set%2(const QModelIndex& index, %3 value)\n{\n")
|
||||
.arg(o.name, upperInitial(ip.name), r);
|
||||
}
|
||||
cpp << " bool set = false;\n";
|
||||
if (ip.optional) {
|
||||
QString test = "!value.isValid()";
|
||||
if (ip.type.isComplex()) {
|
||||
test += " || value.isNull()";
|
||||
QString test = "value.isNull()";
|
||||
if (!ip.type.isComplex()) {
|
||||
test += " || !value.isValid()";
|
||||
}
|
||||
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";
|
||||
}
|
||||
cpp << QString(" if (!value.canConvert(qMetaTypeId<%1>())) {\n return false;\n }\n").arg(ip.type.name);
|
||||
QString val = QString("value.value<%1>()").arg(ip.type.name);
|
||||
if (ip.type.isComplex()) {
|
||||
cpp << QString(" const %1 s = %2;\n").arg(ip.type.name, val);
|
||||
if (ip.type.name == "QString") {
|
||||
val = "s.utf16(), s.length()";
|
||||
} else {
|
||||
val = "s.data(), s.length()";
|
||||
if (ip.optional && !ip.type.isComplex()) {
|
||||
cpp << QString(" if (!value.canConvert(qMetaTypeId<%1>())) {\n return false;\n }\n").arg(ip.type.name);
|
||||
cpp << QString(" set = %1_set_data_%2(m_d%3, value.value<%4>());")
|
||||
.arg(lcname, snakeCase(ip.name), idx, ip.type.name) << endl;
|
||||
} else {
|
||||
QString val = "value";
|
||||
if (ip.type.isComplex()) {
|
||||
if (ip.type.name == "QString") {
|
||||
val = "value.utf16(), value.length()";
|
||||
} else {
|
||||
val = "value.data(), value.length()";
|
||||
}
|
||||
}
|
||||
cpp << QString(" set = %1_set_data_%2(m_d%3, %4);")
|
||||
.arg(lcname, snakeCase(ip.name), idx, val) << endl;
|
||||
}
|
||||
cpp << QString(" set = %1_set_data_%2(m_d%3, %4);")
|
||||
.arg(lcname, snakeCase(ip.name), idx, val) << endl;
|
||||
if (ip.optional) {
|
||||
cpp << " }\n";
|
||||
}
|
||||
|
@ -420,10 +439,13 @@ Qt::ItemFlags %1::flags(const QModelIndex &i) const
|
|||
cpp << QString(" case Qt::%1:\n").arg(metaRoles.valueToKey(role));
|
||||
}
|
||||
cpp << QString(" case Qt::UserRole + %1:\n").arg(i);
|
||||
if (o.type == ObjectType::List) {
|
||||
cpp << QString(" return %1(index.row());\n").arg(ip.name);
|
||||
auto ii = (o.type == ObjectType::List) ?".row()" :"";
|
||||
if (ip.optional && !ip.type.isComplex()) {
|
||||
cpp << QString(" return %1(index%2);\n").arg(ip.name, ii);
|
||||
} else if (ip.optional) {
|
||||
cpp << QString(" return cleanNullQVariant(QVariant::fromValue(%1(index%2)));\n").arg(ip.name, ii);
|
||||
} else {
|
||||
cpp << QString(" return %1(index);\n").arg(ip.name);
|
||||
cpp << QString(" return QVariant::fromValue(%1(index%2));\n").arg(ip.name, ii);
|
||||
}
|
||||
}
|
||||
cpp << " }\n";
|
||||
|
@ -476,12 +498,18 @@ bool %1::setHeaderData(int section, Qt::Orientation orientation, const QVariant
|
|||
cpp << QString("role == Qt::%1 || ").arg(metaRoles.valueToKey(role));
|
||||
}
|
||||
cpp << "role == Qt::UserRole + " << i << ") {\n";
|
||||
if (o.type == ObjectType::List) {
|
||||
cpp << QString(" return set%1(index.row(), value);\n")
|
||||
.arg(upperInitial(ip.name));
|
||||
auto ii = (o.type == ObjectType::List) ?".row()" :"";
|
||||
if (ip.optional && !ip.type.isComplex()) {
|
||||
cpp << QString(" return set%1(index%2, value);\n")
|
||||
.arg(upperInitial(ip.name), ii);
|
||||
} else {
|
||||
cpp << QString(" return set%1(index, value);\n")
|
||||
.arg(upperInitial(ip.name));
|
||||
QString pre = "";
|
||||
if (ip.optional) {
|
||||
pre = "!value.isValid() || value.isNull() ||";
|
||||
}
|
||||
cpp << QString(" if (%2value.canConvert(qMetaTypeId<%1>())) {\n").arg(ip.type.name, pre);
|
||||
cpp << QString(" return set%1(index%2, value.value<%3>());\n").arg(upperInitial(ip.name), ii, ip.type.name);
|
||||
cpp << QString(" }\n");
|
||||
}
|
||||
cpp << " }\n";
|
||||
}
|
||||
|
@ -1037,6 +1065,9 @@ namespace {
|
|||
int row;
|
||||
quintptr id;
|
||||
};
|
||||
inline QVariant cleanNullQVariant(const QVariant& v) {
|
||||
return (v.isNull()) ?QVariant() :v;
|
||||
}
|
||||
)";
|
||||
}
|
||||
|
||||
|
|
66
src/rust.cpp
66
src/rust.cpp
|
@ -164,10 +164,8 @@ pub extern "C" fn %1_%2(ptr: *%3 %4)").arg(lcname, lc, f.mut ? "mut" : "const",
|
|||
// If the return type is QString or QByteArray, append a pointer to the
|
||||
// variable that will be set to the argument list. Also add a setter
|
||||
// function.
|
||||
if (f.type.name == "QString") {
|
||||
r << ", d: *mut QString, set: fn(*mut QString, str: *const c_char, len: c_int)) {\n";
|
||||
} else if (f.type.name == "QByteArray") {
|
||||
r << ", d: *mut QByteArray, set: fn(*mut QString, str: *const c_char, len: c_int)) {\n";
|
||||
if (f.type.isComplex()) {
|
||||
r << QString(", d: *mut %1, set: fn(*mut %1, str: *const c_char, len: c_int)) {\n").arg(f.type.name);
|
||||
} else {
|
||||
r << ") -> " << f.type.rustType << " {\n";
|
||||
}
|
||||
|
@ -332,7 +330,15 @@ pub trait %1Trait {
|
|||
} else {
|
||||
r << QString(" fn %1(&self) -> %2;\n").arg(lc, rustReturnType(p));
|
||||
if (p.write) {
|
||||
r << QString(" fn set_%1(&mut self, value: %2);\n").arg(lc, rustType(p));
|
||||
if (p.type.name == "QByteArray") {
|
||||
if (p.optional) {
|
||||
r << QString(" fn set_%1(&mut self, value: Option<&[u8]>);\n").arg(lc);
|
||||
} else {
|
||||
r << QString(" fn set_%1(&mut self, value: &[u8]);\n").arg(lc);
|
||||
}
|
||||
} else {
|
||||
r << QString(" fn set_%1(&mut self, value: %2);\n").arg(lc, rustType(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -378,8 +384,18 @@ pub trait %1Trait {
|
|||
r << QString(" fn %1(&self, item: usize) -> %2;\n")
|
||||
.arg(snakeCase(ip.name), rustReturnType(ip));
|
||||
if (ip.write) {
|
||||
r << QString(" fn set_%1(&mut self, item: usize, %2) -> bool;\n")
|
||||
.arg(snakeCase(ip.name), rustType(ip));
|
||||
if (ip.type.name == "QByteArray") {
|
||||
if (ip.optional) {
|
||||
r << QString(" fn set_%1(&mut self, item: usize, Option<&[u8]>) -> bool;\n")
|
||||
.arg(snakeCase(ip.name));
|
||||
} else {
|
||||
r << QString(" fn set_%1(&mut self, item: usize, &[u8]) -> bool;\n")
|
||||
.arg(snakeCase(ip.name));
|
||||
}
|
||||
} else {
|
||||
r << QString(" fn set_%1(&mut self, item: usize, %2) -> bool;\n")
|
||||
.arg(snakeCase(ip.name), rustType(ip));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -416,15 +432,15 @@ pub unsafe extern "C" fn %2_get(ptr: *mut %1) -> *mut %4 {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn %2_get(
|
||||
ptr: *const %1,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, *const c_char, c_int),
|
||||
p: *mut %4,
|
||||
set: fn(*mut %4, *const c_char, c_int),
|
||||
) {
|
||||
let o = unsafe { &*ptr };
|
||||
let v = o.%3();
|
||||
let s: *const c_char = v.as_ptr() as (*const c_char);
|
||||
set(p, s, v.len() as c_int);
|
||||
}
|
||||
)").arg(o.name, base, snakeCase(p.name));
|
||||
)").arg(o.name, base, snakeCase(p.name), p.type.name);
|
||||
if (p.write && p.type.name == "QString") {
|
||||
r << QString(R"(
|
||||
#[no_mangle]
|
||||
|
@ -441,7 +457,7 @@ pub extern "C" fn %2_set(ptr: *mut %1, v: *const c_ushort, len: c_int) {
|
|||
pub extern "C" fn %2_set(ptr: *mut %1, v: *const c_char, len: c_int) {
|
||||
let o = unsafe { &mut *ptr };
|
||||
let v = unsafe { slice::from_raw_parts(v as *const u8, len as usize) };
|
||||
o.set_%3(v.into());
|
||||
o.set_%3(v);
|
||||
}
|
||||
)").arg(o.name, base, snakeCase(p.name));
|
||||
}
|
||||
|
@ -450,8 +466,8 @@ pub extern "C" fn %2_set(ptr: *mut %1, v: *const c_char, len: c_int) {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn %2_get(
|
||||
ptr: *const %1,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, *const c_char, c_int),
|
||||
p: *mut %4,
|
||||
set: fn(*mut %4, *const c_char, c_int),
|
||||
) {
|
||||
let o = unsafe { &*ptr };
|
||||
let v = o.%3();
|
||||
|
@ -460,7 +476,7 @@ pub extern "C" fn %2_get(
|
|||
set(p, s, v.len() as c_int);
|
||||
}
|
||||
}
|
||||
)").arg(o.name, base, snakeCase(p.name));
|
||||
)").arg(o.name, base, snakeCase(p.name), p.type.name);
|
||||
if (p.write && p.type.name == "QString") {
|
||||
r << QString(R"(
|
||||
#[no_mangle]
|
||||
|
@ -646,23 +662,23 @@ pub unsafe extern "C" fn %2_row(ptr: *const %1, item: usize) -> c_int {
|
|||
r << QString(R"(
|
||||
#[no_mangle]
|
||||
pub extern "C" fn %2_data_%3(
|
||||
ptr: *const %1%5,
|
||||
d: *mut QString,
|
||||
set: fn(*mut QString, *const c_char, len: c_int),
|
||||
ptr: *const %1%4,
|
||||
d: *mut %6,
|
||||
set: fn(*mut %6, *const c_char, len: c_int),
|
||||
) {
|
||||
let o = unsafe { &*ptr };
|
||||
let data = o.%3(%6);
|
||||
let data = o.%3(%5);
|
||||
let s: *const c_char = data.as_ptr() as (*const c_char);
|
||||
set(d, s, data.len() as c_int);
|
||||
}
|
||||
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index);
|
||||
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index, ip.type.name);
|
||||
} else if (ip.type.isComplex()) {
|
||||
r << QString(R"(
|
||||
#[no_mangle]
|
||||
pub extern "C" fn %2_data_%3(
|
||||
ptr: *const %1%4,
|
||||
d: *mut QString,
|
||||
set: fn(*mut QString, *const c_char, len: c_int),
|
||||
d: *mut %6,
|
||||
set: fn(*mut %6, *const c_char, len: c_int),
|
||||
) {
|
||||
let o = unsafe { &*ptr };
|
||||
let data = o.%3(%5);
|
||||
|
@ -671,7 +687,7 @@ pub extern "C" fn %2_data_%3(
|
|||
set(d, s, data.len() as c_int);
|
||||
}
|
||||
}
|
||||
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index);
|
||||
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index, ip.type.name);
|
||||
} else {
|
||||
r << QString(R"(
|
||||
#[no_mangle]
|
||||
|
@ -707,12 +723,10 @@ pub extern "C" fn %2_set_data_%3(
|
|||
s: *const c_char, len: c_int,
|
||||
) -> bool {
|
||||
let o = unsafe { &mut *ptr };
|
||||
let mut v = Vec::new();
|
||||
let slice = unsafe { ::std::slice::from_raw_parts(s as *const u8, len as usize) };
|
||||
v.extend_from_slice(slice);
|
||||
o.set_%3(%5, %6)
|
||||
}
|
||||
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index, val);
|
||||
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index, ip.optional ?"Some(slice)" :"slice");
|
||||
} else {
|
||||
const QString type = ip.type.rustType;
|
||||
r << QString(R"(
|
||||
|
@ -845,7 +859,7 @@ void writeRustInterface(const Configuration& conf) {
|
|||
r << QString(R"(/* generated by rust_qt_binding_generator */
|
||||
#![allow(unknown_lints)]
|
||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||
use libc::{c_char, c_ushort, c_int, c_void};
|
||||
use libc::{c_char, c_ushort, c_int};
|
||||
use std::slice;
|
||||
use std::char::decode_utf16;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* generated by rust_qt_binding_generator */
|
||||
#![allow(unknown_lints)]
|
||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||
use libc::{c_char, c_ushort, c_int, c_void};
|
||||
use libc::{c_char, c_ushort, c_int};
|
||||
use std::slice;
|
||||
use std::char::decode_utf16;
|
||||
|
||||
|
@ -76,8 +76,8 @@ pub unsafe extern "C" fn person_free(ptr: *mut Person) {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn person_user_name_get(
|
||||
ptr: *const Person,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, *const c_char, c_int),
|
||||
p: *mut QString,
|
||||
set: fn(*mut QString, *const c_char, c_int),
|
||||
) {
|
||||
let o = unsafe { &*ptr };
|
||||
let v = o.user_name();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* generated by rust_qt_binding_generator */
|
||||
#![allow(unknown_lints)]
|
||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||
use libc::{c_char, c_ushort, c_int, c_void};
|
||||
use libc::{c_char, c_ushort, c_int};
|
||||
use std::slice;
|
||||
use std::char::decode_utf16;
|
||||
|
||||
|
|
|
@ -144,15 +144,25 @@ impl ListTrait for List {
|
|||
fn bytearray(&self, item: usize) -> &[u8] {
|
||||
&self.list[item].bytearray
|
||||
}
|
||||
fn set_bytearray(&mut self, item: usize, v: Vec<u8>) -> bool {
|
||||
self.list[item].bytearray = v;
|
||||
fn set_bytearray(&mut self, item: usize, v: &[u8]) -> bool {
|
||||
self.list[item].bytearray.truncate(0);
|
||||
self.list[item].bytearray.extend_from_slice(v);
|
||||
true
|
||||
}
|
||||
fn optional_bytearray(&self, item: usize) -> Option<&[u8]> {
|
||||
self.list[item].optional_bytearray.as_ref().map(|p|&p[..])
|
||||
}
|
||||
fn set_optional_bytearray(&mut self, item: usize, v: Option<Vec<u8>>) -> bool {
|
||||
self.list[item].optional_bytearray = v;
|
||||
fn set_optional_bytearray(&mut self, item: usize, v: Option<&[u8]>) -> bool {
|
||||
match (v, &mut self.list[item].optional_bytearray) {
|
||||
(Some(value), &mut Some(ref mut b)) => {
|
||||
b.truncate(0);
|
||||
b.extend_from_slice(value);
|
||||
},
|
||||
(Some(value), b) => {
|
||||
*b = Some(value.into())
|
||||
},
|
||||
(None, b) => {*b = None;}
|
||||
};
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* generated by rust_qt_binding_generator */
|
||||
#![allow(unknown_lints)]
|
||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||
use libc::{c_char, c_ushort, c_int, c_void};
|
||||
use libc::{c_char, c_ushort, c_int};
|
||||
use std::slice;
|
||||
use std::char::decode_utf16;
|
||||
|
||||
|
@ -136,7 +136,7 @@ pub trait ListTrait {
|
|||
fn boolean(&self, item: usize) -> bool;
|
||||
fn set_boolean(&mut self, item: usize, bool) -> bool;
|
||||
fn bytearray(&self, item: usize) -> &[u8];
|
||||
fn set_bytearray(&mut self, item: usize, Vec<u8>) -> bool;
|
||||
fn set_bytearray(&mut self, item: usize, &[u8]) -> bool;
|
||||
fn f32(&self, item: usize) -> f32;
|
||||
fn set_f32(&mut self, item: usize, f32) -> bool;
|
||||
fn f64(&self, item: usize) -> f64;
|
||||
|
@ -152,7 +152,7 @@ pub trait ListTrait {
|
|||
fn optional_boolean(&self, item: usize) -> Option<bool>;
|
||||
fn set_optional_boolean(&mut self, item: usize, Option<bool>) -> bool;
|
||||
fn optional_bytearray(&self, item: usize) -> Option<&[u8]>;
|
||||
fn set_optional_bytearray(&mut self, item: usize, Option<Vec<u8>>) -> bool;
|
||||
fn set_optional_bytearray(&mut self, item: usize, Option<&[u8]>) -> bool;
|
||||
fn optional_string(&self, item: usize) -> Option<&str>;
|
||||
fn set_optional_string(&mut self, item: usize, Option<String>) -> bool;
|
||||
fn string(&self, item: usize) -> &str;
|
||||
|
@ -248,8 +248,8 @@ pub unsafe extern "C" fn list_set_data_boolean(
|
|||
#[no_mangle]
|
||||
pub extern "C" fn list_data_bytearray(
|
||||
ptr: *const List, row: c_int,
|
||||
d: *mut QString,
|
||||
set: fn(*mut QString, *const c_char, len: c_int),
|
||||
d: *mut QByteArray,
|
||||
set: fn(*mut QByteArray, *const c_char, len: c_int),
|
||||
) {
|
||||
let o = unsafe { &*ptr };
|
||||
let data = o.bytearray(row as usize);
|
||||
|
@ -263,10 +263,8 @@ pub extern "C" fn list_set_data_bytearray(
|
|||
s: *const c_char, len: c_int,
|
||||
) -> bool {
|
||||
let o = unsafe { &mut *ptr };
|
||||
let mut v = Vec::new();
|
||||
let slice = unsafe { ::std::slice::from_raw_parts(s as *const u8, len as usize) };
|
||||
v.extend_from_slice(slice);
|
||||
o.set_bytearray(row as usize, v)
|
||||
o.set_bytearray(row as usize, slice)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -375,8 +373,8 @@ pub unsafe extern "C" fn list_set_data_optional_boolean_none(ptr: *mut List, row
|
|||
#[no_mangle]
|
||||
pub extern "C" fn list_data_optional_bytearray(
|
||||
ptr: *const List, row: c_int,
|
||||
d: *mut QString,
|
||||
set: fn(*mut QString, *const c_char, len: c_int),
|
||||
d: *mut QByteArray,
|
||||
set: fn(*mut QByteArray, *const c_char, len: c_int),
|
||||
) {
|
||||
let o = unsafe { &*ptr };
|
||||
let data = o.optional_bytearray(row as usize);
|
||||
|
@ -392,10 +390,8 @@ pub extern "C" fn list_set_data_optional_bytearray(
|
|||
s: *const c_char, len: c_int,
|
||||
) -> bool {
|
||||
let o = unsafe { &mut *ptr };
|
||||
let mut v = Vec::new();
|
||||
let slice = unsafe { ::std::slice::from_raw_parts(s as *const u8, len as usize) };
|
||||
v.extend_from_slice(slice);
|
||||
o.set_optional_bytearray(row as usize, Some(v))
|
||||
o.set_optional_bytearray(row as usize, Some(slice))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* generated by rust_qt_binding_generator */
|
||||
#![allow(unknown_lints)]
|
||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||
use libc::{c_char, c_ushort, c_int, c_void};
|
||||
use libc::{c_char, c_ushort, c_int};
|
||||
use std::slice;
|
||||
use std::char::decode_utf16;
|
||||
|
||||
|
@ -73,8 +73,8 @@ pub unsafe extern "C" fn person_free(ptr: *mut Person) {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn person_user_name_get(
|
||||
ptr: *const Person,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, *const c_char, c_int),
|
||||
p: *mut QString,
|
||||
set: fn(*mut QString, *const c_char, c_int),
|
||||
) {
|
||||
let o = unsafe { &*ptr };
|
||||
let v = o.user_name();
|
||||
|
|
|
@ -144,15 +144,25 @@ impl ObjectTrait for Object {
|
|||
fn bytearray(&self) -> &[u8] {
|
||||
&self.bytearray
|
||||
}
|
||||
fn set_bytearray(&mut self, value: Vec<u8>) {
|
||||
self.bytearray = value;
|
||||
fn set_bytearray(&mut self, value: &[u8]) {
|
||||
self.bytearray.truncate(0);
|
||||
self.bytearray.extend_from_slice(value);
|
||||
self.emit.bytearray_changed();
|
||||
}
|
||||
fn optional_bytearray(&self) -> Option<&[u8]> {
|
||||
self.optional_bytearray.as_ref().map(|p|&p[..])
|
||||
}
|
||||
fn set_optional_bytearray(&mut self, value: Option<Vec<u8>>) {
|
||||
self.optional_bytearray = value;
|
||||
fn set_optional_bytearray(&mut self, value: Option<&[u8]>) {
|
||||
match (value, &mut self.optional_bytearray) {
|
||||
(Some(value), &mut Some(ref mut b)) => {
|
||||
b.truncate(0);
|
||||
b.extend_from_slice(value);
|
||||
},
|
||||
(Some(value), b) => {
|
||||
*b = Some(value.into())
|
||||
},
|
||||
(None, b) => {*b = None;}
|
||||
};
|
||||
self.emit.optional_bytearray_changed();
|
||||
}
|
||||
fn optional_string(&self) -> Option<&str> {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* generated by rust_qt_binding_generator */
|
||||
#![allow(unknown_lints)]
|
||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||
use libc::{c_char, c_ushort, c_int, c_void};
|
||||
use libc::{c_char, c_ushort, c_int};
|
||||
use std::slice;
|
||||
use std::char::decode_utf16;
|
||||
|
||||
|
@ -192,7 +192,7 @@ pub trait ObjectTrait {
|
|||
fn boolean(&self) -> bool;
|
||||
fn set_boolean(&mut self, value: bool);
|
||||
fn bytearray(&self) -> &[u8];
|
||||
fn set_bytearray(&mut self, value: Vec<u8>);
|
||||
fn set_bytearray(&mut self, value: &[u8]);
|
||||
fn f32(&self) -> f32;
|
||||
fn set_f32(&mut self, value: f32);
|
||||
fn f64(&self) -> f64;
|
||||
|
@ -208,7 +208,7 @@ pub trait ObjectTrait {
|
|||
fn optional_boolean(&self) -> Option<bool>;
|
||||
fn set_optional_boolean(&mut self, value: Option<bool>);
|
||||
fn optional_bytearray(&self) -> Option<&[u8]>;
|
||||
fn set_optional_bytearray(&mut self, value: Option<Vec<u8>>);
|
||||
fn set_optional_bytearray(&mut self, value: Option<&[u8]>);
|
||||
fn optional_string(&self) -> Option<&str>;
|
||||
fn set_optional_string(&mut self, value: Option<String>);
|
||||
fn optional_u64(&self) -> Option<u64>;
|
||||
|
@ -288,8 +288,8 @@ pub unsafe extern "C" fn object_boolean_set(ptr: *mut Object, v: bool) {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn object_bytearray_get(
|
||||
ptr: *const Object,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, *const c_char, c_int),
|
||||
p: *mut QByteArray,
|
||||
set: fn(*mut QByteArray, *const c_char, c_int),
|
||||
) {
|
||||
let o = unsafe { &*ptr };
|
||||
let v = o.bytearray();
|
||||
|
@ -301,7 +301,7 @@ pub extern "C" fn object_bytearray_get(
|
|||
pub extern "C" fn object_bytearray_set(ptr: *mut Object, v: *const c_char, len: c_int) {
|
||||
let o = unsafe { &mut *ptr };
|
||||
let v = unsafe { slice::from_raw_parts(v as *const u8, len as usize) };
|
||||
o.set_bytearray(v.into());
|
||||
o.set_bytearray(v);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -386,8 +386,8 @@ pub extern "C" fn object_optional_boolean_set_none(ptr: *mut Object) {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn object_optional_bytearray_get(
|
||||
ptr: *const Object,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, *const c_char, c_int),
|
||||
p: *mut QByteArray,
|
||||
set: fn(*mut QByteArray, *const c_char, c_int),
|
||||
) {
|
||||
let o = unsafe { &*ptr };
|
||||
let v = o.optional_bytearray();
|
||||
|
@ -413,8 +413,8 @@ pub extern "C" fn object_optional_bytearray_set_none(ptr: *mut Object) {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn object_optional_string_get(
|
||||
ptr: *const Object,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, *const c_char, c_int),
|
||||
p: *mut QString,
|
||||
set: fn(*mut QString, *const c_char, c_int),
|
||||
) {
|
||||
let o = unsafe { &*ptr };
|
||||
let v = o.optional_string();
|
||||
|
@ -460,8 +460,8 @@ pub extern "C" fn object_optional_u64_set_none(ptr: *mut Object) {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn object_string_get(
|
||||
ptr: *const Object,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, *const c_char, c_int),
|
||||
p: *mut QString,
|
||||
set: fn(*mut QString, *const c_char, c_int),
|
||||
) {
|
||||
let o = unsafe { &*ptr };
|
||||
let v = o.string();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* generated by rust_qt_binding_generator */
|
||||
#![allow(unknown_lints)]
|
||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||
use libc::{c_char, c_ushort, c_int, c_void};
|
||||
use libc::{c_char, c_ushort, c_int};
|
||||
use std::slice;
|
||||
use std::char::decode_utf16;
|
||||
|
||||
|
@ -131,8 +131,8 @@ pub unsafe extern "C" fn inner_object_free(ptr: *mut InnerObject) {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn inner_object_description_get(
|
||||
ptr: *const InnerObject,
|
||||
p: *mut c_void,
|
||||
set: fn(*mut c_void, *const c_char, c_int),
|
||||
p: *mut QString,
|
||||
set: fn(*mut QString, *const c_char, c_int),
|
||||
) {
|
||||
let o = unsafe { &*ptr };
|
||||
let v = o.description();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* generated by rust_qt_binding_generator */
|
||||
#![allow(unknown_lints)]
|
||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||
use libc::{c_char, c_ushort, c_int, c_void};
|
||||
use libc::{c_char, c_ushort, c_int};
|
||||
use std::slice;
|
||||
use std::char::decode_utf16;
|
||||
|
||||
|
|
|
@ -25,6 +25,9 @@ namespace {
|
|||
int row;
|
||||
quintptr id;
|
||||
};
|
||||
inline QVariant cleanNullQVariant(const QVariant& v) {
|
||||
return (v.isNull()) ?QVariant() :v;
|
||||
}
|
||||
}
|
||||
extern "C" {
|
||||
void persons_data_user_name(const Persons::Private*, int, QString*, qstring_set);
|
||||
|
@ -100,23 +103,17 @@ Qt::ItemFlags Persons::flags(const QModelIndex &i) const
|
|||
return flags;
|
||||
}
|
||||
|
||||
QVariant Persons::userName(int row) const
|
||||
QString Persons::userName(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
QString s;
|
||||
persons_data_user_name(m_d, row, &s, set_qstring);
|
||||
if (!s.isNull()) v.setValue<QString>(s);
|
||||
return v;
|
||||
return s;
|
||||
}
|
||||
|
||||
bool Persons::setUserName(int row, const QVariant& value)
|
||||
bool Persons::setUserName(int row, const QString& value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<QString>())) {
|
||||
return false;
|
||||
}
|
||||
const QString s = value.value<QString>();
|
||||
set = persons_set_data_user_name(m_d, row, s.utf16(), s.length());
|
||||
set = persons_set_data_user_name(m_d, row, value.utf16(), value.length());
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -133,7 +130,7 @@ QVariant Persons::data(const QModelIndex &index, int role) const
|
|||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
case Qt::UserRole + 0:
|
||||
return userName(index.row());
|
||||
return QVariant::fromValue(userName(index.row()));
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
|
@ -165,7 +162,9 @@ bool Persons::setData(const QModelIndex &index, const QVariant &value, int role)
|
|||
{
|
||||
if (index.column() == 0) {
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 0) {
|
||||
return setUserName(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<QString>())) {
|
||||
return setUserName(index.row(), value.value<QString>());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -36,8 +36,8 @@ public:
|
|||
Q_INVOKABLE bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
Q_INVOKABLE QVariant userName(int row) const;
|
||||
Q_INVOKABLE bool setUserName(int row, const QVariant& value);
|
||||
Q_INVOKABLE QString userName(int row) const;
|
||||
Q_INVOKABLE bool setUserName(int row, const QString& value);
|
||||
|
||||
signals:
|
||||
// new data is ready to be made available to the model with fetchMore()
|
||||
|
|
|
@ -55,37 +55,13 @@ void testSetter(const V v, Set set, Get get)
|
|||
QSignalSpy spy(&list, &List::dataChanged);
|
||||
|
||||
// WHEN
|
||||
const QVariant vv = QVariant::fromValue(v);
|
||||
QVERIFY(!vv.isNull());
|
||||
bool ok = (list.*set)(0, vv);
|
||||
bool ok = (list.*set)(0, v);
|
||||
QVERIFY(ok);
|
||||
|
||||
// THEN
|
||||
QVERIFY(spy.isValid());
|
||||
QCOMPARE(spy.count(), 1);
|
||||
QCOMPARE((list.*get)(0), vv);
|
||||
}
|
||||
|
||||
template <typename V, typename Set, typename Get>
|
||||
void testOptionalSetter(const V v, Set set, Get get)
|
||||
{
|
||||
// GIVEN
|
||||
List list;
|
||||
QSignalSpy spy(&list, &List::dataChanged);
|
||||
QVERIFY((list.*get)(0).isNull());
|
||||
|
||||
// WHEN
|
||||
QVariant vv = QVariant::fromValue(v);
|
||||
if (vv.isNull()) {
|
||||
vv = QVariant();
|
||||
}
|
||||
bool ok = (list.*set)(0, vv);
|
||||
QVERIFY(ok);
|
||||
|
||||
// THEN
|
||||
QVERIFY(spy.isValid());
|
||||
QCOMPARE(spy.count(), 1);
|
||||
QCOMPARE((list.*get)(0), vv);
|
||||
QCOMPARE((V)(list.*get)(0), v);
|
||||
}
|
||||
|
||||
int getRoleFromName(const QAbstractItemModel& model, const char* name)
|
||||
|
@ -156,7 +132,7 @@ void test(const V v, Set set, Get get, const char* roleName)
|
|||
template <typename V, typename Set, typename Get>
|
||||
void testOptional(const V v, Set set, Get get, const char* roleName)
|
||||
{
|
||||
testOptionalSetter(v, set, get);
|
||||
testSetter(v, set, get);
|
||||
testOptionalDataSetter(roleName, v);
|
||||
}
|
||||
|
||||
|
@ -173,9 +149,11 @@ void TestRustListTypes::testBool()
|
|||
|
||||
void TestRustListTypes::testOptionalBool()
|
||||
{
|
||||
testOptional(true, &List::setOptionalBoolean, &List::optionalBoolean,
|
||||
testOptional(QVariant(), &List::setOptionalBoolean, &List::optionalBoolean,
|
||||
"optionalBoolean");
|
||||
testOptional(false, &List::setOptionalBoolean, &List::optionalBoolean,
|
||||
testOptional(QVariant(true), &List::setOptionalBoolean, &List::optionalBoolean,
|
||||
"optionalBoolean");
|
||||
testOptional(QVariant(false), &List::setOptionalBoolean, &List::optionalBoolean,
|
||||
"optionalBoolean");
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,9 @@ namespace {
|
|||
int row;
|
||||
quintptr id;
|
||||
};
|
||||
inline QVariant cleanNullQVariant(const QVariant& v) {
|
||||
return (v.isNull()) ?QVariant() :v;
|
||||
}
|
||||
}
|
||||
extern "C" {
|
||||
bool list_data_boolean(const List::Private*, int);
|
||||
|
@ -156,20 +159,15 @@ Qt::ItemFlags List::flags(const QModelIndex &i) const
|
|||
return flags;
|
||||
}
|
||||
|
||||
QVariant List::boolean(int row) const
|
||||
bool List::boolean(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(list_data_boolean(m_d, row));
|
||||
return v;
|
||||
return list_data_boolean(m_d, row);
|
||||
}
|
||||
|
||||
bool List::setBoolean(int row, const QVariant& value)
|
||||
bool List::setBoolean(int row, bool value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<bool>())) {
|
||||
return false;
|
||||
}
|
||||
set = list_set_data_boolean(m_d, row, value.value<bool>());
|
||||
set = list_set_data_boolean(m_d, row, value);
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -177,23 +175,17 @@ bool List::setBoolean(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant List::bytearray(int row) const
|
||||
QByteArray List::bytearray(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
QByteArray b;
|
||||
list_data_bytearray(m_d, row, &b, set_qbytearray);
|
||||
if (!b.isNull()) v.setValue<QByteArray>(b);
|
||||
return v;
|
||||
return b;
|
||||
}
|
||||
|
||||
bool List::setBytearray(int row, const QVariant& value)
|
||||
bool List::setBytearray(int row, const QByteArray& value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<QByteArray>())) {
|
||||
return false;
|
||||
}
|
||||
const QByteArray s = value.value<QByteArray>();
|
||||
set = list_set_data_bytearray(m_d, row, s.data(), s.length());
|
||||
set = list_set_data_bytearray(m_d, row, value.data(), value.length());
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -201,20 +193,15 @@ bool List::setBytearray(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant List::f32(int row) const
|
||||
float List::f32(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(list_data_f32(m_d, row));
|
||||
return v;
|
||||
return list_data_f32(m_d, row);
|
||||
}
|
||||
|
||||
bool List::setF32(int row, const QVariant& value)
|
||||
bool List::setF32(int row, float value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<float>())) {
|
||||
return false;
|
||||
}
|
||||
set = list_set_data_f32(m_d, row, value.value<float>());
|
||||
set = list_set_data_f32(m_d, row, value);
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -222,20 +209,15 @@ bool List::setF32(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant List::f64(int row) const
|
||||
double List::f64(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(list_data_f64(m_d, row));
|
||||
return v;
|
||||
return list_data_f64(m_d, row);
|
||||
}
|
||||
|
||||
bool List::setF64(int row, const QVariant& value)
|
||||
bool List::setF64(int row, double value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<double>())) {
|
||||
return false;
|
||||
}
|
||||
set = list_set_data_f64(m_d, row, value.value<double>());
|
||||
set = list_set_data_f64(m_d, row, value);
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -243,20 +225,15 @@ bool List::setF64(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant List::i16(int row) const
|
||||
qint16 List::i16(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(list_data_i16(m_d, row));
|
||||
return v;
|
||||
return list_data_i16(m_d, row);
|
||||
}
|
||||
|
||||
bool List::setI16(int row, const QVariant& value)
|
||||
bool List::setI16(int row, qint16 value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<qint16>())) {
|
||||
return false;
|
||||
}
|
||||
set = list_set_data_i16(m_d, row, value.value<qint16>());
|
||||
set = list_set_data_i16(m_d, row, value);
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -264,20 +241,15 @@ bool List::setI16(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant List::i32(int row) const
|
||||
qint32 List::i32(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(list_data_i32(m_d, row));
|
||||
return v;
|
||||
return list_data_i32(m_d, row);
|
||||
}
|
||||
|
||||
bool List::setI32(int row, const QVariant& value)
|
||||
bool List::setI32(int row, qint32 value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<qint32>())) {
|
||||
return false;
|
||||
}
|
||||
set = list_set_data_i32(m_d, row, value.value<qint32>());
|
||||
set = list_set_data_i32(m_d, row, value);
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -285,20 +257,15 @@ bool List::setI32(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant List::i64(int row) const
|
||||
qint64 List::i64(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(list_data_i64(m_d, row));
|
||||
return v;
|
||||
return list_data_i64(m_d, row);
|
||||
}
|
||||
|
||||
bool List::setI64(int row, const QVariant& value)
|
||||
bool List::setI64(int row, qint64 value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<qint64>())) {
|
||||
return false;
|
||||
}
|
||||
set = list_set_data_i64(m_d, row, value.value<qint64>());
|
||||
set = list_set_data_i64(m_d, row, value);
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -306,20 +273,15 @@ bool List::setI64(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant List::i8(int row) const
|
||||
qint8 List::i8(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(list_data_i8(m_d, row));
|
||||
return v;
|
||||
return list_data_i8(m_d, row);
|
||||
}
|
||||
|
||||
bool List::setI8(int row, const QVariant& value)
|
||||
bool List::setI8(int row, qint8 value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<qint8>())) {
|
||||
return false;
|
||||
}
|
||||
set = list_set_data_i8(m_d, row, value.value<qint8>());
|
||||
set = list_set_data_i8(m_d, row, value);
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -337,7 +299,7 @@ QVariant List::optionalBoolean(int row) const
|
|||
bool List::setOptionalBoolean(int row, const QVariant& value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.isValid()) {
|
||||
if (value.isNull() || !value.isValid()) {
|
||||
set = list_set_data_optional_boolean_none(m_d, row);
|
||||
} else {
|
||||
if (!value.canConvert(qMetaTypeId<bool>())) {
|
||||
|
@ -352,26 +314,20 @@ bool List::setOptionalBoolean(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant List::optionalBytearray(int row) const
|
||||
QByteArray List::optionalBytearray(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
QByteArray b;
|
||||
list_data_optional_bytearray(m_d, row, &b, set_qbytearray);
|
||||
if (!b.isNull()) v.setValue<QByteArray>(b);
|
||||
return v;
|
||||
return b;
|
||||
}
|
||||
|
||||
bool List::setOptionalBytearray(int row, const QVariant& value)
|
||||
bool List::setOptionalBytearray(int row, const QByteArray& value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.isValid() || value.isNull()) {
|
||||
if (value.isNull()) {
|
||||
set = list_set_data_optional_bytearray_none(m_d, row);
|
||||
} else {
|
||||
if (!value.canConvert(qMetaTypeId<QByteArray>())) {
|
||||
return false;
|
||||
}
|
||||
const QByteArray s = value.value<QByteArray>();
|
||||
set = list_set_data_optional_bytearray(m_d, row, s.data(), s.length());
|
||||
set = list_set_data_optional_bytearray(m_d, row, value.data(), value.length());
|
||||
}
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
|
@ -380,26 +336,20 @@ bool List::setOptionalBytearray(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant List::optionalString(int row) const
|
||||
QString List::optionalString(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
QString s;
|
||||
list_data_optional_string(m_d, row, &s, set_qstring);
|
||||
if (!s.isNull()) v.setValue<QString>(s);
|
||||
return v;
|
||||
return s;
|
||||
}
|
||||
|
||||
bool List::setOptionalString(int row, const QVariant& value)
|
||||
bool List::setOptionalString(int row, const QString& value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.isValid() || value.isNull()) {
|
||||
if (value.isNull()) {
|
||||
set = list_set_data_optional_string_none(m_d, row);
|
||||
} else {
|
||||
if (!value.canConvert(qMetaTypeId<QString>())) {
|
||||
return false;
|
||||
}
|
||||
const QString s = value.value<QString>();
|
||||
set = list_set_data_optional_string(m_d, row, s.utf16(), s.length());
|
||||
set = list_set_data_optional_string(m_d, row, value.utf16(), value.length());
|
||||
}
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
|
@ -408,23 +358,17 @@ bool List::setOptionalString(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant List::string(int row) const
|
||||
QString List::string(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
QString s;
|
||||
list_data_string(m_d, row, &s, set_qstring);
|
||||
if (!s.isNull()) v.setValue<QString>(s);
|
||||
return v;
|
||||
return s;
|
||||
}
|
||||
|
||||
bool List::setString(int row, const QVariant& value)
|
||||
bool List::setString(int row, const QString& value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<QString>())) {
|
||||
return false;
|
||||
}
|
||||
const QString s = value.value<QString>();
|
||||
set = list_set_data_string(m_d, row, s.utf16(), s.length());
|
||||
set = list_set_data_string(m_d, row, value.utf16(), value.length());
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -432,20 +376,15 @@ bool List::setString(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant List::u16(int row) const
|
||||
quint16 List::u16(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(list_data_u16(m_d, row));
|
||||
return v;
|
||||
return list_data_u16(m_d, row);
|
||||
}
|
||||
|
||||
bool List::setU16(int row, const QVariant& value)
|
||||
bool List::setU16(int row, quint16 value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<quint16>())) {
|
||||
return false;
|
||||
}
|
||||
set = list_set_data_u16(m_d, row, value.value<quint16>());
|
||||
set = list_set_data_u16(m_d, row, value);
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -453,20 +392,15 @@ bool List::setU16(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant List::u32(int row) const
|
||||
quint32 List::u32(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(list_data_u32(m_d, row));
|
||||
return v;
|
||||
return list_data_u32(m_d, row);
|
||||
}
|
||||
|
||||
bool List::setU32(int row, const QVariant& value)
|
||||
bool List::setU32(int row, quint32 value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<quint32>())) {
|
||||
return false;
|
||||
}
|
||||
set = list_set_data_u32(m_d, row, value.value<quint32>());
|
||||
set = list_set_data_u32(m_d, row, value);
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -474,20 +408,15 @@ bool List::setU32(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant List::u64(int row) const
|
||||
quint64 List::u64(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(list_data_u64(m_d, row));
|
||||
return v;
|
||||
return list_data_u64(m_d, row);
|
||||
}
|
||||
|
||||
bool List::setU64(int row, const QVariant& value)
|
||||
bool List::setU64(int row, quint64 value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<quint64>())) {
|
||||
return false;
|
||||
}
|
||||
set = list_set_data_u64(m_d, row, value.value<quint64>());
|
||||
set = list_set_data_u64(m_d, row, value);
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -495,20 +424,15 @@ bool List::setU64(int row, const QVariant& value)
|
|||
return set;
|
||||
}
|
||||
|
||||
QVariant List::u8(int row) const
|
||||
quint8 List::u8(int row) const
|
||||
{
|
||||
QVariant v;
|
||||
v.setValue(list_data_u8(m_d, row));
|
||||
return v;
|
||||
return list_data_u8(m_d, row);
|
||||
}
|
||||
|
||||
bool List::setU8(int row, const QVariant& value)
|
||||
bool List::setU8(int row, quint8 value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<quint8>())) {
|
||||
return false;
|
||||
}
|
||||
set = list_set_data_u8(m_d, row, value.value<quint8>());
|
||||
set = list_set_data_u8(m_d, row, value);
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
emit dataChanged(index, index);
|
||||
|
@ -523,39 +447,39 @@ QVariant List::data(const QModelIndex &index, int role) const
|
|||
case 0:
|
||||
switch (role) {
|
||||
case Qt::UserRole + 0:
|
||||
return boolean(index.row());
|
||||
return QVariant::fromValue(boolean(index.row()));
|
||||
case Qt::UserRole + 1:
|
||||
return bytearray(index.row());
|
||||
return QVariant::fromValue(bytearray(index.row()));
|
||||
case Qt::UserRole + 2:
|
||||
return f32(index.row());
|
||||
return QVariant::fromValue(f32(index.row()));
|
||||
case Qt::UserRole + 3:
|
||||
return f64(index.row());
|
||||
return QVariant::fromValue(f64(index.row()));
|
||||
case Qt::UserRole + 4:
|
||||
return i16(index.row());
|
||||
return QVariant::fromValue(i16(index.row()));
|
||||
case Qt::UserRole + 5:
|
||||
return i32(index.row());
|
||||
return QVariant::fromValue(i32(index.row()));
|
||||
case Qt::UserRole + 6:
|
||||
return i64(index.row());
|
||||
return QVariant::fromValue(i64(index.row()));
|
||||
case Qt::UserRole + 7:
|
||||
return i8(index.row());
|
||||
return QVariant::fromValue(i8(index.row()));
|
||||
case Qt::UserRole + 8:
|
||||
return optionalBoolean(index.row());
|
||||
case Qt::UserRole + 9:
|
||||
return optionalBytearray(index.row());
|
||||
return cleanNullQVariant(QVariant::fromValue(optionalBytearray(index.row())));
|
||||
case Qt::UserRole + 10:
|
||||
return optionalString(index.row());
|
||||
return cleanNullQVariant(QVariant::fromValue(optionalString(index.row())));
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
case Qt::UserRole + 11:
|
||||
return string(index.row());
|
||||
return QVariant::fromValue(string(index.row()));
|
||||
case Qt::UserRole + 12:
|
||||
return u16(index.row());
|
||||
return QVariant::fromValue(u16(index.row()));
|
||||
case Qt::UserRole + 13:
|
||||
return u32(index.row());
|
||||
return QVariant::fromValue(u32(index.row()));
|
||||
case Qt::UserRole + 14:
|
||||
return u64(index.row());
|
||||
return QVariant::fromValue(u64(index.row()));
|
||||
case Qt::UserRole + 15:
|
||||
return u8(index.row());
|
||||
return QVariant::fromValue(u8(index.row()));
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
|
@ -602,52 +526,82 @@ bool List::setData(const QModelIndex &index, const QVariant &value, int role)
|
|||
{
|
||||
if (index.column() == 0) {
|
||||
if (role == Qt::UserRole + 0) {
|
||||
return setBoolean(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<bool>())) {
|
||||
return setBoolean(index.row(), value.value<bool>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::UserRole + 1) {
|
||||
return setBytearray(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<QByteArray>())) {
|
||||
return setBytearray(index.row(), value.value<QByteArray>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::UserRole + 2) {
|
||||
return setF32(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<float>())) {
|
||||
return setF32(index.row(), value.value<float>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::UserRole + 3) {
|
||||
return setF64(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<double>())) {
|
||||
return setF64(index.row(), value.value<double>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::UserRole + 4) {
|
||||
return setI16(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<qint16>())) {
|
||||
return setI16(index.row(), value.value<qint16>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::UserRole + 5) {
|
||||
return setI32(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<qint32>())) {
|
||||
return setI32(index.row(), value.value<qint32>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::UserRole + 6) {
|
||||
return setI64(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<qint64>())) {
|
||||
return setI64(index.row(), value.value<qint64>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::UserRole + 7) {
|
||||
return setI8(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<qint8>())) {
|
||||
return setI8(index.row(), value.value<qint8>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::UserRole + 8) {
|
||||
return setOptionalBoolean(index.row(), value);
|
||||
}
|
||||
if (role == Qt::UserRole + 9) {
|
||||
return setOptionalBytearray(index.row(), value);
|
||||
if (!value.isValid() || value.isNull() ||value.canConvert(qMetaTypeId<QByteArray>())) {
|
||||
return setOptionalBytearray(index.row(), value.value<QByteArray>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::UserRole + 10) {
|
||||
return setOptionalString(index.row(), value);
|
||||
if (!value.isValid() || value.isNull() ||value.canConvert(qMetaTypeId<QString>())) {
|
||||
return setOptionalString(index.row(), value.value<QString>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 11) {
|
||||
return setString(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<QString>())) {
|
||||
return setString(index.row(), value.value<QString>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::UserRole + 12) {
|
||||
return setU16(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<quint16>())) {
|
||||
return setU16(index.row(), value.value<quint16>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::UserRole + 13) {
|
||||
return setU32(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<quint32>())) {
|
||||
return setU32(index.row(), value.value<quint32>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::UserRole + 14) {
|
||||
return setU64(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<quint64>())) {
|
||||
return setU64(index.row(), value.value<quint64>());
|
||||
}
|
||||
}
|
||||
if (role == Qt::UserRole + 15) {
|
||||
return setU8(index.row(), value);
|
||||
if (value.canConvert(qMetaTypeId<quint8>())) {
|
||||
return setU8(index.row(), value.value<quint8>());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -36,38 +36,38 @@ public:
|
|||
Q_INVOKABLE bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
Q_INVOKABLE QVariant boolean(int row) const;
|
||||
Q_INVOKABLE bool setBoolean(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant bytearray(int row) const;
|
||||
Q_INVOKABLE bool setBytearray(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant f32(int row) const;
|
||||
Q_INVOKABLE bool setF32(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant f64(int row) const;
|
||||
Q_INVOKABLE bool setF64(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant i16(int row) const;
|
||||
Q_INVOKABLE bool setI16(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant i32(int row) const;
|
||||
Q_INVOKABLE bool setI32(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant i64(int row) const;
|
||||
Q_INVOKABLE bool setI64(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant i8(int row) const;
|
||||
Q_INVOKABLE bool setI8(int row, const QVariant& value);
|
||||
Q_INVOKABLE bool boolean(int row) const;
|
||||
Q_INVOKABLE bool setBoolean(int row, bool value);
|
||||
Q_INVOKABLE QByteArray bytearray(int row) const;
|
||||
Q_INVOKABLE bool setBytearray(int row, const QByteArray& value);
|
||||
Q_INVOKABLE float f32(int row) const;
|
||||
Q_INVOKABLE bool setF32(int row, float value);
|
||||
Q_INVOKABLE double f64(int row) const;
|
||||
Q_INVOKABLE bool setF64(int row, double value);
|
||||
Q_INVOKABLE qint16 i16(int row) const;
|
||||
Q_INVOKABLE bool setI16(int row, qint16 value);
|
||||
Q_INVOKABLE qint32 i32(int row) const;
|
||||
Q_INVOKABLE bool setI32(int row, qint32 value);
|
||||
Q_INVOKABLE qint64 i64(int row) const;
|
||||
Q_INVOKABLE bool setI64(int row, qint64 value);
|
||||
Q_INVOKABLE qint8 i8(int row) const;
|
||||
Q_INVOKABLE bool setI8(int row, qint8 value);
|
||||
Q_INVOKABLE QVariant optionalBoolean(int row) const;
|
||||
Q_INVOKABLE bool setOptionalBoolean(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant optionalBytearray(int row) const;
|
||||
Q_INVOKABLE bool setOptionalBytearray(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant optionalString(int row) const;
|
||||
Q_INVOKABLE bool setOptionalString(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant string(int row) const;
|
||||
Q_INVOKABLE bool setString(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant u16(int row) const;
|
||||
Q_INVOKABLE bool setU16(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant u32(int row) const;
|
||||
Q_INVOKABLE bool setU32(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant u64(int row) const;
|
||||
Q_INVOKABLE bool setU64(int row, const QVariant& value);
|
||||
Q_INVOKABLE QVariant u8(int row) const;
|
||||
Q_INVOKABLE bool setU8(int row, const QVariant& value);
|
||||
Q_INVOKABLE QByteArray optionalBytearray(int row) const;
|
||||
Q_INVOKABLE bool setOptionalBytearray(int row, const QByteArray& value);
|
||||
Q_INVOKABLE QString optionalString(int row) const;
|
||||
Q_INVOKABLE bool setOptionalString(int row, const QString& value);
|
||||
Q_INVOKABLE QString string(int row) const;
|
||||
Q_INVOKABLE bool setString(int row, const QString& value);
|
||||
Q_INVOKABLE quint16 u16(int row) const;
|
||||
Q_INVOKABLE bool setU16(int row, quint16 value);
|
||||
Q_INVOKABLE quint32 u32(int row) const;
|
||||
Q_INVOKABLE bool setU32(int row, quint32 value);
|
||||
Q_INVOKABLE quint64 u64(int row) const;
|
||||
Q_INVOKABLE bool setU64(int row, quint64 value);
|
||||
Q_INVOKABLE quint8 u8(int row) const;
|
||||
Q_INVOKABLE bool setU8(int row, quint8 value);
|
||||
|
||||
signals:
|
||||
// new data is ready to be made available to the model with fetchMore()
|
||||
|
|
|
@ -25,6 +25,9 @@ namespace {
|
|||
int row;
|
||||
quintptr id;
|
||||
};
|
||||
inline QVariant cleanNullQVariant(const QVariant& v) {
|
||||
return (v.isNull()) ?QVariant() :v;
|
||||
}
|
||||
}
|
||||
extern "C" {
|
||||
void persons_data_user_name(const Persons::Private*, quintptr, QString*, qstring_set);
|
||||
|
@ -116,23 +119,17 @@ Qt::ItemFlags Persons::flags(const QModelIndex &i) const
|
|||
return flags;
|
||||
}
|
||||
|
||||
QVariant Persons::userName(const QModelIndex& index) const
|
||||
QString Persons::userName(const QModelIndex& index) const
|
||||
{
|
||||
QVariant v;
|
||||
QString s;
|
||||
persons_data_user_name(m_d, index.internalId(), &s, set_qstring);
|
||||
if (!s.isNull()) v.setValue<QString>(s);
|
||||
return v;
|
||||
return s;
|
||||
}
|
||||
|
||||
bool Persons::setUserName(const QModelIndex& index, const QVariant& value)
|
||||
bool Persons::setUserName(const QModelIndex& index, const QString& value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<QString>())) {
|
||||
return false;
|
||||
}
|
||||
const QString s = value.value<QString>();
|
||||
set = persons_set_data_user_name(m_d, index.internalId(), s.utf16(), s.length());
|
||||
set = persons_set_data_user_name(m_d, index.internalId(), value.utf16(), value.length());
|
||||
if (set) {
|
||||
emit dataChanged(index, index);
|
||||
}
|
||||
|
@ -148,7 +145,7 @@ QVariant Persons::data(const QModelIndex &index, int role) const
|
|||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
case Qt::UserRole + 0:
|
||||
return userName(index);
|
||||
return QVariant::fromValue(userName(index));
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
|
@ -180,7 +177,9 @@ bool Persons::setData(const QModelIndex &index, const QVariant &value, int role)
|
|||
{
|
||||
if (index.column() == 0) {
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 0) {
|
||||
return setUserName(index, value);
|
||||
if (value.canConvert(qMetaTypeId<QString>())) {
|
||||
return setUserName(index, value.value<QString>());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -36,8 +36,8 @@ public:
|
|||
Q_INVOKABLE bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
Q_INVOKABLE QVariant userName(const QModelIndex& index) const;
|
||||
Q_INVOKABLE bool setUserName(const QModelIndex& index, const QVariant& value);
|
||||
Q_INVOKABLE QString userName(const QModelIndex& index) const;
|
||||
Q_INVOKABLE bool setUserName(const QModelIndex& index, const QString& value);
|
||||
|
||||
signals:
|
||||
// new data is ready to be made available to the model with fetchMore()
|
||||
|
|
Loading…
Reference in New Issue