File indexing completed on 2024-03-24 17:21:48

0001 /* generated by rust_qt_binding_generator */
0002 #include "Bindings.h"
0003 
0004 namespace {
0005 
0006     struct option_quint64 {
0007     public:
0008         quint64 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_quint64>::value, "option_quint64 must be a POD type.");
0018 
0019     struct option_quintptr {
0020     public:
0021         quintptr value;
0022         bool some;
0023         operator QVariant() const {
0024             if (some) {
0025                 return QVariant::fromValue(value);
0026             }
0027             return QVariant();
0028         }
0029     };
0030     static_assert(std::is_pod<option_quintptr>::value, "option_quintptr must be a POD type.");
0031 
0032     typedef void (*qstring_set)(QString* val, const char* utf8, int nbytes);
0033     void set_qstring(QString* val, const char* utf8, int nbytes) {
0034         *val = QString::fromUtf8(utf8, nbytes);
0035     }
0036 
0037     typedef void (*qbytearray_set)(QByteArray* val, const char* bytes, int nbytes);
0038     void set_qbytearray(QByteArray* v, const char* bytes, int nbytes) {
0039         if (v->isNull() && nbytes == 0) {
0040             *v = QByteArray(bytes, nbytes);
0041         } else {
0042             v->truncate(0);
0043             v->append(bytes, nbytes);
0044         }
0045     }
0046 
0047     struct qmodelindex_t {
0048         int row;
0049         quintptr id;
0050     };
0051     inline QVariant cleanNullQVariant(const QVariant& v) {
0052         return (v.isNull()) ?QVariant() :v;
0053     }
0054     inline void fibonacciInputChanged(Fibonacci* o)
0055     {
0056         Q_EMIT o->inputChanged();
0057     }
0058     inline void fibonacciResultChanged(Fibonacci* o)
0059     {
0060         Q_EMIT o->resultChanged();
0061     }
0062     inline void fileSystemTreePathChanged(FileSystemTree* o)
0063     {
0064         Q_EMIT o->pathChanged();
0065     }
0066     inline void processesActiveChanged(Processes* o)
0067     {
0068         Q_EMIT o->activeChanged();
0069     }
0070 }
0071 extern "C" {
0072     Demo::Private* demo_new(Demo*, Fibonacci*, void (*)(Fibonacci*), void (*)(Fibonacci*), FibonacciList*,
0073         void (*)(const FibonacciList*),
0074         void (*)(FibonacciList*),
0075         void (*)(FibonacciList*),
0076         void (*)(FibonacciList*, quintptr, quintptr),
0077         void (*)(FibonacciList*),
0078         void (*)(FibonacciList*),
0079         void (*)(FibonacciList*, int, int),
0080         void (*)(FibonacciList*),
0081         void (*)(FibonacciList*, int, int, int),
0082         void (*)(FibonacciList*),
0083         void (*)(FibonacciList*, int, int),
0084         void (*)(FibonacciList*), FileSystemTree*, void (*)(FileSystemTree*),
0085         void (*)(const FileSystemTree*, option_quintptr),
0086         void (*)(FileSystemTree*),
0087         void (*)(FileSystemTree*),
0088         void (*)(FileSystemTree*, quintptr, quintptr),
0089         void (*)(FileSystemTree*),
0090         void (*)(FileSystemTree*),
0091         void (*)(FileSystemTree*, option_quintptr, int, int),
0092         void (*)(FileSystemTree*),
0093         void (*)(FileSystemTree*, option_quintptr, int, int, option_quintptr, int),
0094         void (*)(FileSystemTree*),
0095         void (*)(FileSystemTree*, option_quintptr, int, int),
0096         void (*)(FileSystemTree*), Processes*, void (*)(Processes*),
0097         void (*)(const Processes*, option_quintptr),
0098         void (*)(Processes*),
0099         void (*)(Processes*),
0100         void (*)(Processes*, quintptr, quintptr),
0101         void (*)(Processes*),
0102         void (*)(Processes*),
0103         void (*)(Processes*, option_quintptr, int, int),
0104         void (*)(Processes*),
0105         void (*)(Processes*, option_quintptr, int, int, option_quintptr, int),
0106         void (*)(Processes*),
0107         void (*)(Processes*, option_quintptr, int, int),
0108         void (*)(Processes*), TimeSeries*,
0109         void (*)(const TimeSeries*),
0110         void (*)(TimeSeries*),
0111         void (*)(TimeSeries*),
0112         void (*)(TimeSeries*, quintptr, quintptr),
0113         void (*)(TimeSeries*),
0114         void (*)(TimeSeries*),
0115         void (*)(TimeSeries*, int, int),
0116         void (*)(TimeSeries*),
0117         void (*)(TimeSeries*, int, int, int),
0118         void (*)(TimeSeries*),
0119         void (*)(TimeSeries*, int, int),
0120         void (*)(TimeSeries*));
0121     void demo_free(Demo::Private*);
0122     Fibonacci::Private* demo_fibonacci_get(const Demo::Private*);
0123     FibonacciList::Private* demo_fibonacci_list_get(const Demo::Private*);
0124     FileSystemTree::Private* demo_file_system_tree_get(const Demo::Private*);
0125     Processes::Private* demo_processes_get(const Demo::Private*);
0126     TimeSeries::Private* demo_time_series_get(const Demo::Private*);
0127 };
0128 
0129 extern "C" {
0130     Fibonacci::Private* fibonacci_new(Fibonacci*, void (*)(Fibonacci*), void (*)(Fibonacci*));
0131     void fibonacci_free(Fibonacci::Private*);
0132     quint32 fibonacci_input_get(const Fibonacci::Private*);
0133     void fibonacci_input_set(Fibonacci::Private*, quint32);
0134     quint64 fibonacci_result_get(const Fibonacci::Private*);
0135 };
0136 
0137 extern "C" {
0138     quint64 fibonacci_list_data_fibonacci_number(const FibonacciList::Private*, int);
0139     quint64 fibonacci_list_data_row(const FibonacciList::Private*, int);
0140     void fibonacci_list_sort(FibonacciList::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
0141 
0142     int fibonacci_list_row_count(const FibonacciList::Private*);
0143     bool fibonacci_list_insert_rows(FibonacciList::Private*, int, int);
0144     bool fibonacci_list_remove_rows(FibonacciList::Private*, int, int);
0145     bool fibonacci_list_can_fetch_more(const FibonacciList::Private*);
0146     void fibonacci_list_fetch_more(FibonacciList::Private*);
0147 }
0148 int FibonacciList::columnCount(const QModelIndex &parent) const
0149 {
0150     return (parent.isValid()) ? 0 : 2;
0151 }
0152 
0153 bool FibonacciList::hasChildren(const QModelIndex &parent) const
0154 {
0155     return rowCount(parent) > 0;
0156 }
0157 
0158 int FibonacciList::rowCount(const QModelIndex &parent) const
0159 {
0160     return (parent.isValid()) ? 0 : fibonacci_list_row_count(m_d);
0161 }
0162 
0163 bool FibonacciList::insertRows(int row, int count, const QModelIndex &)
0164 {
0165     return fibonacci_list_insert_rows(m_d, row, count);
0166 }
0167 
0168 bool FibonacciList::removeRows(int row, int count, const QModelIndex &)
0169 {
0170     return fibonacci_list_remove_rows(m_d, row, count);
0171 }
0172 
0173 QModelIndex FibonacciList::index(int row, int column, const QModelIndex &parent) const
0174 {
0175     if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 2) {
0176         return createIndex(row, column, (quintptr)row);
0177     }
0178     return QModelIndex();
0179 }
0180 
0181 QModelIndex FibonacciList::parent(const QModelIndex &) const
0182 {
0183     return QModelIndex();
0184 }
0185 
0186 bool FibonacciList::canFetchMore(const QModelIndex &parent) const
0187 {
0188     return (parent.isValid()) ? 0 : fibonacci_list_can_fetch_more(m_d);
0189 }
0190 
0191 void FibonacciList::fetchMore(const QModelIndex &parent)
0192 {
0193     if (!parent.isValid()) {
0194         fibonacci_list_fetch_more(m_d);
0195     }
0196 }
0197 void FibonacciList::updatePersistentIndexes() {}
0198 
0199 void FibonacciList::sort(int column, Qt::SortOrder order)
0200 {
0201     fibonacci_list_sort(m_d, column, order);
0202 }
0203 Qt::ItemFlags FibonacciList::flags(const QModelIndex &i) const
0204 {
0205     auto flags = QAbstractItemModel::flags(i);
0206     return flags;
0207 }
0208 
0209 quint64 FibonacciList::fibonacciNumber(int row) const
0210 {
0211     return fibonacci_list_data_fibonacci_number(m_d, row);
0212 }
0213 
0214 quint64 FibonacciList::row(int row) const
0215 {
0216     return fibonacci_list_data_row(m_d, row);
0217 }
0218 
0219 QVariant FibonacciList::data(const QModelIndex &index, int role) const
0220 {
0221     Q_ASSERT(rowCount(index.parent()) > index.row());
0222     switch (index.column()) {
0223     case 0:
0224         switch (role) {
0225         case Qt::UserRole + 0:
0226             return QVariant::fromValue(fibonacciNumber(index.row()));
0227         case Qt::DisplayRole:
0228         case Qt::UserRole + 1:
0229             return QVariant::fromValue(row(index.row()));
0230         }
0231         break;
0232     case 1:
0233         switch (role) {
0234         case Qt::DisplayRole:
0235         case Qt::UserRole + 0:
0236             return QVariant::fromValue(fibonacciNumber(index.row()));
0237         }
0238         break;
0239     }
0240     return QVariant();
0241 }
0242 
0243 int FibonacciList::role(const char* name) const {
0244     auto names = roleNames();
0245     auto i = names.constBegin();
0246     while (i != names.constEnd()) {
0247         if (i.value() == name) {
0248             return i.key();
0249         }
0250         ++i;
0251     }
0252     return -1;
0253 }
0254 QHash<int, QByteArray> FibonacciList::roleNames() const {
0255     QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
0256     names.insert(Qt::UserRole + 0, "fibonacciNumber");
0257     names.insert(Qt::UserRole + 1, "row");
0258     return names;
0259 }
0260 QVariant FibonacciList::headerData(int section, Qt::Orientation orientation, int role) const
0261 {
0262     if (orientation != Qt::Horizontal) {
0263         return QVariant();
0264     }
0265     return m_headerData.value(qMakePair(section, (Qt::ItemDataRole)role), role == Qt::DisplayRole ?QString::number(section + 1) :QVariant());
0266 }
0267 
0268 bool FibonacciList::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
0269 {
0270     if (orientation != Qt::Horizontal) {
0271         return false;
0272     }
0273     m_headerData.insert(qMakePair(section, (Qt::ItemDataRole)role), value);
0274     return true;
0275 }
0276 
0277 extern "C" {
0278     FibonacciList::Private* fibonacci_list_new(FibonacciList*,
0279         void (*)(const FibonacciList*),
0280         void (*)(FibonacciList*),
0281         void (*)(FibonacciList*),
0282         void (*)(FibonacciList*, quintptr, quintptr),
0283         void (*)(FibonacciList*),
0284         void (*)(FibonacciList*),
0285         void (*)(FibonacciList*, int, int),
0286         void (*)(FibonacciList*),
0287         void (*)(FibonacciList*, int, int, int),
0288         void (*)(FibonacciList*),
0289         void (*)(FibonacciList*, int, int),
0290         void (*)(FibonacciList*));
0291     void fibonacci_list_free(FibonacciList::Private*);
0292 };
0293 
0294 extern "C" {
0295     void file_system_tree_data_file_icon(const FileSystemTree::Private*, quintptr, QByteArray*, qbytearray_set);
0296     void file_system_tree_data_file_name(const FileSystemTree::Private*, quintptr, QString*, qstring_set);
0297     void file_system_tree_data_file_path(const FileSystemTree::Private*, quintptr, QString*, qstring_set);
0298     qint32 file_system_tree_data_file_permissions(const FileSystemTree::Private*, quintptr);
0299     option_quint64 file_system_tree_data_file_size(const FileSystemTree::Private*, quintptr);
0300     qint32 file_system_tree_data_file_type(const FileSystemTree::Private*, quintptr);
0301     void file_system_tree_sort(FileSystemTree::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
0302 
0303     int file_system_tree_row_count(const FileSystemTree::Private*, option_quintptr);
0304     bool file_system_tree_can_fetch_more(const FileSystemTree::Private*, option_quintptr);
0305     void file_system_tree_fetch_more(FileSystemTree::Private*, option_quintptr);
0306     quintptr file_system_tree_index(const FileSystemTree::Private*, option_quintptr, int);
0307     qmodelindex_t file_system_tree_parent(const FileSystemTree::Private*, quintptr);
0308     int file_system_tree_row(const FileSystemTree::Private*, quintptr);
0309     option_quintptr file_system_tree_check_row(const FileSystemTree::Private*, quintptr, int);
0310 }
0311 int FileSystemTree::columnCount(const QModelIndex &) const
0312 {
0313     return 5;
0314 }
0315 
0316 bool FileSystemTree::hasChildren(const QModelIndex &parent) const
0317 {
0318     return rowCount(parent) > 0;
0319 }
0320 
0321 int FileSystemTree::rowCount(const QModelIndex &parent) const
0322 {
0323     if (parent.isValid() && parent.column() != 0) {
0324         return 0;
0325     }
0326     const option_quintptr rust_parent = {
0327         parent.internalId(),
0328         parent.isValid()
0329     };
0330     return file_system_tree_row_count(m_d, rust_parent);
0331 }
0332 
0333 bool FileSystemTree::insertRows(int, int, const QModelIndex &)
0334 {
0335     return false; // not supported yet
0336 }
0337 
0338 bool FileSystemTree::removeRows(int, int, const QModelIndex &)
0339 {
0340     return false; // not supported yet
0341 }
0342 
0343 QModelIndex FileSystemTree::index(int row, int column, const QModelIndex &parent) const
0344 {
0345     if (row < 0 || column < 0 || column >= 5) {
0346         return QModelIndex();
0347     }
0348     if (parent.isValid() && parent.column() != 0) {
0349         return QModelIndex();
0350     }
0351     if (row >= rowCount(parent)) {
0352         return QModelIndex();
0353     }
0354     const option_quintptr rust_parent = {
0355         parent.internalId(),
0356         parent.isValid()
0357     };
0358     const quintptr id = file_system_tree_index(m_d, rust_parent, row);
0359     return createIndex(row, column, id);
0360 }
0361 
0362 QModelIndex FileSystemTree::parent(const QModelIndex &index) const
0363 {
0364     if (!index.isValid()) {
0365         return QModelIndex();
0366     }
0367     const qmodelindex_t parent = file_system_tree_parent(m_d, index.internalId());
0368     return parent.row >= 0 ?createIndex(parent.row, 0, parent.id) :QModelIndex();
0369 }
0370 
0371 bool FileSystemTree::canFetchMore(const QModelIndex &parent) const
0372 {
0373     if (parent.isValid() && parent.column() != 0) {
0374         return false;
0375     }
0376     const option_quintptr rust_parent = {
0377         parent.internalId(),
0378         parent.isValid()
0379     };
0380     return file_system_tree_can_fetch_more(m_d, rust_parent);
0381 }
0382 
0383 void FileSystemTree::fetchMore(const QModelIndex &parent)
0384 {
0385     const option_quintptr rust_parent = {
0386         parent.internalId(),
0387         parent.isValid()
0388     };
0389     file_system_tree_fetch_more(m_d, rust_parent);
0390 }
0391 void FileSystemTree::updatePersistentIndexes() {
0392     const auto from = persistentIndexList();
0393     auto to = from;
0394     auto len = to.size();
0395     for (int i = 0; i < len; ++i) {
0396         auto index = to.at(i);
0397         auto row = file_system_tree_check_row(m_d, index.internalId(), index.row());
0398         if (row.some) {
0399             to[i] = createIndex(row.value, index.column(), index.internalId());
0400         } else {
0401             to[i] = QModelIndex();
0402         }
0403     }
0404     changePersistentIndexList(from, to);
0405 }
0406 
0407 void FileSystemTree::sort(int column, Qt::SortOrder order)
0408 {
0409     file_system_tree_sort(m_d, column, order);
0410 }
0411 Qt::ItemFlags FileSystemTree::flags(const QModelIndex &i) const
0412 {
0413     auto flags = QAbstractItemModel::flags(i);
0414     return flags;
0415 }
0416 
0417 QByteArray FileSystemTree::fileIcon(const QModelIndex& index) const
0418 {
0419     QByteArray b;
0420     file_system_tree_data_file_icon(m_d, index.internalId(), &b, set_qbytearray);
0421     return b;
0422 }
0423 
0424 QString FileSystemTree::fileName(const QModelIndex& index) const
0425 {
0426     QString s;
0427     file_system_tree_data_file_name(m_d, index.internalId(), &s, set_qstring);
0428     return s;
0429 }
0430 
0431 QString FileSystemTree::filePath(const QModelIndex& index) const
0432 {
0433     QString s;
0434     file_system_tree_data_file_path(m_d, index.internalId(), &s, set_qstring);
0435     return s;
0436 }
0437 
0438 qint32 FileSystemTree::filePermissions(const QModelIndex& index) const
0439 {
0440     return file_system_tree_data_file_permissions(m_d, index.internalId());
0441 }
0442 
0443 QVariant FileSystemTree::fileSize(const QModelIndex& index) const
0444 {
0445     QVariant v;
0446     v = file_system_tree_data_file_size(m_d, index.internalId());
0447     return v;
0448 }
0449 
0450 qint32 FileSystemTree::fileType(const QModelIndex& index) const
0451 {
0452     return file_system_tree_data_file_type(m_d, index.internalId());
0453 }
0454 
0455 QVariant FileSystemTree::data(const QModelIndex &index, int role) const
0456 {
0457     Q_ASSERT(rowCount(index.parent()) > index.row());
0458     switch (index.column()) {
0459     case 0:
0460         switch (role) {
0461         case Qt::DecorationRole:
0462         case Qt::UserRole + 0:
0463             return QVariant::fromValue(fileIcon(index));
0464         case Qt::DisplayRole:
0465         case Qt::UserRole + 1:
0466             return QVariant::fromValue(fileName(index));
0467         case Qt::UserRole + 2:
0468             return cleanNullQVariant(QVariant::fromValue(filePath(index)));
0469         case Qt::UserRole + 3:
0470             return QVariant::fromValue(filePermissions(index));
0471         case Qt::UserRole + 4:
0472             return fileSize(index);
0473         case Qt::UserRole + 5:
0474             return QVariant::fromValue(fileType(index));
0475         }
0476         break;
0477     case 1:
0478         switch (role) {
0479         case Qt::DisplayRole:
0480         case Qt::UserRole + 4:
0481             return fileSize(index);
0482         }
0483         break;
0484     case 2:
0485         switch (role) {
0486         case Qt::DisplayRole:
0487         case Qt::UserRole + 2:
0488             return cleanNullQVariant(QVariant::fromValue(filePath(index)));
0489         }
0490         break;
0491     case 3:
0492         switch (role) {
0493         case Qt::DisplayRole:
0494         case Qt::UserRole + 3:
0495             return QVariant::fromValue(filePermissions(index));
0496         }
0497         break;
0498     case 4:
0499         switch (role) {
0500         case Qt::DisplayRole:
0501         case Qt::UserRole + 5:
0502             return QVariant::fromValue(fileType(index));
0503         }
0504         break;
0505     }
0506     return QVariant();
0507 }
0508 
0509 int FileSystemTree::role(const char* name) const {
0510     auto names = roleNames();
0511     auto i = names.constBegin();
0512     while (i != names.constEnd()) {
0513         if (i.value() == name) {
0514             return i.key();
0515         }
0516         ++i;
0517     }
0518     return -1;
0519 }
0520 QHash<int, QByteArray> FileSystemTree::roleNames() const {
0521     QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
0522     names.insert(Qt::UserRole + 0, "fileIcon");
0523     names.insert(Qt::UserRole + 1, "fileName");
0524     names.insert(Qt::UserRole + 2, "filePath");
0525     names.insert(Qt::UserRole + 3, "filePermissions");
0526     names.insert(Qt::UserRole + 4, "fileSize");
0527     names.insert(Qt::UserRole + 5, "fileType");
0528     return names;
0529 }
0530 QVariant FileSystemTree::headerData(int section, Qt::Orientation orientation, int role) const
0531 {
0532     if (orientation != Qt::Horizontal) {
0533         return QVariant();
0534     }
0535     return m_headerData.value(qMakePair(section, (Qt::ItemDataRole)role), role == Qt::DisplayRole ?QString::number(section + 1) :QVariant());
0536 }
0537 
0538 bool FileSystemTree::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
0539 {
0540     if (orientation != Qt::Horizontal) {
0541         return false;
0542     }
0543     m_headerData.insert(qMakePair(section, (Qt::ItemDataRole)role), value);
0544     return true;
0545 }
0546 
0547 extern "C" {
0548     FileSystemTree::Private* file_system_tree_new(FileSystemTree*, void (*)(FileSystemTree*),
0549         void (*)(const FileSystemTree*, option_quintptr),
0550         void (*)(FileSystemTree*),
0551         void (*)(FileSystemTree*),
0552         void (*)(FileSystemTree*, quintptr, quintptr),
0553         void (*)(FileSystemTree*),
0554         void (*)(FileSystemTree*),
0555         void (*)(FileSystemTree*, option_quintptr, int, int),
0556         void (*)(FileSystemTree*),
0557         void (*)(FileSystemTree*, option_quintptr, int, int, option_quintptr, int),
0558         void (*)(FileSystemTree*),
0559         void (*)(FileSystemTree*, option_quintptr, int, int),
0560         void (*)(FileSystemTree*));
0561     void file_system_tree_free(FileSystemTree::Private*);
0562     void file_system_tree_path_get(const FileSystemTree::Private*, QString*, qstring_set);
0563     void file_system_tree_path_set(FileSystemTree::Private*, const ushort *str, int len);
0564     void file_system_tree_path_set_none(FileSystemTree::Private*);
0565 };
0566 
0567 extern "C" {
0568     void processes_data_cmd(const Processes::Private*, quintptr, QString*, qstring_set);
0569     quint8 processes_data_cpu_percentage(const Processes::Private*, quintptr);
0570     float processes_data_cpu_usage(const Processes::Private*, quintptr);
0571     quint64 processes_data_memory(const Processes::Private*, quintptr);
0572     void processes_data_name(const Processes::Private*, quintptr, QString*, qstring_set);
0573     quint32 processes_data_pid(const Processes::Private*, quintptr);
0574     quint32 processes_data_uid(const Processes::Private*, quintptr);
0575     void processes_sort(Processes::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
0576 
0577     int processes_row_count(const Processes::Private*, option_quintptr);
0578     bool processes_can_fetch_more(const Processes::Private*, option_quintptr);
0579     void processes_fetch_more(Processes::Private*, option_quintptr);
0580     quintptr processes_index(const Processes::Private*, option_quintptr, int);
0581     qmodelindex_t processes_parent(const Processes::Private*, quintptr);
0582     int processes_row(const Processes::Private*, quintptr);
0583     option_quintptr processes_check_row(const Processes::Private*, quintptr, int);
0584 }
0585 int Processes::columnCount(const QModelIndex &) const
0586 {
0587     return 3;
0588 }
0589 
0590 bool Processes::hasChildren(const QModelIndex &parent) const
0591 {
0592     return rowCount(parent) > 0;
0593 }
0594 
0595 int Processes::rowCount(const QModelIndex &parent) const
0596 {
0597     if (parent.isValid() && parent.column() != 0) {
0598         return 0;
0599     }
0600     const option_quintptr rust_parent = {
0601         parent.internalId(),
0602         parent.isValid()
0603     };
0604     return processes_row_count(m_d, rust_parent);
0605 }
0606 
0607 bool Processes::insertRows(int, int, const QModelIndex &)
0608 {
0609     return false; // not supported yet
0610 }
0611 
0612 bool Processes::removeRows(int, int, const QModelIndex &)
0613 {
0614     return false; // not supported yet
0615 }
0616 
0617 QModelIndex Processes::index(int row, int column, const QModelIndex &parent) const
0618 {
0619     if (row < 0 || column < 0 || column >= 3) {
0620         return QModelIndex();
0621     }
0622     if (parent.isValid() && parent.column() != 0) {
0623         return QModelIndex();
0624     }
0625     if (row >= rowCount(parent)) {
0626         return QModelIndex();
0627     }
0628     const option_quintptr rust_parent = {
0629         parent.internalId(),
0630         parent.isValid()
0631     };
0632     const quintptr id = processes_index(m_d, rust_parent, row);
0633     return createIndex(row, column, id);
0634 }
0635 
0636 QModelIndex Processes::parent(const QModelIndex &index) const
0637 {
0638     if (!index.isValid()) {
0639         return QModelIndex();
0640     }
0641     const qmodelindex_t parent = processes_parent(m_d, index.internalId());
0642     return parent.row >= 0 ?createIndex(parent.row, 0, parent.id) :QModelIndex();
0643 }
0644 
0645 bool Processes::canFetchMore(const QModelIndex &parent) const
0646 {
0647     if (parent.isValid() && parent.column() != 0) {
0648         return false;
0649     }
0650     const option_quintptr rust_parent = {
0651         parent.internalId(),
0652         parent.isValid()
0653     };
0654     return processes_can_fetch_more(m_d, rust_parent);
0655 }
0656 
0657 void Processes::fetchMore(const QModelIndex &parent)
0658 {
0659     const option_quintptr rust_parent = {
0660         parent.internalId(),
0661         parent.isValid()
0662     };
0663     processes_fetch_more(m_d, rust_parent);
0664 }
0665 void Processes::updatePersistentIndexes() {
0666     const auto from = persistentIndexList();
0667     auto to = from;
0668     auto len = to.size();
0669     for (int i = 0; i < len; ++i) {
0670         auto index = to.at(i);
0671         auto row = processes_check_row(m_d, index.internalId(), index.row());
0672         if (row.some) {
0673             to[i] = createIndex(row.value, index.column(), index.internalId());
0674         } else {
0675             to[i] = QModelIndex();
0676         }
0677     }
0678     changePersistentIndexList(from, to);
0679 }
0680 
0681 void Processes::sort(int column, Qt::SortOrder order)
0682 {
0683     processes_sort(m_d, column, order);
0684 }
0685 Qt::ItemFlags Processes::flags(const QModelIndex &i) const
0686 {
0687     auto flags = QAbstractItemModel::flags(i);
0688     return flags;
0689 }
0690 
0691 QString Processes::cmd(const QModelIndex& index) const
0692 {
0693     QString s;
0694     processes_data_cmd(m_d, index.internalId(), &s, set_qstring);
0695     return s;
0696 }
0697 
0698 quint8 Processes::cpuPercentage(const QModelIndex& index) const
0699 {
0700     return processes_data_cpu_percentage(m_d, index.internalId());
0701 }
0702 
0703 float Processes::cpuUsage(const QModelIndex& index) const
0704 {
0705     return processes_data_cpu_usage(m_d, index.internalId());
0706 }
0707 
0708 quint64 Processes::memory(const QModelIndex& index) const
0709 {
0710     return processes_data_memory(m_d, index.internalId());
0711 }
0712 
0713 QString Processes::name(const QModelIndex& index) const
0714 {
0715     QString s;
0716     processes_data_name(m_d, index.internalId(), &s, set_qstring);
0717     return s;
0718 }
0719 
0720 quint32 Processes::pid(const QModelIndex& index) const
0721 {
0722     return processes_data_pid(m_d, index.internalId());
0723 }
0724 
0725 quint32 Processes::uid(const QModelIndex& index) const
0726 {
0727     return processes_data_uid(m_d, index.internalId());
0728 }
0729 
0730 QVariant Processes::data(const QModelIndex &index, int role) const
0731 {
0732     Q_ASSERT(rowCount(index.parent()) > index.row());
0733     switch (index.column()) {
0734     case 0:
0735         switch (role) {
0736         case Qt::UserRole + 0:
0737             return QVariant::fromValue(cmd(index));
0738         case Qt::UserRole + 1:
0739             return QVariant::fromValue(cpuPercentage(index));
0740         case Qt::UserRole + 2:
0741             return QVariant::fromValue(cpuUsage(index));
0742         case Qt::UserRole + 3:
0743             return QVariant::fromValue(memory(index));
0744         case Qt::DisplayRole:
0745         case Qt::UserRole + 4:
0746             return QVariant::fromValue(name(index));
0747         case Qt::ToolTipRole:
0748         case Qt::UserRole + 5:
0749             return QVariant::fromValue(pid(index));
0750         case Qt::UserRole + 6:
0751             return QVariant::fromValue(uid(index));
0752         }
0753         break;
0754     case 1:
0755         switch (role) {
0756         case Qt::DisplayRole:
0757         case Qt::UserRole + 2:
0758             return QVariant::fromValue(cpuUsage(index));
0759         }
0760         break;
0761     case 2:
0762         switch (role) {
0763         case Qt::DisplayRole:
0764         case Qt::UserRole + 3:
0765             return QVariant::fromValue(memory(index));
0766         }
0767         break;
0768     }
0769     return QVariant();
0770 }
0771 
0772 int Processes::role(const char* name) const {
0773     auto names = roleNames();
0774     auto i = names.constBegin();
0775     while (i != names.constEnd()) {
0776         if (i.value() == name) {
0777             return i.key();
0778         }
0779         ++i;
0780     }
0781     return -1;
0782 }
0783 QHash<int, QByteArray> Processes::roleNames() const {
0784     QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
0785     names.insert(Qt::UserRole + 0, "cmd");
0786     names.insert(Qt::UserRole + 1, "cpuPercentage");
0787     names.insert(Qt::UserRole + 2, "cpuUsage");
0788     names.insert(Qt::UserRole + 3, "memory");
0789     names.insert(Qt::UserRole + 4, "name");
0790     names.insert(Qt::UserRole + 5, "pid");
0791     names.insert(Qt::UserRole + 6, "uid");
0792     return names;
0793 }
0794 QVariant Processes::headerData(int section, Qt::Orientation orientation, int role) const
0795 {
0796     if (orientation != Qt::Horizontal) {
0797         return QVariant();
0798     }
0799     return m_headerData.value(qMakePair(section, (Qt::ItemDataRole)role), role == Qt::DisplayRole ?QString::number(section + 1) :QVariant());
0800 }
0801 
0802 bool Processes::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
0803 {
0804     if (orientation != Qt::Horizontal) {
0805         return false;
0806     }
0807     m_headerData.insert(qMakePair(section, (Qt::ItemDataRole)role), value);
0808     return true;
0809 }
0810 
0811 extern "C" {
0812     Processes::Private* processes_new(Processes*, void (*)(Processes*),
0813         void (*)(const Processes*, option_quintptr),
0814         void (*)(Processes*),
0815         void (*)(Processes*),
0816         void (*)(Processes*, quintptr, quintptr),
0817         void (*)(Processes*),
0818         void (*)(Processes*),
0819         void (*)(Processes*, option_quintptr, int, int),
0820         void (*)(Processes*),
0821         void (*)(Processes*, option_quintptr, int, int, option_quintptr, int),
0822         void (*)(Processes*),
0823         void (*)(Processes*, option_quintptr, int, int),
0824         void (*)(Processes*));
0825     void processes_free(Processes::Private*);
0826     bool processes_active_get(const Processes::Private*);
0827     void processes_active_set(Processes::Private*, bool);
0828 };
0829 
0830 extern "C" {
0831     float time_series_data_cos(const TimeSeries::Private*, int);
0832     bool time_series_set_data_cos(TimeSeries::Private*, int, float);
0833     float time_series_data_sin(const TimeSeries::Private*, int);
0834     bool time_series_set_data_sin(TimeSeries::Private*, int, float);
0835     float time_series_data_time(const TimeSeries::Private*, int);
0836     bool time_series_set_data_time(TimeSeries::Private*, int, float);
0837     void time_series_sort(TimeSeries::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
0838 
0839     int time_series_row_count(const TimeSeries::Private*);
0840     bool time_series_insert_rows(TimeSeries::Private*, int, int);
0841     bool time_series_remove_rows(TimeSeries::Private*, int, int);
0842     bool time_series_can_fetch_more(const TimeSeries::Private*);
0843     void time_series_fetch_more(TimeSeries::Private*);
0844 }
0845 int TimeSeries::columnCount(const QModelIndex &parent) const
0846 {
0847     return (parent.isValid()) ? 0 : 3;
0848 }
0849 
0850 bool TimeSeries::hasChildren(const QModelIndex &parent) const
0851 {
0852     return rowCount(parent) > 0;
0853 }
0854 
0855 int TimeSeries::rowCount(const QModelIndex &parent) const
0856 {
0857     return (parent.isValid()) ? 0 : time_series_row_count(m_d);
0858 }
0859 
0860 bool TimeSeries::insertRows(int row, int count, const QModelIndex &)
0861 {
0862     return time_series_insert_rows(m_d, row, count);
0863 }
0864 
0865 bool TimeSeries::removeRows(int row, int count, const QModelIndex &)
0866 {
0867     return time_series_remove_rows(m_d, row, count);
0868 }
0869 
0870 QModelIndex TimeSeries::index(int row, int column, const QModelIndex &parent) const
0871 {
0872     if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 3) {
0873         return createIndex(row, column, (quintptr)row);
0874     }
0875     return QModelIndex();
0876 }
0877 
0878 QModelIndex TimeSeries::parent(const QModelIndex &) const
0879 {
0880     return QModelIndex();
0881 }
0882 
0883 bool TimeSeries::canFetchMore(const QModelIndex &parent) const
0884 {
0885     return (parent.isValid()) ? 0 : time_series_can_fetch_more(m_d);
0886 }
0887 
0888 void TimeSeries::fetchMore(const QModelIndex &parent)
0889 {
0890     if (!parent.isValid()) {
0891         time_series_fetch_more(m_d);
0892     }
0893 }
0894 void TimeSeries::updatePersistentIndexes() {}
0895 
0896 void TimeSeries::sort(int column, Qt::SortOrder order)
0897 {
0898     time_series_sort(m_d, column, order);
0899 }
0900 Qt::ItemFlags TimeSeries::flags(const QModelIndex &i) const
0901 {
0902     auto flags = QAbstractItemModel::flags(i);
0903     if (i.column() == 0) {
0904         flags |= Qt::ItemIsEditable;
0905     }
0906     if (i.column() == 1) {
0907         flags |= Qt::ItemIsEditable;
0908     }
0909     if (i.column() == 2) {
0910         flags |= Qt::ItemIsEditable;
0911     }
0912     return flags;
0913 }
0914 
0915 float TimeSeries::cos(int row) const
0916 {
0917     return time_series_data_cos(m_d, row);
0918 }
0919 
0920 bool TimeSeries::setCos(int row, float value)
0921 {
0922     bool set = false;
0923     set = time_series_set_data_cos(m_d, row, value);
0924     if (set) {
0925         QModelIndex index = createIndex(row, 0, row);
0926         Q_EMIT dataChanged(index, index);
0927     }
0928     return set;
0929 }
0930 
0931 float TimeSeries::sin(int row) const
0932 {
0933     return time_series_data_sin(m_d, row);
0934 }
0935 
0936 bool TimeSeries::setSin(int row, float value)
0937 {
0938     bool set = false;
0939     set = time_series_set_data_sin(m_d, row, value);
0940     if (set) {
0941         QModelIndex index = createIndex(row, 0, row);
0942         Q_EMIT dataChanged(index, index);
0943     }
0944     return set;
0945 }
0946 
0947 float TimeSeries::time(int row) const
0948 {
0949     return time_series_data_time(m_d, row);
0950 }
0951 
0952 bool TimeSeries::setTime(int row, float value)
0953 {
0954     bool set = false;
0955     set = time_series_set_data_time(m_d, row, value);
0956     if (set) {
0957         QModelIndex index = createIndex(row, 0, row);
0958         Q_EMIT dataChanged(index, index);
0959     }
0960     return set;
0961 }
0962 
0963 QVariant TimeSeries::data(const QModelIndex &index, int role) const
0964 {
0965     Q_ASSERT(rowCount(index.parent()) > index.row());
0966     switch (index.column()) {
0967     case 0:
0968         switch (role) {
0969         case Qt::UserRole + 0:
0970             return QVariant::fromValue(cos(index.row()));
0971         case Qt::UserRole + 1:
0972             return QVariant::fromValue(sin(index.row()));
0973         case Qt::DisplayRole:
0974         case Qt::EditRole:
0975         case Qt::UserRole + 2:
0976             return QVariant::fromValue(time(index.row()));
0977         }
0978         break;
0979     case 1:
0980         switch (role) {
0981         case Qt::DisplayRole:
0982         case Qt::EditRole:
0983         case Qt::UserRole + 1:
0984             return QVariant::fromValue(sin(index.row()));
0985         }
0986         break;
0987     case 2:
0988         switch (role) {
0989         case Qt::DisplayRole:
0990         case Qt::EditRole:
0991         case Qt::UserRole + 0:
0992             return QVariant::fromValue(cos(index.row()));
0993         }
0994         break;
0995     }
0996     return QVariant();
0997 }
0998 
0999 int TimeSeries::role(const char* name) const {
1000     auto names = roleNames();
1001     auto i = names.constBegin();
1002     while (i != names.constEnd()) {
1003         if (i.value() == name) {
1004             return i.key();
1005         }
1006         ++i;
1007     }
1008     return -1;
1009 }
1010 QHash<int, QByteArray> TimeSeries::roleNames() const {
1011     QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
1012     names.insert(Qt::UserRole + 0, "cos");
1013     names.insert(Qt::UserRole + 1, "sin");
1014     names.insert(Qt::UserRole + 2, "time");
1015     return names;
1016 }
1017 QVariant TimeSeries::headerData(int section, Qt::Orientation orientation, int role) const
1018 {
1019     if (orientation != Qt::Horizontal) {
1020         return QVariant();
1021     }
1022     return m_headerData.value(qMakePair(section, (Qt::ItemDataRole)role), role == Qt::DisplayRole ?QString::number(section + 1) :QVariant());
1023 }
1024 
1025 bool TimeSeries::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
1026 {
1027     if (orientation != Qt::Horizontal) {
1028         return false;
1029     }
1030     m_headerData.insert(qMakePair(section, (Qt::ItemDataRole)role), value);
1031     return true;
1032 }
1033 
1034 bool TimeSeries::setData(const QModelIndex &index, const QVariant &value, int role)
1035 {
1036     if (index.column() == 0) {
1037         if (role == Qt::UserRole + 0) {
1038             if (value.canConvert(qMetaTypeId<float>())) {
1039                 return setCos(index.row(), value.value<float>());
1040             }
1041         }
1042         if (role == Qt::UserRole + 1) {
1043             if (value.canConvert(qMetaTypeId<float>())) {
1044                 return setSin(index.row(), value.value<float>());
1045             }
1046         }
1047         if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 2) {
1048             if (value.canConvert(qMetaTypeId<float>())) {
1049                 return setTime(index.row(), value.value<float>());
1050             }
1051         }
1052     }
1053     if (index.column() == 1) {
1054         if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 1) {
1055             if (value.canConvert(qMetaTypeId<float>())) {
1056                 return setSin(index.row(), value.value<float>());
1057             }
1058         }
1059     }
1060     if (index.column() == 2) {
1061         if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 0) {
1062             if (value.canConvert(qMetaTypeId<float>())) {
1063                 return setCos(index.row(), value.value<float>());
1064             }
1065         }
1066     }
1067     return false;
1068 }
1069 
1070 extern "C" {
1071     TimeSeries::Private* time_series_new(TimeSeries*,
1072         void (*)(const TimeSeries*),
1073         void (*)(TimeSeries*),
1074         void (*)(TimeSeries*),
1075         void (*)(TimeSeries*, quintptr, quintptr),
1076         void (*)(TimeSeries*),
1077         void (*)(TimeSeries*),
1078         void (*)(TimeSeries*, int, int),
1079         void (*)(TimeSeries*),
1080         void (*)(TimeSeries*, int, int, int),
1081         void (*)(TimeSeries*),
1082         void (*)(TimeSeries*, int, int),
1083         void (*)(TimeSeries*));
1084     void time_series_free(TimeSeries::Private*);
1085 };
1086 
1087 Demo::Demo(bool /*owned*/, QObject *parent):
1088     QObject(parent),
1089     m_fibonacci(new Fibonacci(false, this)),
1090     m_fibonacciList(new FibonacciList(false, this)),
1091     m_fileSystemTree(new FileSystemTree(false, this)),
1092     m_processes(new Processes(false, this)),
1093     m_timeSeries(new TimeSeries(false, this)),
1094     m_d(nullptr),
1095     m_ownsPrivate(false)
1096 {
1097 }
1098 
1099 Demo::Demo(QObject *parent):
1100     QObject(parent),
1101     m_fibonacci(new Fibonacci(false, this)),
1102     m_fibonacciList(new FibonacciList(false, this)),
1103     m_fileSystemTree(new FileSystemTree(false, this)),
1104     m_processes(new Processes(false, this)),
1105     m_timeSeries(new TimeSeries(false, this)),
1106     m_d(demo_new(this, m_fibonacci,
1107         fibonacciInputChanged,
1108         fibonacciResultChanged, m_fibonacciList,
1109         [](const FibonacciList* o) {
1110             Q_EMIT o->newDataReady(QModelIndex());
1111         },
1112         [](FibonacciList* o) {
1113             Q_EMIT o->layoutAboutToBeChanged();
1114         },
1115         [](FibonacciList* o) {
1116             o->updatePersistentIndexes();
1117             Q_EMIT o->layoutChanged();
1118         },
1119         [](FibonacciList* o, quintptr first, quintptr last) {
1120             o->dataChanged(o->createIndex(first, 0, first),
1121                        o->createIndex(last, 1, last));
1122         },
1123         [](FibonacciList* o) {
1124             o->beginResetModel();
1125         },
1126         [](FibonacciList* o) {
1127             o->endResetModel();
1128         },
1129         [](FibonacciList* o, int first, int last) {
1130             o->beginInsertRows(QModelIndex(), first, last);
1131         },
1132         [](FibonacciList* o) {
1133             o->endInsertRows();
1134         },
1135         [](FibonacciList* o, int first, int last, int destination) {
1136             o->beginMoveRows(QModelIndex(), first, last, QModelIndex(), destination);
1137         },
1138         [](FibonacciList* o) {
1139             o->endMoveRows();
1140         },
1141         [](FibonacciList* o, int first, int last) {
1142             o->beginRemoveRows(QModelIndex(), first, last);
1143         },
1144         [](FibonacciList* o) {
1145             o->endRemoveRows();
1146         }
1147 , m_fileSystemTree,
1148         fileSystemTreePathChanged,
1149         [](const FileSystemTree* o, option_quintptr id) {
1150             if (id.some) {
1151                 int row = file_system_tree_row(o->m_d, id.value);
1152                 Q_EMIT o->newDataReady(o->createIndex(row, 0, id.value));
1153             } else {
1154                 Q_EMIT o->newDataReady(QModelIndex());
1155             }
1156         },
1157         [](FileSystemTree* o) {
1158             Q_EMIT o->layoutAboutToBeChanged();
1159         },
1160         [](FileSystemTree* o) {
1161             o->updatePersistentIndexes();
1162             Q_EMIT o->layoutChanged();
1163         },
1164         [](FileSystemTree* o, quintptr first, quintptr last) {
1165             quintptr frow = file_system_tree_row(o->m_d, first);
1166             quintptr lrow = file_system_tree_row(o->m_d, first);
1167             o->dataChanged(o->createIndex(frow, 0, first),
1168                        o->createIndex(lrow, 4, last));
1169         },
1170         [](FileSystemTree* o) {
1171             o->beginResetModel();
1172         },
1173         [](FileSystemTree* o) {
1174             o->endResetModel();
1175         },
1176         [](FileSystemTree* o, option_quintptr id, int first, int last) {
1177             if (id.some) {
1178                 int row = file_system_tree_row(o->m_d, id.value);
1179                 o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
1180             } else {
1181                 o->beginInsertRows(QModelIndex(), first, last);
1182             }
1183         },
1184         [](FileSystemTree* o) {
1185             o->endInsertRows();
1186         },
1187         [](FileSystemTree* o, option_quintptr sourceParent, int first, int last, option_quintptr destinationParent, int destination) {
1188             QModelIndex s;
1189             if (sourceParent.some) {
1190                 int row = file_system_tree_row(o->m_d, sourceParent.value);
1191                 s = o->createIndex(row, 0, sourceParent.value);
1192             }
1193             QModelIndex d;
1194             if (destinationParent.some) {
1195                 int row = file_system_tree_row(o->m_d, destinationParent.value);
1196                 d = o->createIndex(row, 0, destinationParent.value);
1197             }
1198             o->beginMoveRows(s, first, last, d, destination);
1199         },
1200         [](FileSystemTree* o) {
1201             o->endMoveRows();
1202         },
1203         [](FileSystemTree* o, option_quintptr id, int first, int last) {
1204             if (id.some) {
1205                 int row = file_system_tree_row(o->m_d, id.value);
1206                 o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
1207             } else {
1208                 o->beginRemoveRows(QModelIndex(), first, last);
1209             }
1210         },
1211         [](FileSystemTree* o) {
1212             o->endRemoveRows();
1213         }
1214 , m_processes,
1215         processesActiveChanged,
1216         [](const Processes* o, option_quintptr id) {
1217             if (id.some) {
1218                 int row = processes_row(o->m_d, id.value);
1219                 Q_EMIT o->newDataReady(o->createIndex(row, 0, id.value));
1220             } else {
1221                 Q_EMIT o->newDataReady(QModelIndex());
1222             }
1223         },
1224         [](Processes* o) {
1225             Q_EMIT o->layoutAboutToBeChanged();
1226         },
1227         [](Processes* o) {
1228             o->updatePersistentIndexes();
1229             Q_EMIT o->layoutChanged();
1230         },
1231         [](Processes* o, quintptr first, quintptr last) {
1232             quintptr frow = processes_row(o->m_d, first);
1233             quintptr lrow = processes_row(o->m_d, first);
1234             o->dataChanged(o->createIndex(frow, 0, first),
1235                        o->createIndex(lrow, 2, last));
1236         },
1237         [](Processes* o) {
1238             o->beginResetModel();
1239         },
1240         [](Processes* o) {
1241             o->endResetModel();
1242         },
1243         [](Processes* o, option_quintptr id, int first, int last) {
1244             if (id.some) {
1245                 int row = processes_row(o->m_d, id.value);
1246                 o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
1247             } else {
1248                 o->beginInsertRows(QModelIndex(), first, last);
1249             }
1250         },
1251         [](Processes* o) {
1252             o->endInsertRows();
1253         },
1254         [](Processes* o, option_quintptr sourceParent, int first, int last, option_quintptr destinationParent, int destination) {
1255             QModelIndex s;
1256             if (sourceParent.some) {
1257                 int row = processes_row(o->m_d, sourceParent.value);
1258                 s = o->createIndex(row, 0, sourceParent.value);
1259             }
1260             QModelIndex d;
1261             if (destinationParent.some) {
1262                 int row = processes_row(o->m_d, destinationParent.value);
1263                 d = o->createIndex(row, 0, destinationParent.value);
1264             }
1265             o->beginMoveRows(s, first, last, d, destination);
1266         },
1267         [](Processes* o) {
1268             o->endMoveRows();
1269         },
1270         [](Processes* o, option_quintptr id, int first, int last) {
1271             if (id.some) {
1272                 int row = processes_row(o->m_d, id.value);
1273                 o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
1274             } else {
1275                 o->beginRemoveRows(QModelIndex(), first, last);
1276             }
1277         },
1278         [](Processes* o) {
1279             o->endRemoveRows();
1280         }
1281 , m_timeSeries,
1282         [](const TimeSeries* o) {
1283             Q_EMIT o->newDataReady(QModelIndex());
1284         },
1285         [](TimeSeries* o) {
1286             Q_EMIT o->layoutAboutToBeChanged();
1287         },
1288         [](TimeSeries* o) {
1289             o->updatePersistentIndexes();
1290             Q_EMIT o->layoutChanged();
1291         },
1292         [](TimeSeries* o, quintptr first, quintptr last) {
1293             o->dataChanged(o->createIndex(first, 0, first),
1294                        o->createIndex(last, 2, last));
1295         },
1296         [](TimeSeries* o) {
1297             o->beginResetModel();
1298         },
1299         [](TimeSeries* o) {
1300             o->endResetModel();
1301         },
1302         [](TimeSeries* o, int first, int last) {
1303             o->beginInsertRows(QModelIndex(), first, last);
1304         },
1305         [](TimeSeries* o) {
1306             o->endInsertRows();
1307         },
1308         [](TimeSeries* o, int first, int last, int destination) {
1309             o->beginMoveRows(QModelIndex(), first, last, QModelIndex(), destination);
1310         },
1311         [](TimeSeries* o) {
1312             o->endMoveRows();
1313         },
1314         [](TimeSeries* o, int first, int last) {
1315             o->beginRemoveRows(QModelIndex(), first, last);
1316         },
1317         [](TimeSeries* o) {
1318             o->endRemoveRows();
1319         }
1320 )),
1321     m_ownsPrivate(true)
1322 {
1323     m_fibonacci->m_d = demo_fibonacci_get(m_d);
1324     m_fibonacciList->m_d = demo_fibonacci_list_get(m_d);
1325     m_fileSystemTree->m_d = demo_file_system_tree_get(m_d);
1326     m_processes->m_d = demo_processes_get(m_d);
1327     m_timeSeries->m_d = demo_time_series_get(m_d);
1328     connect(this->m_fibonacciList, &FibonacciList::newDataReady, this->m_fibonacciList, [this](const QModelIndex& i) {
1329         this->m_fibonacciList->fetchMore(i);
1330     }, Qt::QueuedConnection);
1331     connect(this->m_fileSystemTree, &FileSystemTree::newDataReady, this->m_fileSystemTree, [this](const QModelIndex& i) {
1332         this->m_fileSystemTree->fetchMore(i);
1333     }, Qt::QueuedConnection);
1334     connect(this->m_processes, &Processes::newDataReady, this->m_processes, [this](const QModelIndex& i) {
1335         this->m_processes->fetchMore(i);
1336     }, Qt::QueuedConnection);
1337     connect(this->m_timeSeries, &TimeSeries::newDataReady, this->m_timeSeries, [this](const QModelIndex& i) {
1338         this->m_timeSeries->fetchMore(i);
1339     }, Qt::QueuedConnection);
1340 }
1341 
1342 Demo::~Demo() {
1343     if (m_ownsPrivate) {
1344         demo_free(m_d);
1345     }
1346 }
1347 const Fibonacci* Demo::fibonacci() const
1348 {
1349     return m_fibonacci;
1350 }
1351 Fibonacci* Demo::fibonacci()
1352 {
1353     return m_fibonacci;
1354 }
1355 const FibonacciList* Demo::fibonacciList() const
1356 {
1357     return m_fibonacciList;
1358 }
1359 FibonacciList* Demo::fibonacciList()
1360 {
1361     return m_fibonacciList;
1362 }
1363 const FileSystemTree* Demo::fileSystemTree() const
1364 {
1365     return m_fileSystemTree;
1366 }
1367 FileSystemTree* Demo::fileSystemTree()
1368 {
1369     return m_fileSystemTree;
1370 }
1371 const Processes* Demo::processes() const
1372 {
1373     return m_processes;
1374 }
1375 Processes* Demo::processes()
1376 {
1377     return m_processes;
1378 }
1379 const TimeSeries* Demo::timeSeries() const
1380 {
1381     return m_timeSeries;
1382 }
1383 TimeSeries* Demo::timeSeries()
1384 {
1385     return m_timeSeries;
1386 }
1387 Fibonacci::Fibonacci(bool /*owned*/, QObject *parent):
1388     QObject(parent),
1389     m_d(nullptr),
1390     m_ownsPrivate(false)
1391 {
1392 }
1393 
1394 Fibonacci::Fibonacci(QObject *parent):
1395     QObject(parent),
1396     m_d(fibonacci_new(this,
1397         fibonacciInputChanged,
1398         fibonacciResultChanged)),
1399     m_ownsPrivate(true)
1400 {
1401 }
1402 
1403 Fibonacci::~Fibonacci() {
1404     if (m_ownsPrivate) {
1405         fibonacci_free(m_d);
1406     }
1407 }
1408 quint32 Fibonacci::input() const
1409 {
1410     return fibonacci_input_get(m_d);
1411 }
1412 void Fibonacci::setInput(quint32 v) {
1413     fibonacci_input_set(m_d, v);
1414 }
1415 quint64 Fibonacci::result() const
1416 {
1417     return fibonacci_result_get(m_d);
1418 }
1419 FibonacciList::FibonacciList(bool /*owned*/, QObject *parent):
1420     QAbstractItemModel(parent),
1421     m_d(nullptr),
1422     m_ownsPrivate(false)
1423 {
1424     initHeaderData();
1425 }
1426 
1427 FibonacciList::FibonacciList(QObject *parent):
1428     QAbstractItemModel(parent),
1429     m_d(fibonacci_list_new(this,
1430         [](const FibonacciList* o) {
1431             Q_EMIT o->newDataReady(QModelIndex());
1432         },
1433         [](FibonacciList* o) {
1434             Q_EMIT o->layoutAboutToBeChanged();
1435         },
1436         [](FibonacciList* o) {
1437             o->updatePersistentIndexes();
1438             Q_EMIT o->layoutChanged();
1439         },
1440         [](FibonacciList* o, quintptr first, quintptr last) {
1441             o->dataChanged(o->createIndex(first, 0, first),
1442                        o->createIndex(last, 1, last));
1443         },
1444         [](FibonacciList* o) {
1445             o->beginResetModel();
1446         },
1447         [](FibonacciList* o) {
1448             o->endResetModel();
1449         },
1450         [](FibonacciList* o, int first, int last) {
1451             o->beginInsertRows(QModelIndex(), first, last);
1452         },
1453         [](FibonacciList* o) {
1454             o->endInsertRows();
1455         },
1456         [](FibonacciList* o, int first, int last, int destination) {
1457             o->beginMoveRows(QModelIndex(), first, last, QModelIndex(), destination);
1458         },
1459         [](FibonacciList* o) {
1460             o->endMoveRows();
1461         },
1462         [](FibonacciList* o, int first, int last) {
1463             o->beginRemoveRows(QModelIndex(), first, last);
1464         },
1465         [](FibonacciList* o) {
1466             o->endRemoveRows();
1467         }
1468 )),
1469     m_ownsPrivate(true)
1470 {
1471     connect(this, &FibonacciList::newDataReady, this, [this](const QModelIndex& i) {
1472         this->fetchMore(i);
1473     }, Qt::QueuedConnection);
1474     initHeaderData();
1475 }
1476 
1477 FibonacciList::~FibonacciList() {
1478     if (m_ownsPrivate) {
1479         fibonacci_list_free(m_d);
1480     }
1481 }
1482 void FibonacciList::initHeaderData() {
1483     m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("row"));
1484     m_headerData.insert(qMakePair(1, Qt::DisplayRole), QVariant("fibonacciNumber"));
1485 }
1486 FileSystemTree::FileSystemTree(bool /*owned*/, QObject *parent):
1487     QAbstractItemModel(parent),
1488     m_d(nullptr),
1489     m_ownsPrivate(false)
1490 {
1491     initHeaderData();
1492 }
1493 
1494 FileSystemTree::FileSystemTree(QObject *parent):
1495     QAbstractItemModel(parent),
1496     m_d(file_system_tree_new(this,
1497         fileSystemTreePathChanged,
1498         [](const FileSystemTree* o, option_quintptr id) {
1499             if (id.some) {
1500                 int row = file_system_tree_row(o->m_d, id.value);
1501                 Q_EMIT o->newDataReady(o->createIndex(row, 0, id.value));
1502             } else {
1503                 Q_EMIT o->newDataReady(QModelIndex());
1504             }
1505         },
1506         [](FileSystemTree* o) {
1507             Q_EMIT o->layoutAboutToBeChanged();
1508         },
1509         [](FileSystemTree* o) {
1510             o->updatePersistentIndexes();
1511             Q_EMIT o->layoutChanged();
1512         },
1513         [](FileSystemTree* o, quintptr first, quintptr last) {
1514             quintptr frow = file_system_tree_row(o->m_d, first);
1515             quintptr lrow = file_system_tree_row(o->m_d, first);
1516             o->dataChanged(o->createIndex(frow, 0, first),
1517                        o->createIndex(lrow, 4, last));
1518         },
1519         [](FileSystemTree* o) {
1520             o->beginResetModel();
1521         },
1522         [](FileSystemTree* o) {
1523             o->endResetModel();
1524         },
1525         [](FileSystemTree* o, option_quintptr id, int first, int last) {
1526             if (id.some) {
1527                 int row = file_system_tree_row(o->m_d, id.value);
1528                 o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
1529             } else {
1530                 o->beginInsertRows(QModelIndex(), first, last);
1531             }
1532         },
1533         [](FileSystemTree* o) {
1534             o->endInsertRows();
1535         },
1536         [](FileSystemTree* o, option_quintptr sourceParent, int first, int last, option_quintptr destinationParent, int destination) {
1537             QModelIndex s;
1538             if (sourceParent.some) {
1539                 int row = file_system_tree_row(o->m_d, sourceParent.value);
1540                 s = o->createIndex(row, 0, sourceParent.value);
1541             }
1542             QModelIndex d;
1543             if (destinationParent.some) {
1544                 int row = file_system_tree_row(o->m_d, destinationParent.value);
1545                 d = o->createIndex(row, 0, destinationParent.value);
1546             }
1547             o->beginMoveRows(s, first, last, d, destination);
1548         },
1549         [](FileSystemTree* o) {
1550             o->endMoveRows();
1551         },
1552         [](FileSystemTree* o, option_quintptr id, int first, int last) {
1553             if (id.some) {
1554                 int row = file_system_tree_row(o->m_d, id.value);
1555                 o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
1556             } else {
1557                 o->beginRemoveRows(QModelIndex(), first, last);
1558             }
1559         },
1560         [](FileSystemTree* o) {
1561             o->endRemoveRows();
1562         }
1563 )),
1564     m_ownsPrivate(true)
1565 {
1566     connect(this, &FileSystemTree::newDataReady, this, [this](const QModelIndex& i) {
1567         this->fetchMore(i);
1568     }, Qt::QueuedConnection);
1569     initHeaderData();
1570 }
1571 
1572 FileSystemTree::~FileSystemTree() {
1573     if (m_ownsPrivate) {
1574         file_system_tree_free(m_d);
1575     }
1576 }
1577 void FileSystemTree::initHeaderData() {
1578     m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("fileName"));
1579     m_headerData.insert(qMakePair(1, Qt::DisplayRole), QVariant("fileSize"));
1580     m_headerData.insert(qMakePair(2, Qt::DisplayRole), QVariant("filePath"));
1581     m_headerData.insert(qMakePair(3, Qt::DisplayRole), QVariant("filePermissions"));
1582     m_headerData.insert(qMakePair(4, Qt::DisplayRole), QVariant("fileType"));
1583 }
1584 QString FileSystemTree::path() const
1585 {
1586     QString v;
1587     file_system_tree_path_get(m_d, &v, set_qstring);
1588     return v;
1589 }
1590 void FileSystemTree::setPath(const QString& v) {
1591     if (v.isNull()) {
1592         file_system_tree_path_set_none(m_d);
1593     } else {
1594     file_system_tree_path_set(m_d, reinterpret_cast<const ushort*>(v.data()), v.size());
1595     }
1596 }
1597 Processes::Processes(bool /*owned*/, QObject *parent):
1598     QAbstractItemModel(parent),
1599     m_d(nullptr),
1600     m_ownsPrivate(false)
1601 {
1602     initHeaderData();
1603 }
1604 
1605 Processes::Processes(QObject *parent):
1606     QAbstractItemModel(parent),
1607     m_d(processes_new(this,
1608         processesActiveChanged,
1609         [](const Processes* o, option_quintptr id) {
1610             if (id.some) {
1611                 int row = processes_row(o->m_d, id.value);
1612                 Q_EMIT o->newDataReady(o->createIndex(row, 0, id.value));
1613             } else {
1614                 Q_EMIT o->newDataReady(QModelIndex());
1615             }
1616         },
1617         [](Processes* o) {
1618             Q_EMIT o->layoutAboutToBeChanged();
1619         },
1620         [](Processes* o) {
1621             o->updatePersistentIndexes();
1622             Q_EMIT o->layoutChanged();
1623         },
1624         [](Processes* o, quintptr first, quintptr last) {
1625             quintptr frow = processes_row(o->m_d, first);
1626             quintptr lrow = processes_row(o->m_d, first);
1627             o->dataChanged(o->createIndex(frow, 0, first),
1628                        o->createIndex(lrow, 2, last));
1629         },
1630         [](Processes* o) {
1631             o->beginResetModel();
1632         },
1633         [](Processes* o) {
1634             o->endResetModel();
1635         },
1636         [](Processes* o, option_quintptr id, int first, int last) {
1637             if (id.some) {
1638                 int row = processes_row(o->m_d, id.value);
1639                 o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
1640             } else {
1641                 o->beginInsertRows(QModelIndex(), first, last);
1642             }
1643         },
1644         [](Processes* o) {
1645             o->endInsertRows();
1646         },
1647         [](Processes* o, option_quintptr sourceParent, int first, int last, option_quintptr destinationParent, int destination) {
1648             QModelIndex s;
1649             if (sourceParent.some) {
1650                 int row = processes_row(o->m_d, sourceParent.value);
1651                 s = o->createIndex(row, 0, sourceParent.value);
1652             }
1653             QModelIndex d;
1654             if (destinationParent.some) {
1655                 int row = processes_row(o->m_d, destinationParent.value);
1656                 d = o->createIndex(row, 0, destinationParent.value);
1657             }
1658             o->beginMoveRows(s, first, last, d, destination);
1659         },
1660         [](Processes* o) {
1661             o->endMoveRows();
1662         },
1663         [](Processes* o, option_quintptr id, int first, int last) {
1664             if (id.some) {
1665                 int row = processes_row(o->m_d, id.value);
1666                 o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
1667             } else {
1668                 o->beginRemoveRows(QModelIndex(), first, last);
1669             }
1670         },
1671         [](Processes* o) {
1672             o->endRemoveRows();
1673         }
1674 )),
1675     m_ownsPrivate(true)
1676 {
1677     connect(this, &Processes::newDataReady, this, [this](const QModelIndex& i) {
1678         this->fetchMore(i);
1679     }, Qt::QueuedConnection);
1680     initHeaderData();
1681 }
1682 
1683 Processes::~Processes() {
1684     if (m_ownsPrivate) {
1685         processes_free(m_d);
1686     }
1687 }
1688 void Processes::initHeaderData() {
1689     m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("name"));
1690     m_headerData.insert(qMakePair(1, Qt::DisplayRole), QVariant("cpuUsage"));
1691     m_headerData.insert(qMakePair(2, Qt::DisplayRole), QVariant("memory"));
1692 }
1693 bool Processes::active() const
1694 {
1695     return processes_active_get(m_d);
1696 }
1697 void Processes::setActive(bool v) {
1698     processes_active_set(m_d, v);
1699 }
1700 TimeSeries::TimeSeries(bool /*owned*/, QObject *parent):
1701     QAbstractItemModel(parent),
1702     m_d(nullptr),
1703     m_ownsPrivate(false)
1704 {
1705     initHeaderData();
1706 }
1707 
1708 TimeSeries::TimeSeries(QObject *parent):
1709     QAbstractItemModel(parent),
1710     m_d(time_series_new(this,
1711         [](const TimeSeries* o) {
1712             Q_EMIT o->newDataReady(QModelIndex());
1713         },
1714         [](TimeSeries* o) {
1715             Q_EMIT o->layoutAboutToBeChanged();
1716         },
1717         [](TimeSeries* o) {
1718             o->updatePersistentIndexes();
1719             Q_EMIT o->layoutChanged();
1720         },
1721         [](TimeSeries* o, quintptr first, quintptr last) {
1722             o->dataChanged(o->createIndex(first, 0, first),
1723                        o->createIndex(last, 2, last));
1724         },
1725         [](TimeSeries* o) {
1726             o->beginResetModel();
1727         },
1728         [](TimeSeries* o) {
1729             o->endResetModel();
1730         },
1731         [](TimeSeries* o, int first, int last) {
1732             o->beginInsertRows(QModelIndex(), first, last);
1733         },
1734         [](TimeSeries* o) {
1735             o->endInsertRows();
1736         },
1737         [](TimeSeries* o, int first, int last, int destination) {
1738             o->beginMoveRows(QModelIndex(), first, last, QModelIndex(), destination);
1739         },
1740         [](TimeSeries* o) {
1741             o->endMoveRows();
1742         },
1743         [](TimeSeries* o, int first, int last) {
1744             o->beginRemoveRows(QModelIndex(), first, last);
1745         },
1746         [](TimeSeries* o) {
1747             o->endRemoveRows();
1748         }
1749 )),
1750     m_ownsPrivate(true)
1751 {
1752     connect(this, &TimeSeries::newDataReady, this, [this](const QModelIndex& i) {
1753         this->fetchMore(i);
1754     }, Qt::QueuedConnection);
1755     initHeaderData();
1756 }
1757 
1758 TimeSeries::~TimeSeries() {
1759     if (m_ownsPrivate) {
1760         time_series_free(m_d);
1761     }
1762 }
1763 void TimeSeries::initHeaderData() {
1764     m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("time"));
1765     m_headerData.insert(qMakePair(1, Qt::DisplayRole), QVariant("sin"));
1766     m_headerData.insert(qMakePair(2, Qt::DisplayRole), QVariant("cos"));
1767 }