File indexing completed on 2024-05-12 13:51:05

0001 /* generated by rust_qt_binding_generator */
0002 #include "Bindings.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     inline void todosActiveCountChanged(Todos* o)
0032     {
0033         Q_EMIT o->activeCountChanged();
0034     }
0035     inline void todosCountChanged(Todos* o)
0036     {
0037         Q_EMIT o->countChanged();
0038     }
0039 }
0040 extern "C" {
0041     bool todos_data_completed(const Todos::Private*, int);
0042     bool todos_set_data_completed(Todos::Private*, int, bool);
0043     void todos_data_description(const Todos::Private*, int, QString*, qstring_set);
0044     bool todos_set_data_description(Todos::Private*, int, const ushort* s, int len);
0045     void todos_sort(Todos::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
0046 
0047     int todos_row_count(const Todos::Private*);
0048     bool todos_insert_rows(Todos::Private*, int, int);
0049     bool todos_remove_rows(Todos::Private*, int, int);
0050     bool todos_can_fetch_more(const Todos::Private*);
0051     void todos_fetch_more(Todos::Private*);
0052 }
0053 int Todos::columnCount(const QModelIndex &parent) const
0054 {
0055     return (parent.isValid()) ? 0 : 1;
0056 }
0057 
0058 bool Todos::hasChildren(const QModelIndex &parent) const
0059 {
0060     return rowCount(parent) > 0;
0061 }
0062 
0063 int Todos::rowCount(const QModelIndex &parent) const
0064 {
0065     return (parent.isValid()) ? 0 : todos_row_count(m_d);
0066 }
0067 
0068 bool Todos::insertRows(int row, int count, const QModelIndex &)
0069 {
0070     return todos_insert_rows(m_d, row, count);
0071 }
0072 
0073 bool Todos::removeRows(int row, int count, const QModelIndex &)
0074 {
0075     return todos_remove_rows(m_d, row, count);
0076 }
0077 
0078 QModelIndex Todos::index(int row, int column, const QModelIndex &parent) const
0079 {
0080     if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 1) {
0081         return createIndex(row, column, (quintptr)row);
0082     }
0083     return QModelIndex();
0084 }
0085 
0086 QModelIndex Todos::parent(const QModelIndex &) const
0087 {
0088     return QModelIndex();
0089 }
0090 
0091 bool Todos::canFetchMore(const QModelIndex &parent) const
0092 {
0093     return (parent.isValid()) ? 0 : todos_can_fetch_more(m_d);
0094 }
0095 
0096 void Todos::fetchMore(const QModelIndex &parent)
0097 {
0098     if (!parent.isValid()) {
0099         todos_fetch_more(m_d);
0100     }
0101 }
0102 void Todos::updatePersistentIndexes() {}
0103 
0104 void Todos::sort(int column, Qt::SortOrder order)
0105 {
0106     todos_sort(m_d, column, order);
0107 }
0108 Qt::ItemFlags Todos::flags(const QModelIndex &i) const
0109 {
0110     auto flags = QAbstractItemModel::flags(i);
0111     if (i.column() == 0) {
0112         flags |= Qt::ItemIsEditable;
0113     }
0114     return flags;
0115 }
0116 
0117 bool Todos::completed(int row) const
0118 {
0119     return todos_data_completed(m_d, row);
0120 }
0121 
0122 bool Todos::setCompleted(int row, bool value)
0123 {
0124     bool set = false;
0125     set = todos_set_data_completed(m_d, row, value);
0126     if (set) {
0127         QModelIndex index = createIndex(row, 0, row);
0128         Q_EMIT dataChanged(index, index);
0129     }
0130     return set;
0131 }
0132 
0133 QString Todos::description(int row) const
0134 {
0135     QString s;
0136     todos_data_description(m_d, row, &s, set_qstring);
0137     return s;
0138 }
0139 
0140 bool Todos::setDescription(int row, const QString& value)
0141 {
0142     bool set = false;
0143     set = todos_set_data_description(m_d, row, value.utf16(), value.length());
0144     if (set) {
0145         QModelIndex index = createIndex(row, 0, row);
0146         Q_EMIT dataChanged(index, index);
0147     }
0148     return set;
0149 }
0150 
0151 QVariant Todos::data(const QModelIndex &index, int role) const
0152 {
0153     Q_ASSERT(rowCount(index.parent()) > index.row());
0154     switch (index.column()) {
0155     case 0:
0156         switch (role) {
0157         case Qt::UserRole + 0:
0158             return QVariant::fromValue(completed(index.row()));
0159         case Qt::UserRole + 1:
0160             return QVariant::fromValue(description(index.row()));
0161         }
0162         break;
0163     }
0164     return QVariant();
0165 }
0166 
0167 int Todos::role(const char* name) const {
0168     auto names = roleNames();
0169     auto i = names.constBegin();
0170     while (i != names.constEnd()) {
0171         if (i.value() == name) {
0172             return i.key();
0173         }
0174         ++i;
0175     }
0176     return -1;
0177 }
0178 QHash<int, QByteArray> Todos::roleNames() const {
0179     QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
0180     names.insert(Qt::UserRole + 0, "completed");
0181     names.insert(Qt::UserRole + 1, "description");
0182     return names;
0183 }
0184 QVariant Todos::headerData(int section, Qt::Orientation orientation, int role) const
0185 {
0186     if (orientation != Qt::Horizontal) {
0187         return QVariant();
0188     }
0189     return m_headerData.value(qMakePair(section, (Qt::ItemDataRole)role), role == Qt::DisplayRole ?QString::number(section + 1) :QVariant());
0190 }
0191 
0192 bool Todos::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
0193 {
0194     if (orientation != Qt::Horizontal) {
0195         return false;
0196     }
0197     m_headerData.insert(qMakePair(section, (Qt::ItemDataRole)role), value);
0198     return true;
0199 }
0200 
0201 bool Todos::setData(const QModelIndex &index, const QVariant &value, int role)
0202 {
0203     if (index.column() == 0) {
0204         if (role == Qt::UserRole + 0) {
0205             if (value.canConvert(qMetaTypeId<bool>())) {
0206                 return setCompleted(index.row(), value.value<bool>());
0207             }
0208         }
0209         if (role == Qt::UserRole + 1) {
0210             if (value.canConvert(qMetaTypeId<QString>())) {
0211                 return setDescription(index.row(), value.value<QString>());
0212             }
0213         }
0214     }
0215     return false;
0216 }
0217 
0218 extern "C" {
0219     Todos::Private* todos_new(Todos*, void (*)(Todos*), void (*)(Todos*),
0220         void (*)(const Todos*),
0221         void (*)(Todos*),
0222         void (*)(Todos*),
0223         void (*)(Todos*, quintptr, quintptr),
0224         void (*)(Todos*),
0225         void (*)(Todos*),
0226         void (*)(Todos*, int, int),
0227         void (*)(Todos*),
0228         void (*)(Todos*, int, int, int),
0229         void (*)(Todos*),
0230         void (*)(Todos*, int, int),
0231         void (*)(Todos*));
0232     void todos_free(Todos::Private*);
0233     quint64 todos_active_count_get(const Todos::Private*);
0234     quint64 todos_count_get(const Todos::Private*);
0235     void todos_add(Todos::Private*, const ushort*, int);
0236     void todos_clear_completed(Todos::Private*);
0237     bool todos_remove(Todos::Private*, quint64);
0238     void todos_set_all(Todos::Private*, bool);
0239 };
0240 
0241 Todos::Todos(bool /*owned*/, QObject *parent):
0242     QAbstractItemModel(parent),
0243     m_d(nullptr),
0244     m_ownsPrivate(false)
0245 {
0246     initHeaderData();
0247 }
0248 
0249 Todos::Todos(QObject *parent):
0250     QAbstractItemModel(parent),
0251     m_d(todos_new(this,
0252         todosActiveCountChanged,
0253         todosCountChanged,
0254         [](const Todos* o) {
0255             Q_EMIT o->newDataReady(QModelIndex());
0256         },
0257         [](Todos* o) {
0258             Q_EMIT o->layoutAboutToBeChanged();
0259         },
0260         [](Todos* o) {
0261             o->updatePersistentIndexes();
0262             Q_EMIT o->layoutChanged();
0263         },
0264         [](Todos* o, quintptr first, quintptr last) {
0265             o->dataChanged(o->createIndex(first, 0, first),
0266                        o->createIndex(last, 0, last));
0267         },
0268         [](Todos* o) {
0269             o->beginResetModel();
0270         },
0271         [](Todos* o) {
0272             o->endResetModel();
0273         },
0274         [](Todos* o, int first, int last) {
0275             o->beginInsertRows(QModelIndex(), first, last);
0276         },
0277         [](Todos* o) {
0278             o->endInsertRows();
0279         },
0280         [](Todos* o, int first, int last, int destination) {
0281             o->beginMoveRows(QModelIndex(), first, last, QModelIndex(), destination);
0282         },
0283         [](Todos* o) {
0284             o->endMoveRows();
0285         },
0286         [](Todos* o, int first, int last) {
0287             o->beginRemoveRows(QModelIndex(), first, last);
0288         },
0289         [](Todos* o) {
0290             o->endRemoveRows();
0291         }
0292 )),
0293     m_ownsPrivate(true)
0294 {
0295     connect(this, &Todos::newDataReady, this, [this](const QModelIndex& i) {
0296         this->fetchMore(i);
0297     }, Qt::QueuedConnection);
0298     initHeaderData();
0299 }
0300 
0301 Todos::~Todos() {
0302     if (m_ownsPrivate) {
0303         todos_free(m_d);
0304     }
0305 }
0306 void Todos::initHeaderData() {
0307 }
0308 quint64 Todos::activeCount() const
0309 {
0310     return todos_active_count_get(m_d);
0311 }
0312 quint64 Todos::count() const
0313 {
0314     return todos_count_get(m_d);
0315 }
0316 void Todos::add(const QString& description)
0317 {
0318     return todos_add(m_d, description.utf16(), description.size());
0319 }
0320 void Todos::clearCompleted()
0321 {
0322     return todos_clear_completed(m_d);
0323 }
0324 bool Todos::remove(quint64 index)
0325 {
0326     return todos_remove(m_d, index);
0327 }
0328 void Todos::setAll(bool completed)
0329 {
0330     return todos_set_all(m_d, completed);
0331 }