2017-08-20 07:11:58 -07:00
|
|
|
/* generated by rust_qt_binding_generator */
|
|
|
|
#include "test_list_rust.h"
|
|
|
|
|
|
|
|
namespace {
|
2017-09-01 13:00:24 -07:00
|
|
|
|
|
|
|
struct option_quintptr {
|
2017-08-22 10:17:35 -07:00
|
|
|
public:
|
2017-09-01 13:00:24 -07:00
|
|
|
quintptr value;
|
2017-08-20 07:11:58 -07:00
|
|
|
bool some;
|
|
|
|
operator QVariant() const {
|
|
|
|
if (some) {
|
2018-05-13 03:48:32 -07:00
|
|
|
return QVariant::fromValue(value);
|
2017-08-20 07:11:58 -07:00
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
};
|
2018-05-13 04:10:59 -07:00
|
|
|
static_assert(std::is_pod<option_quintptr>::value, "option_quintptr must be a POD type.");
|
2017-09-01 13:00:24 -07:00
|
|
|
|
2018-05-02 08:02:07 -07:00
|
|
|
typedef void (*qstring_set)(QString* val, const char* utf8, int nbytes);
|
|
|
|
void set_qstring(QString* val, const char* utf8, int nbytes) {
|
|
|
|
*val = QString::fromUtf8(utf8, nbytes);
|
2017-09-01 13:00:24 -07:00
|
|
|
}
|
|
|
|
|
2017-08-20 07:11:58 -07:00
|
|
|
struct qmodelindex_t {
|
|
|
|
int row;
|
|
|
|
quintptr id;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
extern "C" {
|
|
|
|
void persons_data_user_name(const Persons::Private*, int, QString*, qstring_set);
|
2018-05-02 08:02:07 -07:00
|
|
|
bool persons_set_data_user_name(Persons::Private*, int, const ushort* s, int len);
|
2017-08-22 04:45:34 -07:00
|
|
|
void persons_sort(Persons::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
|
2017-08-20 07:11:58 -07:00
|
|
|
|
|
|
|
int persons_row_count(const Persons::Private*);
|
2017-10-02 15:34:44 -07:00
|
|
|
bool persons_insert_rows(Persons::Private*, int, int);
|
2017-10-03 11:22:44 -07:00
|
|
|
bool persons_remove_rows(Persons::Private*, int, int);
|
2017-08-20 07:11:58 -07:00
|
|
|
bool persons_can_fetch_more(const Persons::Private*);
|
|
|
|
void persons_fetch_more(Persons::Private*);
|
|
|
|
}
|
|
|
|
int Persons::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return (parent.isValid()) ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Persons::hasChildren(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return rowCount(parent) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Persons::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
2017-08-26 10:10:18 -07:00
|
|
|
return (parent.isValid()) ? 0 : persons_row_count(m_d);
|
2017-08-20 07:11:58 -07:00
|
|
|
}
|
|
|
|
|
2017-10-02 15:34:44 -07:00
|
|
|
bool Persons::insertRows(int row, int count, const QModelIndex &parent)
|
|
|
|
{
|
|
|
|
return persons_insert_rows(m_d, row, count);
|
|
|
|
}
|
|
|
|
|
2017-10-03 11:22:44 -07:00
|
|
|
bool Persons::removeRows(int row, int count, const QModelIndex &parent)
|
|
|
|
{
|
|
|
|
return persons_remove_rows(m_d, row, count);
|
|
|
|
}
|
|
|
|
|
2017-08-20 07:11:58 -07:00
|
|
|
QModelIndex Persons::index(int row, int column, const QModelIndex &parent) const
|
|
|
|
{
|
2017-08-21 15:51:48 -07:00
|
|
|
if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 1) {
|
2017-08-28 12:17:06 -07:00
|
|
|
return createIndex(row, column, (quintptr)row);
|
2017-08-20 07:11:58 -07:00
|
|
|
}
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex Persons::parent(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Persons::canFetchMore(const QModelIndex &parent) const
|
|
|
|
{
|
2017-08-26 10:10:18 -07:00
|
|
|
return (parent.isValid()) ? 0 : persons_can_fetch_more(m_d);
|
2017-08-20 07:11:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void Persons::fetchMore(const QModelIndex &parent)
|
|
|
|
{
|
|
|
|
if (!parent.isValid()) {
|
2017-08-26 10:10:18 -07:00
|
|
|
persons_fetch_more(m_d);
|
2017-08-20 07:11:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Persons::sort(int column, Qt::SortOrder order)
|
|
|
|
{
|
2017-08-26 10:10:18 -07:00
|
|
|
persons_sort(m_d, column, order);
|
2017-08-20 07:11:58 -07:00
|
|
|
}
|
|
|
|
Qt::ItemFlags Persons::flags(const QModelIndex &i) const
|
|
|
|
{
|
|
|
|
auto flags = QAbstractItemModel::flags(i);
|
|
|
|
if (i.column() == 0) {
|
|
|
|
flags |= Qt::ItemIsEditable;
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|
2017-09-01 02:57:10 -07:00
|
|
|
|
2017-08-31 17:33:20 -07:00
|
|
|
QVariant Persons::userName(int row) const
|
2017-08-20 07:11:58 -07:00
|
|
|
{
|
|
|
|
QVariant v;
|
|
|
|
QString s;
|
2017-08-31 17:33:20 -07:00
|
|
|
persons_data_user_name(m_d, row, &s, set_qstring);
|
|
|
|
if (!s.isNull()) v.setValue<QString>(s);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-09-01 02:57:10 -07:00
|
|
|
bool Persons::setUserName(int row, const QVariant& value)
|
|
|
|
{
|
2018-05-12 17:21:36 -07:00
|
|
|
if (!value.canConvert(qMetaTypeId<QString>())) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-12 17:27:16 -07:00
|
|
|
bool set = false;
|
|
|
|
const QString s = value.value<QString>();
|
|
|
|
set = persons_set_data_user_name(m_d, row, s.utf16(), s.length());
|
2017-09-01 02:57:10 -07:00
|
|
|
if (set) {
|
|
|
|
QModelIndex index = createIndex(row, 0, row);
|
|
|
|
emit dataChanged(index, index);
|
|
|
|
}
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
2017-08-31 17:33:20 -07:00
|
|
|
QVariant Persons::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
Q_ASSERT(rowCount(index.parent()) > index.row());
|
2017-08-20 07:11:58 -07:00
|
|
|
switch (index.column()) {
|
|
|
|
case 0:
|
|
|
|
switch (role) {
|
2017-08-22 04:45:34 -07:00
|
|
|
case Qt::DisplayRole:
|
|
|
|
case Qt::EditRole:
|
|
|
|
case Qt::UserRole + 0:
|
2017-08-31 17:33:20 -07:00
|
|
|
return userName(index.row());
|
2017-08-20 07:11:58 -07:00
|
|
|
}
|
|
|
|
}
|
2017-08-31 17:33:20 -07:00
|
|
|
return QVariant();
|
2017-08-20 07:11:58 -07:00
|
|
|
}
|
2017-09-01 02:57:10 -07:00
|
|
|
|
2017-08-20 07:11:58 -07:00
|
|
|
QHash<int, QByteArray> Persons::roleNames() const {
|
2017-08-21 15:51:48 -07:00
|
|
|
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
2017-08-22 04:45:34 -07:00
|
|
|
names.insert(Qt::UserRole + 0, "userName");
|
2017-08-20 07:11:58 -07:00
|
|
|
return names;
|
|
|
|
}
|
2017-08-31 10:20:25 -07:00
|
|
|
QVariant Persons::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if (orientation != Qt::Horizontal) {
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
return m_headerData.value(qMakePair(section, (Qt::ItemDataRole)role), role == Qt::DisplayRole ?QString::number(section + 1) :QVariant());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Persons::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
|
|
|
|
{
|
|
|
|
if (orientation != Qt::Horizontal) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_headerData.insert(qMakePair(section, (Qt::ItemDataRole)role), value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-20 07:11:58 -07:00
|
|
|
bool Persons::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
{
|
|
|
|
if (index.column() == 0) {
|
2017-08-22 04:45:34 -07:00
|
|
|
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 0) {
|
2017-09-01 02:57:10 -07:00
|
|
|
return setUserName(index.row(), value);
|
2017-08-20 07:11:58 -07:00
|
|
|
}
|
|
|
|
}
|
2017-09-01 02:57:10 -07:00
|
|
|
return false;
|
2017-08-20 07:11:58 -07:00
|
|
|
}
|
2017-09-01 02:57:10 -07:00
|
|
|
|
2017-08-22 04:45:34 -07:00
|
|
|
extern "C" {
|
|
|
|
Persons::Private* persons_new(Persons*,
|
|
|
|
void (*)(const Persons*),
|
2017-08-28 12:17:06 -07:00
|
|
|
void (*)(Persons*, quintptr, quintptr),
|
2017-08-22 04:45:34 -07:00
|
|
|
void (*)(Persons*),
|
|
|
|
void (*)(Persons*),
|
|
|
|
void (*)(Persons*, int, int),
|
|
|
|
void (*)(Persons*),
|
|
|
|
void (*)(Persons*, int, int),
|
|
|
|
void (*)(Persons*));
|
|
|
|
void persons_free(Persons::Private*);
|
|
|
|
};
|
2017-08-28 00:28:48 -07:00
|
|
|
|
2017-08-26 10:10:18 -07:00
|
|
|
Persons::Persons(bool /*owned*/, QObject *parent):
|
|
|
|
QAbstractItemModel(parent),
|
|
|
|
m_d(0),
|
2017-08-28 00:28:48 -07:00
|
|
|
m_ownsPrivate(false)
|
|
|
|
{
|
2017-08-31 10:20:25 -07:00
|
|
|
initHeaderData();
|
2017-08-28 00:28:48 -07:00
|
|
|
}
|
|
|
|
|
2017-08-22 04:45:34 -07:00
|
|
|
Persons::Persons(QObject *parent):
|
|
|
|
QAbstractItemModel(parent),
|
2017-08-26 10:10:18 -07:00
|
|
|
m_d(persons_new(this,
|
2017-08-22 04:45:34 -07:00
|
|
|
[](const Persons* o) {
|
|
|
|
emit o->newDataReady(QModelIndex());
|
|
|
|
},
|
2017-08-28 12:17:06 -07:00
|
|
|
[](Persons* o, quintptr first, quintptr last) {
|
|
|
|
o->dataChanged(o->createIndex(first, 0, first),
|
|
|
|
o->createIndex(last, 0, last));
|
|
|
|
},
|
2017-08-22 04:45:34 -07:00
|
|
|
[](Persons* o) {
|
|
|
|
o->beginResetModel();
|
|
|
|
},
|
|
|
|
[](Persons* o) {
|
|
|
|
o->endResetModel();
|
|
|
|
},
|
|
|
|
[](Persons* o, int first, int last) {
|
|
|
|
o->beginInsertRows(QModelIndex(), first, last);
|
|
|
|
},
|
|
|
|
[](Persons* o) {
|
|
|
|
o->endInsertRows();
|
|
|
|
},
|
|
|
|
[](Persons* o, int first, int last) {
|
|
|
|
o->beginRemoveRows(QModelIndex(), first, last);
|
|
|
|
},
|
|
|
|
[](Persons* o) {
|
|
|
|
o->endRemoveRows();
|
|
|
|
}
|
2017-08-26 10:10:18 -07:00
|
|
|
)),
|
2017-08-28 00:28:48 -07:00
|
|
|
m_ownsPrivate(true)
|
|
|
|
{
|
2017-08-22 04:45:34 -07:00
|
|
|
connect(this, &Persons::newDataReady, this, [this](const QModelIndex& i) {
|
2017-08-31 10:20:25 -07:00
|
|
|
this->fetchMore(i);
|
2017-08-22 04:45:34 -07:00
|
|
|
}, Qt::QueuedConnection);
|
2017-08-31 10:20:25 -07:00
|
|
|
initHeaderData();
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Persons::~Persons() {
|
2017-08-26 10:10:18 -07:00
|
|
|
if (m_ownsPrivate) {
|
|
|
|
persons_free(m_d);
|
|
|
|
}
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
2017-08-31 10:20:25 -07:00
|
|
|
void Persons::initHeaderData() {
|
|
|
|
m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("userName"));
|
2017-09-01 02:57:10 -07:00
|
|
|
}
|