simplified search rules

search
Marc Zinnschlag 10 years ago
parent 128ccd8151
commit eaaf816dd3

@ -11,7 +11,7 @@
#include "../../model/world/universalid.hpp" #include "../../model/world/universalid.hpp"
void CSMTools::Search::searchTextCell (const CSMWorld::IdTableBase *model, void CSMTools::Search::searchTextCell (const CSMWorld::IdTableBase *model,
const QModelIndex& index, const CSMWorld::UniversalId& id, bool multiple, const QModelIndex& index, const CSMWorld::UniversalId& id,
CSMDoc::Messages& messages) const CSMDoc::Messages& messages) const
{ {
// using QString here for easier handling of case folding. // using QString here for easier handling of case folding.
@ -31,15 +31,12 @@ void CSMTools::Search::searchTextCell (const CSMWorld::IdTableBase *model,
messages.add (id, message.str(), hint.str()); messages.add (id, message.str(), hint.str());
if (!multiple)
break;
pos += search.length(); pos += search.length();
} }
} }
void CSMTools::Search::searchRegExCell (const CSMWorld::IdTableBase *model, void CSMTools::Search::searchRegExCell (const CSMWorld::IdTableBase *model,
const QModelIndex& index, const CSMWorld::UniversalId& id, bool multiple, const QModelIndex& index, const CSMWorld::UniversalId& id,
CSMDoc::Messages& messages) const CSMDoc::Messages& messages) const
{ {
QString text = model->data (index).toString(); QString text = model->data (index).toString();
@ -58,9 +55,6 @@ void CSMTools::Search::searchRegExCell (const CSMWorld::IdTableBase *model,
messages.add (id, message.str(), hint.str()); messages.add (id, message.str(), hint.str());
if (!multiple)
break;
pos += length; pos += length;
} }
} }
@ -134,7 +128,6 @@ void CSMTools::Search::configure (const CSMWorld::IdTableBase *model)
i, Qt::Horizontal, static_cast<int> (CSMWorld::ColumnBase::Role_Display)).toInt()); i, Qt::Horizontal, static_cast<int> (CSMWorld::ColumnBase::Role_Display)).toInt());
bool consider = false; bool consider = false;
bool multiple = false;
switch (mType) switch (mType)
{ {
@ -145,7 +138,6 @@ void CSMTools::Search::configure (const CSMWorld::IdTableBase *model)
CSMWorld::ColumnBase::isScript (display)) CSMWorld::ColumnBase::isScript (display))
{ {
consider = true; consider = true;
multiple = true;
} }
break; break;
@ -153,14 +145,10 @@ void CSMTools::Search::configure (const CSMWorld::IdTableBase *model)
case Type_Id: case Type_Id:
case Type_IdRegEx: case Type_IdRegEx:
if (CSMWorld::ColumnBase::isId (display)) if (CSMWorld::ColumnBase::isId (display) ||
{ CSMWorld::ColumnBase::isScript (display))
consider = true;
}
else if (CSMWorld::ColumnBase::isScript (display))
{ {
consider = true; consider = true;
multiple = true;
} }
break; break;
@ -178,7 +166,7 @@ void CSMTools::Search::configure (const CSMWorld::IdTableBase *model)
} }
if (consider) if (consider)
mColumns.insert (std::make_pair (i, multiple)); mColumns.insert (i);
} }
mIdColumn = model->findColumnIndex (CSMWorld::Columns::ColumnId_Id); mIdColumn = model->findColumnIndex (CSMWorld::Columns::ColumnId_Id);
@ -188,10 +176,9 @@ void CSMTools::Search::configure (const CSMWorld::IdTableBase *model)
void CSMTools::Search::searchRow (const CSMWorld::IdTableBase *model, int row, void CSMTools::Search::searchRow (const CSMWorld::IdTableBase *model, int row,
CSMDoc::Messages& messages) const CSMDoc::Messages& messages) const
{ {
for (std::map<int, bool>::const_iterator iter (mColumns.begin()); iter!=mColumns.end(); for (std::set<int>::const_iterator iter (mColumns.begin()); iter!=mColumns.end(); ++iter)
++iter)
{ {
QModelIndex index = model->index (row, iter->first); QModelIndex index = model->index (row, *iter);
CSMWorld::UniversalId::Type type = static_cast<CSMWorld::UniversalId::Type> ( CSMWorld::UniversalId::Type type = static_cast<CSMWorld::UniversalId::Type> (
model->data (model->index (row, mTypeColumn)).toInt()); model->data (model->index (row, mTypeColumn)).toInt());
@ -204,13 +191,13 @@ void CSMTools::Search::searchRow (const CSMWorld::IdTableBase *model, int row,
case Type_Text: case Type_Text:
case Type_Id: case Type_Id:
searchTextCell (model, index, id, iter->second, messages); searchTextCell (model, index, id, messages);
break; break;
case Type_TextRegEx: case Type_TextRegEx:
case Type_IdRegEx: case Type_IdRegEx:
searchRegExCell (model, index, id, iter->second, messages); searchRegExCell (model, index, id, messages);
break; break;
case Type_RecordState: case Type_RecordState:

@ -2,7 +2,7 @@
#define CSM_TOOLS_SEARCH_H #define CSM_TOOLS_SEARCH_H
#include <string> #include <string>
#include <map> #include <set>
#include <QRegExp> #include <QRegExp>
#include <QMetaType> #include <QMetaType>
@ -42,15 +42,15 @@ namespace CSMTools
std::string mText; std::string mText;
QRegExp mRegExp; QRegExp mRegExp;
int mValue; int mValue;
std::map<int, bool> mColumns; // column, multiple finds per cell std::set<int> mColumns;
int mIdColumn; int mIdColumn;
int mTypeColumn; int mTypeColumn;
void searchTextCell (const CSMWorld::IdTableBase *model, const QModelIndex& index, void searchTextCell (const CSMWorld::IdTableBase *model, const QModelIndex& index,
const CSMWorld::UniversalId& id, bool multiple, CSMDoc::Messages& messages) const; const CSMWorld::UniversalId& id, CSMDoc::Messages& messages) const;
void searchRegExCell (const CSMWorld::IdTableBase *model, const QModelIndex& index, void searchRegExCell (const CSMWorld::IdTableBase *model, const QModelIndex& index,
const CSMWorld::UniversalId& id, bool multiple, CSMDoc::Messages& messages) const; const CSMWorld::UniversalId& id, CSMDoc::Messages& messages) const;
void searchRecordStateCell (const CSMWorld::IdTableBase *model, void searchRecordStateCell (const CSMWorld::IdTableBase *model,
const QModelIndex& index, const CSMWorld::UniversalId& id, const QModelIndex& index, const CSMWorld::UniversalId& id,

Loading…
Cancel
Save