2012-11-21 16:31:18 +00:00
|
|
|
|
|
|
|
#include "document.hpp"
|
|
|
|
|
2012-11-23 13:05:49 +00:00
|
|
|
CSMDoc::Document::Document (const std::string& name)
|
2012-11-22 22:42:17 +00:00
|
|
|
{
|
2012-11-23 13:05:49 +00:00
|
|
|
mName = name; ///< \todo replace with ESX list
|
|
|
|
|
2012-11-22 22:42:17 +00:00
|
|
|
connect (&mUndoStack, SIGNAL (cleanChanged (bool)), this, SLOT (modificationStateChanged (bool)));
|
2012-11-22 23:36:01 +00:00
|
|
|
|
|
|
|
// dummy implementation -> remove when proper save is implemented.
|
|
|
|
mSaveCount = 0;
|
|
|
|
connect (&mSaveTimer, SIGNAL(timeout()), this, SLOT (saving()));
|
2012-11-23 12:15:45 +00:00
|
|
|
|
|
|
|
// dummy implementation -> remove when proper verify is implemented.
|
|
|
|
mVerifyCount = 0;
|
|
|
|
connect (&mVerifyTimer, SIGNAL(timeout()), this, SLOT (verifying()));
|
2012-11-22 22:42:17 +00:00
|
|
|
}
|
2012-11-22 14:54:31 +00:00
|
|
|
|
|
|
|
QUndoStack& CSMDoc::Document::getUndoStack()
|
|
|
|
{
|
|
|
|
return mUndoStack;
|
2012-11-22 22:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CSMDoc::Document::getState() const
|
|
|
|
{
|
|
|
|
int state = 0;
|
|
|
|
|
|
|
|
if (!mUndoStack.isClean())
|
|
|
|
state |= State_Modified;
|
|
|
|
|
2012-11-22 23:36:01 +00:00
|
|
|
if (mSaveCount)
|
2012-11-23 09:52:46 +00:00
|
|
|
state |= State_Locked | State_Saving;
|
2012-11-22 23:36:01 +00:00
|
|
|
|
2012-11-23 12:15:45 +00:00
|
|
|
if (mVerifyCount)
|
|
|
|
state |= State_Locked | State_Verifying;
|
|
|
|
|
2012-11-22 22:42:17 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2012-11-23 13:05:49 +00:00
|
|
|
const std::string& CSMDoc::Document::getName() const
|
|
|
|
{
|
|
|
|
return mName;
|
|
|
|
}
|
|
|
|
|
2012-11-22 23:36:01 +00:00
|
|
|
void CSMDoc::Document::save()
|
|
|
|
{
|
|
|
|
mSaveCount = 1;
|
|
|
|
mSaveTimer.start (500);
|
2012-11-22 23:51:04 +00:00
|
|
|
emit stateChanged (getState(), this);
|
2012-11-23 11:20:35 +00:00
|
|
|
emit progress (1, 16, State_Saving, 1, this);
|
2012-11-22 23:36:01 +00:00
|
|
|
}
|
|
|
|
|
2012-11-23 12:15:45 +00:00
|
|
|
void CSMDoc::Document::verify()
|
|
|
|
{
|
|
|
|
mVerifyCount = 1;
|
|
|
|
mVerifyTimer.start (500);
|
|
|
|
emit stateChanged (getState(), this);
|
|
|
|
emit progress (1, 20, State_Verifying, 1, this);
|
|
|
|
}
|
|
|
|
|
2012-11-23 11:20:35 +00:00
|
|
|
void CSMDoc::Document::abortOperation (int type)
|
2012-11-22 23:36:01 +00:00
|
|
|
{
|
2012-11-23 11:20:35 +00:00
|
|
|
if (type==State_Saving)
|
|
|
|
{
|
|
|
|
mSaveTimer.stop();
|
|
|
|
emit stateChanged (getState(), this);
|
|
|
|
}
|
2012-11-23 12:15:45 +00:00
|
|
|
else if (type==State_Verifying)
|
|
|
|
{
|
|
|
|
mVerifyTimer.stop();
|
|
|
|
emit stateChanged (getState(), this);
|
|
|
|
}
|
2012-11-22 23:36:01 +00:00
|
|
|
}
|
|
|
|
|
2012-11-22 22:42:17 +00:00
|
|
|
void CSMDoc::Document::modificationStateChanged (bool clean)
|
|
|
|
{
|
|
|
|
emit stateChanged (getState(), this);
|
2012-11-22 23:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMDoc::Document::saving()
|
|
|
|
{
|
|
|
|
++mSaveCount;
|
|
|
|
|
2012-11-23 11:20:35 +00:00
|
|
|
emit progress (mSaveCount, 16, State_Saving, 1, this);
|
2012-11-23 09:25:34 +00:00
|
|
|
|
2012-11-22 23:36:01 +00:00
|
|
|
if (mSaveCount>15)
|
|
|
|
{
|
|
|
|
mSaveCount = 0;
|
|
|
|
mSaveTimer.stop();
|
|
|
|
mUndoStack.setClean();
|
2012-11-22 23:51:04 +00:00
|
|
|
emit stateChanged (getState(), this);
|
2012-11-22 23:36:01 +00:00
|
|
|
}
|
2012-11-23 12:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMDoc::Document::verifying()
|
|
|
|
{
|
|
|
|
++mVerifyCount;
|
|
|
|
|
|
|
|
emit progress (mVerifyCount, 20, State_Verifying, 1, this);
|
|
|
|
|
|
|
|
if (mVerifyCount>19)
|
|
|
|
{
|
|
|
|
mVerifyCount = 0;
|
|
|
|
mVerifyTimer.stop();
|
|
|
|
emit stateChanged (getState(), this);
|
|
|
|
}
|
2012-11-26 11:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const CSMWorld::Data& CSMDoc::Document::getData() const
|
|
|
|
{
|
|
|
|
return mData;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSMWorld::Data& CSMDoc::Document::getData()
|
|
|
|
{
|
|
|
|
return mData;
|
2012-11-22 14:54:31 +00:00
|
|
|
}
|