1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 09:53:50 +00:00

create merged document and open a view for it (document is still empty at this point)

This commit is contained in:
Marc Zinnschlag 2015-08-16 15:24:48 +02:00
parent d8655f2ff8
commit 1b663f01af
16 changed files with 165 additions and 19 deletions

View file

@ -35,14 +35,18 @@ opencs_hdrs_noqt (model/world
opencs_units (model/tools opencs_units (model/tools
tools reportmodel tools reportmodel mergeoperation
) )
opencs_units_noqt (model/tools opencs_units_noqt (model/tools
mandatoryid skillcheck classcheck factioncheck racecheck soundcheck regioncheck mandatoryid skillcheck classcheck factioncheck racecheck soundcheck regioncheck
birthsigncheck spellcheck referencecheck referenceablecheck scriptcheck bodypartcheck birthsigncheck spellcheck referencecheck referenceablecheck scriptcheck bodypartcheck
startscriptcheck search searchoperation searchstage pathgridcheck soundgencheck startscriptcheck search searchoperation searchstage pathgridcheck soundgencheck
mergeoperation mergestages
)
opencs_hdrs_noqt (model/tools
mergestate
) )

View file

@ -21,7 +21,8 @@
CS::Editor::Editor () CS::Editor::Editor ()
: mUserSettings (mCfgMgr), mDocumentManager (mCfgMgr), : mUserSettings (mCfgMgr), mDocumentManager (mCfgMgr),
mViewManager (mDocumentManager), mPid(""), mViewManager (mDocumentManager), mPid(""),
mLock(), mIpcServerName ("org.openmw.OpenCS"), mServer(NULL), mClientSocket(NULL) mLock(), mMerge (mDocumentManager),
mIpcServerName ("org.openmw.OpenCS"), mServer(NULL), mClientSocket(NULL)
{ {
std::pair<Files::PathContainer, std::vector<std::string> > config = readConfig(); std::pair<Files::PathContainer, std::vector<std::string> > config = readConfig();

View file

@ -2294,6 +2294,8 @@ CSMDoc::Document::Document (const VFS::Manager* vfs, const Files::ConfigurationM
connect (&mTools, SIGNAL (progress (int, int, int)), this, SLOT (progress (int, int, int))); connect (&mTools, SIGNAL (progress (int, int, int)), this, SLOT (progress (int, int, int)));
connect (&mTools, SIGNAL (done (int, bool)), this, SLOT (operationDone (int, bool))); connect (&mTools, SIGNAL (done (int, bool)), this, SLOT (operationDone (int, bool)));
connect (&mTools, SIGNAL (mergeDone (CSMDoc::Document*)),
this, SIGNAL (mergeDone (CSMDoc::Document*)));
connect (&mSaving, SIGNAL (progress (int, int, int)), this, SLOT (progress (int, int, int))); connect (&mSaving, SIGNAL (progress (int, int, int)), this, SLOT (progress (int, int, int)));
connect (&mSaving, SIGNAL (done (int, bool)), this, SLOT (operationDone (int, bool))); connect (&mSaving, SIGNAL (done (int, bool)), this, SLOT (operationDone (int, bool)));
@ -2388,7 +2390,7 @@ void CSMDoc::Document::runSearch (const CSMWorld::UniversalId& searchId, const C
emit stateChanged (getState(), this); emit stateChanged (getState(), this);
} }
void CSMDoc::Document::runMerge (const boost::filesystem::path& target) void CSMDoc::Document::runMerge (std::auto_ptr<CSMDoc::Document> target)
{ {
mTools.runMerge (target); mTools.runMerge (target);
emit stateChanged (getState(), this); emit stateChanged (getState(), this);

View file

@ -130,7 +130,7 @@ namespace CSMDoc
void runSearch (const CSMWorld::UniversalId& searchId, const CSMTools::Search& search); void runSearch (const CSMWorld::UniversalId& searchId, const CSMTools::Search& search);
void runMerge (const boost::filesystem::path& target); void runMerge (std::auto_ptr<CSMDoc::Document> target);
void abortOperation (int type); void abortOperation (int type);
@ -158,6 +158,10 @@ namespace CSMDoc
void progress (int current, int max, int type, int threads, CSMDoc::Document *document); void progress (int current, int max, int type, int threads, CSMDoc::Document *document);
/// \attention When this signal is emitted, *this hands over the ownership of the
/// document. This signal must be handled to avoid a leak.
void mergeDone (CSMDoc::Document *document);
private slots: private slots:
void modificationStateChanged (bool clean); void modificationStateChanged (bool clean);

View file

@ -57,10 +57,24 @@ bool CSMDoc::DocumentManager::isEmpty()
void CSMDoc::DocumentManager::addDocument (const std::vector<boost::filesystem::path>& files, const boost::filesystem::path& savePath, void CSMDoc::DocumentManager::addDocument (const std::vector<boost::filesystem::path>& files, const boost::filesystem::path& savePath,
bool new_) bool new_)
{ {
Document *document = new Document (mVFS, mConfiguration, files, new_, savePath, mResDir, mEncoding, mResourcesManager, mBlacklistedScripts); Document *document = makeDocument (files, savePath, new_);
insertDocument (document);
}
CSMDoc::Document *CSMDoc::DocumentManager::makeDocument (
const std::vector< boost::filesystem::path >& files,
const boost::filesystem::path& savePath, bool new_)
{
return new Document (mVFS, mConfiguration, files, new_, savePath, mResDir, mEncoding, mResourcesManager, mBlacklistedScripts);
}
void CSMDoc::DocumentManager::insertDocument (CSMDoc::Document *document)
{
mDocuments.push_back (document); mDocuments.push_back (document);
connect (document, SIGNAL (mergeDone (CSMDoc::Document*)),
this, SLOT (insertDocument (CSMDoc::Document*)));
emit loadRequest (document); emit loadRequest (document);
mLoader.hasThingsToDo().wakeAll(); mLoader.hasThingsToDo().wakeAll();

View file

@ -56,6 +56,15 @@ namespace CSMDoc
///< \param new_ Do not load the last content file in \a files and instead create in an ///< \param new_ Do not load the last content file in \a files and instead create in an
/// appropriate way. /// appropriate way.
/// Create a new document. The ownership of the created document is transferred to
/// the calling function. The DocumentManager does not manage it. Loading has not
/// taken place at the point when the document is returned.
///
/// \param new_ Do not load the last content file in \a files and instead create in an
/// appropriate way.
Document *makeDocument (const std::vector< boost::filesystem::path >& files,
const boost::filesystem::path& savePath, bool new_);
void setResourceDir (const boost::filesystem::path& parResDir); void setResourceDir (const boost::filesystem::path& parResDir);
void setEncoding (ToUTF8::FromType encoding); void setEncoding (ToUTF8::FromType encoding);
@ -84,6 +93,10 @@ namespace CSMDoc
void removeDocument (CSMDoc::Document *document); void removeDocument (CSMDoc::Document *document);
///< Emits the lastDocumentDeleted signal, if applicable. ///< Emits the lastDocumentDeleted signal, if applicable.
/// Hand over document to *this. The ownership is transferred. The DocumentManager
/// will initiate the load procedure, if necessary
void insertDocument (CSMDoc::Document *document);
signals: signals:
void documentAdded (CSMDoc::Document *document); void documentAdded (CSMDoc::Document *document);

View file

@ -83,7 +83,9 @@ namespace CSMDoc
void executeStage(); void executeStage();
void operationDone(); protected slots:
virtual void operationDone();
}; };
} }

View file

@ -2,14 +2,25 @@
#include "mergeoperation.hpp" #include "mergeoperation.hpp"
#include "../doc/state.hpp" #include "../doc/state.hpp"
#include "../doc/document.hpp"
#include "mergestages.hpp"
CSMTools::MergeOperation::MergeOperation (CSMDoc::Document& document) CSMTools::MergeOperation::MergeOperation (CSMDoc::Document& document)
: CSMDoc::Operation (CSMDoc::State_Merging, true) : CSMDoc::Operation (CSMDoc::State_Merging, true), mState (document)
{ {
appendStage (new FinishMergedDocumentStage (mState));
} }
void CSMTools::MergeOperation::setTarget (const boost::filesystem::path& target) void CSMTools::MergeOperation::setTarget (std::auto_ptr<CSMDoc::Document> document)
{ {
mState.mTarget = document;
}
void CSMTools::MergeOperation::operationDone()
{
CSMDoc::Operation::operationDone();
if (mState.mCompleted)
emit mergeDone (mState.mTarget.release());
} }

View file

@ -1,10 +1,12 @@
#ifndef CSM_TOOLS_MERGEOPERATION_H #ifndef CSM_TOOLS_MERGEOPERATION_H
#define CSM_TOOLS_MERGEOPERATION_H #define CSM_TOOLS_MERGEOPERATION_H
#include <boost/filesystem/path.hpp> #include <memory>
#include "../doc/operation.hpp" #include "../doc/operation.hpp"
#include "mergestate.hpp"
namespace CSMDoc namespace CSMDoc
{ {
class Document; class Document;
@ -14,14 +16,27 @@ namespace CSMTools
{ {
class MergeOperation : public CSMDoc::Operation class MergeOperation : public CSMDoc::Operation
{ {
Q_OBJECT
MergeState mState;
public: public:
MergeOperation (CSMDoc::Document& document); MergeOperation (CSMDoc::Document& document);
/// \attention Do not call this function while a merge is running. /// \attention Do not call this function while a merge is running.
void setTarget (const boost::filesystem::path& target); void setTarget (std::auto_ptr<CSMDoc::Document> document);
protected slots:
virtual void operationDone();
signals:
/// \attention When this signal is emitted, *this hands over the ownership of the
/// document. This signal must be handled to avoid a leak.
void mergeDone (CSMDoc::Document *document);
}; };
} }

View file

@ -0,0 +1,18 @@
#include "mergestages.hpp"
#include "mergestate.hpp"
CSMTools::FinishMergedDocumentStage::FinishMergedDocumentStage (MergeState& state)
: mState (state)
{}
int CSMTools::FinishMergedDocumentStage::setup()
{
return 1;
}
void CSMTools::FinishMergedDocumentStage::perform (int stage, CSMDoc::Messages& messages)
{
mState.mCompleted = true;
}

View file

@ -0,0 +1,26 @@
#ifndef CSM_TOOLS_MERGESTAGES_H
#define CSM_TOOLS_MERGESTAGES_H
#include "../doc/stage.hpp"
namespace CSMTools
{
struct MergeState;
class FinishMergedDocumentStage : public CSMDoc::Stage
{
MergeState& mState;
public:
FinishMergedDocumentStage (MergeState& state);
virtual int setup();
///< \return number of steps
virtual void perform (int stage, CSMDoc::Messages& messages);
///< Messages resulting from this stage will be appended to \a messages.
};
}
#endif

View file

@ -0,0 +1,20 @@
#ifndef CSM_TOOLS_MERGESTATE_H
#define CSM_TOOLS_MERGESTATE_H
#include <memory>
#include "../doc/document.hpp"
namespace CSMTools
{
struct MergeState
{
std::auto_ptr<CSMDoc::Document> mTarget;
CSMDoc::Document& mSource;
bool mCompleted;
MergeState (CSMDoc::Document& source) : mSource (source), mCompleted (false) {}
};
}
#endif

View file

@ -195,7 +195,7 @@ void CSMTools::Tools::runSearch (const CSMWorld::UniversalId& searchId, const Se
mSearch.start(); mSearch.start();
} }
void CSMTools::Tools::runMerge (const boost::filesystem::path& target) void CSMTools::Tools::runMerge (std::auto_ptr<CSMDoc::Document> target)
{ {
// not setting an active report, because merge does not produce messages // not setting an active report, because merge does not produce messages
@ -203,6 +203,8 @@ void CSMTools::Tools::runMerge (const boost::filesystem::path& target)
{ {
mMergeOperation = new MergeOperation (mDocument); mMergeOperation = new MergeOperation (mDocument);
mMerge.setOperation (mMergeOperation); mMerge.setOperation (mMergeOperation);
connect (mMergeOperation, SIGNAL (mergeDone (CSMDoc::Document*)),
this, SIGNAL (mergeDone (CSMDoc::Document*)));
} }
mMergeOperation->setTarget (target); mMergeOperation->setTarget (target);

View file

@ -1,6 +1,7 @@
#ifndef CSM_TOOLS_TOOLS_H #ifndef CSM_TOOLS_TOOLS_H
#define CSM_TOOLS_TOOLS_H #define CSM_TOOLS_TOOLS_H
#include <memory>
#include <map> #include <map>
#include <QObject> #include <QObject>
@ -73,7 +74,7 @@ namespace CSMTools
void runSearch (const CSMWorld::UniversalId& searchId, const Search& search); void runSearch (const CSMWorld::UniversalId& searchId, const Search& search);
void runMerge (const boost::filesystem::path& target); void runMerge (std::auto_ptr<CSMDoc::Document> target);
void abortOperation (int type); void abortOperation (int type);
///< \attention The operation is not aborted immediately. ///< \attention The operation is not aborted immediately.
@ -92,6 +93,10 @@ namespace CSMTools
void progress (int current, int max, int type); void progress (int current, int max, int type);
void done (int type, bool failed); void done (int type, bool failed);
/// \attention When this signal is emitted, *this hands over the ownership of the
/// document. This signal must be handled to avoid a leak.
void mergeDone (CSMDoc::Document *document);
}; };
} }

View file

@ -10,6 +10,7 @@
#include <QKeyEvent> #include <QKeyEvent>
#include "../../model/doc/document.hpp" #include "../../model/doc/document.hpp"
#include "../../model/doc/documentmanager.hpp"
#include "../doc/filewidget.hpp" #include "../doc/filewidget.hpp"
#include "../doc/adjusterwidget.hpp" #include "../doc/adjusterwidget.hpp"
@ -25,8 +26,8 @@ void CSVTools::Merge::keyPressEvent (QKeyEvent *event)
QWidget::keyPressEvent (event); QWidget::keyPressEvent (event);
} }
CSVTools::Merge::Merge (QWidget *parent) CSVTools::Merge::Merge (CSMDoc::DocumentManager& documentManager, QWidget *parent)
: QWidget (parent), mDocument (0) : QWidget (parent), mDocument (0), mDocumentManager (documentManager)
{ {
setWindowTitle ("Merge Content Files into a new Game File"); setWindowTitle ("Merge Content Files into a new Game File");
@ -124,7 +125,13 @@ void CSVTools::Merge::accept()
{ {
if ((mDocument->getState() & CSMDoc::State_Merging)==0) if ((mDocument->getState() & CSMDoc::State_Merging)==0)
{ {
mDocument->runMerge (mAdjuster->getPath()); std::vector< boost::filesystem::path > files (1, mAdjuster->getPath());
std::auto_ptr<CSMDoc::Document> target (
mDocumentManager.makeDocument (files, files[0], true));
mDocument->runMerge (target);
hide(); hide();
} }
} }

View file

@ -11,6 +11,7 @@ class QListWidget;
namespace CSMDoc namespace CSMDoc
{ {
class Document; class Document;
class DocumentManager;
} }
namespace CSVDoc namespace CSVDoc
@ -30,12 +31,13 @@ namespace CSVTools
QListWidget *mFiles; QListWidget *mFiles;
CSVDoc::FileWidget *mNewFile; CSVDoc::FileWidget *mNewFile;
CSVDoc::AdjusterWidget *mAdjuster; CSVDoc::AdjusterWidget *mAdjuster;
CSMDoc::DocumentManager& mDocumentManager;
void keyPressEvent (QKeyEvent *event); void keyPressEvent (QKeyEvent *event);
public: public:
Merge (QWidget *parent = 0); Merge (CSMDoc::DocumentManager& documentManager, QWidget *parent = 0);
/// Configure dialogue for a new merge /// Configure dialogue for a new merge
void configure (CSMDoc::Document *document); void configure (CSMDoc::Document *document);