addded messages interface for operations/stages

This commit is contained in:
Marc Zinnschlag 2012-12-08 18:38:36 +01:00
parent 89b4497331
commit 72623652e4
5 changed files with 28 additions and 2 deletions

View file

@ -1,6 +1,9 @@
#include "operation.hpp"
#include <string>
#include <vector>
#include <QTimer>
#include "../doc/state.hpp"
@ -54,6 +57,8 @@ void CSMTools::Operation::abort()
void CSMTools::Operation::verify()
{
std::vector<std::string> messages;
while (mCurrentStage!=mStages.end())
{
if (mCurrentStep>=mCurrentStage->second)
@ -63,7 +68,7 @@ void CSMTools::Operation::verify()
}
else
{
mCurrentStage->first->perform (mCurrentStep++);
mCurrentStage->first->perform (mCurrentStep++, messages);
++mCurrentStepTotal;
break;
}
@ -71,6 +76,9 @@ void CSMTools::Operation::verify()
emit progress (mCurrentStepTotal, mTotalSteps ? mTotalSteps : 1, mType);
for (std::vector<std::string>::const_iterator iter (messages.begin()); iter!=messages.end(); ++iter)
emit reportMessage (iter->c_str(), mType);
if (mCurrentStage==mStages.end())
exit();
}

View file

@ -39,6 +39,8 @@ namespace CSMTools
void progress (int current, int max, int type);
void reportMessage (const QString& message, int type);
public slots:
void abort();

View file

@ -1,6 +1,9 @@
#ifndef CSM_TOOLS_STAGE_H
#define CSM_TOOLS_STAGE_H
#include <vector>
#include <string>
namespace CSMTools
{
class Stage
@ -12,7 +15,8 @@ namespace CSMTools
virtual int setup() = 0;
///< \return number of steps
virtual void perform (int stage) = 0;
virtual void perform (int stage, std::vector<std::string>& messages) = 0;
///< Messages resulting from this tage will be appended to \a messages.
};
}

View file

@ -30,6 +30,8 @@ CSMTools::Verifier *CSMTools::Tools::getVerifier()
connect (mVerifier, SIGNAL (progress (int, int, int)), this, SIGNAL (progress (int, int, int)));
connect (mVerifier, SIGNAL (finished()), this, SLOT (verifierDone()));
connect (mVerifier, SIGNAL (reportMessage (const QString&, int)),
this, SLOT (verifierMessage (const QString&, int)));
}
return mVerifier;
@ -77,4 +79,12 @@ int CSMTools::Tools::getRunningOperations() const
void CSMTools::Tools::verifierDone()
{
emit done (CSMDoc::State_Verifying);
}
#include <iostream>
void CSMTools::Tools::verifierMessage (const QString& message, int type)
{
/// \todo store it in a result model instead
std::cout << message.toStdString() << std::endl;
}

View file

@ -43,6 +43,8 @@ namespace CSMTools
void verifierDone();
void verifierMessage (const QString& message, int type);
signals:
void progress (int current, int max, int type);