DLS  1.6
Model.h
1 /*****************************************************************************
2  *
3  * Copyright (C) 2009 - 2017 Florian Pose <fp@igh-essen.com>
4  *
5  * This file is part of the DLS widget library.
6  *
7  * The DLS widget library is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation, either version 3 of the License,
10  * or (at your option) any later version.
11  *
12  * The DLS widget library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with the DLS widget library. If not, see
19  * <http://www.gnu.org/licenses/>.
20  *
21  ****************************************************************************/
22 
23 #ifndef DLS_MODEL_H
24 #define DLS_MODEL_H
25 
26 #include "export.h"
27 
28 #include "DlsTypes.h"
29 
30 #include <QList>
31 #include <QString>
32 #include <QAbstractItemModel>
33 
34 /*****************************************************************************/
35 
36 namespace LibDLS {
37  class Directory;
38 }
39 
40 namespace DLS {
41  class Graph;
42  class Section;
43  class Layer;
44 }
45 
46 namespace QtDls {
47 
48 class Dir;
49 class Channel;
50 
51 class DLSWIDGETS_PUBLIC Model:
52  public QAbstractItemModel
53 {
54  friend class DLS::Graph;
55  friend class DLS::Section;
56  friend class DLS::Layer;
57  friend class Dir;
58 
59  public:
60  Model();
61  ~Model();
62 
63  void addLocalDir(LibDLS::Directory *);
64  void removeDir(LibDLS::Directory *);
65  void clear();
66 
67  void update();
68 
69  bool hasUnusedDirs(DLS::Graph *) const;
70  void removeUnusedDirs(DLS::Graph *);
71 
72  enum NodeType { InvalidNode, DirNode, JobNode, ChannelNode };
73  Q_ENUM(NodeType)
74 
75  enum Roles {
76  NodeTypeRole = Qt::UserRole + 1,
77  DirRole,
78  };
79  Q_ENUM(Roles)
80 
81  NodeType nodeType(const QModelIndex &) const;
82 
83  LibDLS::Directory *dir(const QModelIndex &);
84  LibDLS::Directory *dir(const QModelIndex &) const;
85 
86  Channel *getChannel(QUrl);
87 
88  class Exception
89  {
90  public:
91  Exception(const QString &);
92  QString msg;
93  };
94 
95  // from QAbstractItemModel
96  int rowCount(const QModelIndex &) const;
97  int columnCount(const QModelIndex &) const;
98  QModelIndex index(int, int, const QModelIndex &) const;
99  QModelIndex parent(const QModelIndex &) const;
100  QVariant data(const QModelIndex &, int) const;
101  QVariant headerData(int, Qt::Orientation, int) const;
102  Qt::ItemFlags flags(const QModelIndex &) const;
103  QStringList mimeTypes() const;
104  QMimeData *mimeData(const QModelIndexList &) const;
105  QHash<int, QByteArray> roleNames() const override;
106 
107  QModelIndex dirIndex(const Dir*) const;
108 
109  protected:
110  void prepareLayoutChange();
111  void finishLayoutChange();
112 
113  private:
114  QList<Dir *> dirs;
115 };
116 
117 } // namespace
118 
119 #endif
120 
121 /****************************************************************************/
DLS Data Directory.
Definition: Dir.h:82
Definition: Graph.h:51
Graph section layer.
Definition: Layer.h:58
Definition: Channel.h:44
Graph widget.
Definition: Graph.h:104
Definition: Graph.h:56
Graph section.
Definition: Section.h:61