itom  4.1.0
bookmarkModel.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************** */
22 
23 #ifndef BOOKMARKMODEL_H
24 #define BOOKMARKMODEL_H
25 
26 #include "../common/sharedStructures.h"
27 
28 #include <qabstractitemmodel.h>
29 #include <qlist.h>
30 #include <qaction.h>
31 #include <qicon.h>
32 #include <qstring.h>
33 #include <QDebug>
34 
35 
36 namespace ito {
37 
39 
43 {
45  BookmarkItem(): filename(""), lineIdx(-1), enabled(true) {}
46  BookmarkItem(const QString &filename_, int lineidx_) : filename(filename_), lineIdx(lineidx_), enabled(true) {}
47  QString filename;
48  int lineIdx;
49  bool enabled;
51  bool isValid() const { return lineIdx != -1; }
52 };
53 
54 } //end namespace ito
55 
56 Q_DECLARE_METATYPE(ito::BookmarkItem) //must be outside of namespace
57 
58 namespace ito
59 {
60 
61 QDataStream &operator<<(QDataStream &out, const BookmarkItem &obj);
62 QDataStream &operator>>(QDataStream &in, BookmarkItem &obj);
63 
64 class BookmarkModel : public QAbstractItemModel
65 {
66  Q_OBJECT
67 
68 public:
69  enum BookmarkRole
70  {
71  RoleFilename = Qt::UserRole + 1,
72  RoleLineIdx = Qt::UserRole + 2,
73  RoleEnabled = Qt::UserRole + 3
74  };
75 
76  BookmarkModel();
77  ~BookmarkModel();
78 
79  RetVal saveState();
80  RetVal restoreState();
81 
82  QVariant data(const QModelIndex &index, int role) const;
83  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
84  QModelIndex parent(const QModelIndex &index) const;
85  int rowCount(const QModelIndex &parent = QModelIndex()) const;
86  int columnCount(const QModelIndex &parent = QModelIndex()) const;
87 
88  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
89 
90  RetVal addBookmark(const BookmarkItem &item);
91  RetVal deleteBookmark(const BookmarkItem &item);
92  RetVal deleteBookmarks(const QList<BookmarkItem> &items);
93  RetVal deleteAllBookmarks();
94  RetVal changeBookmark(const BookmarkItem &item, const QString &newFilename, int newLineNo);
95 
96  QList<BookmarkItem> getBookmarks(const QString &filenameFilter = QString()) const;
97 
98  QAction *bookmarkNextAction() const { return m_pBookmarkNext; }
99  QAction *bookmarkPreviousAction() const { return m_pBookmarkPrevious; }
100  QAction *bookmarkClearAllAction() const { return m_pBookmarkClearAll; }
101 
102  bool bookmarkExists(const BookmarkItem &item) const;
103  bool bookmarkExists(const QString &filename, int lineno) const;
104 
105  void gotoBookmark(const QModelIndex &index);
106 
107 protected:
108  const BookmarkItem& itemFromModelIndex(const QModelIndex &index) const;
109  QModelIndex modelIndexFromItem(const BookmarkItem &item) const;
110  void updateActions();
111 
112 private:
113  QList<BookmarkItem> m_bookmarks;
114  QList<QString> m_headers;
115  QList<QVariant> m_alignment;
116  Qt::CaseSensitivity m_filenameCaseSensitivity;
117 
118  int m_currentIndex;
119  QAction *m_pBookmarkNext;
120  QAction *m_pBookmarkPrevious;
121  QAction *m_pBookmarkClearAll;
122  BookmarkItem m_invalidBookmarkItem;
123 
124 Q_SIGNALS:
125  void bookmarkAdded(const BookmarkItem &item);
126  void bookmarkDeleted(const BookmarkItem &item);
127  void gotoBookmark(const BookmarkItem &item);
129 public Q_SLOTS:
130  void clearAllBookmarks();
131  void gotoNextBookmark();
132  void gotoPreviousBookmark();
133 };
134 
135 } //end namespace ito
136 
137 
138 #endif
model for management of all bookmarks. This model will be displayed by a viewer-widget in the main wi...
Definition: apiFunctionsGraph.cpp:39
bool enabled
Definition: bookmarkModel.h:49
BookmarkItem()
Definition: bookmarkModel.h:45
QString filename
Definition: bookmarkModel.h:47
item of BookmarkModel
Definition: bookmarkModel.h:42
int lineIdx
Definition: bookmarkModel.h:48