Consistently use Option instead of two arguments (value and bool)

master
Jos van den Oever 2018-09-08 21:12:00 +02:00
parent 754214e7b4
commit 2a3123eda3
3 changed files with 126 additions and 62 deletions

View File

@ -78,7 +78,7 @@ extern "C" {
void (*)(FibonacciList*),
void (*)(FibonacciList*, int, int),
void (*)(FibonacciList*), FileSystemTree*, void (*)(FileSystemTree*),
void (*)(const FileSystemTree*, quintptr, bool),
void (*)(const FileSystemTree*, option_quintptr),
void (*)(FileSystemTree*, quintptr, quintptr),
void (*)(FileSystemTree*),
void (*)(FileSystemTree*),
@ -86,7 +86,7 @@ extern "C" {
void (*)(FileSystemTree*),
void (*)(FileSystemTree*, option_quintptr, int, int),
void (*)(FileSystemTree*), Processes*, void (*)(Processes*),
void (*)(const Processes*, quintptr, bool),
void (*)(const Processes*, option_quintptr),
void (*)(Processes*, quintptr, quintptr),
void (*)(Processes*),
void (*)(Processes*),
@ -277,10 +277,10 @@ extern "C" {
qint32 file_system_tree_data_file_type(const FileSystemTree::Private*, quintptr);
void file_system_tree_sort(FileSystemTree::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
int file_system_tree_row_count(const FileSystemTree::Private*, quintptr, bool);
bool file_system_tree_can_fetch_more(const FileSystemTree::Private*, quintptr, bool);
void file_system_tree_fetch_more(FileSystemTree::Private*, quintptr, bool);
quintptr file_system_tree_index(const FileSystemTree::Private*, quintptr, bool, int);
int file_system_tree_row_count(const FileSystemTree::Private*, option_quintptr);
bool file_system_tree_can_fetch_more(const FileSystemTree::Private*, option_quintptr);
void file_system_tree_fetch_more(FileSystemTree::Private*, option_quintptr);
quintptr file_system_tree_index(const FileSystemTree::Private*, option_quintptr, int);
qmodelindex_t file_system_tree_parent(const FileSystemTree::Private*, quintptr);
int file_system_tree_row(const FileSystemTree::Private*, quintptr);
}
@ -299,7 +299,11 @@ int FileSystemTree::rowCount(const QModelIndex &parent) const
if (parent.isValid() && parent.column() != 0) {
return 0;
}
return file_system_tree_row_count(m_d, parent.internalId(), parent.isValid());
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
return file_system_tree_row_count(m_d, rust_parent);
}
bool FileSystemTree::insertRows(int, int, const QModelIndex &)
@ -323,7 +327,11 @@ QModelIndex FileSystemTree::index(int row, int column, const QModelIndex &parent
if (row >= rowCount(parent)) {
return QModelIndex();
}
const quintptr id = file_system_tree_index(m_d, parent.internalId(), parent.isValid(), row);
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
const quintptr id = file_system_tree_index(m_d, rust_parent, row);
return createIndex(row, column, id);
}
@ -341,12 +349,20 @@ bool FileSystemTree::canFetchMore(const QModelIndex &parent) const
if (parent.isValid() && parent.column() != 0) {
return false;
}
return file_system_tree_can_fetch_more(m_d, parent.internalId(), parent.isValid());
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
return file_system_tree_can_fetch_more(m_d, rust_parent);
}
void FileSystemTree::fetchMore(const QModelIndex &parent)
{
file_system_tree_fetch_more(m_d, parent.internalId(), parent.isValid());
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
file_system_tree_fetch_more(m_d, rust_parent);
}
void FileSystemTree::sort(int column, Qt::SortOrder order)
@ -486,7 +502,7 @@ bool FileSystemTree::setHeaderData(int section, Qt::Orientation orientation, con
extern "C" {
FileSystemTree::Private* file_system_tree_new(FileSystemTree*, void (*)(FileSystemTree*),
void (*)(const FileSystemTree*, quintptr, bool),
void (*)(const FileSystemTree*, option_quintptr),
void (*)(FileSystemTree*, quintptr, quintptr),
void (*)(FileSystemTree*),
void (*)(FileSystemTree*),
@ -510,10 +526,10 @@ extern "C" {
quint32 processes_data_uid(const Processes::Private*, quintptr);
void processes_sort(Processes::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
int processes_row_count(const Processes::Private*, quintptr, bool);
bool processes_can_fetch_more(const Processes::Private*, quintptr, bool);
void processes_fetch_more(Processes::Private*, quintptr, bool);
quintptr processes_index(const Processes::Private*, quintptr, bool, int);
int processes_row_count(const Processes::Private*, option_quintptr);
bool processes_can_fetch_more(const Processes::Private*, option_quintptr);
void processes_fetch_more(Processes::Private*, option_quintptr);
quintptr processes_index(const Processes::Private*, option_quintptr, int);
qmodelindex_t processes_parent(const Processes::Private*, quintptr);
int processes_row(const Processes::Private*, quintptr);
}
@ -532,7 +548,11 @@ int Processes::rowCount(const QModelIndex &parent) const
if (parent.isValid() && parent.column() != 0) {
return 0;
}
return processes_row_count(m_d, parent.internalId(), parent.isValid());
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
return processes_row_count(m_d, rust_parent);
}
bool Processes::insertRows(int, int, const QModelIndex &)
@ -556,7 +576,11 @@ QModelIndex Processes::index(int row, int column, const QModelIndex &parent) con
if (row >= rowCount(parent)) {
return QModelIndex();
}
const quintptr id = processes_index(m_d, parent.internalId(), parent.isValid(), row);
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
const quintptr id = processes_index(m_d, rust_parent, row);
return createIndex(row, column, id);
}
@ -574,12 +598,20 @@ bool Processes::canFetchMore(const QModelIndex &parent) const
if (parent.isValid() && parent.column() != 0) {
return false;
}
return processes_can_fetch_more(m_d, parent.internalId(), parent.isValid());
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
return processes_can_fetch_more(m_d, rust_parent);
}
void Processes::fetchMore(const QModelIndex &parent)
{
processes_fetch_more(m_d, parent.internalId(), parent.isValid());
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
processes_fetch_more(m_d, rust_parent);
}
void Processes::sort(int column, Qt::SortOrder order)
@ -711,7 +743,7 @@ bool Processes::setHeaderData(int section, Qt::Orientation orientation, const QV
extern "C" {
Processes::Private* processes_new(Processes*, void (*)(Processes*),
void (*)(const Processes*, quintptr, bool),
void (*)(const Processes*, option_quintptr),
void (*)(Processes*, quintptr, quintptr),
void (*)(Processes*),
void (*)(Processes*),
@ -1022,10 +1054,10 @@ Demo::Demo(QObject *parent):
}
, m_fileSystemTree,
fileSystemTreePathChanged,
[](const FileSystemTree* o, quintptr id, bool valid) {
if (valid) {
int row = file_system_tree_row(o->m_d, id);
emit o->newDataReady(o->createIndex(row, 0, id));
[](const FileSystemTree* o, option_quintptr id) {
if (id.some) {
int row = file_system_tree_row(o->m_d, id.value);
emit o->newDataReady(o->createIndex(row, 0, id.value));
} else {
emit o->newDataReady(QModelIndex());
}
@ -1066,10 +1098,10 @@ Demo::Demo(QObject *parent):
}
, m_processes,
processesActiveChanged,
[](const Processes* o, quintptr id, bool valid) {
if (valid) {
int row = processes_row(o->m_d, id);
emit o->newDataReady(o->createIndex(row, 0, id));
[](const Processes* o, option_quintptr id) {
if (id.some) {
int row = processes_row(o->m_d, id.value);
emit o->newDataReady(o->createIndex(row, 0, id.value));
} else {
emit o->newDataReady(QModelIndex());
}
@ -1299,10 +1331,10 @@ FileSystemTree::FileSystemTree(QObject *parent):
QAbstractItemModel(parent),
m_d(file_system_tree_new(this,
fileSystemTreePathChanged,
[](const FileSystemTree* o, quintptr id, bool valid) {
if (valid) {
int row = file_system_tree_row(o->m_d, id);
emit o->newDataReady(o->createIndex(row, 0, id));
[](const FileSystemTree* o, option_quintptr id) {
if (id.some) {
int row = file_system_tree_row(o->m_d, id.value);
emit o->newDataReady(o->createIndex(row, 0, id.value));
} else {
emit o->newDataReady(QModelIndex());
}
@ -1387,10 +1419,10 @@ Processes::Processes(QObject *parent):
QAbstractItemModel(parent),
m_d(processes_new(this,
processesActiveChanged,
[](const Processes* o, quintptr id, bool valid) {
if (valid) {
int row = processes_row(o->m_d, id);
emit o->newDataReady(o->createIndex(row, 0, id));
[](const Processes* o, option_quintptr id) {
if (id.some) {
int row = processes_row(o->m_d, id.value);
emit o->newDataReady(o->createIndex(row, 0, id.value));
} else {
emit o->newDataReady(QModelIndex());
}

View File

@ -327,10 +327,10 @@ void %1::fetchMore(const QModelIndex &parent)
)").arg(o.name, lcname, QString::number(o.columnCount));
} else {
cpp << QString(R"(
int %2_row_count(const %1::Private*, quintptr, bool);
bool %2_can_fetch_more(const %1::Private*, quintptr, bool);
void %2_fetch_more(%1::Private*, quintptr, bool);
quintptr %2_index(const %1::Private*, quintptr, bool, int);
int %2_row_count(const %1::Private*, option_quintptr);
bool %2_can_fetch_more(const %1::Private*, option_quintptr);
void %2_fetch_more(%1::Private*, option_quintptr);
quintptr %2_index(const %1::Private*, option_quintptr, int);
qmodelindex_t %2_parent(const %1::Private*, quintptr);
int %2_row(const %1::Private*, quintptr);
}
@ -349,7 +349,11 @@ int %1::rowCount(const QModelIndex &parent) const
if (parent.isValid() && parent.column() != 0) {
return 0;
}
return %2_row_count(m_d, parent.internalId(), parent.isValid());
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
return %2_row_count(m_d, rust_parent);
}
bool %1::insertRows(int, int, const QModelIndex &)
@ -373,7 +377,11 @@ QModelIndex %1::index(int row, int column, const QModelIndex &parent) const
if (row >= rowCount(parent)) {
return QModelIndex();
}
const quintptr id = %2_index(m_d, parent.internalId(), parent.isValid(), row);
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
const quintptr id = %2_index(m_d, rust_parent, row);
return createIndex(row, column, id);
}
@ -391,12 +399,20 @@ bool %1::canFetchMore(const QModelIndex &parent) const
if (parent.isValid() && parent.column() != 0) {
return false;
}
return %2_can_fetch_more(m_d, parent.internalId(), parent.isValid());
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
return %2_can_fetch_more(m_d, rust_parent);
}
void %1::fetchMore(const QModelIndex &parent)
{
%2_fetch_more(m_d, parent.internalId(), parent.isValid());
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
%2_fetch_more(m_d, rust_parent);
}
)").arg(o.name, lcname, QString::number(o.columnCount));
}
@ -632,7 +648,7 @@ void constructorArgsDecl(QTextStream& cpp, const Object& o, const Configuration&
}
if (o.type == ObjectType::Tree) {
cpp << QString(R"(,
void (*)(const %1*, quintptr, bool),
void (*)(const %1*, option_quintptr),
void (*)(%1*, quintptr, quintptr),
void (*)(%1*),
void (*)(%1*),
@ -689,10 +705,10 @@ void constructorArgs(QTextStream& cpp, const QString& prefix, const Object& o, c
}
if (o.type == ObjectType::Tree) {
cpp << QString(R"(,
[](const %1* o, quintptr id, bool valid) {
if (valid) {
int row = %2_row(o->m_d, id);
emit o->newDataReady(o->createIndex(row, 0, id));
[](const %1* o, option_quintptr id) {
if (id.some) {
int row = %2_row(o->m_d, id.value);
emit o->newDataReady(o->createIndex(row, 0, id.value));
} else {
emit o->newDataReady(QModelIndex());
}

View File

@ -34,10 +34,10 @@ extern "C" {
bool persons_set_data_user_name(Persons::Private*, quintptr, const ushort* s, int len);
void persons_sort(Persons::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
int persons_row_count(const Persons::Private*, quintptr, bool);
bool persons_can_fetch_more(const Persons::Private*, quintptr, bool);
void persons_fetch_more(Persons::Private*, quintptr, bool);
quintptr persons_index(const Persons::Private*, quintptr, bool, int);
int persons_row_count(const Persons::Private*, option_quintptr);
bool persons_can_fetch_more(const Persons::Private*, option_quintptr);
void persons_fetch_more(Persons::Private*, option_quintptr);
quintptr persons_index(const Persons::Private*, option_quintptr, int);
qmodelindex_t persons_parent(const Persons::Private*, quintptr);
int persons_row(const Persons::Private*, quintptr);
}
@ -56,7 +56,11 @@ int Persons::rowCount(const QModelIndex &parent) const
if (parent.isValid() && parent.column() != 0) {
return 0;
}
return persons_row_count(m_d, parent.internalId(), parent.isValid());
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
return persons_row_count(m_d, rust_parent);
}
bool Persons::insertRows(int, int, const QModelIndex &)
@ -80,7 +84,11 @@ QModelIndex Persons::index(int row, int column, const QModelIndex &parent) const
if (row >= rowCount(parent)) {
return QModelIndex();
}
const quintptr id = persons_index(m_d, parent.internalId(), parent.isValid(), row);
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
const quintptr id = persons_index(m_d, rust_parent, row);
return createIndex(row, column, id);
}
@ -98,12 +106,20 @@ bool Persons::canFetchMore(const QModelIndex &parent) const
if (parent.isValid() && parent.column() != 0) {
return false;
}
return persons_can_fetch_more(m_d, parent.internalId(), parent.isValid());
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
return persons_can_fetch_more(m_d, rust_parent);
}
void Persons::fetchMore(const QModelIndex &parent)
{
persons_fetch_more(m_d, parent.internalId(), parent.isValid());
const option_quintptr rust_parent = {
parent.internalId(),
parent.isValid()
};
persons_fetch_more(m_d, rust_parent);
}
void Persons::sort(int column, Qt::SortOrder order)
@ -198,7 +214,7 @@ bool Persons::setData(const QModelIndex &index, const QVariant &value, int role)
extern "C" {
Persons::Private* persons_new(Persons*,
void (*)(const Persons*, quintptr, bool),
void (*)(const Persons*, option_quintptr),
void (*)(Persons*, quintptr, quintptr),
void (*)(Persons*),
void (*)(Persons*),
@ -220,10 +236,10 @@ Persons::Persons(bool /*owned*/, QObject *parent):
Persons::Persons(QObject *parent):
QAbstractItemModel(parent),
m_d(persons_new(this,
[](const Persons* o, quintptr id, bool valid) {
if (valid) {
int row = persons_row(o->m_d, id);
emit o->newDataReady(o->createIndex(row, 0, id));
[](const Persons* o, option_quintptr id) {
if (id.some) {
int row = persons_row(o->m_d, id.value);
emit o->newDataReady(o->createIndex(row, 0, id.value));
} else {
emit o->newDataReady(QModelIndex());
}