mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 09:23:51 +00:00
added merge functions; temporarily merge on document creation
This commit is contained in:
parent
bd5e364ac1
commit
db29e411c4
6 changed files with 71 additions and 2 deletions
|
@ -35,6 +35,8 @@ void CS::Editor::createDocument()
|
||||||
document->getData().getGlobals().add (record);
|
document->getData().getGlobals().add (record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document->getData().merge(); /// \todo remove once proper ESX loading is implemented
|
||||||
|
|
||||||
mViewManager.addView (document);
|
mViewManager.addView (document);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,9 @@ namespace CSMWorld
|
||||||
|
|
||||||
virtual QVariant get (const Record<ESXRecordT>& record) const
|
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);
|
return static_cast<int> (record.mState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,3 +47,8 @@ QAbstractTableModel *CSMWorld::Data::getTableModel (const UniversalId& id)
|
||||||
|
|
||||||
return iter->second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSMWorld::Data::merge()
|
||||||
|
{
|
||||||
|
mGlobals.merge();
|
||||||
|
}
|
|
@ -33,6 +33,9 @@ namespace CSMWorld
|
||||||
|
|
||||||
QAbstractTableModel *getTableModel (const UniversalId& id);
|
QAbstractTableModel *getTableModel (const UniversalId& id);
|
||||||
///< If no table model is available for \æ id, an exception is thrown.
|
///< 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 <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
@ -58,6 +59,12 @@ namespace CSMWorld
|
||||||
virtual void setData (int index, int column, const QVariant& data) = 0;
|
virtual void setData (int index, int column, const QVariant& data) = 0;
|
||||||
|
|
||||||
virtual bool isEditable (int column) const = 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
|
///< \brief Collection of ID-based records
|
||||||
|
@ -95,6 +102,12 @@ namespace CSMWorld
|
||||||
|
|
||||||
virtual bool isEditable (int column) const;
|
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);
|
void addColumn (Column<ESXRecordT> *column);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -181,6 +194,23 @@ namespace CSMWorld
|
||||||
{
|
{
|
||||||
mColumns.push_back (column);
|
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
|
#endif
|
||||||
|
|
|
@ -13,7 +13,8 @@ namespace CSMWorld
|
||||||
State_BaseOnly, // defined in base only
|
State_BaseOnly, // defined in base only
|
||||||
State_Modified, // exists in base, but has been modified
|
State_Modified, // exists in base, but has been modified
|
||||||
State_ModifiedOnly, // newly created in 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;
|
ESXRecordT mBase;
|
||||||
|
@ -22,6 +23,8 @@ namespace CSMWorld
|
||||||
|
|
||||||
bool isDeleted() const;
|
bool isDeleted() const;
|
||||||
|
|
||||||
|
bool isErased() const;
|
||||||
|
|
||||||
bool isModified() const;
|
bool isModified() const;
|
||||||
|
|
||||||
const ESXRecordT& get() const;
|
const ESXRecordT& get() const;
|
||||||
|
@ -32,12 +35,21 @@ namespace CSMWorld
|
||||||
|
|
||||||
void setModified (const ESXRecordT& modified);
|
void setModified (const ESXRecordT& modified);
|
||||||
///< Throws an exception, if the record is deleted.
|
///< Throws an exception, if the record is deleted.
|
||||||
|
|
||||||
|
void merge();
|
||||||
|
///< Merge modified into base.
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename ESXRecordT>
|
template <typename ESXRecordT>
|
||||||
bool Record<ESXRecordT>::isDeleted() const
|
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>
|
template <typename ESXRecordT>
|
||||||
|
@ -75,6 +87,20 @@ namespace CSMWorld
|
||||||
if (mState!=State_ModifiedOnly)
|
if (mState!=State_ModifiedOnly)
|
||||||
mState = mBase==mModified ? State_BaseOnly : State_Modified;
|
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
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue