mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-10 03:39:55 +00:00
added operations progress bar
This commit is contained in:
parent
eaa58e0530
commit
2fc183d595
@ -4,7 +4,7 @@ set (OPENCS_SRC
|
||||
|
||||
model/doc/documentmanager.cpp model/doc/document.cpp
|
||||
|
||||
view/doc/viewmanager.cpp view/doc/view.cpp
|
||||
view/doc/viewmanager.cpp view/doc/view.cpp view/doc/operations.cpp view/doc/operation.cpp
|
||||
)
|
||||
|
||||
set (OPENCS_HDR
|
||||
@ -12,7 +12,7 @@ set (OPENCS_HDR
|
||||
|
||||
model/doc/documentmanager.hpp model/doc/document.hpp
|
||||
|
||||
view/doc/viewmanager.hpp view/doc/view.hpp
|
||||
view/doc/viewmanager.hpp view/doc/view.hpp view/doc/operations.hpp view/doc/operation.hpp
|
||||
)
|
||||
|
||||
set (OPENCS_US
|
||||
|
@ -33,13 +33,16 @@ void CSMDoc::Document::save()
|
||||
mSaveCount = 1;
|
||||
mSaveTimer.start (500);
|
||||
emit stateChanged (getState(), this);
|
||||
emit progress (1, 16, State_Saving, this);
|
||||
emit progress (1, 16, State_Saving, 1, this);
|
||||
}
|
||||
|
||||
void CSMDoc::Document::abortSave()
|
||||
void CSMDoc::Document::abortOperation (int type)
|
||||
{
|
||||
mSaveTimer.stop();
|
||||
emit stateChanged (getState(), this);
|
||||
if (type==State_Saving)
|
||||
{
|
||||
mSaveTimer.stop();
|
||||
emit stateChanged (getState(), this);
|
||||
}
|
||||
}
|
||||
|
||||
void CSMDoc::Document::modificationStateChanged (bool clean)
|
||||
@ -51,7 +54,7 @@ void CSMDoc::Document::saving()
|
||||
{
|
||||
++mSaveCount;
|
||||
|
||||
emit progress (mSaveCount, 16, State_Saving, this);
|
||||
emit progress (mSaveCount, 16, State_Saving, 1, this);
|
||||
|
||||
if (mSaveCount>15)
|
||||
{
|
||||
|
@ -39,13 +39,13 @@ namespace CSMDoc
|
||||
|
||||
void save();
|
||||
|
||||
void abortSave();
|
||||
void abortOperation (int type);
|
||||
|
||||
signals:
|
||||
|
||||
void stateChanged (int state, CSMDoc::Document *document);
|
||||
|
||||
void progress (int current, int max, int type, CSMDoc::Document *document);
|
||||
void progress (int current, int max, int type, int threads, CSMDoc::Document *document);
|
||||
|
||||
private slots:
|
||||
|
||||
|
49
apps/opencs/view/doc/operation.cpp
Normal file
49
apps/opencs/view/doc/operation.cpp
Normal file
@ -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;
|
||||
}
|
31
apps/opencs/view/doc/operation.hpp
Normal file
31
apps/opencs/view/doc/operation.hpp
Normal file
@ -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
|
47
apps/opencs/view/doc/operations.cpp
Normal file
47
apps/opencs/view/doc/operations.cpp
Normal file
@ -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;
|
||||
}
|
||||
}
|
37
apps/opencs/view/doc/operations.hpp
Normal file
37
apps/opencs/view/doc/operations.hpp
Normal file
@ -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
|
@ -9,6 +9,7 @@
|
||||
#include "../../model/doc/document.hpp"
|
||||
|
||||
#include "viewmanager.hpp"
|
||||
#include "operations.hpp"
|
||||
|
||||
void CSVDoc::View::closeEvent (QCloseEvent *event)
|
||||
{
|
||||
@ -94,6 +95,9 @@ CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int to
|
||||
setCentralWidget (new QWidget);
|
||||
resize (200, 200);
|
||||
|
||||
mOperations = new Operations;
|
||||
addDockWidget (Qt::BottomDockWidgetArea, mOperations);
|
||||
|
||||
updateTitle();
|
||||
|
||||
setupUi();
|
||||
@ -120,11 +124,23 @@ void CSVDoc::View::updateDocumentState()
|
||||
{
|
||||
updateTitle();
|
||||
updateActions();
|
||||
|
||||
static const int operations[] =
|
||||
{
|
||||
CSMDoc::Document::State_Saving,
|
||||
-1 // end marker
|
||||
};
|
||||
|
||||
int state = mDocument->getState() ;
|
||||
|
||||
for (int i=0; operations[i]!=-1; ++i)
|
||||
if (!(state & operations[i]))
|
||||
mOperations->quitOperation (operations[i]);
|
||||
}
|
||||
|
||||
void CSVDoc::View::updateProgress (int current, int max, int type)
|
||||
void CSVDoc::View::updateProgress (int current, int max, int type, int threads)
|
||||
{
|
||||
|
||||
mOperations->setProgress (current, max, type, threads);
|
||||
}
|
||||
|
||||
void CSVDoc::View::newView()
|
||||
|
@ -15,6 +15,7 @@ namespace CSMDoc
|
||||
namespace CSVDoc
|
||||
{
|
||||
class ViewManager;
|
||||
class Operations;
|
||||
|
||||
class View : public QMainWindow
|
||||
{
|
||||
@ -28,6 +29,7 @@ namespace CSVDoc
|
||||
QAction *mRedo;
|
||||
QAction *mSave;
|
||||
std::vector<QAction *> mEditingActions;
|
||||
Operations *mOperations;
|
||||
|
||||
// not implemented
|
||||
View (const View&);
|
||||
@ -62,7 +64,7 @@ namespace CSVDoc
|
||||
|
||||
void updateDocumentState();
|
||||
|
||||
void updateProgress (int current, int max, int type);
|
||||
void updateProgress (int current, int max, int type, int threads);
|
||||
|
||||
private slots:
|
||||
|
||||
|
@ -46,8 +46,8 @@ CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document)
|
||||
connect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)),
|
||||
this, SLOT (documentStateChanged (int, CSMDoc::Document *)));
|
||||
|
||||
connect (document, SIGNAL (progress (int, int, int, CSMDoc::Document *)),
|
||||
this, SLOT (progress (int, int, int, CSMDoc::Document *)));
|
||||
connect (document, SIGNAL (progress (int, int, int, int, CSMDoc::Document *)),
|
||||
this, SLOT (progress (int, int, int, int, CSMDoc::Document *)));
|
||||
}
|
||||
|
||||
View *view = new View (*this, document, countViews (document)+1);
|
||||
@ -102,9 +102,9 @@ void CSVDoc::ViewManager::documentStateChanged (int state, CSMDoc::Document *doc
|
||||
(*iter)->updateDocumentState();
|
||||
}
|
||||
|
||||
void CSVDoc::ViewManager::progress (int current, int max, int type, CSMDoc::Document *document)
|
||||
void CSVDoc::ViewManager::progress (int current, int max, int type, int threads, CSMDoc::Document *document)
|
||||
{
|
||||
for (std::vector<View *>::const_iterator iter (mViews.begin()); iter!=mViews.end(); ++iter)
|
||||
if ((*iter)->getDocument()==document)
|
||||
(*iter)->updateProgress (current, max, type);
|
||||
(*iter)->updateProgress (current, max, type, threads);
|
||||
}
|
@ -46,7 +46,7 @@ namespace CSVDoc
|
||||
|
||||
void documentStateChanged (int state, CSMDoc::Document *document);
|
||||
|
||||
void progress (int current, int max, int type, CSMDoc::Document *document);
|
||||
void progress (int current, int max, int type, int threads, CSMDoc::Document *document);
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user