1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 03:53:54 +00:00
openmw/apps/opencs/view/world/genericcreator.cpp

82 lines
1.8 KiB
C++
Raw Normal View History

2013-07-26 19:09:23 +00:00
#include "genericcreator.hpp"
#include <QHBoxLayout>
#include <QPushButton>
#include <QLineEdit>
#include <QUndoStack>
2013-07-26 19:09:23 +00:00
#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)
2013-07-26 19:09:23 +00:00
{
QHBoxLayout *layout = new QHBoxLayout;
2013-07-28 12:00:26 +00:00
layout->setContentsMargins (0, 0, 0, 0);
2013-07-26 19:09:23 +00:00
mId = new QLineEdit;
layout->addWidget (mId, 1);
2013-07-26 19:09:23 +00:00
mCreate = new QPushButton ("Create");
layout->addWidget (mCreate);
2013-07-26 19:09:23 +00:00
QPushButton *cancelButton = new QPushButton ("Cancel");
layout->addWidget (cancelButton);
setLayout (layout);
2013-07-26 19:09:23 +00:00
connect (cancelButton, SIGNAL (clicked (bool)), this, SIGNAL (done()));
connect (mCreate, SIGNAL (clicked (bool)), this, SLOT (create()));
2013-07-26 19:09:23 +00:00
connect (mId, SIGNAL (textChanged (const QString&)), this, SLOT (textChanged (const QString&)));
2013-07-26 19:09:23 +00:00
}
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()));
2013-07-26 19:09:23 +00:00
emit done();
2013-07-26 19:09:23 +00:00
}