|
|
|
@ -11,6 +11,36 @@
|
|
|
|
|
#include "reporttable.hpp"
|
|
|
|
|
#include "searchbox.hpp"
|
|
|
|
|
|
|
|
|
|
void CSVTools::SearchSubView::replace (bool selection)
|
|
|
|
|
{
|
|
|
|
|
if (mLocked)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
std::vector<int> indices = mTable->getReplaceIndices (selection);
|
|
|
|
|
|
|
|
|
|
std::string replace = mSearchBox.getReplaceText();
|
|
|
|
|
|
|
|
|
|
const CSMTools::ReportModel& model =
|
|
|
|
|
dynamic_cast<const CSMTools::ReportModel&> (*mTable->model());
|
|
|
|
|
|
|
|
|
|
// We are running through the indices in reverse order to avoid messing up multiple results
|
|
|
|
|
// in a single string.
|
|
|
|
|
for (std::vector<int>::const_reverse_iterator iter (indices.rbegin()); iter!=indices.rend(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
CSMWorld::UniversalId id = model.getUniversalId (*iter);
|
|
|
|
|
|
|
|
|
|
CSMWorld::UniversalId::Type type = CSMWorld::UniversalId::getParentType (id.getType());
|
|
|
|
|
|
|
|
|
|
CSMWorld::IdTableBase *table = &dynamic_cast<CSMWorld::IdTableBase&> (
|
|
|
|
|
*mDocument.getData().getTableModel (type));
|
|
|
|
|
|
|
|
|
|
std::string hint = model.getHint (*iter);
|
|
|
|
|
|
|
|
|
|
mSearch.replace (mDocument, table, id, hint, replace);
|
|
|
|
|
mTable->flagAsReplaced (*iter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSVTools::SearchSubView::SearchSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
|
|
|
|
: CSVDoc::SubView (id), mDocument (document), mPaddingBefore (10), mPaddingAfter (10),
|
|
|
|
|
mLocked (false)
|
|
|
|
@ -41,11 +71,14 @@ CSVTools::SearchSubView::SearchSubView (const CSMWorld::UniversalId& id, CSMDoc:
|
|
|
|
|
|
|
|
|
|
connect (&mSearchBox, SIGNAL (startSearch (const CSMTools::Search&)),
|
|
|
|
|
this, SLOT (startSearch (const CSMTools::Search&)));
|
|
|
|
|
|
|
|
|
|
connect (&mSearchBox, SIGNAL (replaceAll()), this, SLOT (replaceAllRequest()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVTools::SearchSubView::setEditLock (bool locked)
|
|
|
|
|
{
|
|
|
|
|
mLocked = false;
|
|
|
|
|
mLocked = locked;
|
|
|
|
|
mSearchBox.setEditLock (locked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVTools::SearchSubView::updateUserSetting (const QString &name, const QStringList &list)
|
|
|
|
@ -77,30 +110,10 @@ void CSVTools::SearchSubView::startSearch (const CSMTools::Search& search)
|
|
|
|
|
|
|
|
|
|
void CSVTools::SearchSubView::replaceRequest()
|
|
|
|
|
{
|
|
|
|
|
if (mLocked)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
std::vector<int> indices = mTable->getReplaceIndices (true);
|
|
|
|
|
|
|
|
|
|
std::string replace = mSearchBox.getReplaceText();
|
|
|
|
|
|
|
|
|
|
const CSMTools::ReportModel& model =
|
|
|
|
|
dynamic_cast<const CSMTools::ReportModel&> (*mTable->model());
|
|
|
|
|
|
|
|
|
|
// We are running through the indices in reverse order to avoid messing up multiple results
|
|
|
|
|
// in a single string.
|
|
|
|
|
for (std::vector<int>::const_reverse_iterator iter (indices.rbegin()); iter!=indices.rend(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
CSMWorld::UniversalId id = model.getUniversalId (*iter);
|
|
|
|
|
|
|
|
|
|
CSMWorld::UniversalId::Type type = CSMWorld::UniversalId::getParentType (id.getType());
|
|
|
|
|
replace (true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSMWorld::IdTableBase *table = &dynamic_cast<CSMWorld::IdTableBase&> (
|
|
|
|
|
*mDocument.getData().getTableModel (type));
|
|
|
|
|
|
|
|
|
|
std::string hint = model.getHint (*iter);
|
|
|
|
|
|
|
|
|
|
mSearch.replace (mDocument, table, id, hint, replace);
|
|
|
|
|
mTable->flagAsReplaced (*iter);
|
|
|
|
|
}
|
|
|
|
|
void CSVTools::SearchSubView::replaceAllRequest()
|
|
|
|
|
{
|
|
|
|
|
replace (false);
|
|
|
|
|
}
|
|
|
|
|