mirror of https://github.com/OpenMW/openmw.git
added operations progress bar
parent
eaa58e0530
commit
2fc183d595
@ -0,0 +1,49 @@
|
||||
|
||||
#include "operation.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "../../model/doc/document.hpp"
|
||||
|
||||
void CSVDoc::Operation::updateLabel (int threads)
|
||||
{
|
||||
if (threads==-1 || ((threads==0)!=mStalling))
|
||||
{
|
||||
std::string name ("unknown operation");
|
||||
|
||||
switch (mType)
|
||||
{
|
||||
case CSMDoc::Document::State_Saving: name = "saving"; break;
|
||||
}
|
||||
|
||||
std::ostringstream stream;
|
||||
|
||||
if ((mStalling = (threads<=0)))
|
||||
{
|
||||
stream << name << " (waiting for a free worker thread)";
|
||||
}
|
||||
else
|
||||
{
|
||||
stream << name << " (%p%)";
|
||||
}
|
||||
|
||||
setFormat (stream.str().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
CSVDoc::Operation::Operation (int type) : mType (type), mStalling (false)
|
||||
{
|
||||
updateLabel();
|
||||
}
|
||||
|
||||
void CSVDoc::Operation::setProgress (int current, int max, int threads)
|
||||
{
|
||||
updateLabel (threads);
|
||||
setRange (0, max);
|
||||
setValue (current);
|
||||
}
|
||||
|
||||
int CSVDoc::Operation::getType() const
|
||||
{
|
||||
return mType;
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#ifndef CSV_DOC_OPERATION_H
|
||||
#define CSV_DOC_OPERATION_H
|
||||
|
||||
#include <QProgressBar>
|
||||
|
||||
namespace CSVDoc
|
||||
{
|
||||
class Operation : public QProgressBar
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
int mType;
|
||||
bool mStalling;
|
||||
|
||||
// not implemented
|
||||
Operation (const Operation&);
|
||||
Operation& operator= (const Operation&);
|
||||
|
||||
void updateLabel (int threads = -1);
|
||||
|
||||
public:
|
||||
|
||||
Operation (int type);
|
||||
|
||||
void setProgress (int current, int max, int threads);
|
||||
|
||||
int getType() const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,47 @@
|
||||
|
||||
#include "operations.hpp"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "operation.hpp"
|
||||
|
||||
CSVDoc::Operations::Operations()
|
||||
{
|
||||
/// \todo make widget height fixed (exactly the height required to display all operations)
|
||||
|
||||
setFeatures (QDockWidget::NoDockWidgetFeatures);
|
||||
|
||||
QWidget *widget = new QWidget;
|
||||
setWidget (widget);
|
||||
|
||||
mLayout = new QVBoxLayout;
|
||||
|
||||
widget->setLayout (mLayout);
|
||||
}
|
||||
|
||||
void CSVDoc::Operations::setProgress (int current, int max, int type, int threads)
|
||||
{
|
||||
for (std::vector<Operation *>::iterator iter (mOperations.begin()); iter!=mOperations.end(); ++iter)
|
||||
if ((*iter)->getType()==type)
|
||||
{
|
||||
(*iter)->setProgress (current, max, threads);
|
||||
return;
|
||||
}
|
||||
|
||||
Operation *operation = new Operation (type);
|
||||
|
||||
mLayout->addWidget (operation);
|
||||
mOperations.push_back (operation);
|
||||
operation->setProgress (current, max, threads);
|
||||
}
|
||||
|
||||
void CSVDoc::Operations::quitOperation (int type)
|
||||
{
|
||||
for (std::vector<Operation *>::iterator iter (mOperations.begin()); iter!=mOperations.end(); ++iter)
|
||||
if ((*iter)->getType()==type)
|
||||
{
|
||||
delete *iter;
|
||||
mOperations.erase (iter);
|
||||
break;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
#ifndef CSV_DOC_OPERATIONS_H
|
||||
#define CSV_DOC_OPERATIONS_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <QDockWidget>
|
||||
|
||||
class QVBoxLayout;
|
||||
|
||||
namespace CSVDoc
|
||||
{
|
||||
class Operation;
|
||||
|
||||
class Operations : public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QVBoxLayout *mLayout;
|
||||
std::vector<Operation *> mOperations;
|
||||
|
||||
// not implemented
|
||||
Operations (const Operations&);
|
||||
Operations& operator= (const Operations&);
|
||||
|
||||
public:
|
||||
|
||||
Operations();
|
||||
|
||||
void setProgress (int current, int max, int type, int threads);
|
||||
///< Implicitly starts the operation, if it is not running already.
|
||||
|
||||
void quitOperation (int type);
|
||||
///< Calling this function for an operation that is not running is a no-op.
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue