itom
Loading...
Searching...
No Matches
bookmarkModel.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität 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
36namespace 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
56Q_DECLARE_METATYPE(ito::BookmarkItem) //must be outside of namespace
57
58namespace ito
59{
60
61QDataStream &operator<<(QDataStream &out, const BookmarkItem &obj);
62QDataStream &operator>>(QDataStream &in, BookmarkItem &obj);
63
64class BookmarkModel : public QAbstractItemModel
65{
66 Q_OBJECT
67
68public:
69 enum BookmarkRole
70 {
71 RoleFilename = Qt::UserRole + 1,
72 RoleLineIdx = Qt::UserRole + 2,
73 RoleEnabled = Qt::UserRole + 3
74 };
75
78
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);
92 RetVal deleteBookmarks(const QList<BookmarkItem> &items);
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
107protected:
108 const BookmarkItem& itemFromModelIndex(const QModelIndex &index) const;
109 QModelIndex modelIndexFromItem(const BookmarkItem &item) const;
110 void updateActions();
111
112private:
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
124Q_SIGNALS:
125 void bookmarkAdded(const BookmarkItem &item);
126 void bookmarkDeleted(const BookmarkItem &item);
127 void gotoBookmark(const BookmarkItem &item);
129public 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 bookmarkModel.h:65
int rowCount(const QModelIndex &parent=QModelIndex()) const
counts number of bookmarks in this model
Definition bookmarkModel.cpp:296
RetVal restoreState()
Restores the breakpoint model from the settings.
Definition bookmarkModel.cpp:137
RetVal deleteBookmark(const BookmarkItem &item)
delete a given bookmark
Definition bookmarkModel.cpp:200
QList< QVariant > m_alignment
Definition bookmarkModel.h:115
const BookmarkItem & itemFromModelIndex(const QModelIndex &index) const
returns BookmarkItem for given QModelIndex
Definition bookmarkModel.cpp:424
int columnCount(const QModelIndex &parent=QModelIndex()) const
counts number of columns in this model (corresponds to number of header-elements)
Definition bookmarkModel.cpp:306
void bookmarkAdded(const BookmarkItem &item)
void gotoBookmark(const BookmarkItem &item)
RetVal deleteBookmarks(const QList< BookmarkItem > &items)
delete the given bookmarks
Definition bookmarkModel.cpp:225
RetVal saveState()
Saves the breakpoint model into the settings.
Definition bookmarkModel.cpp:107
QVariant data(const QModelIndex &index, int role) const
overwritten data method of QAbstractItemModel
Definition bookmarkModel.cpp:319
QModelIndex parent(const QModelIndex &index) const
returns parent of given QModelIndex
Definition bookmarkModel.cpp:392
RetVal addBookmark(const BookmarkItem &item)
adds given bookmark to model
Definition bookmarkModel.cpp:174
RetVal deleteAllBookmarks()
delete all bookmarks
Definition bookmarkModel.cpp:252
void bookmarkDeleted(const BookmarkItem &item)
QList< QString > m_headers
Definition bookmarkModel.h:114
~BookmarkModel()
destructor
Definition bookmarkModel.cpp:94
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
returns QModelIndex for given row and column
Definition bookmarkModel.cpp:370
QList< BookmarkItem > m_bookmarks
Definition bookmarkModel.h:113
BookmarkModel()
constructor
Definition bookmarkModel.cpp:62
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
returns header element at given position
Definition bookmarkModel.cpp:405
Class for managing status values (like errors or warning)
Definition retVal.h:54
Definition apiFunctionsGraph.cpp:40
item of BookmarkModel
Definition bookmarkModel.h:43
QString filename
Definition bookmarkModel.h:47
BookmarkItem()
Definition bookmarkModel.h:45
bool enabled
Definition bookmarkModel.h:49
int lineIdx
Definition bookmarkModel.h:48