mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 08:23:53 +00:00
added replace all button
This commit is contained in:
parent
36ce2d61f4
commit
b939fd440e
4 changed files with 68 additions and 28 deletions
|
@ -36,7 +36,7 @@ void CSVTools::SearchBox::updateSearchButton()
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVTools::SearchBox::SearchBox (QWidget *parent)
|
CSVTools::SearchBox::SearchBox (QWidget *parent)
|
||||||
: QWidget (parent), mSearch ("Search"), mSearchEnabled (false)
|
: QWidget (parent), mSearch ("Search"), mSearchEnabled (false), mReplace ("Replace All")
|
||||||
{
|
{
|
||||||
mLayout = new QGridLayout (this);
|
mLayout = new QGridLayout (this);
|
||||||
|
|
||||||
|
@ -79,12 +79,16 @@ CSVTools::SearchBox::SearchBox (QWidget *parent)
|
||||||
|
|
||||||
mLayout->addWidget (&mReplaceInput, 1, 1);
|
mLayout->addWidget (&mReplaceInput, 1, 1);
|
||||||
|
|
||||||
|
mLayout->addWidget (&mReplace, 1, 3);
|
||||||
|
|
||||||
// layout adjustments
|
// layout adjustments
|
||||||
mLayout->setColumnMinimumWidth (2, 50);
|
mLayout->setColumnMinimumWidth (2, 50);
|
||||||
mLayout->setColumnStretch (1, 1);
|
mLayout->setColumnStretch (1, 1);
|
||||||
|
|
||||||
mLayout->setContentsMargins (0, 0, 0, 0);
|
mLayout->setContentsMargins (0, 0, 0, 0);
|
||||||
|
|
||||||
|
connect (&mReplace, (SIGNAL (clicked (bool))), this, SLOT (replaceAll (bool)));
|
||||||
|
|
||||||
// update
|
// update
|
||||||
modeSelected (0);
|
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)
|
void CSVTools::SearchBox::modeSelected (int index)
|
||||||
{
|
{
|
||||||
switch (index)
|
switch (index)
|
||||||
|
@ -176,3 +185,8 @@ void CSVTools::SearchBox::startSearch (bool checked)
|
||||||
if (mSearch.isEnabled())
|
if (mSearch.isEnabled())
|
||||||
emit startSearch (getSearch());
|
emit startSearch (getSearch());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVTools::SearchBox::replaceAll (bool checked)
|
||||||
|
{
|
||||||
|
emit replaceAll();
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace CSVTools
|
||||||
QStackedWidget mReplaceInput;
|
QStackedWidget mReplaceInput;
|
||||||
QLineEdit mReplaceText;
|
QLineEdit mReplaceText;
|
||||||
QLabel mReplacePlaceholder;
|
QLabel mReplacePlaceholder;
|
||||||
|
QPushButton mReplace;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -46,6 +47,8 @@ namespace CSVTools
|
||||||
|
|
||||||
std::string getReplaceText() const;
|
std::string getReplaceText() const;
|
||||||
|
|
||||||
|
void setEditLock (bool locked);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void modeSelected (int index);
|
void modeSelected (int index);
|
||||||
|
@ -54,9 +57,13 @@ namespace CSVTools
|
||||||
|
|
||||||
void startSearch (bool checked = true);
|
void startSearch (bool checked = true);
|
||||||
|
|
||||||
|
void replaceAll (bool checked);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void startSearch (const CSMTools::Search& search);
|
void startSearch (const CSMTools::Search& search);
|
||||||
|
|
||||||
|
void replaceAll();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,36 @@
|
||||||
#include "reporttable.hpp"
|
#include "reporttable.hpp"
|
||||||
#include "searchbox.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)
|
CSVTools::SearchSubView::SearchSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
||||||
: CSVDoc::SubView (id), mDocument (document), mPaddingBefore (10), mPaddingAfter (10),
|
: CSVDoc::SubView (id), mDocument (document), mPaddingBefore (10), mPaddingAfter (10),
|
||||||
mLocked (false)
|
mLocked (false)
|
||||||
|
@ -41,11 +71,14 @@ CSVTools::SearchSubView::SearchSubView (const CSMWorld::UniversalId& id, CSMDoc:
|
||||||
|
|
||||||
connect (&mSearchBox, SIGNAL (startSearch (const CSMTools::Search&)),
|
connect (&mSearchBox, SIGNAL (startSearch (const CSMTools::Search&)),
|
||||||
this, SLOT (startSearch (const CSMTools::Search&)));
|
this, SLOT (startSearch (const CSMTools::Search&)));
|
||||||
|
|
||||||
|
connect (&mSearchBox, SIGNAL (replaceAll()), this, SLOT (replaceAllRequest()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVTools::SearchSubView::setEditLock (bool locked)
|
void CSVTools::SearchSubView::setEditLock (bool locked)
|
||||||
{
|
{
|
||||||
mLocked = false;
|
mLocked = locked;
|
||||||
|
mSearchBox.setEditLock (locked);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVTools::SearchSubView::updateUserSetting (const QString &name, const QStringList &list)
|
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()
|
void CSVTools::SearchSubView::replaceRequest()
|
||||||
{
|
{
|
||||||
if (mLocked)
|
replace (true);
|
||||||
return;
|
}
|
||||||
|
|
||||||
std::vector<int> indices = mTable->getReplaceIndices (true);
|
void CSVTools::SearchSubView::replaceAllRequest()
|
||||||
|
{
|
||||||
std::string replace = mSearchBox.getReplaceText();
|
replace (false);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,10 @@ namespace CSVTools
|
||||||
CSMTools::Search mSearch;
|
CSMTools::Search mSearch;
|
||||||
bool mLocked;
|
bool mLocked;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void replace (bool selection);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SearchSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
|
SearchSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
|
||||||
|
@ -46,6 +50,8 @@ namespace CSVTools
|
||||||
void startSearch (const CSMTools::Search& search);
|
void startSearch (const CSMTools::Search& search);
|
||||||
|
|
||||||
void replaceRequest();
|
void replaceRequest();
|
||||||
|
|
||||||
|
void replaceAllRequest();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue