mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-27 05:37:25 +00:00
added merge functions; temporarily merge on document creation
This commit is contained in:
parent
bd5e364ac1
commit
db29e411c4
@ -35,6 +35,8 @@ void CS::Editor::createDocument()
|
||||
document->getData().getGlobals().add (record);
|
||||
}
|
||||
|
||||
document->getData().merge(); /// \todo remove once proper ESX loading is implemented
|
||||
|
||||
mViewManager.addView (document);
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,9 @@ namespace CSMWorld
|
||||
|
||||
virtual QVariant get (const Record<ESXRecordT>& record) const
|
||||
{
|
||||
if (record.mState==Record<ESXRecordT>::State_Erased)
|
||||
return static_cast<int> (Record<ESXRecordT>::State_Deleted);
|
||||
|
||||
return static_cast<int> (record.mState);
|
||||
}
|
||||
|
||||
|
@ -46,4 +46,9 @@ QAbstractTableModel *CSMWorld::Data::getTableModel (const UniversalId& id)
|
||||
throw std::logic_error ("No table model available for " + id.toString());
|
||||
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
void CSMWorld::Data::merge()
|
||||
{
|
||||
mGlobals.merge();
|
||||
}
|
@ -33,6 +33,9 @@ namespace CSMWorld
|
||||
|
||||
QAbstractTableModel *getTableModel (const UniversalId& id);
|
||||
///< If no table model is available for \æ id, an exception is thrown.
|
||||
|
||||
void merge();
|
||||
///< Merge modified into base.
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <stdexcept>
|
||||
#include <functional>
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
@ -58,6 +59,12 @@ namespace CSMWorld
|
||||
virtual void setData (int index, int column, const QVariant& data) = 0;
|
||||
|
||||
virtual bool isEditable (int column) const = 0;
|
||||
|
||||
virtual void merge() = 0;
|
||||
///< Merge modified into base.
|
||||
|
||||
virtual void purge() = 0;
|
||||
///< Remove records that are flagged as erased.
|
||||
};
|
||||
|
||||
///< \brief Collection of ID-based records
|
||||
@ -95,6 +102,12 @@ namespace CSMWorld
|
||||
|
||||
virtual bool isEditable (int column) const;
|
||||
|
||||
virtual void merge();
|
||||
///< Merge modified into base.
|
||||
|
||||
virtual void purge();
|
||||
///< Remove records that are flagged as erased.
|
||||
|
||||
void addColumn (Column<ESXRecordT> *column);
|
||||
};
|
||||
|
||||
@ -181,6 +194,23 @@ namespace CSMWorld
|
||||
{
|
||||
mColumns.push_back (column);
|
||||
}
|
||||
|
||||
template<typename ESXRecordT>
|
||||
void IdCollection<ESXRecordT>::merge()
|
||||
{
|
||||
for (typename std::vector<Record<ESXRecordT> >::iterator iter (mRecords.begin()); iter!=mRecords.end(); ++iter)
|
||||
iter->merge();
|
||||
|
||||
purge();
|
||||
}
|
||||
|
||||
template<typename ESXRecordT>
|
||||
void IdCollection<ESXRecordT>::purge()
|
||||
{
|
||||
mRecords.erase (std::remove_if (mRecords.begin(), mRecords.end(),
|
||||
std::mem_fun_ref (&Record<ESXRecordT>::isErased) // I want lambda :(
|
||||
), mRecords.end());
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -13,7 +13,8 @@ namespace CSMWorld
|
||||
State_BaseOnly, // defined in base only
|
||||
State_Modified, // exists in base, but has been modified
|
||||
State_ModifiedOnly, // newly created in modified
|
||||
State_Deleted // exists in base, but has been deleted
|
||||
State_Deleted, // exists in base, but has been deleted
|
||||
State_Erased // does not exist at all (we mostly treat that the same way as deleted)
|
||||
};
|
||||
|
||||
ESXRecordT mBase;
|
||||
@ -22,6 +23,8 @@ namespace CSMWorld
|
||||
|
||||
bool isDeleted() const;
|
||||
|
||||
bool isErased() const;
|
||||
|
||||
bool isModified() const;
|
||||
|
||||
const ESXRecordT& get() const;
|
||||
@ -32,12 +35,21 @@ namespace CSMWorld
|
||||
|
||||
void setModified (const ESXRecordT& modified);
|
||||
///< Throws an exception, if the record is deleted.
|
||||
|
||||
void merge();
|
||||
///< Merge modified into base.
|
||||
};
|
||||
|
||||
template <typename ESXRecordT>
|
||||
bool Record<ESXRecordT>::isDeleted() const
|
||||
{
|
||||
return mState==State_Deleted;
|
||||
return mState==State_Deleted || mState==State_Erased;
|
||||
}
|
||||
|
||||
template <typename ESXRecordT>
|
||||
bool Record<ESXRecordT>::isErased() const
|
||||
{
|
||||
return mState==State_Erased;
|
||||
}
|
||||
|
||||
template <typename ESXRecordT>
|
||||
@ -75,6 +87,20 @@ namespace CSMWorld
|
||||
if (mState!=State_ModifiedOnly)
|
||||
mState = mBase==mModified ? State_BaseOnly : State_Modified;
|
||||
}
|
||||
|
||||
template <typename ESXRecordT>
|
||||
void Record<ESXRecordT>::merge()
|
||||
{
|
||||
if (isModified())
|
||||
{
|
||||
mBase = mModified;
|
||||
mState = State_BaseOnly;
|
||||
}
|
||||
else if (mState==State_Deleted)
|
||||
{
|
||||
mState = State_Erased;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user