1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-31 20:45:34 +00:00
openmw/apps/opencs/view/doc/operations.cpp

73 lines
1.9 KiB
C++
Raw Normal View History

2012-11-23 11:20:35 +00:00
#include "operations.hpp"
2022-10-19 17:02:00 +00:00
#include <algorithm>
#include <QDockWidget>
2012-11-23 11:20:35 +00:00
#include <QVBoxLayout>
2022-10-19 17:02:00 +00:00
#include <QWidget>
2012-11-23 11:20:35 +00:00
#include "operation.hpp"
2024-05-19 09:36:02 +00:00
namespace
{
2024-05-22 10:19:37 +00:00
constexpr int operationLineHeight = 36;
2024-05-19 09:36:02 +00:00
}
2012-11-23 11:20:35 +00:00
CSVDoc::Operations::Operations()
{
2022-09-22 18:26:05 +00:00
setFeatures(QDockWidget::NoDockWidgetFeatures);
2012-11-23 11:20:35 +00:00
2022-09-22 18:26:05 +00:00
QWidget* widgetContainer = new QWidget(this);
2012-11-23 11:20:35 +00:00
mLayout = new QVBoxLayout;
2024-05-22 10:19:37 +00:00
mLayout->setContentsMargins(0, 0, 0, 0);
2012-11-23 11:20:35 +00:00
2024-05-22 10:19:37 +00:00
widgetContainer->setContentsMargins(0, 0, 0, 0);
2022-09-22 18:26:05 +00:00
widgetContainer->setLayout(mLayout);
setWidget(widgetContainer);
setVisible(false);
2024-05-19 09:36:02 +00:00
setFixedHeight(operationLineHeight);
2022-09-22 18:26:05 +00:00
setTitleBarWidget(new QWidget(this));
2012-11-23 11:20:35 +00:00
}
2022-09-22 18:26:05 +00:00
void CSVDoc::Operations::setProgress(int current, int max, int type, int threads)
2012-11-23 11:20:35 +00:00
{
2022-09-22 18:26:05 +00:00
for (std::vector<Operation*>::iterator iter(mOperations.begin()); iter != mOperations.end(); ++iter)
if ((*iter)->getType() == type)
2012-11-23 11:20:35 +00:00
{
2022-09-22 18:26:05 +00:00
(*iter)->setProgress(current, max, threads);
2012-11-23 11:20:35 +00:00
return;
}
2022-09-22 18:26:05 +00:00
Operation* operation = new Operation(type, this);
connect(operation, qOverload<int>(&Operation::abortOperation), this, &Operations::abortOperation);
2022-09-22 18:26:05 +00:00
mLayout->addLayout(operation->getLayout());
mOperations.push_back(operation);
operation->setProgress(current, max, threads);
2024-05-19 09:36:02 +00:00
int newCount = static_cast<int>(mOperations.size());
setFixedHeight(operationLineHeight * newCount);
2022-09-22 18:26:05 +00:00
setVisible(true);
2012-11-23 11:20:35 +00:00
}
2022-09-22 18:26:05 +00:00
void CSVDoc::Operations::quitOperation(int type)
2012-11-23 11:20:35 +00:00
{
2022-09-22 18:26:05 +00:00
for (std::vector<Operation*>::iterator iter(mOperations.begin()); iter != mOperations.end(); ++iter)
if ((*iter)->getType() == type)
2012-11-23 11:20:35 +00:00
{
2022-09-22 18:26:05 +00:00
mLayout->removeItem((*iter)->getLayout());
2013-03-02 13:57:41 +00:00
(*iter)->deleteLater();
2022-09-22 18:26:05 +00:00
mOperations.erase(iter);
2024-05-19 09:36:02 +00:00
int newCount = static_cast<int>(mOperations.size());
if (newCount > 0)
setFixedHeight(operationLineHeight * newCount);
else
2022-09-22 18:26:05 +00:00
setVisible(false);
2012-11-23 11:20:35 +00:00
break;
}
}