mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-30 21:32:42 +00:00
Change the loader's top progress bar to show total number of records processed rather than the number of files.
This commit is contained in:
parent
65df15a89d
commit
ff072441fd
@ -77,19 +77,19 @@ void CSMDoc::Loader::load()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iter->second.mFile<size)
|
if (iter->second.mFile<size) // start loading the files
|
||||||
{
|
{
|
||||||
boost::filesystem::path path = document->getContentFiles()[iter->second.mFile];
|
boost::filesystem::path path = document->getContentFiles()[iter->second.mFile];
|
||||||
|
|
||||||
int steps = document->getData().startLoading (path, iter->second.mFile!=editedIndex, false);
|
int steps = document->getData().startLoading (path, iter->second.mFile!=editedIndex, /*project*/false);
|
||||||
iter->second.mRecordsLeft = true;
|
iter->second.mRecordsLeft = true;
|
||||||
iter->second.mRecordsLoaded = 0;
|
iter->second.mRecordsLoaded = 0;
|
||||||
|
|
||||||
emit nextStage (document, path.filename().string(), steps);
|
emit nextStage (document, path.filename().string(), steps);
|
||||||
}
|
}
|
||||||
else if (iter->second.mFile==size)
|
else if (iter->second.mFile==size) // start loading the last (project) file
|
||||||
{
|
{
|
||||||
int steps = document->getData().startLoading (document->getProjectPath(), false, true);
|
int steps = document->getData().startLoading (document->getProjectPath(), /*base*/false, true);
|
||||||
iter->second.mRecordsLeft = true;
|
iter->second.mRecordsLeft = true;
|
||||||
iter->second.mRecordsLoaded = 0;
|
iter->second.mRecordsLoaded = 0;
|
||||||
|
|
||||||
|
@ -897,6 +897,22 @@ void CSMWorld::Data::merge()
|
|||||||
mGlobals.merge();
|
mGlobals.merge();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CSMWorld::Data::getTotalRecords (const std::vector<boost::filesystem::path>& files)
|
||||||
|
{
|
||||||
|
int records = 0;
|
||||||
|
|
||||||
|
std::unique_ptr<ESM::ESMReader> reader = std::unique_ptr<ESM::ESMReader>(new ESM::ESMReader);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < files.size(); ++i)
|
||||||
|
{
|
||||||
|
reader->open(files[i].string());
|
||||||
|
records += reader->getRecordCount();
|
||||||
|
reader->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return records;
|
||||||
|
}
|
||||||
|
|
||||||
int CSMWorld::Data::startLoading (const boost::filesystem::path& path, bool base, bool project)
|
int CSMWorld::Data::startLoading (const boost::filesystem::path& path, bool base, bool project)
|
||||||
{
|
{
|
||||||
// Don't delete the Reader yet. Some record types store a reference to the Reader to handle on-demand loading
|
// Don't delete the Reader yet. Some record types store a reference to the Reader to handle on-demand loading
|
||||||
|
@ -260,6 +260,8 @@ namespace CSMWorld
|
|||||||
void merge();
|
void merge();
|
||||||
///< Merge modified into base.
|
///< Merge modified into base.
|
||||||
|
|
||||||
|
int getTotalRecords (const std::vector<boost::filesystem::path>& files); // for better loading bar
|
||||||
|
|
||||||
int startLoading (const boost::filesystem::path& path, bool base, bool project);
|
int startLoading (const boost::filesystem::path& path, bool base, bool project);
|
||||||
///< Begin merging content of a file into base or modified.
|
///< Begin merging content of a file into base or modified.
|
||||||
///
|
///
|
||||||
|
@ -17,7 +17,7 @@ void CSVDoc::LoadingDocument::closeEvent (QCloseEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
||||||
: mDocument (document), mAborted (false), mMessages (0), mTotalRecords (0)
|
: mDocument (document), mAborted (false), mMessages (0), mRecordsLabel (0), mTotalRecordsLabel (0)
|
||||||
{
|
{
|
||||||
setWindowTitle (QString::fromUtf8((std::string("Opening ") + document->getSavePath().filename().string()).c_str()));
|
setWindowTitle (QString::fromUtf8((std::string("Opening ") + document->getSavePath().filename().string()).c_str()));
|
||||||
|
|
||||||
@ -25,26 +25,25 @@ CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
|||||||
|
|
||||||
mLayout = new QVBoxLayout (this);
|
mLayout = new QVBoxLayout (this);
|
||||||
|
|
||||||
// file progress
|
// total progress
|
||||||
mFile = new QLabel (this);
|
mTotalRecordsLabel = new QLabel (this);
|
||||||
|
|
||||||
mLayout->addWidget (mFile);
|
mLayout->addWidget (mTotalRecordsLabel);
|
||||||
|
|
||||||
mFileProgress = new QProgressBar (this);
|
mTotalProgress = new QProgressBar (this);
|
||||||
|
|
||||||
mLayout->addWidget (mFileProgress);
|
mLayout->addWidget (mTotalProgress);
|
||||||
|
|
||||||
int size = static_cast<int> (document->getContentFiles().size())+1;
|
mTotalProgress->setMinimum (0);
|
||||||
if (document->isNew())
|
mTotalProgress->setMaximum (document->getData().getTotalRecords(document->getContentFiles()));
|
||||||
--size;
|
mTotalProgress->setTextVisible (true);
|
||||||
|
mTotalProgress->setValue (0);
|
||||||
|
mTotalRecords = 0;
|
||||||
|
|
||||||
mFileProgress->setMinimum (0);
|
mFilesLoaded = 0;
|
||||||
mFileProgress->setMaximum (size);
|
|
||||||
mFileProgress->setTextVisible (true);
|
|
||||||
mFileProgress->setValue (0);
|
|
||||||
|
|
||||||
// record progress
|
// record progress
|
||||||
mLayout->addWidget (mRecords = new QLabel ("Records", this));
|
mLayout->addWidget (mRecordsLabel = new QLabel ("Records", this));
|
||||||
|
|
||||||
mRecordProgress = new QProgressBar (this);
|
mRecordProgress = new QProgressBar (this);
|
||||||
|
|
||||||
@ -74,29 +73,32 @@ CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
|||||||
connect (mButtons, SIGNAL (rejected()), this, SLOT (cancel()));
|
connect (mButtons, SIGNAL (rejected()), this, SLOT (cancel()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVDoc::LoadingDocument::nextStage (const std::string& name, int totalRecords)
|
void CSVDoc::LoadingDocument::nextStage (const std::string& name, int fileRecords)
|
||||||
{
|
{
|
||||||
mFile->setText (QString::fromUtf8 (("Loading: " + name).c_str()));
|
++mFilesLoaded;
|
||||||
|
size_t numFiles = mDocument->getContentFiles().size();
|
||||||
|
|
||||||
mFileProgress->setValue (mFileProgress->value()+1);
|
mTotalRecordsLabel->setText (QString::fromUtf8 (("Loading: "+name
|
||||||
|
+" ("+std::to_string(mFilesLoaded)+" of "+std::to_string((numFiles))+")").c_str()));
|
||||||
|
|
||||||
|
mTotalRecords = mTotalProgress->value();
|
||||||
|
|
||||||
mRecordProgress->setValue (0);
|
mRecordProgress->setValue (0);
|
||||||
mRecordProgress->setMaximum (totalRecords>0 ? totalRecords : 1);
|
mRecordProgress->setMaximum (fileRecords>0 ? fileRecords : 1);
|
||||||
|
|
||||||
mTotalRecords = totalRecords;
|
mRecords = fileRecords;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVDoc::LoadingDocument::nextRecord (int records)
|
void CSVDoc::LoadingDocument::nextRecord (int records)
|
||||||
{
|
{
|
||||||
if (records<=mTotalRecords)
|
if (records <= mRecords)
|
||||||
{
|
{
|
||||||
mRecordProgress->setValue (records);
|
mTotalProgress->setValue (mTotalRecords+records);
|
||||||
|
|
||||||
std::ostringstream stream;
|
mRecordProgress->setValue(records);
|
||||||
|
|
||||||
stream << "Records: " << records << " of " << mTotalRecords;
|
mRecordsLabel->setText(QString::fromStdString(
|
||||||
|
"Records: "+std::to_string(records)+" of "+std::to_string(mRecords)));
|
||||||
mRecords->setText (QString::fromUtf8 (stream.str().c_str()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,12 +178,12 @@ 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 totalRecords)
|
int fileRecords)
|
||||||
{
|
{
|
||||||
std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter = mDocuments.find (document);
|
std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter = mDocuments.find (document);
|
||||||
|
|
||||||
if (iter!=mDocuments.end())
|
if (iter!=mDocuments.end())
|
||||||
iter->second->nextStage (name, totalRecords);
|
iter->second->nextStage (name, fileRecords);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVDoc::Loader::nextRecord (CSMDoc::Document *document, int records)
|
void CSVDoc::Loader::nextRecord (CSMDoc::Document *document, int records)
|
||||||
|
@ -25,16 +25,18 @@ namespace CSVDoc
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
CSMDoc::Document *mDocument;
|
CSMDoc::Document *mDocument;
|
||||||
QLabel *mFile;
|
QLabel *mTotalRecordsLabel;
|
||||||
QLabel *mRecords;
|
QLabel *mRecordsLabel;
|
||||||
QProgressBar *mFileProgress;
|
QProgressBar *mTotalProgress;
|
||||||
QProgressBar *mRecordProgress;
|
QProgressBar *mRecordProgress;
|
||||||
bool mAborted;
|
bool mAborted;
|
||||||
QDialogButtonBox *mButtons;
|
QDialogButtonBox *mButtons;
|
||||||
QLabel *mError;
|
QLabel *mError;
|
||||||
QListWidget *mMessages;
|
QListWidget *mMessages;
|
||||||
QVBoxLayout *mLayout;
|
QVBoxLayout *mLayout;
|
||||||
|
int mRecords;
|
||||||
int mTotalRecords;
|
int mTotalRecords;
|
||||||
|
int mFilesLoaded;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user