leocad/qt/lc_qpropertiesdialog.cpp

156 lines
4.7 KiB
C++
Raw Permalink Normal View History

2013-08-09 06:57:18 +02:00
#include "lc_global.h"
#include "lc_qpropertiesdialog.h"
#include "ui_lc_qpropertiesdialog.h"
#include "lc_qutils.h"
2013-08-09 06:57:18 +02:00
#include "lc_colors.h"
#include "lc_application.h"
#include "pieceinf.h"
2019-12-22 21:42:02 +01:00
class lcPartsTableWidgetItem : public QTableWidgetItem
{
public:
explicit lcPartsTableWidgetItem(const QString& Text, int Type = QTableWidgetItem::Type)
2019-12-22 21:42:02 +01:00
: QTableWidgetItem(Text, Type)
{
mLast = false;
}
bool operator<(const QTableWidgetItem& Other) const override
2019-12-22 21:42:02 +01:00
{
if (mLast)
return false;
if (((const lcPartsTableWidgetItem&)Other).mLast)
return true;
2020-12-24 03:07:12 +01:00
if (column() > 0)
{
int Count = text().toInt();
int OtherCount = Other.text().toInt();
return Count < OtherCount;
}
2019-12-22 21:42:02 +01:00
return QTableWidgetItem::operator<(Other);
}
bool mLast;
};
2020-12-24 03:07:12 +01:00
lcQPropertiesDialog::lcQPropertiesDialog(QWidget* Parent, lcPropertiesDialogOptions* Options)
: QDialog(Parent), mOptions(Options), ui(new Ui::lcQPropertiesDialog)
2013-08-09 06:57:18 +02:00
{
ui->setupUi(this);
2020-12-24 03:07:12 +01:00
setWindowTitle(tr("%1 Properties").arg(mOptions->Properties.mFileName));
2014-12-31 18:05:23 +01:00
2021-03-01 00:57:02 +01:00
ui->DescriptionEdit->setText(mOptions->Properties.mDescription);
ui->AuthorEdit->setText(mOptions->Properties.mAuthor);
ui->CommentsEdit->setText(mOptions->Properties.mComments);
const lcVector3 Dimensions = Options->BoundingBox.Max - Options->BoundingBox.Min;
QString Format = tr("%1 x %2 x %3 cm\n%4 x %5 x %6 inches\n%7 x %8 x %9 LDU");
QString Measurements = Format.arg(QString::number(Dimensions.x * 0.04, 'f', 2), QString::number(Dimensions.y * 0.04, 'f', 2), QString::number(Dimensions.z * 0.04, 'f', 2),
QString::number(Dimensions.x / 64.0, 'f', 2), QString::number(Dimensions.y / 64.0, 'f', 2), QString::number(Dimensions.z / 64.0, 'f', 2),
QString::number(Dimensions.x, 'f', 2), QString::number(Dimensions.y, 'f', 2), QString::number(Dimensions.z, 'f', 2));
ui->MeasurementsLabel->setText(Measurements);
2013-08-09 06:57:18 +02:00
2020-12-24 03:07:12 +01:00
const lcPartsList& PartsList = mOptions->PartsList;
2021-03-01 00:57:02 +01:00
QStringList HorizontalLabels;
2013-08-09 06:57:18 +02:00
2021-01-23 19:21:00 +01:00
std::vector<bool> ColorsUsed(gColorList.size());
2013-08-09 06:57:18 +02:00
for (const auto& PartIt : PartsList)
for (const auto& ColorIt : PartIt.second)
ColorsUsed[ColorIt.first] = true;
2013-08-19 03:01:06 +02:00
2021-01-23 19:21:00 +01:00
std::vector<int> ColorColumns(gColorList.size());
2021-03-01 00:57:02 +01:00
int ColorCount = 0;
2013-08-19 03:01:06 +02:00
2021-03-01 00:57:02 +01:00
HorizontalLabels.append(tr("Part"));
2013-08-19 03:01:06 +02:00
2021-01-23 19:21:00 +01:00
for (size_t ColorIndex = 0; ColorIndex < gColorList.size(); ColorIndex++)
2013-08-19 03:01:06 +02:00
{
2021-01-23 19:21:00 +01:00
if (ColorsUsed[ColorIndex])
2013-08-19 03:01:06 +02:00
{
2021-03-01 00:57:02 +01:00
ColorColumns[ColorIndex] = ColorCount++;
HorizontalLabels.append(gColorList[ColorIndex].Name);
2013-08-09 06:57:18 +02:00
}
}
2021-03-01 00:57:02 +01:00
HorizontalLabels.append(tr("Total"));
2021-03-01 00:57:02 +01:00
QTableWidget* PartsTable = ui->PartsTable;
PartsTable->setColumnCount(ColorCount + 2);
PartsTable->setRowCount((int)PartsList.size() + 1);
PartsTable->setHorizontalHeaderLabels(HorizontalLabels);
PartsTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
2013-08-19 03:01:06 +02:00
2019-05-18 20:33:27 +02:00
std::vector<int> InfoTotals(PartsList.size());
2021-03-01 00:57:02 +01:00
std::vector<int> ColorTotals(ColorCount);
2019-05-28 01:22:49 +02:00
int Row = 0, Total = 0;
for (const auto& PartIt : PartsList)
2013-08-09 06:57:18 +02:00
{
2021-03-01 00:57:02 +01:00
PartsTable->setItem(Row, 0, new lcPartsTableWidgetItem(PartIt.first->m_strDescription));
for (const auto& ColorIt : PartIt.second)
{
int ColorIndex = ColorIt.first;
int Count = ColorIt.second;
2019-12-22 21:42:02 +01:00
lcPartsTableWidgetItem* Item = new lcPartsTableWidgetItem(QString::number(Count));
Item->setTextAlignment(Qt::AlignCenter);
2021-03-01 00:57:02 +01:00
PartsTable->setItem(Row, ColorColumns[ColorIndex] + 1, Item);
InfoTotals[Row] += Count;
ColorTotals[ColorColumns[ColorIndex]] += Count;
Total += Count;
}
2021-03-01 00:57:02 +01:00
for (int Column = 0; Column <= ColorCount; Column++)
if (!PartsTable->item(Row, Column))
PartsTable->setItem(Row, Column, new lcPartsTableWidgetItem(QString()));
2019-12-22 21:42:02 +01:00
Row++;
}
2013-08-09 06:57:18 +02:00
2019-12-22 21:42:02 +01:00
lcPartsTableWidgetItem* Item = new lcPartsTableWidgetItem(tr("Total"));
Item->mLast = true;
2021-03-01 00:57:02 +01:00
PartsTable->setItem((int)InfoTotals.size(), 0, Item);
2019-06-03 22:23:04 +02:00
for (Row = 0; Row < (int)InfoTotals.size(); Row++)
{
2021-03-01 00:57:02 +01:00
Item = new lcPartsTableWidgetItem(QString::number(InfoTotals[Row]));
Item->setTextAlignment(Qt::AlignCenter);
PartsTable->setItem(Row, ColorCount + 1, Item);
2013-08-09 06:57:18 +02:00
}
2021-03-01 00:57:02 +01:00
for (int ColorIndex = 0; ColorIndex < ColorCount; ColorIndex++)
{
2021-03-01 00:57:02 +01:00
Item = new lcPartsTableWidgetItem(QString::number(ColorTotals[ColorIndex]));
Item->mLast = true;
Item->setTextAlignment(Qt::AlignCenter);
PartsTable->setItem((int)InfoTotals.size(), ColorIndex + 1, Item);
}
2021-03-01 00:57:02 +01:00
Item = new lcPartsTableWidgetItem(QString::number(Total));
Item->mLast = true;
Item->setTextAlignment(Qt::AlignCenter);
PartsTable->setItem((int)InfoTotals.size(), ColorCount + 1, Item);
2013-08-09 06:57:18 +02:00
}
lcQPropertiesDialog::~lcQPropertiesDialog()
{
delete ui;
}
void lcQPropertiesDialog::accept()
{
2021-03-01 00:57:02 +01:00
mOptions->Properties.mDescription = ui->DescriptionEdit->text();
mOptions->Properties.mAuthor = ui->AuthorEdit->text();
mOptions->Properties.mComments = ui->CommentsEdit->toPlainText();
2013-08-09 06:57:18 +02:00
QDialog::accept();
}