Automatically update index when calling layoutChanged
parent
f0eb78457b
commit
9549c50217
|
@ -280,6 +280,13 @@ where
|
|||
fn row(&self, index: usize) -> usize {
|
||||
self.entries[index].row
|
||||
}
|
||||
fn check_row(&self, index: usize, _row: usize) -> Option<usize> {
|
||||
if index < self.entries.len() {
|
||||
Some(self.row(index))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn file_name(&self, index: usize) -> String {
|
||||
self.get(index).data.file_name()
|
||||
}
|
||||
|
|
|
@ -390,6 +390,14 @@ impl ProcessesTrait for Processes {
|
|||
fn row(&self, index: usize) -> usize {
|
||||
self.get(index).row
|
||||
}
|
||||
fn check_row(&self, index: usize, _row: usize) -> Option<usize> {
|
||||
let pid = index as pid_t;
|
||||
if self.p.processes.contains_key(&pid) {
|
||||
Some(self.row(index))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn pid(&self, index: usize) -> u32 {
|
||||
self.process(index).pid as u32
|
||||
}
|
||||
|
|
|
@ -653,6 +653,7 @@ pub trait FileSystemTreeTrait {
|
|||
}
|
||||
fn fetch_more(&mut self, Option<usize>) {}
|
||||
fn sort(&mut self, u8, SortOrder) {}
|
||||
fn check_row(&self, index: usize, row: usize) -> Option<usize>;
|
||||
fn index(&self, item: Option<usize>, row: usize) -> usize;
|
||||
fn parent(&self, index: usize) -> Option<usize>;
|
||||
fn row(&self, index: usize) -> usize;
|
||||
|
@ -764,6 +765,14 @@ pub unsafe extern "C" fn file_system_tree_sort(
|
|||
(&mut *ptr).sort(column, order)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn file_system_tree_check_row(
|
||||
ptr: *const FileSystemTree,
|
||||
index: usize,
|
||||
row: c_int,
|
||||
) -> COption<usize> {
|
||||
(&*ptr).check_row(index.into(), to_usize(row)).into()
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn file_system_tree_index(
|
||||
ptr: *const FileSystemTree,
|
||||
index: COption<usize>,
|
||||
|
@ -938,6 +947,7 @@ pub trait ProcessesTrait {
|
|||
}
|
||||
fn fetch_more(&mut self, Option<usize>) {}
|
||||
fn sort(&mut self, u8, SortOrder) {}
|
||||
fn check_row(&self, index: usize, row: usize) -> Option<usize>;
|
||||
fn index(&self, item: Option<usize>, row: usize) -> usize;
|
||||
fn parent(&self, index: usize) -> Option<usize>;
|
||||
fn row(&self, index: usize) -> usize;
|
||||
|
@ -1032,6 +1042,14 @@ pub unsafe extern "C" fn processes_sort(
|
|||
(&mut *ptr).sort(column, order)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_check_row(
|
||||
ptr: *const Processes,
|
||||
index: usize,
|
||||
row: c_int,
|
||||
) -> COption<usize> {
|
||||
(&*ptr).check_row(index.into(), to_usize(row)).into()
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_index(
|
||||
ptr: *const Processes,
|
||||
index: COption<usize>,
|
||||
|
|
|
@ -194,6 +194,7 @@ void FibonacciList::fetchMore(const QModelIndex &parent)
|
|||
fibonacci_list_fetch_more(m_d);
|
||||
}
|
||||
}
|
||||
void FibonacciList::updatePersistentIndexes() {}
|
||||
|
||||
void FibonacciList::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
|
@ -303,6 +304,7 @@ extern "C" {
|
|||
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);
|
||||
option_quintptr file_system_tree_check_row(const FileSystemTree::Private*, quintptr, int);
|
||||
}
|
||||
int FileSystemTree::columnCount(const QModelIndex &) const
|
||||
{
|
||||
|
@ -384,6 +386,21 @@ void FileSystemTree::fetchMore(const QModelIndex &parent)
|
|||
};
|
||||
file_system_tree_fetch_more(m_d, rust_parent);
|
||||
}
|
||||
void FileSystemTree::updatePersistentIndexes() {
|
||||
const auto from = persistentIndexList();
|
||||
auto to = from;
|
||||
auto len = to.size();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
auto index = to.at(i);
|
||||
auto row = file_system_tree_check_row(m_d, index.internalId(), index.row());
|
||||
if (row.some) {
|
||||
to[i] = createIndex(row.value, index.column(), index.internalId());
|
||||
} else {
|
||||
to[i] = QModelIndex();
|
||||
}
|
||||
}
|
||||
changePersistentIndexList(from, to);
|
||||
}
|
||||
|
||||
void FileSystemTree::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
|
@ -556,6 +573,7 @@ extern "C" {
|
|||
quintptr processes_index(const Processes::Private*, option_quintptr, int);
|
||||
qmodelindex_t processes_parent(const Processes::Private*, quintptr);
|
||||
int processes_row(const Processes::Private*, quintptr);
|
||||
option_quintptr processes_check_row(const Processes::Private*, quintptr, int);
|
||||
}
|
||||
int Processes::columnCount(const QModelIndex &) const
|
||||
{
|
||||
|
@ -637,6 +655,21 @@ void Processes::fetchMore(const QModelIndex &parent)
|
|||
};
|
||||
processes_fetch_more(m_d, rust_parent);
|
||||
}
|
||||
void Processes::updatePersistentIndexes() {
|
||||
const auto from = persistentIndexList();
|
||||
auto to = from;
|
||||
auto len = to.size();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
auto index = to.at(i);
|
||||
auto row = processes_check_row(m_d, index.internalId(), index.row());
|
||||
if (row.some) {
|
||||
to[i] = createIndex(row.value, index.column(), index.internalId());
|
||||
} else {
|
||||
to[i] = QModelIndex();
|
||||
}
|
||||
}
|
||||
changePersistentIndexList(from, to);
|
||||
}
|
||||
|
||||
void Processes::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
|
@ -848,6 +881,7 @@ void TimeSeries::fetchMore(const QModelIndex &parent)
|
|||
time_series_fetch_more(m_d);
|
||||
}
|
||||
}
|
||||
void TimeSeries::updatePersistentIndexes() {}
|
||||
|
||||
void TimeSeries::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
|
@ -1066,6 +1100,7 @@ Demo::Demo(QObject *parent):
|
|||
emit o->layoutAboutToBeChanged();
|
||||
},
|
||||
[](FibonacciList* o) {
|
||||
o->updatePersistentIndexes();
|
||||
emit o->layoutChanged();
|
||||
},
|
||||
[](FibonacciList* o, quintptr first, quintptr last) {
|
||||
|
@ -1110,6 +1145,7 @@ Demo::Demo(QObject *parent):
|
|||
emit o->layoutAboutToBeChanged();
|
||||
},
|
||||
[](FileSystemTree* o) {
|
||||
o->updatePersistentIndexes();
|
||||
emit o->layoutChanged();
|
||||
},
|
||||
[](FileSystemTree* o, quintptr first, quintptr last) {
|
||||
|
@ -1176,6 +1212,7 @@ Demo::Demo(QObject *parent):
|
|||
emit o->layoutAboutToBeChanged();
|
||||
},
|
||||
[](Processes* o) {
|
||||
o->updatePersistentIndexes();
|
||||
emit o->layoutChanged();
|
||||
},
|
||||
[](Processes* o, quintptr first, quintptr last) {
|
||||
|
@ -1236,6 +1273,7 @@ Demo::Demo(QObject *parent):
|
|||
emit o->layoutAboutToBeChanged();
|
||||
},
|
||||
[](TimeSeries* o) {
|
||||
o->updatePersistentIndexes();
|
||||
emit o->layoutChanged();
|
||||
},
|
||||
[](TimeSeries* o, quintptr first, quintptr last) {
|
||||
|
@ -1383,6 +1421,7 @@ FibonacciList::FibonacciList(QObject *parent):
|
|||
emit o->layoutAboutToBeChanged();
|
||||
},
|
||||
[](FibonacciList* o) {
|
||||
o->updatePersistentIndexes();
|
||||
emit o->layoutChanged();
|
||||
},
|
||||
[](FibonacciList* o, quintptr first, quintptr last) {
|
||||
|
@ -1455,6 +1494,7 @@ FileSystemTree::FileSystemTree(QObject *parent):
|
|||
emit o->layoutAboutToBeChanged();
|
||||
},
|
||||
[](FileSystemTree* o) {
|
||||
o->updatePersistentIndexes();
|
||||
emit o->layoutChanged();
|
||||
},
|
||||
[](FileSystemTree* o, quintptr first, quintptr last) {
|
||||
|
@ -1565,6 +1605,7 @@ Processes::Processes(QObject *parent):
|
|||
emit o->layoutAboutToBeChanged();
|
||||
},
|
||||
[](Processes* o) {
|
||||
o->updatePersistentIndexes();
|
||||
emit o->layoutChanged();
|
||||
},
|
||||
[](Processes* o, quintptr first, quintptr last) {
|
||||
|
@ -1661,6 +1702,7 @@ TimeSeries::TimeSeries(QObject *parent):
|
|||
emit o->layoutAboutToBeChanged();
|
||||
},
|
||||
[](TimeSeries* o) {
|
||||
o->updatePersistentIndexes();
|
||||
emit o->layoutChanged();
|
||||
},
|
||||
[](TimeSeries* o, quintptr first, quintptr last) {
|
||||
|
|
|
@ -114,6 +114,7 @@ signals:
|
|||
private:
|
||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||
void initHeaderData();
|
||||
void updatePersistentIndexes();
|
||||
signals:
|
||||
};
|
||||
|
||||
|
@ -163,6 +164,7 @@ signals:
|
|||
private:
|
||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||
void initHeaderData();
|
||||
void updatePersistentIndexes();
|
||||
signals:
|
||||
void pathChanged();
|
||||
};
|
||||
|
@ -214,6 +216,7 @@ signals:
|
|||
private:
|
||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||
void initHeaderData();
|
||||
void updatePersistentIndexes();
|
||||
signals:
|
||||
void activeChanged();
|
||||
};
|
||||
|
@ -262,6 +265,7 @@ signals:
|
|||
private:
|
||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||
void initHeaderData();
|
||||
void updatePersistentIndexes();
|
||||
signals:
|
||||
};
|
||||
#endif // BINDINGS_H
|
||||
|
|
20
src/cpp.cpp
20
src/cpp.cpp
|
@ -117,6 +117,7 @@ signals:
|
|||
private:
|
||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||
void initHeaderData();
|
||||
void updatePersistentIndexes();
|
||||
)";
|
||||
}
|
||||
|
||||
|
@ -324,6 +325,7 @@ void %1::fetchMore(const QModelIndex &parent)
|
|||
%2_fetch_more(m_d);
|
||||
}
|
||||
}
|
||||
void %1::updatePersistentIndexes() {}
|
||||
)").arg(o.name, lcname, QString::number(o.columnCount));
|
||||
} else {
|
||||
cpp << QString(R"(
|
||||
|
@ -333,6 +335,7 @@ void %1::fetchMore(const QModelIndex &parent)
|
|||
quintptr %2_index(const %1::Private*, option_quintptr, int);
|
||||
qmodelindex_t %2_parent(const %1::Private*, quintptr);
|
||||
int %2_row(const %1::Private*, quintptr);
|
||||
option_quintptr %2_check_row(const %1::Private*, quintptr, int);
|
||||
}
|
||||
int %1::columnCount(const QModelIndex &) const
|
||||
{
|
||||
|
@ -414,6 +417,21 @@ void %1::fetchMore(const QModelIndex &parent)
|
|||
};
|
||||
%2_fetch_more(m_d, rust_parent);
|
||||
}
|
||||
void %1::updatePersistentIndexes() {
|
||||
const auto from = persistentIndexList();
|
||||
auto to = from;
|
||||
auto len = to.size();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
auto index = to.at(i);
|
||||
auto row = %2_check_row(m_d, index.internalId(), index.row());
|
||||
if (row.some) {
|
||||
to[i] = createIndex(row.value, index.column(), index.internalId());
|
||||
} else {
|
||||
to[i] = QModelIndex();
|
||||
}
|
||||
}
|
||||
changePersistentIndexList(from, to);
|
||||
}
|
||||
)").arg(o.name, lcname, QString::number(o.columnCount));
|
||||
}
|
||||
|
||||
|
@ -691,6 +709,7 @@ void constructorArgs(QTextStream& cpp, const QString& prefix, const Object& o, c
|
|||
emit o->layoutAboutToBeChanged();
|
||||
},
|
||||
[](%1* o) {
|
||||
o->updatePersistentIndexes();
|
||||
emit o->layoutChanged();
|
||||
},
|
||||
[](%1* o, quintptr first, quintptr last) {
|
||||
|
@ -737,6 +756,7 @@ void constructorArgs(QTextStream& cpp, const QString& prefix, const Object& o, c
|
|||
emit o->layoutAboutToBeChanged();
|
||||
},
|
||||
[](%1* o) {
|
||||
o->updatePersistentIndexes();
|
||||
emit o->layoutChanged();
|
||||
},
|
||||
[](%1* o, quintptr first, quintptr last) {
|
||||
|
|
|
@ -413,6 +413,7 @@ pub trait %1Trait {
|
|||
}
|
||||
fn fetch_more(&mut self, Option<usize>) {}
|
||||
fn sort(&mut self, u8, SortOrder) {}
|
||||
fn check_row(&self, index: usize, row: usize) -> Option<usize>;
|
||||
fn index(&self, item: Option<usize>, row: usize) -> usize;
|
||||
fn parent(&self, index: usize) -> Option<usize>;
|
||||
fn row(&self, index: usize) -> usize;
|
||||
|
@ -660,6 +661,14 @@ pub unsafe extern "C" fn %2_sort(
|
|||
(&mut *ptr).sort(column, order)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_check_row(
|
||||
ptr: *const %1,
|
||||
index: usize,
|
||||
row: c_int,
|
||||
) -> COption<usize> {
|
||||
(&*ptr).check_row(index.into(), to_usize(row)).into()
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_index(
|
||||
ptr: *const %1,
|
||||
index: COption<usize>,
|
||||
|
|
|
@ -37,6 +37,13 @@ impl PersonsTrait for Persons {
|
|||
fn row(&self, index: usize) -> usize {
|
||||
index
|
||||
}
|
||||
fn check_row(&self, index: usize, _row: usize) -> Option<usize> {
|
||||
if index < self.list.len() {
|
||||
Some(index)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn user_name(&self, index: usize) -> &str {
|
||||
&self.list[index].user_name
|
||||
}
|
||||
|
|
|
@ -174,6 +174,7 @@ pub trait PersonsTrait {
|
|||
}
|
||||
fn fetch_more(&mut self, Option<usize>) {}
|
||||
fn sort(&mut self, u8, SortOrder) {}
|
||||
fn check_row(&self, index: usize, row: usize) -> Option<usize>;
|
||||
fn index(&self, item: Option<usize>, row: usize) -> usize;
|
||||
fn parent(&self, index: usize) -> Option<usize>;
|
||||
fn row(&self, index: usize) -> usize;
|
||||
|
@ -251,6 +252,14 @@ pub unsafe extern "C" fn persons_sort(
|
|||
(&mut *ptr).sort(column, order)
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_check_row(
|
||||
ptr: *const Persons,
|
||||
index: usize,
|
||||
row: c_int,
|
||||
) -> COption<usize> {
|
||||
(&*ptr).check_row(index.into(), to_usize(row)).into()
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_index(
|
||||
ptr: *const Persons,
|
||||
index: COption<usize>,
|
||||
|
|
|
@ -91,6 +91,7 @@ void NoRole::fetchMore(const QModelIndex &parent)
|
|||
no_role_fetch_more(m_d);
|
||||
}
|
||||
}
|
||||
void NoRole::updatePersistentIndexes() {}
|
||||
|
||||
void NoRole::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
|
@ -282,6 +283,7 @@ void Persons::fetchMore(const QModelIndex &parent)
|
|||
persons_fetch_more(m_d);
|
||||
}
|
||||
}
|
||||
void Persons::updatePersistentIndexes() {}
|
||||
|
||||
void Persons::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
|
@ -409,6 +411,7 @@ NoRole::NoRole(QObject *parent):
|
|||
emit o->layoutAboutToBeChanged();
|
||||
},
|
||||
[](NoRole* o) {
|
||||
o->updatePersistentIndexes();
|
||||
emit o->layoutChanged();
|
||||
},
|
||||
[](NoRole* o, quintptr first, quintptr last) {
|
||||
|
@ -473,6 +476,7 @@ Persons::Persons(QObject *parent):
|
|||
emit o->layoutAboutToBeChanged();
|
||||
},
|
||||
[](Persons* o) {
|
||||
o->updatePersistentIndexes();
|
||||
emit o->layoutChanged();
|
||||
},
|
||||
[](Persons* o, quintptr first, quintptr last) {
|
||||
|
|
|
@ -49,6 +49,7 @@ signals:
|
|||
private:
|
||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||
void initHeaderData();
|
||||
void updatePersistentIndexes();
|
||||
signals:
|
||||
};
|
||||
|
||||
|
@ -91,6 +92,7 @@ signals:
|
|||
private:
|
||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||
void initHeaderData();
|
||||
void updatePersistentIndexes();
|
||||
signals:
|
||||
};
|
||||
#endif // TEST_LIST_RUST_H
|
||||
|
|
|
@ -145,6 +145,7 @@ void List::fetchMore(const QModelIndex &parent)
|
|||
list_fetch_more(m_d);
|
||||
}
|
||||
}
|
||||
void List::updatePersistentIndexes() {}
|
||||
|
||||
void List::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
|
@ -653,6 +654,7 @@ List::List(QObject *parent):
|
|||
emit o->layoutAboutToBeChanged();
|
||||
},
|
||||
[](List* o) {
|
||||
o->updatePersistentIndexes();
|
||||
emit o->layoutChanged();
|
||||
},
|
||||
[](List* o, quintptr first, quintptr last) {
|
||||
|
|
|
@ -76,6 +76,7 @@ signals:
|
|||
private:
|
||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||
void initHeaderData();
|
||||
void updatePersistentIndexes();
|
||||
signals:
|
||||
};
|
||||
#endif // TEST_LIST_TYPES_RUST_H
|
||||
|
|
|
@ -40,6 +40,7 @@ extern "C" {
|
|||
quintptr persons_index(const Persons::Private*, option_quintptr, int);
|
||||
qmodelindex_t persons_parent(const Persons::Private*, quintptr);
|
||||
int persons_row(const Persons::Private*, quintptr);
|
||||
option_quintptr persons_check_row(const Persons::Private*, quintptr, int);
|
||||
}
|
||||
int Persons::columnCount(const QModelIndex &) const
|
||||
{
|
||||
|
@ -121,6 +122,21 @@ void Persons::fetchMore(const QModelIndex &parent)
|
|||
};
|
||||
persons_fetch_more(m_d, rust_parent);
|
||||
}
|
||||
void Persons::updatePersistentIndexes() {
|
||||
const auto from = persistentIndexList();
|
||||
auto to = from;
|
||||
auto len = to.size();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
auto index = to.at(i);
|
||||
auto row = persons_check_row(m_d, index.internalId(), index.row());
|
||||
if (row.some) {
|
||||
to[i] = createIndex(row.value, index.column(), index.internalId());
|
||||
} else {
|
||||
to[i] = QModelIndex();
|
||||
}
|
||||
}
|
||||
changePersistentIndexList(from, to);
|
||||
}
|
||||
|
||||
void Persons::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
|
@ -252,6 +268,7 @@ Persons::Persons(QObject *parent):
|
|||
emit o->layoutAboutToBeChanged();
|
||||
},
|
||||
[](Persons* o) {
|
||||
o->updatePersistentIndexes();
|
||||
emit o->layoutChanged();
|
||||
},
|
||||
[](Persons* o, quintptr first, quintptr last) {
|
||||
|
|
|
@ -46,6 +46,7 @@ signals:
|
|||
private:
|
||||
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||
void initHeaderData();
|
||||
void updatePersistentIndexes();
|
||||
signals:
|
||||
};
|
||||
#endif // TEST_TREE_RUST_H
|
||||
|
|
Loading…
Reference in New Issue