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-12-08 22:27:59 +00:00
|
|
|
: mTools (mData)
|
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
|
|
|
|
2012-12-08 10:59:13 +00:00
|
|
|
connect (&mTools, SIGNAL (progress (int, int, int)), this, SLOT (progress (int, int, int)));
|
|
|
|
connect (&mTools, SIGNAL (done (int)), this, SLOT (operationDone (int)));
|
|
|
|
|
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-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-12-08 13:44:03 +00:00
|
|
|
state |= State_Locked | State_Saving | State_Operation;
|
2012-11-22 23:36:01 +00:00
|
|
|
|
2012-12-08 16:00:58 +00:00
|
|
|
if (int operations = mTools.getRunningOperations())
|
|
|
|
state |= State_Locked | State_Operation | operations;
|
2012-11-23 12:15:45 +00:00
|
|
|
|
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-12-11 14:35:47 +00:00
|
|
|
CSMWorld::UniversalId CSMDoc::Document::verify()
|
2012-11-23 12:15:45 +00:00
|
|
|
{
|
2012-12-11 14:35:47 +00:00
|
|
|
CSMWorld::UniversalId id = mTools.runVerifier();
|
2012-12-08 16:00:58 +00:00
|
|
|
emit stateChanged (getState(), this);
|
2012-12-11 14:35:47 +00:00
|
|
|
return id;
|
2012-11-23 12:15:45 +00:00
|
|
|
}
|
|
|
|
|
2012-11-23 11:20:35 +00:00
|
|
|
void CSMDoc::Document::abortOperation (int type)
|
2012-11-22 23:36:01 +00:00
|
|
|
{
|
2012-12-08 10:59:13 +00:00
|
|
|
mTools.abortOperation (type);
|
|
|
|
|
2012-11-23 11:20:35 +00:00
|
|
|
if (type==State_Saving)
|
|
|
|
{
|
|
|
|
mSaveTimer.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
|
|
|
}
|
|
|
|
|
2012-12-08 10:59:13 +00:00
|
|
|
void CSMDoc::Document::operationDone (int type)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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-12-08 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 14:35:47 +00:00
|
|
|
CSMTools::ReportModel *CSMDoc::Document::getReport (const CSMWorld::UniversalId& id)
|
|
|
|
{
|
|
|
|
return mTools.getReport (id);
|
|
|
|
}
|
|
|
|
|
2012-12-08 10:59:13 +00:00
|
|
|
void CSMDoc::Document::progress (int current, int max, int type)
|
|
|
|
{
|
|
|
|
emit progress (current, max, type, 1, this);
|
2012-11-22 14:54:31 +00:00
|
|
|
}
|