forked from mirror/openmw-tes3mp
made FilterCreator redundant by generalising GenericCreator
This commit is contained in:
parent
35803bc9b6
commit
a54efbcfa0
6 changed files with 117 additions and 142 deletions
|
@ -131,7 +131,7 @@ opencs_hdrs_noqt (model/filter
|
|||
)
|
||||
|
||||
opencs_units (view/filter
|
||||
filtercreator filterbox recordfilterbox editwidget
|
||||
filterbox recordfilterbox editwidget
|
||||
)
|
||||
|
||||
set (OPENCS_US
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
|
||||
#include "filtercreator.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
|
||||
#include "../../model/filter/filter.hpp"
|
||||
|
||||
#include "../../model/world/data.hpp"
|
||||
#include "../../model/world/commands.hpp"
|
||||
#include "../../model/world/columns.hpp"
|
||||
#include "../../model/world/idtable.hpp"
|
||||
|
||||
std::string CSVFilter::FilterCreator::getNamespace() const
|
||||
{
|
||||
switch (mScope->currentIndex())
|
||||
{
|
||||
case CSMFilter::Filter::Scope_Project: return "project::";
|
||||
case CSMFilter::Filter::Scope_Session: return "session::";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void CSVFilter::FilterCreator::update()
|
||||
{
|
||||
mNamespace->setText (QString::fromUtf8 (getNamespace().c_str()));
|
||||
GenericCreator::update();
|
||||
}
|
||||
|
||||
std::string CSVFilter::FilterCreator::getId() const
|
||||
{
|
||||
return getNamespace() + GenericCreator::getId();
|
||||
}
|
||||
|
||||
void CSVFilter::FilterCreator::configureCreateCommand (CSMWorld::CreateCommand& command) const
|
||||
{
|
||||
int index =
|
||||
dynamic_cast<CSMWorld::IdTable&> (*getData().getTableModel (getCollectionId())).
|
||||
findColumnIndex (CSMWorld::Columns::ColumnId_Scope);
|
||||
|
||||
command.addValue (index, mScope->currentIndex());
|
||||
}
|
||||
|
||||
CSVFilter::FilterCreator::FilterCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||
const CSMWorld::UniversalId& id)
|
||||
: GenericCreator (data, undoStack, id)
|
||||
{
|
||||
mNamespace = new QLabel ("::", this);
|
||||
insertAtBeginning (mNamespace, false);
|
||||
|
||||
mScope = new QComboBox (this);
|
||||
|
||||
mScope->addItem ("Project");
|
||||
mScope->addItem ("Session");
|
||||
/// \todo re-enable for OpenMW 1.1
|
||||
// mScope->addItem ("Content");
|
||||
|
||||
connect (mScope, SIGNAL (currentIndexChanged (int)), this, SLOT (setScope2 (int)));
|
||||
|
||||
insertAtBeginning (mScope, false);
|
||||
|
||||
QLabel *label = new QLabel ("Scope", this);
|
||||
insertAtBeginning (label, false);
|
||||
|
||||
mScope->setCurrentIndex (1);
|
||||
}
|
||||
|
||||
void CSVFilter::FilterCreator::reset()
|
||||
{
|
||||
GenericCreator::reset();
|
||||
}
|
||||
|
||||
void CSVFilter::FilterCreator::setScope2 (int index)
|
||||
{
|
||||
update();
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
#ifndef CSV_FILTER_FILTERCREATOR_H
|
||||
#define CSV_FILTER_FILTERCREATOR_H
|
||||
|
||||
class QComboBox;
|
||||
class QLabel;
|
||||
|
||||
#include "../world/genericcreator.hpp"
|
||||
|
||||
namespace CSVFilter
|
||||
{
|
||||
class FilterCreator : public CSVWorld::GenericCreator
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QComboBox *mScope;
|
||||
QLabel *mNamespace;
|
||||
|
||||
private:
|
||||
|
||||
std::string getNamespace() const;
|
||||
|
||||
protected:
|
||||
|
||||
void update();
|
||||
|
||||
virtual std::string getId() const;
|
||||
|
||||
virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const;
|
||||
|
||||
public:
|
||||
|
||||
FilterCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||
const CSMWorld::UniversalId& id);
|
||||
|
||||
virtual void reset();
|
||||
|
||||
private slots:
|
||||
|
||||
void setScope2 (int index);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -7,6 +7,8 @@
|
|||
#include <QPushButton>
|
||||
#include <QLineEdit>
|
||||
#include <QUndoStack>
|
||||
#include <QLabel>
|
||||
#include <QComboBox>
|
||||
|
||||
#include "../../model/world/commands.hpp"
|
||||
#include "../../model/world/data.hpp"
|
||||
|
@ -22,6 +24,9 @@ void CSVWorld::GenericCreator::update()
|
|||
mId->setToolTip (QString::fromUtf8 (mErrors.c_str()));
|
||||
|
||||
mCreate->setEnabled (mErrors.empty() && !mLocked);
|
||||
|
||||
if (mNamespace)
|
||||
mNamespace->setText (QString::fromUtf8 (getNamespace().c_str()));
|
||||
}
|
||||
|
||||
void CSVWorld::GenericCreator::setManualEditing (bool enabled)
|
||||
|
@ -41,7 +46,7 @@ void CSVWorld::GenericCreator::insertBeforeButtons (QWidget *widget, bool stretc
|
|||
|
||||
std::string CSVWorld::GenericCreator::getId() const
|
||||
{
|
||||
return mId->text().toUtf8().constData();
|
||||
return getNamespace() + mId->text().toUtf8().constData();
|
||||
}
|
||||
|
||||
void CSVWorld::GenericCreator::configureCreateCommand (CSMWorld::CreateCommand& command) const {}
|
||||
|
@ -56,16 +61,37 @@ const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const
|
|||
return mListId;
|
||||
}
|
||||
|
||||
std::string CSVWorld::GenericCreator::getNamespace() const
|
||||
{
|
||||
CSMWorld::Scope scope = CSMWorld::Scope_Content;
|
||||
|
||||
if (mScope)
|
||||
{
|
||||
scope = static_cast<CSMWorld::Scope> (mScope->itemData (mScope->currentIndex()).toInt());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mScopes & CSMWorld::Scope_Project)
|
||||
scope = CSMWorld::Scope_Project;
|
||||
else if (mScopes & CSMWorld::Scope_Session)
|
||||
scope = CSMWorld::Scope_Session;
|
||||
}
|
||||
|
||||
switch (scope)
|
||||
{
|
||||
case CSMWorld::Scope_Content: return "";
|
||||
case CSMWorld::Scope_Project: return "project::";
|
||||
case CSMWorld::Scope_Session: return "session::";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||
const CSMWorld::UniversalId& id, bool relaxedIdRules):
|
||||
|
||||
mData (data),
|
||||
mUndoStack (undoStack),
|
||||
mListId (id),
|
||||
mLocked (false),
|
||||
mCloneMode(false),
|
||||
mClonedType(CSMWorld::UniversalId::Type_None)
|
||||
|
||||
const CSMWorld::UniversalId& id, bool relaxedIdRules)
|
||||
: mData (data), mUndoStack (undoStack), mListId (id), mLocked (false), mCloneMode (false),
|
||||
mClonedType (CSMWorld::UniversalId::Type_None), mScopes (CSMWorld::Scope_Content), mScope (0),
|
||||
mScopeLabel (0), mNamespace (0)
|
||||
{
|
||||
mLayout = new QHBoxLayout;
|
||||
mLayout->setContentsMargins (0, 0, 0, 0);
|
||||
|
@ -128,29 +154,28 @@ void CSVWorld::GenericCreator::create()
|
|||
{
|
||||
if (!mLocked)
|
||||
{
|
||||
std::string id = getId();
|
||||
|
||||
if (mCloneMode)
|
||||
{
|
||||
std::string id = getId();
|
||||
std::auto_ptr<CSMWorld::CloneCommand> command (new CSMWorld::CloneCommand (
|
||||
dynamic_cast<CSMWorld::IdTable&> (*mData.getTableModel(mListId)), mClonedId, id, mClonedType));
|
||||
|
||||
mUndoStack.push(command.release());
|
||||
|
||||
emit done();
|
||||
emit requestFocus(id);
|
||||
} else {
|
||||
std::string id = getId();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
std::auto_ptr<CSMWorld::CreateCommand> command (new CSMWorld::CreateCommand (
|
||||
dynamic_cast<CSMWorld::IdTable&> (*mData.getTableModel (mListId)), id));
|
||||
|
||||
configureCreateCommand (*command);
|
||||
|
||||
mUndoStack.push (command.release());
|
||||
|
||||
emit done();
|
||||
emit requestFocus (id);
|
||||
}
|
||||
|
||||
emit done();
|
||||
emit requestFocus(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,3 +190,61 @@ void CSVWorld::GenericCreator::cloneMode(const std::string& originId,
|
|||
void CSVWorld::GenericCreator::toggleWidgets(bool active)
|
||||
{
|
||||
}
|
||||
|
||||
void CSVWorld::GenericCreator::setScope (unsigned int scope)
|
||||
{
|
||||
mScopes = scope;
|
||||
int count = (mScopes & CSMWorld::Scope_Content) + (mScopes & CSMWorld::Scope_Project) +
|
||||
(mScopes & CSMWorld::Scope_Session);
|
||||
|
||||
// namespace widget
|
||||
if (count>1 || (count>0 && !(mScopes & CSMWorld::Scope_Content)))
|
||||
{
|
||||
if (!mNamespace)
|
||||
{
|
||||
mNamespace = new QLabel ("::", this);
|
||||
insertAtBeginning (mNamespace, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete mNamespace;
|
||||
mNamespace = 0;
|
||||
}
|
||||
|
||||
// scope selector widget
|
||||
if (count>1)
|
||||
{
|
||||
mScope = new QComboBox (this);
|
||||
insertAtBeginning (mScope, false);
|
||||
|
||||
if (mScopes & CSMWorld::Scope_Content)
|
||||
mScope->addItem ("Content", static_cast<int> (CSMWorld::Scope_Content));
|
||||
|
||||
if (mScopes & CSMWorld::Scope_Project)
|
||||
mScope->addItem ("Project", static_cast<int> (CSMWorld::Scope_Project));
|
||||
|
||||
if (mScopes & CSMWorld::Scope_Session)
|
||||
mScope->addItem ("Session", static_cast<int> (CSMWorld::Scope_Session));
|
||||
|
||||
connect (mScope, SIGNAL (currentIndexChanged (int)), this, SLOT (scopeChanged (int)));
|
||||
|
||||
mScopeLabel = new QLabel ("Scope", this);
|
||||
insertAtBeginning (mScopeLabel, false);
|
||||
|
||||
mScope->setCurrentIndex (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete mScope;
|
||||
mScope = 0;
|
||||
|
||||
delete mScopeLabel;
|
||||
mScopeLabel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CSVWorld::GenericCreator::scopeChanged (int index)
|
||||
{
|
||||
update();
|
||||
}
|
|
@ -5,6 +5,8 @@ class QString;
|
|||
class QPushButton;
|
||||
class QLineEdit;
|
||||
class QHBoxLayout;
|
||||
class QComboBox;
|
||||
class QLabel;
|
||||
|
||||
#include "creator.hpp"
|
||||
|
||||
|
@ -31,6 +33,10 @@ namespace CSVWorld
|
|||
bool mLocked;
|
||||
std::string mClonedId;
|
||||
CSMWorld::UniversalId::Type mClonedType;
|
||||
unsigned int mScopes;
|
||||
QComboBox *mScope;
|
||||
QLabel *mScopeLabel;
|
||||
QLabel *mNamespace;
|
||||
|
||||
protected:
|
||||
bool mCloneMode;
|
||||
|
@ -54,6 +60,8 @@ namespace CSVWorld
|
|||
|
||||
const CSMWorld::UniversalId& getCollectionId() const;
|
||||
|
||||
std::string getNamespace() const;
|
||||
|
||||
public:
|
||||
|
||||
GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||
|
@ -65,18 +73,22 @@ namespace CSVWorld
|
|||
|
||||
virtual void toggleWidgets (bool active = true);
|
||||
|
||||
virtual void cloneMode(const std::string& originId,
|
||||
virtual void cloneMode(const std::string& originId,
|
||||
const CSMWorld::UniversalId::Type type);
|
||||
|
||||
virtual std::string getErrors() const;
|
||||
///< Return formatted error descriptions for the current state of the creator. if an empty
|
||||
/// string is returned, there is no error.
|
||||
|
||||
virtual void setScope (unsigned int scope);
|
||||
|
||||
private slots:
|
||||
|
||||
void textChanged (const QString& text);
|
||||
|
||||
void create();
|
||||
|
||||
void scopeChanged (int index);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
|
|||
|
||||
manager.add (CSMWorld::UniversalId::Type_Filters,
|
||||
new CSVDoc::SubViewFactoryWithCreator<TableSubView,
|
||||
CreatorFactory<CSVFilter::FilterCreator> >);
|
||||
CreatorFactory<GenericCreator, CSMWorld::Scope_Project | CSMWorld::Scope_Session> >);
|
||||
|
||||
manager.add (CSMWorld::UniversalId::Type_DebugProfiles,
|
||||
new CSVDoc::SubViewFactoryWithCreator<TableSubView,
|
||||
|
|
Loading…
Reference in a new issue