diff --git a/apps/opencs/model/tools/search.cpp b/apps/opencs/model/tools/search.cpp index a0eb429b0..9f1beb064 100644 --- a/apps/opencs/model/tools/search.cpp +++ b/apps/opencs/model/tools/search.cpp @@ -23,9 +23,6 @@ void CSMTools::Search::searchTextCell (const CSMWorld::IdTableBase *model, while ((pos = text.indexOf (search, pos, Qt::CaseInsensitive))!=-1) { - std::ostringstream message; - message << getLocation (model, index, id) << text.mid (pos).toUtf8().data(); - std::ostringstream hint; hint << "r: " @@ -33,7 +30,7 @@ void CSMTools::Search::searchTextCell (const CSMWorld::IdTableBase *model, << " " << pos << " " << search.length(); - messages.add (id, message.str(), hint.str()); + messages.add (id, formatDescription (text, pos, search.length()).toUtf8().data(), hint.str()); pos += search.length(); } @@ -49,15 +46,12 @@ void CSMTools::Search::searchRegExCell (const CSMWorld::IdTableBase *model, while ((pos = mRegExp.indexIn (text, pos))!=-1) { - std::ostringstream message; - message << getLocation (model, index, id) << text.mid (pos).toUtf8().data(); - int length = mRegExp.matchedLength(); std::ostringstream hint; - hint << "r: " << index.column() << " " << pos << " " << length; + hint << "r: " << model->getColumnId (index.column()) << " " << pos << " " << length; - messages.add (id, message.str(), hint.str()); + messages.add (id, formatDescription (text, pos, length).toUtf8().data(), hint.str()); pos += length; } @@ -74,26 +68,42 @@ void CSMTools::Search::searchRecordStateCell (const CSMWorld::IdTableBase *model CSMWorld::Columns::getEnums (CSMWorld::Columns::ColumnId_Modification); std::ostringstream message; - message << getLocation (model, index, id) << states.at (data); + message << states.at (data); std::ostringstream hint; - hint << "r: " << index.column(); + hint << "r: " << model->getColumnId (index.column()); messages.add (id, message.str(), hint.str()); } } -std::string CSMTools::Search::getLocation (const CSMWorld::IdTableBase *model, const QModelIndex& index, const CSMWorld::UniversalId& id) const +QString CSMTools::Search::formatDescription (const QString& description, int pos, int length) const { - std::ostringstream stream; + int padding = 10; ///< \todo make this configurable + + if (posheaderData (index.column(), Qt::Horizontal).toString().toUtf8().data() - << ": "; + QString text = description.mid (pos, length); + + // compensate for Windows nonsense + text.remove ('\r'); - return stream.str(); + // improve layout for single line display + text.replace ("\n", ""); + text.replace ('\t', ' '); + + return text; } CSMTools::Search::Search() : mType (Type_None) {} diff --git a/apps/opencs/model/tools/search.hpp b/apps/opencs/model/tools/search.hpp index 81b8840bf..320323f03 100644 --- a/apps/opencs/model/tools/search.hpp +++ b/apps/opencs/model/tools/search.hpp @@ -56,7 +56,7 @@ namespace CSMTools const QModelIndex& index, const CSMWorld::UniversalId& id, CSMDoc::Messages& messages) const; - std::string getLocation (const CSMWorld::IdTableBase *model, const QModelIndex& index, const CSMWorld::UniversalId& id) const; + QString formatDescription (const QString& description, int pos, int length) const; public: