forked from teamnwah/openmw-tes3coop
moved record creation to GenericCreator class (now taking ID from user instead of using a procedurally generated one)
This commit is contained in:
parent
2d46a1db2f
commit
00fcb79f08
9 changed files with 104 additions and 36 deletions
|
@ -7,7 +7,7 @@ CSVWorld::CreatorFactoryBase::~CreatorFactoryBase() {}
|
||||||
|
|
||||||
|
|
||||||
CSVWorld::Creator *CSVWorld::NullCreatorFactory::makeCreator (CSMWorld::Data& data,
|
CSVWorld::Creator *CSVWorld::NullCreatorFactory::makeCreator (CSMWorld::Data& data,
|
||||||
QUndoStack& undoStack) const
|
QUndoStack& undoStack, const CSMWorld::UniversalId& id) const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@ class QUndoStack;
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
class Data;
|
class Data;
|
||||||
|
class UniversalId;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace CSVWorld
|
namespace CSVWorld
|
||||||
|
@ -35,7 +36,8 @@ namespace CSVWorld
|
||||||
|
|
||||||
virtual ~CreatorFactoryBase();
|
virtual ~CreatorFactoryBase();
|
||||||
|
|
||||||
virtual Creator *makeCreator (CSMWorld::Data& data, QUndoStack& undoStack) const = 0;
|
virtual Creator *makeCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
|
const CSMWorld::UniversalId& id) const = 0;
|
||||||
///< The ownership of the returned Creator is transferred to the caller.
|
///< The ownership of the returned Creator is transferred to the caller.
|
||||||
///
|
///
|
||||||
/// \note The function can return a 0-pointer, which means no UI for creating/deleting
|
/// \note The function can return a 0-pointer, which means no UI for creating/deleting
|
||||||
|
@ -47,7 +49,8 @@ namespace CSVWorld
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual Creator *makeCreator (CSMWorld::Data& data, QUndoStack& undoStack) const;
|
virtual Creator *makeCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
|
const CSMWorld::UniversalId& id) const;
|
||||||
///< The ownership of the returned Creator is transferred to the caller.
|
///< The ownership of the returned Creator is transferred to the caller.
|
||||||
///
|
///
|
||||||
/// \note The function always returns 0.
|
/// \note The function always returns 0.
|
||||||
|
@ -58,7 +61,8 @@ namespace CSVWorld
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual Creator *makeCreator (CSMWorld::Data& data, QUndoStack& undoStac) const;
|
virtual Creator *makeCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
|
const CSMWorld::UniversalId& id) const;
|
||||||
///< The ownership of the returned Creator is transferred to the caller.
|
///< The ownership of the returned Creator is transferred to the caller.
|
||||||
///
|
///
|
||||||
/// \note The function can return a 0-pointer, which means no UI for creating/deleting
|
/// \note The function can return a 0-pointer, which means no UI for creating/deleting
|
||||||
|
@ -66,9 +70,10 @@ namespace CSVWorld
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class CreatorT>
|
template<class CreatorT>
|
||||||
Creator *CreatorFactory<CreatorT>::makeCreator (CSMWorld::Data& data, QUndoStack& undoStack) const
|
Creator *CreatorFactory<CreatorT>::makeCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
|
const CSMWorld::UniversalId& id) const
|
||||||
{
|
{
|
||||||
return new CreatorT (data, undoStack);
|
return new CreatorT (data, undoStack, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,26 +4,78 @@
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
#include <QUndoStack>
|
||||||
|
|
||||||
CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack)
|
#include "../../model/world/commands.hpp"
|
||||||
|
#include "../../model/world/data.hpp"
|
||||||
|
#include "../../model/world/idtable.hpp"
|
||||||
|
|
||||||
|
void CSVWorld::GenericCreator::update()
|
||||||
|
{
|
||||||
|
mErrors = getErrors();
|
||||||
|
|
||||||
|
mCreate->setToolTip (QString::fromUtf8 (mErrors.c_str()));
|
||||||
|
|
||||||
|
mCreate->setEnabled (mErrors.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
|
const CSMWorld::UniversalId& id)
|
||||||
|
: mData (data), mUndoStack (undoStack), mListId (id)
|
||||||
{
|
{
|
||||||
QHBoxLayout *layout = new QHBoxLayout;
|
QHBoxLayout *layout = new QHBoxLayout;
|
||||||
|
|
||||||
QLineEdit *name = new QLineEdit;
|
mId = new QLineEdit;
|
||||||
layout->addWidget (name, 1);
|
layout->addWidget (mId, 1);
|
||||||
|
|
||||||
QPushButton *createButton = new QPushButton ("Create");
|
mCreate = new QPushButton ("Create");
|
||||||
layout->addWidget (createButton);
|
layout->addWidget (mCreate);
|
||||||
|
|
||||||
QPushButton *cancelButton = new QPushButton ("Cancel");
|
QPushButton *cancelButton = new QPushButton ("Cancel");
|
||||||
layout->addWidget (cancelButton);
|
layout->addWidget (cancelButton);
|
||||||
|
|
||||||
connect (cancelButton, SIGNAL (clicked (bool)), this, SIGNAL (done()));
|
|
||||||
|
|
||||||
setLayout (layout);
|
setLayout (layout);
|
||||||
|
|
||||||
|
connect (cancelButton, SIGNAL (clicked (bool)), this, SIGNAL (done()));
|
||||||
|
connect (mCreate, SIGNAL (clicked (bool)), this, SLOT (create()));
|
||||||
|
|
||||||
|
connect (mId, SIGNAL (textChanged (const QString&)), this, SLOT (textChanged (const QString&)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::GenericCreator::reset()
|
void CSVWorld::GenericCreator::reset()
|
||||||
{
|
{
|
||||||
|
mId->setText ("");
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CSVWorld::GenericCreator::getErrors() const
|
||||||
|
{
|
||||||
|
std::string errors;
|
||||||
|
|
||||||
|
std::string id = mId->text().toUtf8().constData();
|
||||||
|
|
||||||
|
if (id.empty())
|
||||||
|
{
|
||||||
|
errors = "Missing ID";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::GenericCreator::textChanged (const QString& text)
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::GenericCreator::create()
|
||||||
|
{
|
||||||
|
mUndoStack.push (new CSMWorld::CreateCommand (
|
||||||
|
dynamic_cast<CSMWorld::IdTable&> (*mData.getTableModel (mListId)),
|
||||||
|
mId->text().toUtf8().constData()));
|
||||||
|
|
||||||
|
emit done();
|
||||||
}
|
}
|
|
@ -1,19 +1,46 @@
|
||||||
#ifndef CSV_WORLD_GENERICCREATOR_H
|
#ifndef CSV_WORLD_GENERICCREATOR_H
|
||||||
#define CSV_WORLD_GENERICCREATOR_H
|
#define CSV_WORLD_GENERICCREATOR_H
|
||||||
|
|
||||||
|
class QPushButton;
|
||||||
|
class QLineEdit;
|
||||||
|
|
||||||
#include "creator.hpp"
|
#include "creator.hpp"
|
||||||
|
|
||||||
|
#include "../../model/world/universalid.hpp"
|
||||||
|
|
||||||
namespace CSVWorld
|
namespace CSVWorld
|
||||||
{
|
{
|
||||||
class GenericCreator : public Creator
|
class GenericCreator : public Creator
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
CSMWorld::Data& mData;
|
||||||
|
QUndoStack& mUndoStack;
|
||||||
|
CSMWorld::UniversalId mListId;
|
||||||
|
QPushButton *mCreate;
|
||||||
|
QLineEdit *mId;
|
||||||
|
std::string mErrors;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void update();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack);
|
GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack,
|
||||||
|
const CSMWorld::UniversalId& id);
|
||||||
|
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void textChanged (const QString& text);
|
||||||
|
|
||||||
|
void create();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,22 +187,6 @@ CSMWorld::UniversalId CSVWorld::Table::getUniversalId (int row) const
|
||||||
mProxyModel->data (mProxyModel->index (row, 0)).toString().toStdString());
|
mProxyModel->data (mProxyModel->index (row, 0)).toString().toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <sstream> /// \todo remove
|
|
||||||
void CSVWorld::Table::createRecord()
|
|
||||||
{
|
|
||||||
if (!mEditLock)
|
|
||||||
{
|
|
||||||
/// \todo ask the user for an ID instead.
|
|
||||||
static int index = 0;
|
|
||||||
|
|
||||||
std::ostringstream stream;
|
|
||||||
stream << "id" << index++;
|
|
||||||
|
|
||||||
mUndoStack.push (new CSMWorld::CreateCommand (*mProxyModel, stream.str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSVWorld::Table::revertRecord()
|
void CSVWorld::Table::revertRecord()
|
||||||
{
|
{
|
||||||
if (!mEditLock)
|
if (!mEditLock)
|
||||||
|
|
|
@ -71,8 +71,6 @@ namespace CSVWorld
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void createRecord();
|
|
||||||
|
|
||||||
void revertRecord();
|
void revertRecord();
|
||||||
|
|
||||||
void deleteRecord();
|
void deleteRecord();
|
||||||
|
|
|
@ -40,7 +40,7 @@ void CSVWorld::TableBottomBox::updateStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVWorld::TableBottomBox::TableBottomBox (const CreatorFactoryBase& creatorFactory,
|
CSVWorld::TableBottomBox::TableBottomBox (const CreatorFactoryBase& creatorFactory,
|
||||||
CSMWorld::Data& data, QUndoStack& undoStack, QWidget *parent)
|
CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id, QWidget *parent)
|
||||||
: QWidget (parent), mShowStatusBar (false), mCreating (false)
|
: QWidget (parent), mShowStatusBar (false), mCreating (false)
|
||||||
{
|
{
|
||||||
for (int i=0; i<4; ++i)
|
for (int i=0; i<4; ++i)
|
||||||
|
@ -60,7 +60,7 @@ CSVWorld::TableBottomBox::TableBottomBox (const CreatorFactoryBase& creatorFacto
|
||||||
|
|
||||||
setLayout (mLayout);
|
setLayout (mLayout);
|
||||||
|
|
||||||
mCreator = creatorFactory.makeCreator (data, undoStack);
|
mCreator = creatorFactory.makeCreator (data, undoStack, id);
|
||||||
|
|
||||||
mLayout->addWidget (mCreator);
|
mLayout->addWidget (mCreator);
|
||||||
|
|
||||||
|
@ -139,6 +139,7 @@ void CSVWorld::TableBottomBox::tableSizeChanged (int size, int deleted, int modi
|
||||||
|
|
||||||
void CSVWorld::TableBottomBox::createRequest()
|
void CSVWorld::TableBottomBox::createRequest()
|
||||||
{
|
{
|
||||||
|
mCreator->reset();
|
||||||
mLayout->setCurrentWidget (mCreator);
|
mLayout->setCurrentWidget (mCreator);
|
||||||
setVisible (true);
|
setVisible (true);
|
||||||
mCreating = true;
|
mCreating = true;
|
||||||
|
|
|
@ -11,6 +11,7 @@ class QUndoStack;
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
class Data;
|
class Data;
|
||||||
|
class UniversalId;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace CSVWorld
|
namespace CSVWorld
|
||||||
|
@ -41,7 +42,7 @@ namespace CSVWorld
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TableBottomBox (const CreatorFactoryBase& creatorFactory, CSMWorld::Data& data,
|
TableBottomBox (const CreatorFactoryBase& creatorFactory, CSMWorld::Data& data,
|
||||||
QUndoStack& undoStack, QWidget *parent = 0);
|
QUndoStack& undoStack, const CSMWorld::UniversalId& id, QWidget *parent = 0);
|
||||||
|
|
||||||
virtual ~TableBottomBox();
|
virtual ~TableBottomBox();
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D
|
||||||
layout->setContentsMargins (QMargins (0, 0, 0, 0));
|
layout->setContentsMargins (QMargins (0, 0, 0, 0));
|
||||||
|
|
||||||
layout->addWidget (mBottom =
|
layout->addWidget (mBottom =
|
||||||
new TableBottomBox (creatorFactory, document.getData(), document.getUndoStack(), this), 0);
|
new TableBottomBox (creatorFactory, document.getData(), document.getUndoStack(), id, this), 0);
|
||||||
|
|
||||||
layout->insertWidget (0, mTable =
|
layout->insertWidget (0, mTable =
|
||||||
new Table (id, document.getData(), document.getUndoStack(), mBottom->canCreateAndDelete()), 2);
|
new Table (id, document.getData(), document.getUndoStack(), mBottom->canCreateAndDelete()), 2);
|
||||||
|
|
Loading…
Reference in a new issue