Add signal for changed data in lists and trees

master
Jos van den Oever 2017-08-28 21:17:06 +02:00
parent aecb026fe4
commit a7565a254c
15 changed files with 96 additions and 24 deletions

View File

@ -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,

View File

@ -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<usize>, 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,

View File

@ -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<usize>, 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,

View File

@ -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,

View File

@ -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();
},

View File

@ -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<quintptr>, 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();
},

View File

@ -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();
},

View File

@ -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<quintptr>, 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();
},

17
dev
View File

@ -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

View File

@ -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<quintptr>, 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) {

View File

@ -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);
}

View File

@ -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,

View File

@ -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<usize>, 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,

View File

@ -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();
},

View File

@ -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<quintptr>, 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();
},