1#ifndef H_EXTENSIONS_CUTEHMI_DATAACQUISITION_1_INCLUDE_CUTEHMI_DATAACQUISITION_INTERNAL_MODELMIXIN_HPP
2#define H_EXTENSIONS_CUTEHMI_DATAACQUISITION_1_INCLUDE_CUTEHMI_DATAACQUISITION_INTERNAL_MODELMIXIN_HPP
4#include <cutehmi/services/Serviceable.hpp>
6#include <cutehmi/shareddatabase/Database.hpp>
11namespace dataacquisition {
14template <
class DERIVED>
18 template <
typename COLUMN_VALUES>
22 const DERIVED & derived()
const;
27template <
typename DERIVED>
28template <
typename COLUMN_VALUES>
31 int newRowCount = newColumnValues.length();
32 int currentRowCount = derived().rowCount();
34 for (
int i = 0; i <
std::min(currentRowCount, newRowCount); i++) {
35 if (!derived().m->columnValues.isEqual(i, newColumnValues)) {
36 if (changedFrom == -1)
38 derived().m->columnValues.replace(i, newColumnValues);
39 }
else if (changedFrom != -1) {
40 emit derived().dataChanged(derived().createIndex(changedFrom, 0), derived().createIndex(i, 0));
45 if (changedFrom != -1)
46 emit derived().dataChanged(derived().createIndex(changedFrom, 0), derived().createIndex(derived().rowCount() - 1, 0));
48 if (derived().rowCount() < newRowCount) {
49 derived().beginInsertRows(
QModelIndex(), derived().rowCount(), newRowCount - 1);
50 for (
int i = derived().rowCount(); i < newRowCount; i++)
51 derived().m->columnValues.insert(i, newColumnValues);
52 derived().endInsertRows();
55 if (derived().rowCount() > newRowCount) {
56 derived().beginRemoveRows(
QModelIndex(), newRowCount, derived().rowCount() - 1);
57 derived().m->columnValues.eraseFrom(newRowCount);
58 derived().endRemoveRows();
62template <
typename DERIVED>
65 return static_cast<const DERIVED &
>(*this);
68template <
typename DERIVED>
69DERIVED & ModelMixin<DERIVED>::derived()
71 return static_cast<DERIVED &
>(*this);
Definition: ModelMixin.hpp:16
void onSelected(const COLUMN_VALUES &newColumnValues)
Definition: ModelMixin.hpp:29