OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
search.hpp
Go to the documentation of this file.
1 #ifndef CSM_TOOLS_SEARCH_H
2 #define CSM_TOOLS_SEARCH_H
3 
4 #include <string>
5 #include <set>
6 
7 #include <QRegExp>
8 #include <QMetaType>
9 
10 class QModelIndex;
11 
12 namespace CSMDoc
13 {
14  class Messages;
15  class Document;
16 }
17 
18 namespace CSMWorld
19 {
20  class IdTableBase;
21  class UniversalId;
22 }
23 
24 namespace CSMTools
25 {
26  class Search
27  {
28  public:
29 
30  enum Type
31  {
32  Type_Text = 0,
34  Type_Id = 2,
38  };
39 
40  private:
41 
43  std::string mText;
44  QRegExp mRegExp;
45  int mValue;
46  std::set<int> mColumns;
47  int mIdColumn;
51 
52  void searchTextCell (const CSMWorld::IdTableBase *model, const QModelIndex& index,
53  const CSMWorld::UniversalId& id, bool writable, CSMDoc::Messages& messages) const;
54 
55  void searchRegExCell (const CSMWorld::IdTableBase *model, const QModelIndex& index,
56  const CSMWorld::UniversalId& id, bool writable, CSMDoc::Messages& messages) const;
57 
59  const QModelIndex& index, const CSMWorld::UniversalId& id, bool writable,
60  CSMDoc::Messages& messages) const;
61 
62  QString formatDescription (const QString& description, int pos, int length) const;
63 
64  QString flatten (const QString& text) const;
65 
66  public:
67 
68  Search();
69 
70  Search (Type type, const std::string& value);
71 
72  Search (Type type, const QRegExp& value);
73 
74  Search (Type type, int value);
75 
76  // Configure search for the specified model.
77  void configure (const CSMWorld::IdTableBase *model);
78 
79  // Search row in \a model and store results in \a messages.
80  //
81  // \attention *this needs to be configured for \a model.
82  void searchRow (const CSMWorld::IdTableBase *model, int row,
83  CSMDoc::Messages& messages) const;
84 
85  void setPadding (int before, int after);
86 
87  // Configuring *this for the model is not necessary when calling this function.
88  void replace (CSMDoc::Document& document, CSMWorld::IdTableBase *model,
89  const CSMWorld::UniversalId& id, const std::string& messageHint,
90  const std::string& replaceText) const;
91 
92  // Check if model still matches search results.
93  bool verify (CSMDoc::Document& document, CSMWorld::IdTableBase *model,
94  const CSMWorld::UniversalId& id, const std::string& messageHint) const;
95  };
96 }
97 
98 Q_DECLARE_METATYPE (CSMTools::Search)
99 
100 #endif
void searchRegExCell(const CSMWorld::IdTableBase *model, const QModelIndex &index, const CSMWorld::UniversalId &id, bool writable, CSMDoc::Messages &messages) const
Definition: search.cpp:41
Type mType
Definition: search.hpp:42
QString flatten(const QString &text) const
Definition: search.cpp:113
std::set< int > mColumns
Definition: search.hpp:46
QString formatDescription(const QString &description, int pos, int length) const
Definition: search.cpp:90
void searchRecordStateCell(const CSMWorld::IdTableBase *model, const QModelIndex &index, const CSMWorld::UniversalId &id, bool writable, CSMDoc::Messages &messages) const
Definition: search.cpp:67
void searchTextCell(const CSMWorld::IdTableBase *model, const QModelIndex &index, const CSMWorld::UniversalId &id, bool writable, CSMDoc::Messages &messages) const
Definition: search.cpp:14
Definition: search.hpp:35
int mPaddingAfter
Definition: search.hpp:50
Definition: messages.hpp:38
int mIdColumn
Definition: search.hpp:47
Definition: search.hpp:32
Definition: search.hpp:33
bool verify(CSMDoc::Document &document, CSMWorld::IdTableBase *model, const CSMWorld::UniversalId &id, const std::string &messageHint) const
Definition: search.cpp:280
Definition: search.hpp:36
int mPaddingBefore
Definition: search.hpp:49
int mTypeColumn
Definition: search.hpp:48
Definition: document.hpp:57
void configure(const CSMWorld::IdTableBase *model)
Definition: search.cpp:147
QRegExp mRegExp
Definition: search.hpp:44
void searchRow(const CSMWorld::IdTableBase *model, int row, CSMDoc::Messages &messages) const
Definition: search.cpp:205
std::string mText
Definition: search.hpp:43
void replace(CSMDoc::Document &document, CSMWorld::IdTableBase *model, const CSMWorld::UniversalId &id, const std::string &messageHint, const std::string &replaceText) const
Definition: search.cpp:252
Definition: search.hpp:34
Search()
Definition: search.cpp:123
void setPadding(int before, int after)
Definition: search.cpp:246
Definition: idtablebase.hpp:12
Definition: search.hpp:37
Definition: search.hpp:26
Type
Definition: search.hpp:30
int mValue
Definition: search.hpp:45
Definition: universalid.hpp:12