mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-19 17:39:44 +00:00
record loading progress bar
This commit is contained in:
parent
6692d2dc72
commit
6bc5869222
7 changed files with 77 additions and 22 deletions
|
@ -29,8 +29,10 @@ CSMDoc::DocumentManager::DocumentManager (const Files::ConfigurationManager& con
|
|||
this, SLOT (documentNotLoaded (Document *, const std::string&)));
|
||||
connect (this, SIGNAL (loadRequest (CSMDoc::Document *)),
|
||||
&mLoader, SLOT (loadDocument (CSMDoc::Document *)));
|
||||
connect (&mLoader, SIGNAL (nextStage (CSMDoc::Document *, const std::string&)),
|
||||
this, SIGNAL (nextStage (CSMDoc::Document *, const std::string&)));
|
||||
connect (&mLoader, SIGNAL (nextStage (CSMDoc::Document *, const std::string&, int)),
|
||||
this, SIGNAL (nextStage (CSMDoc::Document *, const std::string&, int)));
|
||||
connect (&mLoader, SIGNAL (nextRecord (CSMDoc::Document *)),
|
||||
this, SIGNAL (nextRecord (CSMDoc::Document *)));
|
||||
}
|
||||
|
||||
CSMDoc::DocumentManager::~DocumentManager()
|
||||
|
|
|
@ -72,7 +72,9 @@ namespace CSMDoc
|
|||
void loadingStopped (CSMDoc::Document *document, bool completed,
|
||||
const std::string& error);
|
||||
|
||||
void nextStage (CSMDoc::Document *document, const std::string& name);
|
||||
void nextStage (CSMDoc::Document *document, const std::string& name, int steps);
|
||||
|
||||
void nextRecord (CSMDoc::Document *document);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -42,12 +42,20 @@ void CSMDoc::Loader::load()
|
|||
|
||||
bool done = false;
|
||||
|
||||
const int batchingSize = 100;
|
||||
|
||||
try
|
||||
{
|
||||
if (iter->second.mRecordsLeft)
|
||||
{
|
||||
if (document->getData().continueLoading())
|
||||
iter->second.mRecordsLeft = false;
|
||||
for (int i=0; i<batchingSize; ++i) // do not flood the system with update signals
|
||||
if (document->getData().continueLoading())
|
||||
{
|
||||
iter->second.mRecordsLeft = false;
|
||||
break;
|
||||
}
|
||||
|
||||
emit nextRecord (document);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -56,17 +64,17 @@ void CSMDoc::Loader::load()
|
|||
{
|
||||
boost::filesystem::path path = document->getContentFiles()[iter->second.mFile];
|
||||
|
||||
emit nextStage (document, path.filename().string());
|
||||
|
||||
document->getData().startLoading (path, iter->second.mFile<size-1, false);
|
||||
int steps = document->getData().startLoading (path, iter->second.mFile<size-1, false);
|
||||
iter->second.mRecordsLeft = true;
|
||||
|
||||
emit nextStage (document, path.filename().string(), steps/batchingSize);
|
||||
}
|
||||
else if (iter->second.mFile==size)
|
||||
{
|
||||
emit nextStage (document, "Project File");
|
||||
|
||||
document->getData().startLoading (document->getProjectPath(), false, true);
|
||||
int steps = document->getData().startLoading (document->getProjectPath(), false, true);
|
||||
iter->second.mRecordsLeft = true;
|
||||
|
||||
emit nextStage (document, "Project File", steps/batchingSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -56,7 +56,12 @@ namespace CSMDoc
|
|||
///< Document load has been interrupted either because of a call to abortLoading
|
||||
/// or a problem during loading). In the former case error will be an empty string.
|
||||
|
||||
void nextStage (CSMDoc::Document *document, const std::string& name);
|
||||
void nextStage (CSMDoc::Document *document, const std::string& name, int steps);
|
||||
|
||||
void nextRecord (CSMDoc::Document *document);
|
||||
///< \note This signal is only given once per group of records. The group size is
|
||||
/// approximately the total number of records divided by the steps value of the
|
||||
/// previous nextStage signal.
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,11 @@ CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
|||
|
||||
QVBoxLayout *layout = new QVBoxLayout (this);
|
||||
|
||||
// file progress
|
||||
mFile = new QLabel (this);
|
||||
|
||||
layout->addWidget (mFile);
|
||||
|
||||
mFileProgress = new QProgressBar (this);
|
||||
|
||||
layout->addWidget (mFileProgress);
|
||||
|
@ -27,9 +32,16 @@ CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
|||
mFileProgress->setTextVisible (true);
|
||||
mFileProgress->setValue (0);
|
||||
|
||||
mFile = new QLabel (this);
|
||||
// record progress
|
||||
layout->addWidget (new QLabel ("Records", this));
|
||||
|
||||
layout->addWidget (mFile);
|
||||
mRecordProgress = new QProgressBar (this);
|
||||
|
||||
layout->addWidget (mRecordProgress);
|
||||
|
||||
mRecordProgress->setMinimum (0);
|
||||
mRecordProgress->setTextVisible (true);
|
||||
mRecordProgress->setValue (0);
|
||||
|
||||
setLayout (layout);
|
||||
|
||||
|
@ -38,19 +50,28 @@ CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
|||
show();
|
||||
}
|
||||
|
||||
void CSVDoc::LoadingDocument::nextStage (const std::string& name)
|
||||
void CSVDoc::LoadingDocument::nextStage (const std::string& name, int steps)
|
||||
{
|
||||
mFile->setText (QString::fromUtf8 (("Loading: " + name).c_str()));
|
||||
|
||||
mFileProgress->setValue (mFileProgress->value()+1);
|
||||
|
||||
mRecordProgress->setValue (0);
|
||||
mRecordProgress->setMaximum (steps);
|
||||
}
|
||||
|
||||
|
||||
CSVDoc::Loader::Loader()
|
||||
void CSVDoc::LoadingDocument::nextRecord()
|
||||
{
|
||||
int value = mRecordProgress->value()+1;
|
||||
|
||||
if (value<=mRecordProgress->maximum())
|
||||
mRecordProgress->setValue (value);
|
||||
}
|
||||
|
||||
|
||||
CSVDoc::Loader::Loader() {}
|
||||
|
||||
CSVDoc::Loader::~Loader()
|
||||
{
|
||||
for (std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter (mDocuments.begin());
|
||||
|
@ -79,10 +100,18 @@ void CSVDoc::Loader::loadingStopped (CSMDoc::Document *document, bool completed,
|
|||
}
|
||||
}
|
||||
|
||||
void CSVDoc::Loader::nextStage (CSMDoc::Document *document, const std::string& name)
|
||||
void CSVDoc::Loader::nextStage (CSMDoc::Document *document, const std::string& name, int steps)
|
||||
{
|
||||
std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter = mDocuments.find (document);
|
||||
|
||||
if (iter!=mDocuments.end())
|
||||
iter->second->nextStage (name);
|
||||
iter->second->nextStage (name, steps);
|
||||
}
|
||||
|
||||
void CSVDoc::Loader::nextRecord (CSMDoc::Document *document)
|
||||
{
|
||||
std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter = mDocuments.find (document);
|
||||
|
||||
if (iter!=mDocuments.end())
|
||||
iter->second->nextRecord();
|
||||
}
|
|
@ -22,12 +22,15 @@ namespace CSVDoc
|
|||
|
||||
QLabel *mFile;
|
||||
QProgressBar *mFileProgress;
|
||||
QProgressBar *mRecordProgress;
|
||||
|
||||
public:
|
||||
|
||||
LoadingDocument (CSMDoc::Document *document);
|
||||
|
||||
void nextStage (const std::string& name);
|
||||
void nextStage (const std::string& name, int steps);
|
||||
|
||||
void nextRecord();
|
||||
};
|
||||
|
||||
class Loader : public QObject
|
||||
|
@ -49,7 +52,9 @@ namespace CSVDoc
|
|||
void loadingStopped (CSMDoc::Document *document, bool completed,
|
||||
const std::string& error);
|
||||
|
||||
void nextStage (CSMDoc::Document *document, const std::string& name);
|
||||
void nextStage (CSMDoc::Document *document, const std::string& name, int steps);
|
||||
|
||||
void nextRecord (CSMDoc::Document *document);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -93,8 +93,12 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
|
|||
&mLoader, SLOT (loadingStopped (CSMDoc::Document *, bool, const std::string&)));
|
||||
|
||||
connect (
|
||||
&mDocumentManager, SIGNAL (nextStage (CSMDoc::Document *, const std::string&)),
|
||||
&mLoader, SLOT (nextStage (CSMDoc::Document *, const std::string&)));
|
||||
&mDocumentManager, SIGNAL (nextStage (CSMDoc::Document *, const std::string&, int)),
|
||||
&mLoader, SLOT (nextStage (CSMDoc::Document *, const std::string&, int)));
|
||||
|
||||
connect (
|
||||
&mDocumentManager, SIGNAL (nextRecord (CSMDoc::Document *)),
|
||||
&mLoader, SLOT (nextRecord (CSMDoc::Document *)));
|
||||
}
|
||||
|
||||
CSVDoc::ViewManager::~ViewManager()
|
||||
|
|
Loading…
Reference in a new issue