added search-related user settings

search
Marc Zinnschlag 10 years ago
parent 4928e3705f
commit cb6caf5e39

@ -208,6 +208,21 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
shiftCtrlDoubleClick->setToolTip ("Action on shift control double click in table:<p>" + toolTip);
}
declareSection ("search", "Search & Replace");
{
Setting *before = createSetting (Type_SpinBox, "char-before",
"Characters before search string");
before->setDefaultValue (10);
before->setRange (0, 1000);
before->setToolTip ("Maximum number of character to display in search result before the searched text");
Setting *after = createSetting (Type_SpinBox, "char-after",
"Characters after search string");
after->setDefaultValue (10);
after->setRange (0, 1000);
after->setToolTip ("Maximum number of character to display in search result after the searched text");
}
{
/******************************************************************
* There are three types of values:

@ -85,11 +85,10 @@ QString CSMTools::Search::formatDescription (const QString& description, int pos
text.remove ('\r');
// split
int padding = 10; ///< \todo make this configurable
QString highlight = flatten (text.mid (pos, length));
QString before = flatten (padding<=pos ? text.mid (0, pos) : text.mid (pos-padding, padding));
QString after = flatten (text.mid (pos+length, padding));
QString before = flatten (mPaddingBefore<=pos ?
text.mid (0, pos) : text.mid (pos-mPaddingBefore, mPaddingBefore));
QString after = flatten (text.mid (pos+length, mPaddingAfter));
// join
text = before + "<b>" + highlight + "</b>" + after;
@ -111,24 +110,24 @@ QString CSMTools::Search::flatten (const QString& text) const
return flat;
}
CSMTools::Search::Search() : mType (Type_None) {}
CSMTools::Search::Search() : mType (Type_None), mPaddingBefore (10), mPaddingAfter (10) {}
CSMTools::Search::Search (Type type, const std::string& value)
: mType (type), mText (value)
: mType (type), mText (value), mPaddingBefore (10), mPaddingAfter (10)
{
if (type!=Type_Text && type!=Type_Id)
throw std::logic_error ("Invalid search parameter (string)");
}
CSMTools::Search::Search (Type type, const QRegExp& value)
: mType (type), mRegExp (value)
: mType (type), mRegExp (value), mPaddingBefore (10), mPaddingAfter (10)
{
if (type!=Type_TextRegEx && type!=Type_IdRegEx)
throw std::logic_error ("Invalid search parameter (RegExp)");
}
CSMTools::Search::Search (Type type, int value)
: mType (type), mValue (value)
: mType (type), mValue (value), mPaddingBefore (10), mPaddingAfter (10)
{
if (type!=Type_RecordState)
throw std::logic_error ("invalid search parameter (int)");
@ -230,3 +229,9 @@ void CSMTools::Search::searchRow (const CSMWorld::IdTableBase *model, int row,
}
}
}
void CSMTools::Search::setPadding (int before, int after)
{
mPaddingBefore = before;
mPaddingAfter = after;
}

@ -45,6 +45,8 @@ namespace CSMTools
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, CSMDoc::Messages& messages) const;
@ -78,6 +80,8 @@ namespace CSMTools
// \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);
};
}

@ -4,12 +4,13 @@
#include <QVBoxLayout>
#include "../../model/doc/document.hpp"
#include "../../model/tools/search.hpp"
#include "reporttable.hpp"
#include "searchbox.hpp"
CSVTools::SearchSubView::SearchSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
: CSVDoc::SubView (id), mDocument (document)
: CSVDoc::SubView (id), mDocument (document), mPaddingBefore (10), mPaddingAfter (10)
{
QVBoxLayout *layout = new QVBoxLayout;
@ -45,6 +46,14 @@ void CSVTools::SearchSubView::setEditLock (bool locked)
void CSVTools::SearchSubView::updateUserSetting (const QString &name, const QStringList &list)
{
mTable->updateUserSetting (name, list);
if (!list.empty())
{
if (name=="search/char-before")
mPaddingBefore = list.at (0).toInt();
else if (name=="search/char-after")
mPaddingAfter = list.at (0).toInt();
}
}
void CSVTools::SearchSubView::stateChanged (int state, CSMDoc::Document *document)
@ -54,6 +63,9 @@ void CSVTools::SearchSubView::stateChanged (int state, CSMDoc::Document *documen
void CSVTools::SearchSubView::startSearch (const CSMTools::Search& search)
{
CSMTools::Search search2 (search);
search2.setPadding (mPaddingBefore, mPaddingAfter);
mTable->clear();
mDocument.runSearch (getUniversalId(), search);
mDocument.runSearch (getUniversalId(), search2);
}

@ -24,6 +24,8 @@ namespace CSVTools
ReportTable *mTable;
SearchBox mSearchBox;
CSMDoc::Document& mDocument;
int mPaddingBefore;
int mPaddingAfter;
public:

Loading…
Cancel
Save