File indexing completed on 2024-04-21 05:44:56

0001 /* generated by rust_qt_binding_generator */
0002 #include "test_list_rust.h"
0003 
0004 namespace {
0005 
0006     struct option_quintptr {
0007     public:
0008         quintptr value;
0009         bool some;
0010         operator QVariant() const {
0011             if (some) {
0012                 return QVariant::fromValue(value);
0013             }
0014             return QVariant();
0015         }
0016     };
0017     static_assert(std::is_pod<option_quintptr>::value, "option_quintptr must be a POD type.");
0018 
0019     typedef void (*qstring_set)(QString* val, const char* utf8, int nbytes);
0020     void set_qstring(QString* val, const char* utf8, int nbytes) {
0021         *val = QString::fromUtf8(utf8, nbytes);
0022     }
0023 
0024     struct qmodelindex_t {
0025         int row;
0026         quintptr id;
0027     };
0028     inline QVariant cleanNullQVariant(const QVariant& v) {
0029         return (v.isNull()) ?QVariant() :v;
0030     }
0031 }
0032 extern "C" {
0033     quint8 no_role_data_user_age(const NoRole::Private*, int);
0034     bool no_role_set_data_user_age(NoRole::Private*, int, quint8);
0035     void no_role_data_user_name(const NoRole::Private*, int, QString*, qstring_set);
0036     bool no_role_set_data_user_name(NoRole::Private*, int, const ushort* s, int len);
0037     void no_role_sort(NoRole::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
0038 
0039     int no_role_row_count(const NoRole::Private*);
0040     bool no_role_insert_rows(NoRole::Private*, int, int);
0041     bool no_role_remove_rows(NoRole::Private*, int, int);
0042     bool no_role_can_fetch_more(const NoRole::Private*);
0043     void no_role_fetch_more(NoRole::Private*);
0044 }
0045 int NoRole::columnCount(const QModelIndex &parent) const
0046 {
0047     return (parent.isValid()) ? 0 : 1;
0048 }
0049 
0050 bool NoRole::hasChildren(const QModelIndex &parent) const
0051 {
0052     return rowCount(parent) > 0;
0053 }
0054 
0055 int NoRole::rowCount(const QModelIndex &parent) const
0056 {
0057     return (parent.isValid()) ? 0 : no_role_row_count(m_d);
0058 }
0059 
0060 bool NoRole::insertRows(int row, int count, const QModelIndex &)
0061 {
0062     return no_role_insert_rows(m_d, row, count);
0063 }
0064 
0065 bool NoRole::removeRows(int row, int count, const QModelIndex &)
0066 {
0067     return no_role_remove_rows(m_d, row, count);
0068 }
0069 
0070 QModelIndex NoRole::index(int row, int column, const QModelIndex &parent) const
0071 {
0072     if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 1) {
0073         return createIndex(row, column, (quintptr)row);
0074     }
0075     return QModelIndex();
0076 }
0077 
0078 QModelIndex NoRole::parent(const QModelIndex &) const
0079 {
0080     return QModelIndex();
0081 }
0082 
0083 bool NoRole::canFetchMore(const QModelIndex &parent) const
0084 {
0085     return (parent.isValid()) ? 0 : no_role_can_fetch_more(m_d);
0086 }
0087 
0088 void NoRole::fetchMore(const QModelIndex &parent)
0089 {
0090     if (!parent.isValid()) {
0091         no_role_fetch_more(m_d);
0092     }
0093 }
0094 void NoRole::updatePersistentIndexes() {}
0095 
0096 void NoRole::sort(int column, Qt::SortOrder order)
0097 {
0098     no_role_sort(m_d, column, order);
0099 }
0100 Qt::ItemFlags NoRole::flags(const QModelIndex &i) const
0101 {
0102     auto flags = QAbstractItemModel::flags(i);
0103     if (i.column() == 0) {
0104         flags |= Qt::ItemIsEditable;
0105     }
0106     return flags;
0107 }
0108 
0109 quint8 NoRole::userAge(int row) const
0110 {
0111     return no_role_data_user_age(m_d, row);
0112 }
0113 
0114 bool NoRole::setUserAge(int row, quint8 value)
0115 {
0116     bool set = false;
0117     set = no_role_set_data_user_age(m_d, row, value);
0118     if (set) {
0119         QModelIndex index = createIndex(row, 0, row);
0120         Q_EMIT dataChanged(index, index);
0121     }
0122     return set;
0123 }
0124 
0125 QString NoRole::userName(int row) const
0126 {
0127     QString s;
0128     no_role_data_user_name(m_d, row, &s, set_qstring);
0129     return s;
0130 }
0131 
0132 bool NoRole::setUserName(int row, const QString& value)
0133 {
0134     bool set = false;
0135     set = no_role_set_data_user_name(m_d, row, value.utf16(), value.length());
0136     if (set) {
0137         QModelIndex index = createIndex(row, 0, row);
0138         Q_EMIT dataChanged(index, index);
0139     }
0140     return set;
0141 }
0142 
0143 QVariant NoRole::data(const QModelIndex &index, int role) const
0144 {
0145     Q_ASSERT(rowCount(index.parent()) > index.row());
0146     switch (index.column()) {
0147     case 0:
0148         switch (role) {
0149         case Qt::UserRole + 0:
0150             return QVariant::fromValue(userAge(index.row()));
0151         case Qt::UserRole + 1:
0152             return QVariant::fromValue(userName(index.row()));
0153         }
0154         break;
0155     }
0156     return QVariant();
0157 }
0158 
0159 int NoRole::role(const char* name) const {
0160     auto names = roleNames();
0161     auto i = names.constBegin();
0162     while (i != names.constEnd()) {
0163         if (i.value() == name) {
0164             return i.key();
0165         }
0166         ++i;
0167     }
0168     return -1;
0169 }
0170 QHash<int, QByteArray> NoRole::roleNames() const {
0171     QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
0172     names.insert(Qt::UserRole + 0, "userAge");
0173     names.insert(Qt::UserRole + 1, "userName");
0174     return names;
0175 }
0176 QVariant NoRole::headerData(int section, Qt::Orientation orientation, int role) const
0177 {
0178     if (orientation != Qt::Horizontal) {
0179         return QVariant();
0180     }
0181     return m_headerData.value(qMakePair(section, (Qt::ItemDataRole)role), role == Qt::DisplayRole ?QString::number(section + 1) :QVariant());
0182 }
0183 
0184 bool NoRole::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
0185 {
0186     if (orientation != Qt::Horizontal) {
0187         return false;
0188     }
0189     m_headerData.insert(qMakePair(section, (Qt::ItemDataRole)role), value);
0190     return true;
0191 }
0192 
0193 bool NoRole::setData(const QModelIndex &index, const QVariant &value, int role)
0194 {
0195     if (index.column() == 0) {
0196         if (role == Qt::UserRole + 0) {
0197             if (value.canConvert(qMetaTypeId<quint8>())) {
0198                 return setUserAge(index.row(), value.value<quint8>());
0199             }
0200         }
0201         if (role == Qt::UserRole + 1) {
0202             if (value.canConvert(qMetaTypeId<QString>())) {
0203                 return setUserName(index.row(), value.value<QString>());
0204             }
0205         }
0206     }
0207     return false;
0208 }
0209 
0210 extern "C" {
0211     NoRole::Private* no_role_new(NoRole*,
0212         void (*)(const NoRole*),
0213         void (*)(NoRole*),
0214         void (*)(NoRole*),
0215         void (*)(NoRole*, quintptr, quintptr),
0216         void (*)(NoRole*),
0217         void (*)(NoRole*),
0218         void (*)(NoRole*, int, int),
0219         void (*)(NoRole*),
0220         void (*)(NoRole*, int, int, int),
0221         void (*)(NoRole*),
0222         void (*)(NoRole*, int, int),
0223         void (*)(NoRole*));
0224     void no_role_free(NoRole::Private*);
0225 };
0226 
0227 extern "C" {
0228     void persons_data_user_name(const Persons::Private*, int, QString*, qstring_set);
0229     bool persons_set_data_user_name(Persons::Private*, int, const ushort* s, int len);
0230     void persons_sort(Persons::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
0231 
0232     int persons_row_count(const Persons::Private*);
0233     bool persons_insert_rows(Persons::Private*, int, int);
0234     bool persons_remove_rows(Persons::Private*, int, int);
0235     bool persons_can_fetch_more(const Persons::Private*);
0236     void persons_fetch_more(Persons::Private*);
0237 }
0238 int Persons::columnCount(const QModelIndex &parent) const
0239 {
0240     return (parent.isValid()) ? 0 : 1;
0241 }
0242 
0243 bool Persons::hasChildren(const QModelIndex &parent) const
0244 {
0245     return rowCount(parent) > 0;
0246 }
0247 
0248 int Persons::rowCount(const QModelIndex &parent) const
0249 {
0250     return (parent.isValid()) ? 0 : persons_row_count(m_d);
0251 }
0252 
0253 bool Persons::insertRows(int row, int count, const QModelIndex &)
0254 {
0255     return persons_insert_rows(m_d, row, count);
0256 }
0257 
0258 bool Persons::removeRows(int row, int count, const QModelIndex &)
0259 {
0260     return persons_remove_rows(m_d, row, count);
0261 }
0262 
0263 QModelIndex Persons::index(int row, int column, const QModelIndex &parent) const
0264 {
0265     if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 1) {
0266         return createIndex(row, column, (quintptr)row);
0267     }
0268     return QModelIndex();
0269 }
0270 
0271 QModelIndex Persons::parent(const QModelIndex &) const
0272 {
0273     return QModelIndex();
0274 }
0275 
0276 bool Persons::canFetchMore(const QModelIndex &parent) const
0277 {
0278     return (parent.isValid()) ? 0 : persons_can_fetch_more(m_d);
0279 }
0280 
0281 void Persons::fetchMore(const QModelIndex &parent)
0282 {
0283     if (!parent.isValid()) {
0284         persons_fetch_more(m_d);
0285     }
0286 }
0287 void Persons::updatePersistentIndexes() {}
0288 
0289 void Persons::sort(int column, Qt::SortOrder order)
0290 {
0291     persons_sort(m_d, column, order);
0292 }
0293 Qt::ItemFlags Persons::flags(const QModelIndex &i) const
0294 {
0295     auto flags = QAbstractItemModel::flags(i);
0296     if (i.column() == 0) {
0297         flags |= Qt::ItemIsEditable;
0298     }
0299     return flags;
0300 }
0301 
0302 QString Persons::userName(int row) const
0303 {
0304     QString s;
0305     persons_data_user_name(m_d, row, &s, set_qstring);
0306     return s;
0307 }
0308 
0309 bool Persons::setUserName(int row, const QString& value)
0310 {
0311     bool set = false;
0312     set = persons_set_data_user_name(m_d, row, value.utf16(), value.length());
0313     if (set) {
0314         QModelIndex index = createIndex(row, 0, row);
0315         Q_EMIT dataChanged(index, index);
0316     }
0317     return set;
0318 }
0319 
0320 QVariant Persons::data(const QModelIndex &index, int role) const
0321 {
0322     Q_ASSERT(rowCount(index.parent()) > index.row());
0323     switch (index.column()) {
0324     case 0:
0325         switch (role) {
0326         case Qt::DisplayRole:
0327         case Qt::EditRole:
0328         case Qt::UserRole + 0:
0329             return QVariant::fromValue(userName(index.row()));
0330         }
0331         break;
0332     }
0333     return QVariant();
0334 }
0335 
0336 int Persons::role(const char* name) const {
0337     auto names = roleNames();
0338     auto i = names.constBegin();
0339     while (i != names.constEnd()) {
0340         if (i.value() == name) {
0341             return i.key();
0342         }
0343         ++i;
0344     }
0345     return -1;
0346 }
0347 QHash<int, QByteArray> Persons::roleNames() const {
0348     QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
0349     names.insert(Qt::UserRole + 0, "userName");
0350     return names;
0351 }
0352 QVariant Persons::headerData(int section, Qt::Orientation orientation, int role) const
0353 {
0354     if (orientation != Qt::Horizontal) {
0355         return QVariant();
0356     }
0357     return m_headerData.value(qMakePair(section, (Qt::ItemDataRole)role), role == Qt::DisplayRole ?QString::number(section + 1) :QVariant());
0358 }
0359 
0360 bool Persons::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
0361 {
0362     if (orientation != Qt::Horizontal) {
0363         return false;
0364     }
0365     m_headerData.insert(qMakePair(section, (Qt::ItemDataRole)role), value);
0366     return true;
0367 }
0368 
0369 bool Persons::setData(const QModelIndex &index, const QVariant &value, int role)
0370 {
0371     if (index.column() == 0) {
0372         if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 0) {
0373             if (value.canConvert(qMetaTypeId<QString>())) {
0374                 return setUserName(index.row(), value.value<QString>());
0375             }
0376         }
0377     }
0378     return false;
0379 }
0380 
0381 extern "C" {
0382     Persons::Private* persons_new(Persons*,
0383         void (*)(const Persons*),
0384         void (*)(Persons*),
0385         void (*)(Persons*),
0386         void (*)(Persons*, quintptr, quintptr),
0387         void (*)(Persons*),
0388         void (*)(Persons*),
0389         void (*)(Persons*, int, int),
0390         void (*)(Persons*),
0391         void (*)(Persons*, int, int, int),
0392         void (*)(Persons*),
0393         void (*)(Persons*, int, int),
0394         void (*)(Persons*));
0395     void persons_free(Persons::Private*);
0396 };
0397 
0398 NoRole::NoRole(bool /*owned*/, QObject *parent):
0399     QAbstractItemModel(parent),
0400     m_d(nullptr),
0401     m_ownsPrivate(false)
0402 {
0403     initHeaderData();
0404 }
0405 
0406 NoRole::NoRole(QObject *parent):
0407     QAbstractItemModel(parent),
0408     m_d(no_role_new(this,
0409         [](const NoRole* o) {
0410             Q_EMIT o->newDataReady(QModelIndex());
0411         },
0412         [](NoRole* o) {
0413             Q_EMIT o->layoutAboutToBeChanged();
0414         },
0415         [](NoRole* o) {
0416             o->updatePersistentIndexes();
0417             Q_EMIT o->layoutChanged();
0418         },
0419         [](NoRole* o, quintptr first, quintptr last) {
0420             o->dataChanged(o->createIndex(first, 0, first),
0421                        o->createIndex(last, 0, last));
0422         },
0423         [](NoRole* o) {
0424             o->beginResetModel();
0425         },
0426         [](NoRole* o) {
0427             o->endResetModel();
0428         },
0429         [](NoRole* o, int first, int last) {
0430             o->beginInsertRows(QModelIndex(), first, last);
0431         },
0432         [](NoRole* o) {
0433             o->endInsertRows();
0434         },
0435         [](NoRole* o, int first, int last, int destination) {
0436             o->beginMoveRows(QModelIndex(), first, last, QModelIndex(), destination);
0437         },
0438         [](NoRole* o) {
0439             o->endMoveRows();
0440         },
0441         [](NoRole* o, int first, int last) {
0442             o->beginRemoveRows(QModelIndex(), first, last);
0443         },
0444         [](NoRole* o) {
0445             o->endRemoveRows();
0446         }
0447 )),
0448     m_ownsPrivate(true)
0449 {
0450     connect(this, &NoRole::newDataReady, this, [this](const QModelIndex& i) {
0451         this->fetchMore(i);
0452     }, Qt::QueuedConnection);
0453     initHeaderData();
0454 }
0455 
0456 NoRole::~NoRole() {
0457     if (m_ownsPrivate) {
0458         no_role_free(m_d);
0459     }
0460 }
0461 void NoRole::initHeaderData() {
0462 }
0463 Persons::Persons(bool /*owned*/, QObject *parent):
0464     QAbstractItemModel(parent),
0465     m_d(nullptr),
0466     m_ownsPrivate(false)
0467 {
0468     initHeaderData();
0469 }
0470 
0471 Persons::Persons(QObject *parent):
0472     QAbstractItemModel(parent),
0473     m_d(persons_new(this,
0474         [](const Persons* o) {
0475             Q_EMIT o->newDataReady(QModelIndex());
0476         },
0477         [](Persons* o) {
0478             Q_EMIT o->layoutAboutToBeChanged();
0479         },
0480         [](Persons* o) {
0481             o->updatePersistentIndexes();
0482             Q_EMIT o->layoutChanged();
0483         },
0484         [](Persons* o, quintptr first, quintptr last) {
0485             o->dataChanged(o->createIndex(first, 0, first),
0486                        o->createIndex(last, 0, last));
0487         },
0488         [](Persons* o) {
0489             o->beginResetModel();
0490         },
0491         [](Persons* o) {
0492             o->endResetModel();
0493         },
0494         [](Persons* o, int first, int last) {
0495             o->beginInsertRows(QModelIndex(), first, last);
0496         },
0497         [](Persons* o) {
0498             o->endInsertRows();
0499         },
0500         [](Persons* o, int first, int last, int destination) {
0501             o->beginMoveRows(QModelIndex(), first, last, QModelIndex(), destination);
0502         },
0503         [](Persons* o) {
0504             o->endMoveRows();
0505         },
0506         [](Persons* o, int first, int last) {
0507             o->beginRemoveRows(QModelIndex(), first, last);
0508         },
0509         [](Persons* o) {
0510             o->endRemoveRows();
0511         }
0512 )),
0513     m_ownsPrivate(true)
0514 {
0515     connect(this, &Persons::newDataReady, this, [this](const QModelIndex& i) {
0516         this->fetchMore(i);
0517     }, Qt::QueuedConnection);
0518     initHeaderData();
0519 }
0520 
0521 Persons::~Persons() {
0522     if (m_ownsPrivate) {
0523         persons_free(m_d);
0524     }
0525 }
0526 void Persons::initHeaderData() {
0527     m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("userName"));
0528 }