##// END OF EJS Templates
Adapts VariableModel to be a QabstractTableModel...
Alexandre Leroux -
r149:5bdc904b0565
parent child
Show More
@@ -3,6 +3,7
3 3
4 4 #include <Common/spimpl.h>
5 5
6 #include <QAbstractTableModel>
6 7 #include <QLoggingCategory>
7 8
8 9 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
@@ -12,9 +13,9 class Variable;
12 13 /**
13 14 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
14 15 */
15 class VariableModel {
16 class VariableModel : public QAbstractTableModel {
16 17 public:
17 explicit VariableModel();
18 explicit VariableModel(QObject *parent = nullptr);
18 19
19 20 /**
20 21 * Creates a new variable in the model
@@ -23,6 +24,15 public:
23 24 */
24 25 Variable *createVariable(const QString &name) noexcept;
25 26
27 // /////////////////////////// //
28 // QAbstractTableModel methods //
29 // /////////////////////////// //
30 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
31 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
32 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
33 virtual QVariant headerData(int section, Qt::Orientation orientation,
34 int role = Qt::DisplayRole) const override;
35
26 36 private:
27 37 class VariableModelPrivate;
28 38 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
@@ -4,12 +4,19
4 4
5 5 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
6 6
7 namespace {
8
9 const auto NB_COLUMNS = 3;
10
11 } // namespace
12
7 13 struct VariableModel::VariableModelPrivate {
8 14 /// Variables created in SciQlop
9 15 std::vector<std::unique_ptr<Variable> > m_Variables;
10 16 };
11 17
12 VariableModel::VariableModel() : impl{spimpl::make_unique_impl<VariableModelPrivate>()}
18 VariableModel::VariableModel(QObject *parent)
19 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
13 20 {
14 21 }
15 22
@@ -22,3 +29,28 Variable *VariableModel::createVariable(const QString &name) noexcept
22 29
23 30 return impl->m_Variables.back().get();
24 31 }
32
33 int VariableModel::columnCount(const QModelIndex &parent) const
34 {
35 Q_UNUSED(parent);
36
37 return NB_COLUMNS;
38 }
39
40 int VariableModel::rowCount(const QModelIndex &parent) const
41 {
42 Q_UNUSED(parent);
43
44 return impl->m_Variables.size();
45 }
46
47 QVariant VariableModel::data(const QModelIndex &index, int role) const
48 {
49 return QVariant{};
50 }
51
52 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
53 {
54
55 return QVariant{};
56 }
General Comments 0
You need to be logged in to leave comments. Login now