Tulip  4.2.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
ParameterListModel.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef PARAMETERLISTMODEL_H
22 #define PARAMETERLISTMODEL_H
23 
24 #include "tulip/TulipModel.h"
25 #include <tulip/WithParameter.h>
26 #include <tulip/DataSet.h>
27 #include <tulip/TulipMetaTypes.h>
28 #include <QtCore/QVector>
29 
30 namespace tlp {
31 
32 class TLP_QT_SCOPE ParameterListModel : public TulipModel {
33  struct ParamInfos {
34  inline ParamInfos() {}
35  inline ParamInfos(bool m,const QString &n,const QString &d, const std::string& t): mandatory(m), name(n),desc(d), type(t) {}
36  bool mandatory;
37  QString name;
38  QString desc;
39  std::string type;
40 
41  QString getNameForDisplay() {
42  // if a a subtype prefix exists, don't show it
43  int pos = name.indexOf("::");
44 
45  if (pos != -1)
46  return name.mid(pos + 2);
47  else
48  return name;
49  }
50  };
51 
52  struct ParamInfosSorter {
53  bool operator()(ParamInfos a, ParamInfos b);
54  };
55 
56  QVector<ParamInfos> _params;
57  tlp::DataSet _data;
58  tlp::Graph* _graph;
59 
60 public:
61  explicit ParameterListModel(const tlp::ParameterDescriptionList &params, tlp::Graph *graph=NULL, QObject *parent=NULL);
62  tlp::DataSet parametersValues() const;
63  void setParametersValues(const tlp::DataSet& data);
64 
65  QModelIndex index(int row, int column,const QModelIndex &parent = QModelIndex()) const;
66  QModelIndex parent(const QModelIndex &child) const;
67  int rowCount(const QModelIndex &parent = QModelIndex()) const;
68  int columnCount(const QModelIndex &parent = QModelIndex()) const;
69  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
70  QVariant headerData(int section, Qt::Orientation orientation, int role) const;
71  Qt::ItemFlags flags(const QModelIndex &index) const;
72  bool setData(const QModelIndex &index, const QVariant &value, int role);
73 };
74 
75 }
76 
77 #endif // PARAMETERLISTMODEL_H
78 ///@endcond