From a7565a254c58f6ebc130279a6f36b05a63660f73 Mon Sep 17 00:00:00 2001 From: Jos van den Oever Date: Mon, 28 Aug 2017 21:17:06 +0200 Subject: [PATCH] Add signal for changed data in lists and trees --- demo/rust/src/fibonacci_interface.rs | 6 ++++++ demo/rust/src/interface.rs | 6 ++++++ demo/rust/src/processes_interface.rs | 6 ++++++ demo/rust/src/time_series_interface.rs | 6 ++++++ demo/src/Fibonacci.cpp | 7 ++++++- demo/src/Processes.cpp | 7 +++++++ demo/src/TimeSeries.cpp | 7 ++++++- demo/src/Tree.cpp | 7 +++++++ dev | 17 ----------------- src/cpp.cpp | 19 +++++++++++++++---- src/rust.cpp | 6 ++++++ tests/rust_list/src/interface.rs | 6 ++++++ tests/rust_tree/src/interface.rs | 6 ++++++ tests/test_list_rust.cpp | 7 ++++++- tests/test_tree_rust.cpp | 7 +++++++ 15 files changed, 96 insertions(+), 24 deletions(-) delete mode 100644 dev diff --git a/demo/rust/src/fibonacci_interface.rs b/demo/rust/src/fibonacci_interface.rs index acab3df..27ccea1 100644 --- a/demo/rust/src/fibonacci_interface.rs +++ b/demo/rust/src/fibonacci_interface.rs @@ -140,6 +140,7 @@ impl FibonacciListEmitter { pub struct FibonacciListList { qobject: *const FibonacciListQObject, + data_changed: fn(*const FibonacciListQObject, usize, usize), begin_reset_model: fn(*const FibonacciListQObject), end_reset_model: fn(*const FibonacciListQObject), begin_insert_rows: fn(*const FibonacciListQObject, usize, usize), @@ -149,6 +150,9 @@ pub struct FibonacciListList { } impl FibonacciListList { + pub fn data_changed(&self, first: usize, last: usize) { + (self.data_changed)(self.qobject, first, last); + } pub fn begin_reset_model(&self) { (self.begin_reset_model)(self.qobject); } @@ -182,6 +186,7 @@ pub trait FibonacciListTrait { #[no_mangle] pub extern "C" fn fibonacci_list_new(fibonacci_list: *mut FibonacciListQObject, new_data_ready: fn(*const FibonacciListQObject), + data_changed: fn(*const FibonacciListQObject, usize, usize), begin_reset_model: fn(*const FibonacciListQObject), end_reset_model: fn(*const FibonacciListQObject), begin_insert_rows: fn(*const FibonacciListQObject, @@ -199,6 +204,7 @@ pub extern "C" fn fibonacci_list_new(fibonacci_list: *mut FibonacciListQObject, }; let model = FibonacciListList { qobject: fibonacci_list, + data_changed: data_changed, begin_reset_model: begin_reset_model, end_reset_model: end_reset_model, begin_insert_rows: begin_insert_rows, diff --git a/demo/rust/src/interface.rs b/demo/rust/src/interface.rs index 8db5f21..9ea8fa1 100644 --- a/demo/rust/src/interface.rs +++ b/demo/rust/src/interface.rs @@ -128,6 +128,7 @@ impl TreeEmitter { pub struct TreeUniformTree { qobject: *const TreeQObject, + data_changed: fn(*const TreeQObject, usize, usize), begin_reset_model: fn(*const TreeQObject), end_reset_model: fn(*const TreeQObject), begin_insert_rows: fn(*const TreeQObject, item: usize, valid: bool, usize, usize), @@ -137,6 +138,9 @@ pub struct TreeUniformTree { } impl TreeUniformTree { + pub fn data_changed(&self, item: Option, first: usize, last: usize) { + (self.data_changed)(self.qobject, first, last); + } pub fn begin_reset_model(&self) { (self.begin_reset_model)(self.qobject); } @@ -181,6 +185,7 @@ pub trait TreeTrait { pub extern "C" fn tree_new(tree: *mut TreeQObject, path_changed: fn(*const TreeQObject), new_data_ready: fn(*const TreeQObject, item: usize, valid: bool), + data_changed: fn(*const TreeQObject, usize, usize), begin_reset_model: fn(*const TreeQObject), end_reset_model: fn(*const TreeQObject), begin_insert_rows: fn(*const TreeQObject, item: usize, valid: bool, @@ -199,6 +204,7 @@ pub extern "C" fn tree_new(tree: *mut TreeQObject, }; let model = TreeUniformTree { qobject: tree, + data_changed: data_changed, begin_reset_model: begin_reset_model, end_reset_model: end_reset_model, begin_insert_rows: begin_insert_rows, diff --git a/demo/rust/src/processes_interface.rs b/demo/rust/src/processes_interface.rs index 45680f8..9337dea 100644 --- a/demo/rust/src/processes_interface.rs +++ b/demo/rust/src/processes_interface.rs @@ -98,6 +98,7 @@ impl ProcessesEmitter { pub struct ProcessesUniformTree { qobject: *const ProcessesQObject, + data_changed: fn(*const ProcessesQObject, usize, usize), begin_reset_model: fn(*const ProcessesQObject), end_reset_model: fn(*const ProcessesQObject), begin_insert_rows: fn(*const ProcessesQObject, item: usize, valid: bool, usize, usize), @@ -107,6 +108,9 @@ pub struct ProcessesUniformTree { } impl ProcessesUniformTree { + pub fn data_changed(&self, item: Option, first: usize, last: usize) { + (self.data_changed)(self.qobject, first, last); + } pub fn begin_reset_model(&self) { (self.begin_reset_model)(self.qobject); } @@ -149,6 +153,7 @@ pub trait ProcessesTrait { #[no_mangle] pub extern "C" fn processes_new(processes: *mut ProcessesQObject, new_data_ready: fn(*const ProcessesQObject, item: usize, valid: bool), + data_changed: fn(*const ProcessesQObject, usize, usize), begin_reset_model: fn(*const ProcessesQObject), end_reset_model: fn(*const ProcessesQObject), begin_insert_rows: fn(*const ProcessesQObject, item: usize, valid: bool, @@ -166,6 +171,7 @@ pub extern "C" fn processes_new(processes: *mut ProcessesQObject, }; let model = ProcessesUniformTree { qobject: processes, + data_changed: data_changed, begin_reset_model: begin_reset_model, end_reset_model: end_reset_model, begin_insert_rows: begin_insert_rows, diff --git a/demo/rust/src/time_series_interface.rs b/demo/rust/src/time_series_interface.rs index 58a2ca6..b57ec79 100644 --- a/demo/rust/src/time_series_interface.rs +++ b/demo/rust/src/time_series_interface.rs @@ -69,6 +69,7 @@ impl TimeSeriesEmitter { pub struct TimeSeriesList { qobject: *const TimeSeriesQObject, + data_changed: fn(*const TimeSeriesQObject, usize, usize), begin_reset_model: fn(*const TimeSeriesQObject), end_reset_model: fn(*const TimeSeriesQObject), begin_insert_rows: fn(*const TimeSeriesQObject, usize, usize), @@ -78,6 +79,9 @@ pub struct TimeSeriesList { } impl TimeSeriesList { + pub fn data_changed(&self, first: usize, last: usize) { + (self.data_changed)(self.qobject, first, last); + } pub fn begin_reset_model(&self) { (self.begin_reset_model)(self.qobject); } @@ -114,6 +118,7 @@ pub trait TimeSeriesTrait { #[no_mangle] pub extern "C" fn time_series_new(time_series: *mut TimeSeriesQObject, new_data_ready: fn(*const TimeSeriesQObject), + data_changed: fn(*const TimeSeriesQObject, usize, usize), begin_reset_model: fn(*const TimeSeriesQObject), end_reset_model: fn(*const TimeSeriesQObject), begin_insert_rows: fn(*const TimeSeriesQObject, @@ -131,6 +136,7 @@ pub extern "C" fn time_series_new(time_series: *mut TimeSeriesQObject, }; let model = TimeSeriesList { qobject: time_series, + data_changed: data_changed, begin_reset_model: begin_reset_model, end_reset_model: end_reset_model, begin_insert_rows: begin_insert_rows, diff --git a/demo/src/Fibonacci.cpp b/demo/src/Fibonacci.cpp index 270d5a0..3030a8f 100644 --- a/demo/src/Fibonacci.cpp +++ b/demo/src/Fibonacci.cpp @@ -96,7 +96,7 @@ int FibonacciList::rowCount(const QModelIndex &parent) const QModelIndex FibonacciList::index(int row, int column, const QModelIndex &parent) const { if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 1) { - return createIndex(row, column, (quintptr)0); + return createIndex(row, column, (quintptr)row); } return QModelIndex(); } @@ -161,6 +161,7 @@ bool FibonacciList::setData(const QModelIndex &index, const QVariant &value, int extern "C" { FibonacciList::Private* fibonacci_list_new(FibonacciList*, void (*)(const FibonacciList*), + void (*)(FibonacciList*, quintptr, quintptr), void (*)(FibonacciList*), void (*)(FibonacciList*), void (*)(FibonacciList*, int, int), @@ -215,6 +216,10 @@ FibonacciList::FibonacciList(QObject *parent): [](const FibonacciList* o) { emit o->newDataReady(QModelIndex()); }, + [](FibonacciList* o, quintptr first, quintptr last) { + o->dataChanged(o->createIndex(first, 0, first), + o->createIndex(last, 0, last)); + }, [](FibonacciList* o) { o->beginResetModel(); }, diff --git a/demo/src/Processes.cpp b/demo/src/Processes.cpp index bf841e5..f1e6ace 100644 --- a/demo/src/Processes.cpp +++ b/demo/src/Processes.cpp @@ -212,6 +212,7 @@ bool Processes::setData(const QModelIndex &index, const QVariant &value, int rol extern "C" { Processes::Private* processes_new(Processes*, void (*)(const Processes*, quintptr, bool), + void (*)(Processes*, quintptr, quintptr), void (*)(Processes*), void (*)(Processes*), void (*)(Processes*, option, int, int), @@ -239,6 +240,12 @@ Processes::Processes(QObject *parent): emit o->newDataReady(QModelIndex()); } }, + [](Processes* o, quintptr first, quintptr last) { + quintptr frow = processes_row(o->m_d, first); + quintptr lrow = processes_row(o->m_d, first); + o->dataChanged(o->createIndex(frow, 0, first), + o->createIndex(lrow, 2, last)); + }, [](Processes* o) { o->beginResetModel(); }, diff --git a/demo/src/TimeSeries.cpp b/demo/src/TimeSeries.cpp index 0cfac34..388c71b 100644 --- a/demo/src/TimeSeries.cpp +++ b/demo/src/TimeSeries.cpp @@ -83,7 +83,7 @@ int TimeSeries::rowCount(const QModelIndex &parent) const QModelIndex TimeSeries::index(int row, int column, const QModelIndex &parent) const { if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 2) { - return createIndex(row, column, (quintptr)0); + return createIndex(row, column, (quintptr)row); } return QModelIndex(); } @@ -181,6 +181,7 @@ bool TimeSeries::setData(const QModelIndex &index, const QVariant &value, int ro extern "C" { TimeSeries::Private* time_series_new(TimeSeries*, void (*)(const TimeSeries*), + void (*)(TimeSeries*, quintptr, quintptr), void (*)(TimeSeries*), void (*)(TimeSeries*), void (*)(TimeSeries*, int, int), @@ -203,6 +204,10 @@ TimeSeries::TimeSeries(QObject *parent): [](const TimeSeries* o) { emit o->newDataReady(QModelIndex()); }, + [](TimeSeries* o, quintptr first, quintptr last) { + o->dataChanged(o->createIndex(first, 0, first), + o->createIndex(last, 1, last)); + }, [](TimeSeries* o) { o->beginResetModel(); }, diff --git a/demo/src/Tree.cpp b/demo/src/Tree.cpp index 2c10052..b2e103f 100644 --- a/demo/src/Tree.cpp +++ b/demo/src/Tree.cpp @@ -229,6 +229,7 @@ bool Tree::setData(const QModelIndex &index, const QVariant &value, int role) extern "C" { Tree::Private* tree_new(Tree*, void (*)(Tree*), void (*)(const Tree*, quintptr, bool), + void (*)(Tree*, quintptr, quintptr), void (*)(Tree*), void (*)(Tree*), void (*)(Tree*, option, int, int), @@ -260,6 +261,12 @@ Tree::Tree(QObject *parent): emit o->newDataReady(QModelIndex()); } }, + [](Tree* o, quintptr first, quintptr last) { + quintptr frow = tree_row(o->m_d, first); + quintptr lrow = tree_row(o->m_d, first); + o->dataChanged(o->createIndex(frow, 0, first), + o->createIndex(lrow, 4, last)); + }, [](Tree* o) { o->beginResetModel(); }, diff --git a/dev b/dev deleted file mode 100644 index d7a5008..0000000 --- a/dev +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/bash -set -o errexit -set -o nounset -set -o pipefail - -rm -rf __nix_qt5__/ - -if [ -z "${1-}" ]; then - charts= -else - # run with NixPkgs master that has Qt5.9 and QtCharts - export NIX_PATH=nixpkgs=$HOME/nixpkgs -# export QML2_IMPORT_PATH=$QML2_IMPORT_PATH:/nix/store/cmnbj3s42vfwfkibr9ksv28g44iqbq1y-qtquickcontrols2-5.9.1-bin/lib/qt-5.9/qml/:/nix/store/cv2ayyx56jsqifb1b65ksm0n522ji733-kirigami2-2.1.0/lib/qt-5.9/qml - charts="qt5.qtcharts libsForQt5.kirigami_2" -fi - -nix-shell -p kdevelop qtcreator qt5.qtsensors qt5.qtdoc cmake ninja gcc rustc cargo qt5.full extra-cmake-modules kdeFrameworks.kwidgetsaddons kdeFrameworks.kcoreaddons kdeFrameworks.ki18n appstream cmakeCurses kdeFrameworks.ktexteditor qt5.qtquickcontrols2 $charts diff --git a/src/cpp.cpp b/src/cpp.cpp index fa55cf5..773c3e6 100644 --- a/src/cpp.cpp +++ b/src/cpp.cpp @@ -116,7 +116,7 @@ int %1::rowCount(const QModelIndex &parent) const QModelIndex %1::index(int row, int column, const QModelIndex &parent) const { if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < %3) { - return createIndex(row, column, (quintptr)0); + return createIndex(row, column, (quintptr)row); } return QModelIndex(); } @@ -391,6 +391,7 @@ void constructorArgsDecl(QTextStream& cpp, const Object& o, const Configuration& if (o.type == ObjectType::List) { cpp << QString(R"(, void (*)(const %1*), + void (*)(%1*, quintptr, quintptr), void (*)(%1*), void (*)(%1*), void (*)(%1*, int, int), @@ -401,6 +402,7 @@ void constructorArgsDecl(QTextStream& cpp, const Object& o, const Configuration& if (o.type == ObjectType::UniformTree) { cpp << QString(R"(, void (*)(const %1*, quintptr, bool), + void (*)(%1*, quintptr, quintptr), void (*)(%1*), void (*)(%1*), void (*)(%1*, option, int, int), @@ -430,6 +432,10 @@ void constructorArgs(QTextStream& cpp, const QString& prefix, const Object& o, c [](const %1* o) { emit o->newDataReady(QModelIndex()); }, + [](%1* o, quintptr first, quintptr last) { + o->dataChanged(o->createIndex(first, 0, first), + o->createIndex(last, %2, last)); + }, [](%1* o) { o->beginResetModel(); }, @@ -448,7 +454,7 @@ void constructorArgs(QTextStream& cpp, const QString& prefix, const Object& o, c [](%1* o) { o->endRemoveRows(); } -)").arg(o.name); +)").arg(o.name, QString::number(o.columnCount - 1)); } if (o.type == ObjectType::UniformTree) { cpp << QString(R"(, @@ -460,6 +466,12 @@ void constructorArgs(QTextStream& cpp, const QString& prefix, const Object& o, c emit o->newDataReady(QModelIndex()); } }, + [](%1* o, quintptr first, quintptr last) { + quintptr frow = %2_row(o->m_d, first); + quintptr lrow = %2_row(o->m_d, first); + o->dataChanged(o->createIndex(frow, 0, first), + o->createIndex(lrow, %3, last)); + }, [](%1* o) { o->beginResetModel(); }, @@ -488,7 +500,7 @@ void constructorArgs(QTextStream& cpp, const QString& prefix, const Object& o, c [](%1* o) { o->endRemoveRows(); } -)").arg(o.name, lcname); +)").arg(o.name, lcname, QString::number(o.columnCount - 1)); } } @@ -533,7 +545,6 @@ void initializeMembersEmpty(QTextStream& cpp, const Object& o, const Configurati } } - void initializeMembersZero(QTextStream& cpp, const Object& o, const Configuration& conf) { for (const Property& p: o.properties) { diff --git a/src/rust.cpp b/src/rust.cpp index 4980cff..44ef1c8 100644 --- a/src/rust.cpp +++ b/src/rust.cpp @@ -52,6 +52,7 @@ void rConstructorArgsDecl(QTextStream& r, const QString& name, const Object& o, indexDecl = " item: usize, valid: bool,"; } r << QString(R"(, + data_changed: fn(*const %1QObject, usize, usize), begin_reset_model: fn(*const %1QObject), end_reset_model: fn(*const %1QObject), begin_insert_rows: fn(*const %1QObject,%2 @@ -89,6 +90,7 @@ void rConstructorArgs(QTextStream& r, const QString& name, const Object& o, cons r << QString(R"( }; let model = %1%2 { qobject: %3, + data_changed: data_changed, begin_reset_model: begin_reset_model, end_reset_model: end_reset_model, begin_insert_rows: begin_insert_rows, @@ -185,6 +187,7 @@ impl %1Emitter { pub struct %1%2 { qobject: *const %1QObject, + data_changed: fn(*const %1QObject, usize, usize), begin_reset_model: fn(*const %1QObject), end_reset_model: fn(*const %1QObject), begin_insert_rows: fn(*const %1QObject,%5 usize, usize), @@ -194,6 +197,9 @@ pub struct %1%2 { } impl %1%2 { + pub fn data_changed(&self,%3 first: usize, last: usize) { + (self.data_changed)(self.qobject, first, last); + } pub fn begin_reset_model(&self) { (self.begin_reset_model)(self.qobject); } diff --git a/tests/rust_list/src/interface.rs b/tests/rust_list/src/interface.rs index b5f7943..3a3d7ec 100644 --- a/tests/rust_list/src/interface.rs +++ b/tests/rust_list/src/interface.rs @@ -98,6 +98,7 @@ impl PersonsEmitter { pub struct PersonsList { qobject: *const PersonsQObject, + data_changed: fn(*const PersonsQObject, usize, usize), begin_reset_model: fn(*const PersonsQObject), end_reset_model: fn(*const PersonsQObject), begin_insert_rows: fn(*const PersonsQObject, usize, usize), @@ -107,6 +108,9 @@ pub struct PersonsList { } impl PersonsList { + pub fn data_changed(&self, first: usize, last: usize) { + (self.data_changed)(self.qobject, first, last); + } pub fn begin_reset_model(&self) { (self.begin_reset_model)(self.qobject); } @@ -141,6 +145,7 @@ pub trait PersonsTrait { #[no_mangle] pub extern "C" fn persons_new(persons: *mut PersonsQObject, new_data_ready: fn(*const PersonsQObject), + data_changed: fn(*const PersonsQObject, usize, usize), begin_reset_model: fn(*const PersonsQObject), end_reset_model: fn(*const PersonsQObject), begin_insert_rows: fn(*const PersonsQObject, @@ -158,6 +163,7 @@ pub extern "C" fn persons_new(persons: *mut PersonsQObject, }; let model = PersonsList { qobject: persons, + data_changed: data_changed, begin_reset_model: begin_reset_model, end_reset_model: end_reset_model, begin_insert_rows: begin_insert_rows, diff --git a/tests/rust_tree/src/interface.rs b/tests/rust_tree/src/interface.rs index 5e4401e..82ca503 100644 --- a/tests/rust_tree/src/interface.rs +++ b/tests/rust_tree/src/interface.rs @@ -98,6 +98,7 @@ impl PersonsEmitter { pub struct PersonsUniformTree { qobject: *const PersonsQObject, + data_changed: fn(*const PersonsQObject, usize, usize), begin_reset_model: fn(*const PersonsQObject), end_reset_model: fn(*const PersonsQObject), begin_insert_rows: fn(*const PersonsQObject, item: usize, valid: bool, usize, usize), @@ -107,6 +108,9 @@ pub struct PersonsUniformTree { } impl PersonsUniformTree { + pub fn data_changed(&self, item: Option, first: usize, last: usize) { + (self.data_changed)(self.qobject, first, last); + } pub fn begin_reset_model(&self) { (self.begin_reset_model)(self.qobject); } @@ -144,6 +148,7 @@ pub trait PersonsTrait { #[no_mangle] pub extern "C" fn persons_new(persons: *mut PersonsQObject, new_data_ready: fn(*const PersonsQObject, item: usize, valid: bool), + data_changed: fn(*const PersonsQObject, usize, usize), begin_reset_model: fn(*const PersonsQObject), end_reset_model: fn(*const PersonsQObject), begin_insert_rows: fn(*const PersonsQObject, item: usize, valid: bool, @@ -161,6 +166,7 @@ pub extern "C" fn persons_new(persons: *mut PersonsQObject, }; let model = PersonsUniformTree { qobject: persons, + data_changed: data_changed, begin_reset_model: begin_reset_model, end_reset_model: end_reset_model, begin_insert_rows: begin_insert_rows, diff --git a/tests/test_list_rust.cpp b/tests/test_list_rust.cpp index c73991c..25ac48b 100644 --- a/tests/test_list_rust.cpp +++ b/tests/test_list_rust.cpp @@ -81,7 +81,7 @@ int Persons::rowCount(const QModelIndex &parent) const QModelIndex Persons::index(int row, int column, const QModelIndex &parent) const { if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 1) { - return createIndex(row, column, (quintptr)0); + return createIndex(row, column, (quintptr)row); } return QModelIndex(); } @@ -156,6 +156,7 @@ bool Persons::setData(const QModelIndex &index, const QVariant &value, int role) extern "C" { Persons::Private* persons_new(Persons*, void (*)(const Persons*), + void (*)(Persons*, quintptr, quintptr), void (*)(Persons*), void (*)(Persons*), void (*)(Persons*, int, int), @@ -178,6 +179,10 @@ Persons::Persons(QObject *parent): [](const Persons* o) { emit o->newDataReady(QModelIndex()); }, + [](Persons* o, quintptr first, quintptr last) { + o->dataChanged(o->createIndex(first, 0, first), + o->createIndex(last, 0, last)); + }, [](Persons* o) { o->beginResetModel(); }, diff --git a/tests/test_tree_rust.cpp b/tests/test_tree_rust.cpp index fa55c1c..9396581 100644 --- a/tests/test_tree_rust.cpp +++ b/tests/test_tree_rust.cpp @@ -174,6 +174,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 (*)(Persons*, quintptr, quintptr), void (*)(Persons*), void (*)(Persons*), void (*)(Persons*, option, int, int), @@ -201,6 +202,12 @@ Persons::Persons(QObject *parent): emit o->newDataReady(QModelIndex()); } }, + [](Persons* o, quintptr first, quintptr last) { + quintptr frow = persons_row(o->m_d, first); + quintptr lrow = persons_row(o->m_d, first); + o->dataChanged(o->createIndex(frow, 0, first), + o->createIndex(lrow, 0, last)); + }, [](Persons* o) { o->beginResetModel(); },