Merge remote-tracking branch 'smbas/feature-cloning-enhancements'

c++11
Marc Zinnschlag 10 years ago
commit d3bcf0711c

@ -58,6 +58,25 @@ void CSMWorld::CreateCommand::applyModifications()
{
for (std::map<int, QVariant>::const_iterator iter (mValues.begin()); iter!=mValues.end(); ++iter)
mModel.setData (mModel.getModelIndex (mId, iter->first), iter->second);
if (!mNestedValues.empty())
{
CSMWorld::IdTree *tree = dynamic_cast<CSMWorld::IdTree *>(&mModel);
if (tree == NULL)
{
throw std::logic_error("CSMWorld::CreateCommand: Attempt to add nested values to the non-nested model");
}
std::map<int, std::pair<int, QVariant> >::const_iterator current = mNestedValues.begin();
std::map<int, std::pair<int, QVariant> >::const_iterator end = mNestedValues.end();
for (; current != end; ++current)
{
QModelIndex index = tree->index(0,
current->second.first,
tree->getNestedModelIndex(mId, current->first));
tree->setData(index, current->second.second);
}
}
}
CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, QUndoCommand* parent)
@ -71,6 +90,11 @@ void CSMWorld::CreateCommand::addValue (int column, const QVariant& value)
mValues[column] = value;
}
void CSMWorld::CreateCommand::addNestedValue(int parentColumn, int nestedColumn, const QVariant &value)
{
mNestedValues[parentColumn] = std::make_pair(nestedColumn, value);
}
void CSMWorld::CreateCommand::setType (UniversalId::Type type)
{
mType = type;

@ -48,6 +48,9 @@ namespace CSMWorld
class CreateCommand : public QUndoCommand
{
std::map<int, QVariant> mValues;
std::map<int, std::pair<int, QVariant> > mNestedValues;
///< Parameter order: a parent column, a nested column, a data.
///< A nested row has index of 0.
protected:
@ -68,6 +71,8 @@ namespace CSMWorld
void addValue (int column, const QVariant& value);
void addNestedValue(int parentColumn, int nestedColumn, const QVariant &value);
virtual void redo();
virtual void undo();

@ -261,3 +261,13 @@ CSMWorld::NestedTableWrapperBase* CSMWorld::IdTree::nestedTable(const QModelInde
return mNestedCollection->nestedTable(index.row(), index.column());
}
int CSMWorld::IdTree::searchNestedColumnIndex(int parentColumn, Columns::ColumnId id)
{
return mNestedCollection->searchNestedColumnIndex(parentColumn, id);
}
int CSMWorld::IdTree::findNestedColumnIndex(int parentColumn, Columns::ColumnId id)
{
return mNestedCollection->findNestedColumnIndex(parentColumn, id);
}

@ -73,6 +73,12 @@ namespace CSMWorld
virtual bool hasChildren (const QModelIndex& index) const;
virtual int searchNestedColumnIndex(int parentColumn, Columns::ColumnId id);
///< \return the column index or -1 if the requested column wasn't found.
virtual int findNestedColumnIndex(int parentColumn, Columns::ColumnId id);
///< \return the column index or throws an exception if the requested column wasn't found.
signals:
void resetStart(const QString& id);

@ -15,3 +15,28 @@ int CSMWorld::NestedCollection::getNestedColumnsCount(int row, int column) const
{
return 0;
}
int CSMWorld::NestedCollection::searchNestedColumnIndex(int parentColumn, Columns::ColumnId id)
{
// Assumed that the parentColumn is always a valid index
const NestableColumn *parent = getNestableColumn(parentColumn);
int nestedColumnCount = getNestedColumnsCount(0, parentColumn);
for (int i = 0; i < nestedColumnCount; ++i)
{
if (parent->nestedColumn(i).mColumnId == id)
{
return i;
}
}
return -1;
}
int CSMWorld::NestedCollection::findNestedColumnIndex(int parentColumn, Columns::ColumnId id)
{
int index = searchNestedColumnIndex(parentColumn, id);
if (index == -1)
{
throw std::logic_error("CSMWorld::NestedCollection: No such nested column");
}
return index;
}

@ -1,6 +1,8 @@
#ifndef CSM_WOLRD_NESTEDCOLLECTION_H
#define CSM_WOLRD_NESTEDCOLLECTION_H
#include "columns.hpp"
class QVariant;
namespace CSMWorld
@ -33,6 +35,12 @@ namespace CSMWorld
virtual int getNestedColumnsCount(int row, int column) const;
virtual NestableColumn *getNestableColumn(int column) = 0;
virtual int searchNestedColumnIndex(int parentColumn, Columns::ColumnId id);
///< \return the column index or -1 if the requested column wasn't found.
virtual int findNestedColumnIndex(int parentColumn, Columns::ColumnId id);
///< \return the column index or throws an exception if the requested column wasn't found.
};
}

@ -8,6 +8,9 @@
#include <QSpinBox>
#include <QLabel>
#include "../../model/world/commands.hpp"
#include "../../model/world/idtree.hpp"
std::string CSVWorld::CellCreator::getId() const
{
if (mType->currentIndex()==0)
@ -20,6 +23,15 @@ std::string CSVWorld::CellCreator::getId() const
return stream.str();
}
void CSVWorld::CellCreator::configureCreateCommand(CSMWorld::CreateCommand& command) const
{
CSMWorld::IdTree *model = dynamic_cast<CSMWorld::IdTree *>(getData().getTableModel(getCollectionId()));
Q_ASSERT(model != NULL);
int parentIndex = model->findColumnIndex(CSMWorld::Columns::ColumnId_Cell);
int index = model->findNestedColumnIndex(parentIndex, CSMWorld::Columns::ColumnId_Interior);
command.addNestedValue(parentIndex, index, mType->currentIndex() == 0);
}
CSVWorld::CellCreator::CellCreator (CSMWorld::Data& data, QUndoStack& undoStack,
const CSMWorld::UniversalId& id)
: GenericCreator (data, undoStack, id)
@ -95,9 +107,16 @@ void CSVWorld::CellCreator::cloneMode(const std::string& originId,
}
}
void CSVWorld::CellCreator::toggleWidgets(bool active)
std::string CSVWorld::CellCreator::getErrors() const
{
CSVWorld::GenericCreator::toggleWidgets(active);
mType->setEnabled(active);
std::string errors;
if (mType->currentIndex() == 0)
{
errors = GenericCreator::getErrors();
}
else if (getData().hasId(getId()))
{
errors = "The Exterior Cell is already exist";
}
return errors;
}

@ -23,17 +23,22 @@ namespace CSVWorld
virtual std::string getId() const;
/// Allow subclasses to add additional data to \a command.
virtual void configureCreateCommand(CSMWorld::CreateCommand& command) const;
public:
CellCreator (CSMWorld::Data& data, QUndoStack& undoStack, const CSMWorld::UniversalId& id);
virtual void reset();
virtual void toggleWidgets(bool active = true);
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.
private slots:
void setType (int index);

@ -161,6 +161,8 @@ CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undo
connect (mCreate, SIGNAL (clicked (bool)), this, SLOT (create()));
connect (mId, SIGNAL (textChanged (const QString&)), this, SLOT (textChanged (const QString&)));
connect (&mData, SIGNAL (idListChanged()), this, SLOT (dataIdListChanged()));
}
void CSVWorld::GenericCreator::setEditLock (bool locked)
@ -291,3 +293,12 @@ void CSVWorld::GenericCreator::scopeChanged (int index)
update();
updateNamespace();
}
void CSVWorld::GenericCreator::dataIdListChanged()
{
// If the original ID of cloned record was removed, cancel the creator
if (mCloneMode && !mData.hasId(mClonedId))
{
emit done();
}
}

@ -113,6 +113,8 @@ namespace CSVWorld
void create();
void scopeChanged (int index);
void dataIdListChanged();
};
}

@ -447,7 +447,7 @@ void CSVWorld::Table::cloneRecord()
{
QModelIndexList selectedRows = selectionModel()->selectedRows();
const CSMWorld::UniversalId& toClone = getUniversalId(selectedRows.begin()->row());
if (selectedRows.size()==1 && !mModel->isDeleted (toClone.getId()))
if (selectedRows.size() == 1)
{
emit cloneRequest (toClone);
}

Loading…
Cancel
Save