17#ifndef __gui_mrview_tool_list_model_base_h__
18#define __gui_mrview_tool_list_model_base_h__
36 QAbstractItemModel (
parent) { }
38 QVariant
data (
const QModelIndex&
index,
int role)
const override {
41 if (!
index.isValid())
return QVariant();
42 if (role == Qt::CheckStateRole) {
45 if (role != Qt::DisplayRole && role != Qt::ToolTipRole)
return QVariant();
49 bool setData (
const QModelIndex& idx,
const QVariant&
value,
int role)
override {
50 if (role == Qt::CheckStateRole) {
51 Qt::KeyboardModifiers keyMod = QApplication::keyboardModifiers ();
52 if (keyMod.testFlag (Qt::ShiftModifier)) {
53 for (
int i = 0; i < (int)
items.size(); ++i) {
55 items[i]->show =
true;
57 items[i]->show =
false;
61 items[idx.row()]->show = (
value == Qt::Checked);
62 emit dataChanged (idx, idx);
66 return QAbstractItemModel::setData (idx,
value, role);
71 return Qt::CopyAction | Qt::MoveAction;
77 bool insertRows(
int row,
int count,
const QModelIndex &)
override {
78 if (count < 1 || row < 0 || row >
rowCount ()) {
79 swapped_rows = { 0, 0 };
83 swapped_rows = { row, count };
90 bool removeRows (
int row,
int count,
const QModelIndex&
parent = QModelIndex())
override {
91 if (count < 1 || row < 0 || row >
rowCount () || count != swapped_rows.second)
96 swapped_items.insert ( swapped_items.begin(),
97 std::make_move_iterator (
items.begin() + row),
98 std::make_move_iterator (
items.begin() + row + count));
100 beginRemoveRows (
parent, row, row + count - 1);
105 if (swapped_rows.first >= row)
106 swapped_rows.first -= count;
108 beginInsertRows (
parent, swapped_rows.first, swapped_rows.first + swapped_rows.second - 1);
109 items.insert (
items.begin() + swapped_rows.first,
110 std::make_move_iterator (swapped_items.begin ()),
111 std::make_move_iterator (swapped_items.end ()));
117 Qt::ItemFlags
flags (
const QModelIndex&
index)
const override {
119 static const auto valid_flags = Qt::ItemIsDragEnabled | Qt::ItemIsEnabled |
120 Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
121 static const auto invalid_flags = valid_flags | Qt::ItemIsDropEnabled;
123 if (!
index.isValid())
return invalid_flags;
127 QModelIndex
index (
int row,
int column,
const QModelIndex&
parent = QModelIndex())
const override {
129 return createIndex (row, column);
132 QModelIndex
parent (
const QModelIndex&)
const override {
return QModelIndex(); }
145 beginRemoveRows (QModelIndex(),
index.row(),
index.row());
152 std::pair<int, int> swapped_rows;
VectorType::Scalar value(const VectorType &coefs, typename VectorType::Scalar cos_elevation, typename VectorType::Scalar cos_azimuth, typename VectorType::Scalar sin_azimuth, int lmax)
QString qstr(const std::string &s)