mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-10 03:39:55 +00:00
added replace all button
This commit is contained in:
parent
36ce2d61f4
commit
b939fd440e
@ -36,7 +36,7 @@ void CSVTools::SearchBox::updateSearchButton()
|
||||
}
|
||||
|
||||
CSVTools::SearchBox::SearchBox (QWidget *parent)
|
||||
: QWidget (parent), mSearch ("Search"), mSearchEnabled (false)
|
||||
: QWidget (parent), mSearch ("Search"), mSearchEnabled (false), mReplace ("Replace All")
|
||||
{
|
||||
mLayout = new QGridLayout (this);
|
||||
|
||||
@ -78,12 +78,16 @@ CSVTools::SearchBox::SearchBox (QWidget *parent)
|
||||
mReplaceInput.insertWidget (1, &mReplacePlaceholder);
|
||||
|
||||
mLayout->addWidget (&mReplaceInput, 1, 1);
|
||||
|
||||
mLayout->addWidget (&mReplace, 1, 3);
|
||||
|
||||
// layout adjustments
|
||||
mLayout->setColumnMinimumWidth (2, 50);
|
||||
mLayout->setColumnStretch (1, 1);
|
||||
|
||||
mLayout->setContentsMargins (0, 0, 0, 0);
|
||||
|
||||
connect (&mReplace, (SIGNAL (clicked (bool))), this, SLOT (replaceAll (bool)));
|
||||
|
||||
// update
|
||||
modeSelected (0);
|
||||
@ -144,6 +148,11 @@ std::string CSVTools::SearchBox::getReplaceText() const
|
||||
}
|
||||
}
|
||||
|
||||
void CSVTools::SearchBox::setEditLock (bool locked)
|
||||
{
|
||||
mReplace.setEnabled (!locked);
|
||||
}
|
||||
|
||||
void CSVTools::SearchBox::modeSelected (int index)
|
||||
{
|
||||
switch (index)
|
||||
@ -176,3 +185,8 @@ void CSVTools::SearchBox::startSearch (bool checked)
|
||||
if (mSearch.isEnabled())
|
||||
emit startSearch (getSearch());
|
||||
}
|
||||
|
||||
void CSVTools::SearchBox::replaceAll (bool checked)
|
||||
{
|
||||
emit replaceAll();
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ namespace CSVTools
|
||||
QStackedWidget mReplaceInput;
|
||||
QLineEdit mReplaceText;
|
||||
QLabel mReplacePlaceholder;
|
||||
QPushButton mReplace;
|
||||
|
||||
private:
|
||||
|
||||
@ -46,6 +47,8 @@ namespace CSVTools
|
||||
|
||||
std::string getReplaceText() const;
|
||||
|
||||
void setEditLock (bool locked);
|
||||
|
||||
private slots:
|
||||
|
||||
void modeSelected (int index);
|
||||
@ -54,9 +57,13 @@ namespace CSVTools
|
||||
|
||||
void startSearch (bool checked = true);
|
||||
|
||||
void replaceAll (bool checked);
|
||||
|
||||
signals:
|
||||
|
||||
void startSearch (const CSMTools::Search& search);
|
||||
|
||||
void replaceAll();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
|
||||
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);
|
||||
}
|
||||
replace (true);
|
||||
}
|
||||
|
||||
void CSVTools::SearchSubView::replaceAllRequest()
|
||||
{
|
||||
replace (false);
|
||||
}
|
||||
|
@ -31,6 +31,10 @@ namespace CSVTools
|
||||
CSMTools::Search mSearch;
|
||||
bool mLocked;
|
||||
|
||||
private:
|
||||
|
||||
void replace (bool selection);
|
||||
|
||||
public:
|
||||
|
||||
SearchSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
|
||||
@ -46,6 +50,8 @@ namespace CSVTools
|
||||
void startSearch (const CSMTools::Search& search);
|
||||
|
||||
void replaceRequest();
|
||||
|
||||
void replaceAllRequest();
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user