QCodeEdit  2.2
qlinemarksinfocenter.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
4 **
5 ** This file is part of the Edyuk project <http://edyuk.org>
6 **
7 ** This file may be used under the terms of the GNU General Public License
8 ** version 3 as published by the Free Software Foundation and appearing in the
9 ** file GPL.txt included in the packaging of this file.
10 **
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 **
14 ****************************************************************************/
15 
16 #ifndef _QLINE_MARKS_INFO_CENTER_H_
17 #define _QLINE_MARKS_INFO_CENTER_H_
18 
30 #include "qce-config.h"
31 
32 #include <QColor>
33 #include <QPixmap>
34 #include <QObject>
35 #include <QMetaType>
36 #include <QStringList>
37 
38 class QEditor;
39 class QDataStream;
41 
42 struct QLineMark
43 {
44  inline QLineMark() : line(-1) {}
45 
46  inline QLineMark(const QString& f, int l, int m)
47  : mark(m), line(l), file(f)
48  {}
49 
50  inline bool operator == (const QLineMark& m)
51  { return (line == m.line) && (file == m.file) && (mark == m.mark); }
52 
53  inline bool operator != (const QLineMark& m)
54  { return (line != m.line) || (file != m.file) || (mark != m.mark); }
55 
56  int mark;
57  int line;
58  QString file;
59 };
60 
61 Q_DECLARE_METATYPE(QLineMark)
62 
63 typedef QList<QLineMark> QLineMarkList;
64 
65 Q_DECLARE_TYPEINFO(QLineMark, Q_MOVABLE_TYPE);
66 
68 {
69  inline QLineMarkHandle() : line(0) {}
70 
71  inline QLineMarkHandle(const QString& f, QDocumentLineHandle *l, int m)
72  : mark(m), line(l), file(f)
73  {}
74 
75  inline bool operator == (const QLineMarkHandle& m)
76  { return (line == m.line) && (file == m.file) && (mark == m.mark); }
77 
78  inline bool operator != (const QLineMarkHandle& m)
79  { return (line != m.line) || (file != m.file) || (mark != m.mark); }
80 
81  int mark;
82  QDocumentLineHandle *line;
83  QString file;
84 };
85 
86 Q_DECLARE_METATYPE(QLineMarkHandle)
87 
88 typedef QList<QLineMarkHandle> QLineMarkHandleList;
89 
90 Q_DECLARE_TYPEINFO(QLineMarkHandle, Q_MOVABLE_TYPE);
91 
92 QCE_EXPORT QDataStream& operator >> (QDataStream& d, QLineMark& m);
93 QCE_EXPORT QDataStream& operator << (QDataStream& d, const QLineMark& m);
94 
96 {
97  inline QLineMarkType()
98  : user(false), focus(false), priority(-1), persistency(0)
99  {}
100 
101  bool user;
102  bool focus;
103  QString id;
104  QPixmap icon;
105  QColor color;
106  int priority;
107  int persistency;
108  QStringList rules;
109 };
110 
111 Q_DECLARE_METATYPE(QLineMarkType)
112 
113 typedef QList<QLineMarkType> QLineMarkTypeList;
114 
115 Q_DECLARE_TYPEINFO(QLineMarkType, Q_MOVABLE_TYPE);
116 
118 {
119  friend class QEditor;
120  friend class QCodeEdit;
121 
122  Q_OBJECT
123 
124  public:
125  static QLineMarksInfoCenter* instance();
126  static void destroy();
127 
128  QLineMarkList marks(const QString& file = QString());
129 
130  QString markTypeId(int id);
131  int markTypeId(const QString& id);
132 
133  QLineMarkType markType(int id);
134  QLineMarkType markType(const QString& id);
135 
136  int priority(const QList<int>& marks);
137  QString priority(const QStringList& marks);
138 
139  QStringList availableMarkTypes(const QString& context = QString());
140  QList<QStringList> marksLayout(const QString& context = QString());
141 
142  public slots:
143  void loadMarks(const QString& f);
144  void saveMarks(const QString& f);
145 
146  void loadMarkTypes(const QString& f);
147 
148  void clear();
149 
150  void removeMarks(const QString& file);
151 
152  void addLineMark(const QLineMark& mark);
153  void toggleLineMark(const QLineMark& mark);
154  void removeLineMark(const QLineMark& mark);
155 
156  void addLineMark(const QLineMarkHandle& mark);
157  void toggleLineMark(const QLineMarkHandle& mark);
158  void removeLineMark(const QLineMarkHandle& mark);
159 
160  void flush(const QString& file);
161 
162  signals:
163  void lineMarkAdded(const QLineMark& mark);
164  void lineMarkRemoved(const QLineMark& mark);
165 
166  protected:
168  virtual ~QLineMarksInfoCenter();
169 
170  protected slots:
171  void cursorMoved(QEditor *e);
172  void lineDeleted(QDocumentLineHandle *h);
173  void markChanged(const QString& f, QDocumentLineHandle *h, int mark, bool on);
174 
175  private:
176  QLineMarkList m_delayed;
177  QLineMarkHandleList m_lineMarks;
178  QLineMarkTypeList m_lineMarkTypes;
179 
180  static QLineMarksInfoCenter *m_instance;
181 };
182 
183 #endif // !_QLINE_MARKS_INFO_CENTER_H_
#define QCE_EXPORT
Macro needed for cross-platform shared libraries creation.
Definition: qce-config.h:40
Utility file for shared library creation.
A text editing widget.
Definition: qeditor.h:55
Definition: qlinemarksinfocenter.h:95
Definition: qlinemarksinfocenter.h:42
A class managing line marks accross all managed editors.
Definition: qlinemarksinfocenter.h:117
Private implementation of a document line.
Definition: qdocumentline_p.h:55
Definition: qlinemarksinfocenter.h:67
A thin layer over QEditor.
Definition: qcodeedit.h:41