From 33ea7ff459fd24bcdc5b043d295cb39d745f05d9 Mon Sep 17 00:00:00 2001 From: leca Date: Sat, 17 May 2025 15:06:47 +0300 Subject: [PATCH] load output order from settings --- CMakeLists.txt | 2 +- main.cpp | 4 +- outputdialog.cpp | 42 +++++----- translations/en_US.ts | 25 +++--- translations/ru_RU.ts | 21 ++--- widgets/tablewidgetmovable.cpp | 136 --------------------------------- widgets/tablewidgetmovable.hpp | 17 ----- 7 files changed, 37 insertions(+), 210 deletions(-) delete mode 100644 widgets/tablewidgetmovable.cpp delete mode 100644 widgets/tablewidgetmovable.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 36882b9..fe07f73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,7 +95,7 @@ set(PROJECT_SOURCES net/net.h net/net.cpp settings/settings.h settings/settings.cpp - widgets/tablewidgetmovable.hpp widgets/tablewidgetmovable.cpp + widgets/checklistviewwidget.h widgets/checklistviewwidget.cpp widgets/outputcolumn.h widgets/outputcolumn.cpp widgets/outputcolumnmodel.h widgets/outputcolumnmodel.cpp diff --git a/main.cpp b/main.cpp index f8880b7..dad189c 100644 --- a/main.cpp +++ b/main.cpp @@ -63,7 +63,9 @@ int main(int argc, char *argv[]) { std::cout << QObject::tr("Using locale: ").toStdString() << lang.toStdString() << std::endl; - translator.load(":/translation/" + lang + ".qm"); + if (!translator.load(":/translation/" + lang + ".qm")) { + std::cerr << "Could not load translation!!" << std::endl; + } app.installTranslator(&translator); #endif MainWindow w; diff --git a/outputdialog.cpp b/outputdialog.cpp index 1c1f7db..f6bede7 100644 --- a/outputdialog.cpp +++ b/outputdialog.cpp @@ -11,6 +11,7 @@ #include #include "settings/settings.h" #include "utils/utils.h" +#include OutputDialog::OutputDialog(QWidget *parent, std::vector *checks) : QDialog(parent), ui(new Ui::OutputDialog), checks(checks), @@ -21,35 +22,27 @@ OutputDialog::OutputDialog(QWidget *parent, std::vector *checks) columns = new std::vector; - columns->push_back(OutputColumn(tr("Date"), ColumnType::date)); - columns->push_back(OutputColumn(tr("Goods name"), ColumnType::goods_name)); - columns->push_back(OutputColumn(tr("Goods price per unit"), ColumnType::goods_price_per_unit)); - columns->push_back(OutputColumn(tr("Goods quantity"), ColumnType::goods_quantity)); - columns->push_back(OutputColumn(tr("Goods net weight"), ColumnType::goods_net_weight)); - columns->push_back(OutputColumn(tr("Goods total"), ColumnType::goods_total)); - OutputColumnModel *model = new OutputColumnModel(&(*columns), this); ui->listView->setModel(model); - // ui->tableWidget->item(0, 1)->setText(QString::fromStdString(settings.get_all_settings()["output_order"]["date"]["name"])); - // ui->tableWidget->item(0, 0)->setText(QString::number((int)settings.get_all_settings()["output_order"]["date"]["position"])); - - // ui->tableWidget->item(1, 1)->setText(QString::fromStdString(settings.get_all_settings()["output_order"]["goods_name"]["name"])); - // ui->tableWidget->item(1, 0)->setText(QString::number((int)settings.get_all_settings()["output_order"]["goods_name"]["position"])); - - // ui->tableWidget->item(2, 1)->setText(QString::fromStdString(settings.get_all_settings()["output_order"]["goods_price_per_unit"]["name"])); - // ui->tableWidget->item(2, 0)->setText(QString::number((int)settings.get_all_settings()["output_order"]["goods_price_per_unit"]["position"])); - - // ui->tableWidget->item(3, 1)->setText(QString::fromStdString(settings.get_all_settings()["output_order"]["goods_quantity"]["name"])); - // ui->tableWidget->item(3, 0)->setText(QString::number((int)settings.get_all_settings()["output_order"]["goods_quantity"]["position"])); - - // ui->tableWidget->item(4, 1)->setText(QString::fromStdString(settings.get_all_settings()["output_order"]["goods_net_weight"]["name"])); - // ui->tableWidget->item(4, 0)->setText(QString::number((int)settings.get_all_settings()["output_order"]["goods_net_weight"]["position"])); - - // ui->tableWidget->item(5, 1)->setText(QString::fromStdString(settings.get_all_settings()["output_order"]["goods_total"]["name"])); - // ui->tableWidget->item(5, 0)->setText(QString::number((int)settings.get_all_settings()["output_order"]["goods_total"]["position"])); + const std::map column_names = { + {"date", ColumnType::date}, + {"goods_name", ColumnType::goods_name}, + {"goods_price_per_unit", ColumnType::goods_price_per_unit}, + {"goods_quantity", ColumnType::goods_quantity}, + {"goods_net_weight", ColumnType::goods_net_weight}, + {"goods_total", ColumnType::goods_total} + }; + for (unsigned short i = 0; i < 6; i ++) + columns->push_back(OutputColumn(tr("Кто здесь?"), ColumnType::date)); + for (auto &column : column_names) { + std::string name = settings.get_all_settings()["output_order"][column.first]["name"]; + unsigned short position = settings.get_all_settings()["output_order"][column.first]["position"]; + ColumnType type = column.second; + columns->at(position - 1) = (OutputColumn(QString::fromStdString(name), type)); + } ui->printHeaderCheckBox->setChecked(settings.get_all_settings()["print_header"]); ui->printTotalCheckBox->setChecked(settings.get_all_settings()["print_total"]); @@ -67,7 +60,6 @@ void OutputDialog::on_buttonBox_accepted() { for (auto it = check.get_goods().begin(); it != check.get_goods().end(); it++, row_number++) { for (int i = 0; i < columns->size(); i ++) { OutputColumn &column = columns->at(i); - std::cout << column.get_text().toStdString() << std::endl; switch (column.get_column_type()) { case ColumnType::date: if (row_number == 0) output_file << check.get_date(); diff --git a/translations/en_US.ts b/translations/en_US.ts index 702febe..4e36341 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -537,38 +537,28 @@ Print header - Date - Date + Date - Goods name - Goods name + Goods name Goods price Goods price - - Goods price per unit - - - - Goods quantity - Goods quantity + Goods quantity - Goods net weight - Goods net weight + Goods net weight - Goods total - Goods total + Goods total position @@ -627,6 +617,11 @@ Print total Print total + + + Кто здесь? + + QObject diff --git a/translations/ru_RU.ts b/translations/ru_RU.ts index 5aa2014..1ad25de 100644 --- a/translations/ru_RU.ts +++ b/translations/ru_RU.ts @@ -525,33 +525,24 @@ Печатать заголовок - Goods name - Имя товара + Имя товара Goods price Цена товара - - Goods price per unit - - - - Goods quantity - Количество товара + Количество товара - Goods net weight - Масса нетто товара + Масса нетто товара - Goods total - Всего за товар + Всего за товар position @@ -611,8 +602,8 @@ Печатать Итого - - Date + + Кто здесь? diff --git a/widgets/tablewidgetmovable.cpp b/widgets/tablewidgetmovable.cpp deleted file mode 100644 index ba6defa..0000000 --- a/widgets/tablewidgetmovable.cpp +++ /dev/null @@ -1,136 +0,0 @@ -#include "tablewidgetmovable.hpp" -#include -#include -#include -#include -#include - -TableWidgetMovable::TableWidgetMovable(QWidget *parent) : QTableWidget(parent) { } - -// void TableWidgetMovable::dropEvent(QDropEvent *event) { -// if (event->source() == this) { -// // Get the index of the row being dragged -// QModelIndex sourceIndex = currentIndex(); -// if (!sourceIndex.isValid()) { -// return; -// } - -// // Get the index of the target row -// QModelIndex targetIndex = indexAt(event->pos()); -// if (!targetIndex.isValid()) { -// return; -// } - -// int sourceRow = sourceIndex.row(); -// int targetRow = targetIndex.row(); - -// // Swap rows -// if (sourceRow != targetRow) { -// // Store the data of the source row -// QList itemsSource; -// for (int col = 0; col < columnCount(); ++col) { -// itemsSource.append(takeItem(sourceRow, col)); -// } - -// QList itemsTarget; -// for (int col = 0; col < columnCount(); ++col) { -// itemsTarget.append(takeItem(targetRow, col)); -// } - -// // Insert the items into the target row -// for (int col = 0; col < columnCount(); ++col) { -// setItem(targetRow, col, itemsSource[col]); -// setItem(sourceRow, col, itemsTarget[col]); -// } - -// // for (int col = 0; col < columnCount(); ++col) { - -// // } - -// // Remove the original row -// // removeRow(sourceRow < targetRow ? sourceRow : sourceRow + 1); -// } - -// event->acceptProposedAction(); -// } else { -// QTableWidget::dropEvent(event); -// } -// } - -// TOOD: fix None of these works. WIP - -// void TableWidgetMovable::dropEvent(QDropEvent *event) { -// std::cout << event->type() << std::endl; -// if(event->source() == this && event->type() == QEvent::Type::Drop) { -// int oldRow = this->selectedItems()[0]->row(); -// int oldColumn = this->selectedItems()[0]->column(); - -// int newRow = this->indexAt(event->pos()).row(); -// int newColumn = this->indexAt(event->pos()).column(); - -// auto oldCell = this->cellWidget(oldRow, oldColumn); -// auto newCell = this->cellWidget(newRow, newColumn); - -// this->removeCellWidget(oldRow, oldColumn); -// this->removeCellWidget(newRow, newColumn); - -// this->setCellWidget(newRow, newColumn, oldCell); -// this->setCellWidget(oldRow, oldColumn, newCell); -// event->accept(); -// } -// } - -// void TableWidgetMovable::dropEvent(QDropEvent *event) { -// std::cout << event->type() << std::endl; -// if(event->source() == this && event->type() == QEvent::Type::Drop) { -// int oldRow = this->selectedItems()[0]->row(); -// int oldColumn = this->selectedItems()[0]->column(); - -// int newRow = this->indexAt(event->pos()).row(); -// int newColumn = this->indexAt(event->pos()).column(); -// std::cout << oldRow << " " << oldColumn<< " " << newRow << " " << newColumn << std::endl; -// QTableWidgetItem *from = this->itemAt(oldColumn, oldRow), *to = this->itemAt(newColumn, newRow); - -// // QList selectedItems = this->selectedItems(); -// if(newRow == -1) { -// std::cout << newRow << std::endl; -// // newRow = this->rowCount(); -// return; -// } -// // QTableWidgetItem bufferTo, bufferFrom; -// QTableWidgetItem *bufferTo = new QTableWidgetItem("123"), *bufferFrom = new QTableWidgetItem("321"); -// std::cout << to->text().toStdString() << " " << from->text().toStdString() << std::endl; -// *bufferTo = *to; -// *bufferFrom = *from; -// // this->setItem(newRow, newColumn, nullptr); -// // this->setItem(oldRow, oldColumn, nullptr); -// this->takeItem(newRow, newColumn); -// this->takeItem(oldRow, oldColumn); -// this->setItem(newRow, newColumn, from); -// // this->setItem(oldRow, oldColumn, to); -// // *to = *from; -// // *from = buffer; -// return; - -// // int i; -// // for(i = 0; i < selectedItems.length()/this->columnCount(); i++) -// // this->insertRow(newRow); - -// // int currentOldRow = -1; -// // int currentNewRow = newRow-1; -// // QList deleteRows; -// // foreach(selectedItem, selectedItems) { -// // int column = selectedItem->column(); -// // if(selectedItem->row() != currentOldRow) { -// // currentOldRow = selectedItem->row(); -// // deleteRows.append(currentOldRow); -// // currentNewRow++; -// // } -// // this->takeItem(currentOldRow, column); -// // this->setItem(currentNewRow, column, selectedItem); -// // } - -// // for(i = deleteRows.count()-1; i>=0; i--) -// // this->removeRow(deleteRows.at(i)); -// } -// } diff --git a/widgets/tablewidgetmovable.hpp b/widgets/tablewidgetmovable.hpp deleted file mode 100644 index 21935ee..0000000 --- a/widgets/tablewidgetmovable.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef TABLEWIDGETMOVABLE_HPP -#define TABLEWIDGETMOVABLE_HPP - -#include -#include -#include - -class TableWidgetMovable : public QTableWidget -{ - Q_OBJECT -public: - TableWidgetMovable(QWidget *parent = nullptr); - // void dropEvent(QDropEvent *event); - // void swapRows(int row1, int row2); -}; - -#endif // TABLEWIDGETMOVABLE_HPP