mirror of https://github.com/OpenMW/openmw.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.0 KiB
C++
73 lines
2.0 KiB
C++
#include "operations.hpp"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <QDockWidget>
|
|
#include <QVBoxLayout>
|
|
#include <QWidget>
|
|
|
|
#include "operation.hpp"
|
|
|
|
CSVDoc::Operations::Operations()
|
|
{
|
|
/// \todo make widget height fixed (exactly the height required to display all operations)
|
|
|
|
setFeatures(QDockWidget::NoDockWidgetFeatures);
|
|
|
|
QWidget* widgetContainer = new QWidget(this);
|
|
mLayout = new QVBoxLayout;
|
|
|
|
widgetContainer->setLayout(mLayout);
|
|
setWidget(widgetContainer);
|
|
setVisible(false);
|
|
setFixedHeight(widgetContainer->height());
|
|
setTitleBarWidget(new QWidget(this));
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
int oldCount = static_cast<int>(mOperations.size());
|
|
int newCount = oldCount + 1;
|
|
|
|
Operation* operation = new Operation(type, this);
|
|
connect(operation, qOverload<int>(&Operation::abortOperation), this, &Operations::abortOperation);
|
|
|
|
mLayout->addLayout(operation->getLayout());
|
|
mOperations.push_back(operation);
|
|
operation->setProgress(current, max, threads);
|
|
|
|
if (oldCount > 0)
|
|
setFixedHeight(height() / oldCount * newCount);
|
|
|
|
setVisible(true);
|
|
}
|
|
|
|
void CSVDoc::Operations::quitOperation(int type)
|
|
{
|
|
for (std::vector<Operation*>::iterator iter(mOperations.begin()); iter != mOperations.end(); ++iter)
|
|
if ((*iter)->getType() == type)
|
|
{
|
|
int oldCount = static_cast<int>(mOperations.size());
|
|
int newCount = oldCount - 1;
|
|
|
|
mLayout->removeItem((*iter)->getLayout());
|
|
|
|
(*iter)->deleteLater();
|
|
mOperations.erase(iter);
|
|
|
|
if (oldCount > 1)
|
|
setFixedHeight(height() / oldCount * newCount);
|
|
else
|
|
setVisible(false);
|
|
|
|
break;
|
|
}
|
|
}
|