mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-10 15:45:37 +00:00
Merge branch 'qregexp' into 'master'
Simplify regex search in the editor See merge request OpenMW/openmw!2610
This commit is contained in:
commit
203eb80afd
@ -46,22 +46,24 @@ void CSMTools::Search::searchTextCell(const CSMWorld::IdTableBase* model, const
|
|||||||
void CSMTools::Search::searchRegExCell(const CSMWorld::IdTableBase* model, const QModelIndex& index,
|
void CSMTools::Search::searchRegExCell(const CSMWorld::IdTableBase* model, const QModelIndex& index,
|
||||||
const CSMWorld::UniversalId& id, bool writable, CSMDoc::Messages& messages) const
|
const CSMWorld::UniversalId& id, bool writable, CSMDoc::Messages& messages) const
|
||||||
{
|
{
|
||||||
|
// TODO: verify regular expression before starting a search
|
||||||
|
if (!mRegExp.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
QString text = model->data(index).toString();
|
QString text = model->data(index).toString();
|
||||||
|
|
||||||
int pos = 0;
|
QRegularExpressionMatchIterator i = mRegExp.globalMatch(text);
|
||||||
QRegularExpressionMatch match;
|
while (i.hasNext())
|
||||||
|
|
||||||
while ((match = mRegExp.match(text, pos)).hasMatch())
|
|
||||||
{
|
{
|
||||||
pos = match.capturedStart();
|
QRegularExpressionMatch match = i.next();
|
||||||
|
|
||||||
|
int pos = match.capturedStart();
|
||||||
int length = match.capturedLength();
|
int length = match.capturedLength();
|
||||||
|
|
||||||
std::ostringstream hint;
|
std::ostringstream hint;
|
||||||
hint << (writable ? 'R' : 'r') << ": " << model->getColumnId(index.column()) << " " << pos << " " << length;
|
hint << (writable ? 'R' : 'r') << ": " << model->getColumnId(index.column()) << " " << pos << " " << length;
|
||||||
|
|
||||||
messages.add(id, formatDescription(text, pos, length).toUtf8().data(), hint.str());
|
messages.add(id, formatDescription(text, pos, length).toUtf8().data(), hint.str());
|
||||||
|
|
||||||
pos += length;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user