Developer documentation
Version 3.0.3-105-gd3941f44
matrix_list.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __gui_mrview_tool_connectome_matrix_list_h__
18#define __gui_mrview_tool_connectome_matrix_list_h__
19
20#include <memory>
21
22#include <QAbstractItemModel>
23
24#include "mrtrix.h"
26
27
28namespace MR
29{
30 namespace GUI
31 {
32 namespace MRView
33 {
34
35 class Window;
36
37 namespace Tool
38 {
39
40
41 class Connectome;
42
43
44 class Matrix_list_model : public QAbstractItemModel
46 public:
47
49
50 QVariant data (const QModelIndex& index, int role) const override {
51 if (!index.isValid()) return {};
52 if (role != Qt::DisplayRole) return {};
53 return qstr (shorten (items[index.row()].get_name().toStdString(), 35, 0));
54 }
55
56 Qt::ItemFlags flags (const QModelIndex& index) const override {
57 if (!index.isValid()) return {};
58 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
59 }
60
61 QModelIndex parent (const QModelIndex&) const override {
62 return {};
63 }
64
65 int rowCount (const QModelIndex& parent = QModelIndex()) const override {
66 (void) parent; // to suppress warnings about unused parameters
67 return items.size();
68 }
69
70 int columnCount (const QModelIndex& parent = QModelIndex()) const override {
71 (void) parent;
72 return 1;
73 }
74
75 QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex()) const override {
76 (void ) parent;
77 return createIndex (row, column);
78 }
79
80 void remove_item (QModelIndex& index) {
81 beginRemoveRows (QModelIndex(), index.row(), index.row());
82 items.erase (items.begin() + index.row());
83 endRemoveRows();
84 }
85
86 void clear() {
87 beginRemoveRows (QModelIndex(), 0, items.size());
88 items.clear();
89 endRemoveRows();
90 }
91
92 void add_items (vector<FileDataVector>&);
93
94 const FileDataVector& get (const size_t index) { assert (index < items.size()); return items[index]; }
95 const FileDataVector& get (QModelIndex& index) { assert (size_t(index.row()) < items.size()); return items[index.row()]; }
96
97 protected:
99
100 };
101
102
103 }
104 }
105 }
106}
107
108#endif
109
110
111
vector< FileDataVector > items
Definition: matrix_list.h:98
QString qstr(const std::string &s)
Definition: gui.h:31
Definition: base.h:24
std::string shorten(const std::string &text, size_t longest=40, size_t prefix=10)
convert a long string to 'beginningofstring...endofstring' for display
Definition: mrtrix.h:88
size_t index
#define MEMALIGN(...)
Definition: types.h:185