OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
FAR.h
Go to the documentation of this file.
1
4// ###########################################################################################################################################################################################################################################################################################################################
5
6#pragma once
7
8// Toolkit API header
10#include "OTCore/Flags.h"
11#include "OToolkitAPI/Tool.h"
12
13// Qt header
14#include <QtCore/qstringlist.h>
15
16// std header
17#include <list>
18
19class QLabel;
20class QWidget;
21class QGroupBox;
22class QCheckBox;
23class QLineEdit;
24class QTabWidget;
25class QVBoxLayout;
26class QHBoxLayout;
27class QGridLayout;
28class QPlainTextEdit;
29class QPushButton;
30
31namespace ot { class Splitter; }
32
33class FARMatch {
34public:
35 FARMatch() : m_line(0) {};
36 FARMatch(const QString& _fullPath, int _line, const QString& _text) : m_fullPath(_fullPath), m_line(_line), m_text(_text) {};
37 FARMatch(const FARMatch& _other) : m_text(_other.m_text), m_fullPath(_other.m_fullPath), m_line(_other.m_line) {};
38
39 void setText(const QString& _text) { m_text = _text; };
40 const QString& text(void) const { return m_text; };
41
42 void setLine(int _line) { m_line = _line; };
43 int line(void) const { return m_line; };
44
45 void setFullPath(const QString& _path) { m_fullPath = _path; };
46 const QString& fullPath(void) const { return m_fullPath; };
47
48private:
49 QString m_text;
50 int m_line;
51 QString m_fullPath;
52};
53
54class FARFile;
55class FARDirectory;
56
57class FARFilter {
58public:
60 NoFlags = 0x00,
61 StartsWith = 0x01,
62 Contains = 0x02,
63 EndsWith = 0x04,
64 AsRegex = 0x08,
65 CheckCase = 0x10
66 };
68
69 FARFilter();
70 FARFilter(const FARFilter& _other);
71
72 bool validate(const FARFile& _file) const;
73 bool validate(const FARDirectory& _dir) const;
74
75 void setWhitelistFiles(const QStringList& _whitelist) { m_whitelistFiles = _whitelist; };
76 const QStringList& whitelistFiles(void) const { return m_whitelistFiles; };
77
78 void setWhitelistFilesFlags(FilterFlags _flags) { m_whitelistFilesFlags = _flags; };
79 FilterFlags whitelistFilesFlags(void) const { return m_whitelistFilesFlags; };
80
81 void setBlacklistFiles(const QStringList& _blacklist) { m_blacklistFiles = _blacklist; };
82 const QStringList& blacklistFiles(void) const { return m_blacklistFiles; };
83
84 void setBlacklistFilesFlags(FilterFlags _flags) { m_blacklistFilesFlags = _flags; };
85 FilterFlags blacklistFilesFlags(void) const { return m_blacklistFilesFlags; };
86
87 void setWhitelistDirectories(const QStringList& _whitelist) { m_whitelistDirectories = _whitelist; };
88 const QStringList& whitelistDirectories(void) const { return m_whitelistDirectories; };
89
90 void setWhitelistDirectoriesFlags(FilterFlags _flags) { m_whitelistDirectoriesFlags = _flags; };
91 FilterFlags whitelistDirectoriesFlags(void) const { return m_whitelistDirectoriesFlags; };
92
93 void setBlacklistDirectories(const QStringList& _blacklist) { m_blacklistDirectories = _blacklist; };
94 const QStringList& blacklistDirectories(void) const { return m_blacklistDirectories; };
95
96 void setBlacklistDirectoriesFlags(FilterFlags _flags) { m_blacklistDirectoriesFlags = _flags; };
97 FilterFlags blacklistDirectoriesFlags(void) const { return m_blacklistDirectoriesFlags; };
98
99private:
100 QStringList m_whitelistFiles;
101 FilterFlags m_whitelistFilesFlags;
102 QStringList m_blacklistFiles;
103 FilterFlags m_blacklistFilesFlags;
104 QStringList m_whitelistDirectories;
105 FilterFlags m_whitelistDirectoriesFlags;
106 QStringList m_blacklistDirectories;
107 FilterFlags m_blacklistDirectoriesFlags;
108};
109
110class FARFile {
111public:
112
113 FARFile(const QString& _fullPath);
114 FARFile(const FARFile& _other);
115
116 bool exists(void) const;
117
118 bool readAll(void);
119
120 bool writeAll(void);
121
122 bool findText(const QString& _text, FARFilter::FilterFlags _textFilter, std::list<FARMatch>& _matches, int& _longestText, int& _longestPath) const;
123
124 bool replaceText(const QString& _text, const QString& _newText, FARFilter::FilterFlags _textFilter, std::list<FARMatch>& _matches, int& _longestText, int& _longestPath);
125
126 void setFullPath(const QString& _fullPath) { m_fullPath = _fullPath; };
127 const QString& fullPath(void) const { return m_fullPath; };
128
129 void setNameOnly(const QString& _name) { m_nameOnly = _name; };
130 const QString& nameOnly(void) const { return m_nameOnly; };
131
132 void setFileExtension(const QString& _extension) { m_fileExtension = _extension; };
133 const QString& fileExtension(void) const { return m_fileExtension; };
134
135 void setTextLines(const QStringList& _lines) { m_textLines = _lines; };
136 const QStringList& textLines(void) const { return m_textLines; };
137
138private:
139 QString m_fullPath;
140 QString m_nameOnly;
141 QString m_fileExtension;
142 QStringList m_textLines;
143};
144
146public:
147
148 FARDirectory(const QString& _fullPath);
149 FARDirectory(const FARDirectory& _parentDirectory, const QString& _directoryName);
150 FARDirectory(const FARDirectory& _other);
151
152 bool exists(void) const;
153
156 bool scanFiles(const FARFilter& _filter, int& _counter);
157
162 bool readAllFiles(bool _topLevelOnly = true);
163
167 bool scanDirectories(const FARFilter& _filter, int& _counter, bool _topLevelOnly = true);
168
173 bool scanAll(const FARFilter& _filter, int& _fileCounter, int& _directoryCounter, bool _topLevelOnly = true, bool _readFiles = false);
174
175 bool findText(const QString& _text, FARFilter::FilterFlags _textFilter, std::list<FARMatch>& _matches, int& _longestText, int& _longestPath, bool _topLevelOnly = true) const;
176
177 bool replaceText(const QString& _text, const QString& _newText, FARFilter::FilterFlags _textFilter, std::list<FARMatch>& _matches, int& _longestText, int& _longestPath, bool _topLevelOnly = true);
178
179 void setFullPath(const QString& _path) { m_fullPath = _path; };
180 const QString& fullPath(void) const { return m_fullPath; };
181
182 void setNameOnly(const QString& _name) { m_nameOnly = _name; };
183 const QString& nameOnly(void) const { return m_nameOnly; };
184
185 void setFiles(const std::list<FARFile>& _files) { m_files = _files; };
186 const std::list<FARFile>& files(void) const { return m_files; };
187
188 void setDirectories(const std::list<FARDirectory>& _directories) { m_directories = _directories; };
189 const std::list<FARDirectory>& directories(void) const { return m_directories; };
190
191private:
192 QString m_fullPath;
193 QString m_nameOnly;
194 std::list<FARFile> m_files;
195 std::list<FARDirectory> m_directories;
196};
197
198class FAR : public QObject, public otoolkit::Tool {
199 Q_OBJECT
200public:
201 FAR();
202 virtual ~FAR();
203
204 // ###########################################################################################################################################################################################################################################################################################################################
205
206 // API base functions
207
210 virtual QString getToolName(void) const override;
211
213 virtual bool runTool(QMenu* _rootMenu, otoolkit::ToolWidgets& _content) override;
214
215 virtual void restoreToolSettings(QSettings& _settings) override;
216
218 virtual bool prepareToolShutdown(QSettings& _settings) override;
219
220private Q_SLOTS:
221 void slotBrowseRoot(void);
222 void slotFindText(void);
223 void slotReplaceText(void);
224 void slotLock(void);
225 void slotUnlock(void);
226
227private:
228 struct FilterGroup {
229 QLabel* label;
230 QPlainTextEdit* edit;
231 QCheckBox* checkCase;
232 QCheckBox* starts;
233 QCheckBox* contains;
234 QCheckBox* ends;
235 QCheckBox* regex;
236 QVBoxLayout* layout;
237 };
238
240 void setupFilter(FARFilter& _filter) const;
241 FARFilter::FilterFlags filterFlagsFromGroup(const FilterGroup& _group) const;
242
243 void workerFindText(QString _root, QString _text, FARFilter::FilterFlags _textFilter, FARFilter _filter);
244 void workerFindTextLogic(const QString& _root, const QString& _text, FARFilter::FilterFlags _textFilter, const FARFilter& _filter);
245
246 void workerReplaceText(QString _root, QString _text, QString _newText, FARFilter::FilterFlags _textFilter, FARFilter _filter);
247 void workerReplaceTextLogic(const QString& _root, const QString& _text, const QString& _newText, FARFilter::FilterFlags _textFilter, FARFilter _filter);
248
249 FilterGroup createFilterGroup(const QString& _labelText, QGridLayout* _layout, int _row);
250 void restoreFilterGroupSettings(FilterGroup& _group, const QString& _settingsKey, QSettings& _settings);
251
252 void saveFilterGroup(const FilterGroup& _group, const QString& _settingsKey, QSettings& _settings);
253
254 ot::WidgetView* m_root;
255
256 QWidget* m_leftGridW;
257 QGridLayout* m_leftGrid;
258
259 QLabel* m_leftTitle;
260
261 FilterGroup m_whitelistFiles;
262 FilterGroup m_blacklistFiles;
263 FilterGroup m_whitelistDirectories;
264 FilterGroup m_blacklistDirectories;
265
266 QWidget* m_rightLayoutW;
267 QVBoxLayout* m_rightLayout;
268
269 QHBoxLayout* m_rightTopLayout;
270
271 QLabel* m_rootDirL;
272 QLineEdit* m_rootDir;
273 QPushButton* m_browseRootDir;
274
275 QTabWidget* m_findModeTab;
276
277 QWidget* m_findTextLayoutW;
278 QVBoxLayout* m_findTextLayout;
279 QGridLayout* m_findTextTopLayout;
280 QHBoxLayout* m_findTextButtonLayout;
281 QLabel* m_findTextL;
282 QLineEdit* m_findText;
283 QLabel* m_findTextMode;
284 QCheckBox* m_findTextCaseSensitive;
285 QCheckBox* m_findTextStartsWith;
286 QCheckBox* m_findTextContains;
287 QCheckBox* m_findTextEndsWith;
288 QCheckBox* m_findTextRegex;
289 QPushButton* m_findTextBtn;
290
291 QWidget* m_replaceTextLayoutW;
292 QVBoxLayout* m_replaceTextLayout;
293 QGridLayout* m_replaceTextTopLayout;
294 QHBoxLayout* m_replaceTextButtonLayout;
295 QLabel* m_replaceTextL;
296 QLineEdit* m_replaceText;
297 QCheckBox* m_replaceTextCaseSensitive;
298 QLabel* m_replaceWithTextL;
299 QLineEdit* m_replaceWithText;
300 QPushButton* m_replaceTextBtn;
301};
302
#define OT_ADD_FLAG_FUNCTIONS(___enumName)
Will add the default bitwise operations for the provided private 32/64 bit bitfield....
Definition Flags.h:129
This file contains defines that may be used simplyfy class creation.
Definition FAR.h:145
bool exists(void) const
Definition FAR.cpp:331
void setDirectories(const std::list< FARDirectory > &_directories)
Definition FAR.h:188
const QString & fullPath(void) const
Definition FAR.h:180
void setNameOnly(const QString &_name)
Definition FAR.h:182
const std::list< FARFile > & files(void) const
Definition FAR.h:186
bool scanFiles(const FARFilter &_filter, int &_counter)
Find all files in this directory. Result is buffered.
Definition FAR.cpp:336
bool readAllFiles(bool _topLevelOnly=true)
Read all the files found in this directory. Note that scan files must be called first if the files ar...
Definition FAR.cpp:358
bool findText(const QString &_text, FARFilter::FilterFlags _textFilter, std::list< FARMatch > &_matches, int &_longestText, int &_longestPath, bool _topLevelOnly=true) const
Definition FAR.cpp:424
FARDirectory(const QString &_fullPath)
Definition FAR.cpp:316
const std::list< FARDirectory > & directories(void) const
Definition FAR.h:189
void setFullPath(const QString &_path)
Definition FAR.h:179
const QString & nameOnly(void) const
Definition FAR.h:183
bool scanAll(const FARFilter &_filter, int &_fileCounter, int &_directoryCounter, bool _topLevelOnly=true, bool _readFiles=false)
Find all files and directories in this directory. Result is buffered.
Definition FAR.cpp:397
bool scanDirectories(const FARFilter &_filter, int &_counter, bool _topLevelOnly=true)
Find all the child directories in this directory. Result is buffered.
Definition FAR.cpp:370
bool replaceText(const QString &_text, const QString &_newText, FARFilter::FilterFlags _textFilter, std::list< FARMatch > &_matches, int &_longestText, int &_longestPath, bool _topLevelOnly=true)
Definition FAR.cpp:438
void setFiles(const std::list< FARFile > &_files)
Definition FAR.h:185
Definition FAR.h:110
void setTextLines(const QStringList &_lines)
Definition FAR.h:135
bool readAll(void)
Definition FAR.cpp:194
const QString & nameOnly(void) const
Definition FAR.h:130
void setFileExtension(const QString &_extension)
Definition FAR.h:132
void setFullPath(const QString &_fullPath)
Definition FAR.h:126
const QStringList & textLines(void) const
Definition FAR.h:136
bool replaceText(const QString &_text, const QString &_newText, FARFilter::FilterFlags _textFilter, std::list< FARMatch > &_matches, int &_longestText, int &_longestPath)
Definition FAR.cpp:285
bool exists(void) const
Definition FAR.cpp:236
const QString & fileExtension(void) const
Definition FAR.h:133
const QString & fullPath(void) const
Definition FAR.h:127
bool findText(const QString &_text, FARFilter::FilterFlags _textFilter, std::list< FARMatch > &_matches, int &_longestText, int &_longestPath) const
Definition FAR.cpp:241
bool writeAll(void)
Definition FAR.cpp:219
FARFile(const QString &_fullPath)
Definition FAR.cpp:185
void setNameOnly(const QString &_name)
Definition FAR.h:129
Definition FAR.h:57
void setBlacklistDirectoriesFlags(FilterFlags _flags)
Definition FAR.h:96
FilterFlags whitelistFilesFlags(void) const
Definition FAR.h:79
void setWhitelistFiles(const QStringList &_whitelist)
Definition FAR.h:75
void setWhitelistFilesFlags(FilterFlags _flags)
Definition FAR.h:78
void setBlacklistDirectories(const QStringList &_blacklist)
Definition FAR.h:93
FilterFlags blacklistFilesFlags(void) const
Definition FAR.h:85
void setBlacklistFiles(const QStringList &_blacklist)
Definition FAR.h:81
const QStringList & blacklistFiles(void) const
Definition FAR.h:82
const QStringList & blacklistDirectories(void) const
Definition FAR.h:94
void setWhitelistDirectories(const QStringList &_whitelist)
Definition FAR.h:87
FilterFlag
Definition FAR.h:59
@ StartsWith
Definition FAR.h:61
@ AsRegex
Definition FAR.h:64
@ CheckCase
Definition FAR.h:65
@ EndsWith
Definition FAR.h:63
@ NoFlags
Definition FAR.h:60
@ Contains
Definition FAR.h:62
void setWhitelistDirectoriesFlags(FilterFlags _flags)
Definition FAR.h:90
bool validate(const FARFile &_file) const
Definition FAR.cpp:56
FARFilter()
Definition FAR.cpp:41
FilterFlags whitelistDirectoriesFlags(void) const
Definition FAR.h:91
FilterFlags blacklistDirectoriesFlags(void) const
Definition FAR.h:97
ot::Flags< FilterFlag > FilterFlags
Definition FAR.h:67
const QStringList & whitelistFiles(void) const
Definition FAR.h:76
const QStringList & whitelistDirectories(void) const
Definition FAR.h:88
void setBlacklistFilesFlags(FilterFlags _flags)
Definition FAR.h:84
Definition FAR.h:198
virtual ~FAR()
Definition FAR.cpp:462
FAR()
Definition FAR.cpp:458
virtual void restoreToolSettings(QSettings &_settings) override
Definition FAR.cpp:611
virtual QString getToolName(void) const override
Return the unique tool name The name will be used to create all required menu entries.
Definition FAR.cpp:470
virtual bool prepareToolShutdown(QSettings &_settings) override
Stop all the logic of this tool.
Definition FAR.cpp:631
virtual bool runTool(QMenu *_rootMenu, otoolkit::ToolWidgets &_content) override
Create the central widget that will be displayed to the user in the main tab view.
Definition FAR.cpp:474
Definition FAR.h:33
void setFullPath(const QString &_path)
Definition FAR.h:45
FARMatch(const QString &_fullPath, int _line, const QString &_text)
Definition FAR.h:36
FARMatch()
Definition FAR.h:35
FARMatch(const FARMatch &_other)
Definition FAR.h:37
int line(void) const
Definition FAR.h:43
const QString & text(void) const
Definition FAR.h:40
void setLine(int _line)
Definition FAR.h:42
const QString & fullPath(void) const
Definition FAR.h:46
void setText(const QString &_text)
Definition FAR.h:39
The Flags class is a wrapper around a enum that allows bitwise operations (flags)....
Definition Flags.h:214
The WidgetView class is used to integrate the Qt-ADS functionallity into open twin.
Definition WidgetView.h:33
Definition Tool.h:27
Definition ToolWidgets.h:24
Definition Connector.h:8