1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-03 12:45:38 +00:00
openmw/apps/opencs/model/tools/search.hpp

96 lines
2.7 KiB
C++
Raw Normal View History

#ifndef CSM_TOOLS_SEARCH_H
#define CSM_TOOLS_SEARCH_H
2015-03-28 11:05:49 +00:00
#include <set>
2022-09-22 18:26:05 +00:00
#include <string>
#include <QMetaType>
#include <QRegularExpression>
class QModelIndex;
namespace CSMDoc
{
class Messages;
2015-04-16 16:50:22 +00:00
class Document;
}
namespace CSMWorld
{
class IdTableBase;
class UniversalId;
}
namespace CSMTools
{
class Search
{
2022-09-22 18:26:05 +00:00
public:
enum Type
{
Type_Text = 0,
Type_TextRegEx = 1,
Type_Id = 2,
Type_IdRegEx = 3,
Type_RecordState = 4,
Type_None
};
private:
Type mType;
std::string mText;
QRegularExpression mRegExp;
2022-09-22 18:26:05 +00:00
int mValue;
bool mCase;
std::set<int> mColumns;
int mIdColumn;
int mTypeColumn;
int mPaddingBefore;
int mPaddingAfter;
void searchTextCell(const CSMWorld::IdTableBase* model, const QModelIndex& index,
const CSMWorld::UniversalId& id, bool writable, CSMDoc::Messages& messages) const;
void searchRegExCell(const CSMWorld::IdTableBase* model, const QModelIndex& index,
const CSMWorld::UniversalId& id, bool writable, CSMDoc::Messages& messages) const;
void searchRecordStateCell(const CSMWorld::IdTableBase* model, const QModelIndex& index,
const CSMWorld::UniversalId& id, bool writable, CSMDoc::Messages& messages) const;
QString formatDescription(const QString& description, int pos, int length) const;
QString flatten(const QString& text) const;
public:
Search();
Search(Type type, bool caseSensitive, const std::string& value);
Search(Type type, bool caseSensitive, const QRegularExpression& value);
2022-09-22 18:26:05 +00:00
Search(Type type, bool caseSensitive, int value);
// Configure search for the specified model.
void configure(const CSMWorld::IdTableBase* model);
// Search row in \a model and store results in \a messages.
//
// \attention *this needs to be configured for \a model.
void searchRow(const CSMWorld::IdTableBase* model, int row, CSMDoc::Messages& messages) const;
void setPadding(int before, int after);
// Configuring *this for the model is not necessary when calling this function.
void replace(CSMDoc::Document& document, CSMWorld::IdTableBase* model, const CSMWorld::UniversalId& id,
const std::string& messageHint, const std::string& replaceText) const;
// Check if model still matches search results.
bool verify(CSMDoc::Document& document, CSMWorld::IdTableBase* model, const CSMWorld::UniversalId& id,
const std::string& messageHint) const;
};
}
2022-09-22 18:26:05 +00:00
Q_DECLARE_METATYPE(CSMTools::Search)
#endif