forked from teamnwah/openmw-tes3coop
added search-related user settings
This commit is contained in:
parent
4928e3705f
commit
cb6caf5e39
5 changed files with 48 additions and 10 deletions
|
@ -208,6 +208,21 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
|
||||||
shiftCtrlDoubleClick->setToolTip ("Action on shift control double click in table:<p>" + toolTip);
|
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:
|
* There are three types of values:
|
||||||
|
|
|
@ -85,11 +85,10 @@ QString CSMTools::Search::formatDescription (const QString& description, int pos
|
||||||
text.remove ('\r');
|
text.remove ('\r');
|
||||||
|
|
||||||
// split
|
// split
|
||||||
int padding = 10; ///< \todo make this configurable
|
|
||||||
|
|
||||||
QString highlight = flatten (text.mid (pos, length));
|
QString highlight = flatten (text.mid (pos, length));
|
||||||
QString before = flatten (padding<=pos ? text.mid (0, pos) : text.mid (pos-padding, padding));
|
QString before = flatten (mPaddingBefore<=pos ?
|
||||||
QString after = flatten (text.mid (pos+length, padding));
|
text.mid (0, pos) : text.mid (pos-mPaddingBefore, mPaddingBefore));
|
||||||
|
QString after = flatten (text.mid (pos+length, mPaddingAfter));
|
||||||
|
|
||||||
// join
|
// join
|
||||||
text = before + "<b>" + highlight + "</b>" + after;
|
text = before + "<b>" + highlight + "</b>" + after;
|
||||||
|
@ -111,24 +110,24 @@ QString CSMTools::Search::flatten (const QString& text) const
|
||||||
return flat;
|
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)
|
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)
|
if (type!=Type_Text && type!=Type_Id)
|
||||||
throw std::logic_error ("Invalid search parameter (string)");
|
throw std::logic_error ("Invalid search parameter (string)");
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMTools::Search::Search (Type type, const QRegExp& value)
|
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)
|
if (type!=Type_TextRegEx && type!=Type_IdRegEx)
|
||||||
throw std::logic_error ("Invalid search parameter (RegExp)");
|
throw std::logic_error ("Invalid search parameter (RegExp)");
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMTools::Search::Search (Type type, int value)
|
CSMTools::Search::Search (Type type, int value)
|
||||||
: mType (type), mValue (value)
|
: mType (type), mValue (value), mPaddingBefore (10), mPaddingAfter (10)
|
||||||
{
|
{
|
||||||
if (type!=Type_RecordState)
|
if (type!=Type_RecordState)
|
||||||
throw std::logic_error ("invalid search parameter (int)");
|
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;
|
std::set<int> mColumns;
|
||||||
int mIdColumn;
|
int mIdColumn;
|
||||||
int mTypeColumn;
|
int mTypeColumn;
|
||||||
|
int mPaddingBefore;
|
||||||
|
int mPaddingAfter;
|
||||||
|
|
||||||
void searchTextCell (const CSMWorld::IdTableBase *model, const QModelIndex& index,
|
void searchTextCell (const CSMWorld::IdTableBase *model, const QModelIndex& index,
|
||||||
const CSMWorld::UniversalId& id, CSMDoc::Messages& messages) const;
|
const CSMWorld::UniversalId& id, CSMDoc::Messages& messages) const;
|
||||||
|
@ -78,6 +80,8 @@ namespace CSMTools
|
||||||
// \attention *this needs to be configured for \a model.
|
// \attention *this needs to be configured for \a model.
|
||||||
void searchRow (const CSMWorld::IdTableBase *model, int row,
|
void searchRow (const CSMWorld::IdTableBase *model, int row,
|
||||||
CSMDoc::Messages& messages) const;
|
CSMDoc::Messages& messages) const;
|
||||||
|
|
||||||
|
void setPadding (int before, int after);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,13 @@
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include "../../model/doc/document.hpp"
|
#include "../../model/doc/document.hpp"
|
||||||
|
#include "../../model/tools/search.hpp"
|
||||||
|
|
||||||
#include "reporttable.hpp"
|
#include "reporttable.hpp"
|
||||||
#include "searchbox.hpp"
|
#include "searchbox.hpp"
|
||||||
|
|
||||||
CSVTools::SearchSubView::SearchSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
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;
|
QVBoxLayout *layout = new QVBoxLayout;
|
||||||
|
|
||||||
|
@ -45,6 +46,14 @@ void CSVTools::SearchSubView::setEditLock (bool locked)
|
||||||
void CSVTools::SearchSubView::updateUserSetting (const QString &name, const QStringList &list)
|
void CSVTools::SearchSubView::updateUserSetting (const QString &name, const QStringList &list)
|
||||||
{
|
{
|
||||||
mTable->updateUserSetting (name, 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)
|
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)
|
void CSVTools::SearchSubView::startSearch (const CSMTools::Search& search)
|
||||||
{
|
{
|
||||||
|
CSMTools::Search search2 (search);
|
||||||
|
search2.setPadding (mPaddingBefore, mPaddingAfter);
|
||||||
|
|
||||||
mTable->clear();
|
mTable->clear();
|
||||||
mDocument.runSearch (getUniversalId(), search);
|
mDocument.runSearch (getUniversalId(), search2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ namespace CSVTools
|
||||||
ReportTable *mTable;
|
ReportTable *mTable;
|
||||||
SearchBox mSearchBox;
|
SearchBox mSearchBox;
|
||||||
CSMDoc::Document& mDocument;
|
CSMDoc::Document& mDocument;
|
||||||
|
int mPaddingBefore;
|
||||||
|
int mPaddingAfter;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue