full rework of the output order
This commit is contained in:
parent
463edd3df9
commit
f32da712e8
|
@ -97,6 +97,8 @@ set(PROJECT_SOURCES
|
|||
|
||||
widgets/tablewidgetmovable.hpp widgets/tablewidgetmovable.cpp
|
||||
widgets/checklistviewwidget.h widgets/checklistviewwidget.cpp
|
||||
widgets/outputcolumn.h widgets/outputcolumn.cpp
|
||||
widgets/outputcolumnmodel.h widgets/outputcolumnmodel.cpp
|
||||
|
||||
${TRANSLATION_SOURCES}
|
||||
)
|
||||
|
|
1
main.cpp
1
main.cpp
|
@ -33,6 +33,7 @@
|
|||
int main(int argc, char *argv[]) {
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
|
||||
std::string program_data_path = get_path_relative_to_home(".local/share/checks_parser");
|
||||
create_directories(program_data_path);
|
||||
|
||||
|
|
|
@ -2,48 +2,6 @@
|
|||
|
||||
OutputOptions::OutputOptions() {}
|
||||
|
||||
void OutputOptions::add_or_update_column(Column &column) {
|
||||
if (column_exist(column.type)) {
|
||||
update_column(column, find_column(column.type));
|
||||
} else {
|
||||
this->order.push_back(column);
|
||||
}
|
||||
}
|
||||
|
||||
void OutputOptions::update_column(Column &column, unsigned short index) {
|
||||
this->order[index] = column;
|
||||
}
|
||||
|
||||
void OutputOptions::remove_column(unsigned short index) {
|
||||
this->order.erase(this->order.begin() + index);
|
||||
}
|
||||
void OutputOptions::remove_column(ColumnType t) {
|
||||
this->order.erase(this->order.begin() + find_column(t));
|
||||
}
|
||||
|
||||
unsigned short OutputOptions::find_column(ColumnType t) {
|
||||
for (unsigned short i = 0; i < this->order.size(); i++) {
|
||||
if (this->order[i].type == t)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool OutputOptions::column_exist(ColumnType t) {
|
||||
for (unsigned short i = 0; i < this->order.size(); i++) {
|
||||
if (this->order[i].type == t)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Column &OutputOptions::get_column(ColumnType t) {
|
||||
return this->order[find_column(t)];
|
||||
}
|
||||
|
||||
std::vector<Column> &OutputOptions::get_columns() { return this->order; }
|
||||
|
||||
void OutputOptions::set_print_header(bool value) { this->print_header = value; }
|
||||
bool OutputOptions::get_print_header() { return this->print_header; }
|
||||
|
||||
|
@ -52,3 +10,4 @@ bool OutputOptions::get_print_total() { return this->print_total; }
|
|||
|
||||
void OutputOptions::set_path(std::string path) { this->path = path; }
|
||||
std::string &OutputOptions::get_path() { return this->path; }
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include "../net/net.h"
|
||||
#include "../settings/settings.h"
|
||||
|
||||
enum class ColumnType {
|
||||
enum ColumnType {
|
||||
date,
|
||||
goods_name,
|
||||
goods_price_per_unit,
|
||||
|
@ -23,32 +23,26 @@ enum class ColumnType {
|
|||
goods_total
|
||||
};
|
||||
|
||||
struct Column { // Example:
|
||||
ColumnType type; // goods_name
|
||||
std::string name; // "Товар"
|
||||
unsigned int position; // "0" <-- 0 = "A", 1 = "B", etc.. column letter in
|
||||
// table processor (i.e. excel or libreoffice)
|
||||
} typedef Column;
|
||||
// Q_DECLARE_METATYPE(ColumnType);
|
||||
|
||||
// struct Column { // Example:
|
||||
// ColumnType type; // goods_name
|
||||
// std::string name; // "Товар"
|
||||
// unsigned int position; // "0" <-- 0 = "A", 1 = "B", etc.. column letter in
|
||||
// // table processor (i.e. excel or libreoffice)
|
||||
// } typedef Column;
|
||||
|
||||
class OutputOptions {
|
||||
|
||||
std::vector<Column> order;
|
||||
bool print_header;
|
||||
bool print_total;
|
||||
std::string path;
|
||||
|
||||
public:
|
||||
OutputOptions();
|
||||
|
||||
void add_or_update_column(Column &);
|
||||
void update_column(Column&, unsigned short);
|
||||
void remove_column(unsigned short);
|
||||
void remove_column(ColumnType);
|
||||
unsigned short find_column(ColumnType);
|
||||
bool column_exist(ColumnType);
|
||||
Column& get_column(ColumnType);
|
||||
std::vector<Column>& get_columns();
|
||||
|
||||
void set_print_header(bool);
|
||||
bool get_print_header();
|
||||
|
||||
|
@ -60,3 +54,5 @@ public:
|
|||
};
|
||||
|
||||
#endif // OUTPUT_OPTIONS_H
|
||||
|
||||
|
||||
|
|
162
outputdialog.cpp
162
outputdialog.cpp
|
@ -3,8 +3,12 @@
|
|||
#include "output/output_options.h"
|
||||
#include "ui_outputdialog.h"
|
||||
#include <QFileDialog>
|
||||
#include <QLineEdit>
|
||||
#include <QMainWindow>
|
||||
#include <QStandardItemModel>
|
||||
#include <fstream>
|
||||
#include <outputcolumn.h>
|
||||
#include <outputcolumnmodel.h>
|
||||
#include "settings/settings.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
|
@ -15,29 +19,36 @@ OutputDialog::OutputDialog(QWidget *parent, std::vector<Check> *checks)
|
|||
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->tableWidget->resizeColumnsToContents();
|
||||
ui->tableWidget->verticalHeader()->setSectionsMovable(true);
|
||||
ui->tableWidget->verticalHeader()->setDragDropOverwriteMode(false);
|
||||
ui->tableWidget->verticalHeader()->setDragEnabled(true);
|
||||
ui->tableWidget->verticalHeader()->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
columns = new std::vector<OutputColumn>;
|
||||
|
||||
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"]));
|
||||
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));
|
||||
|
||||
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"]));
|
||||
OutputColumnModel *model = new OutputColumnModel(&(*columns), this);
|
||||
|
||||
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->listView->setModel(model);
|
||||
|
||||
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(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(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(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(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"]));
|
||||
// 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"]));
|
||||
|
||||
|
||||
ui->printHeaderCheckBox->setChecked(settings.get_all_settings()["print_header"]);
|
||||
|
@ -46,65 +57,39 @@ OutputDialog::OutputDialog(QWidget *parent, std::vector<Check> *checks)
|
|||
|
||||
OutputDialog::~OutputDialog() { delete ui; }
|
||||
|
||||
bool compare_position(Column &c1, Column &c2) {
|
||||
return c1.position < c2.position;
|
||||
}
|
||||
|
||||
void OutputDialog::on_buttonBox_accepted() {
|
||||
std::ofstream output_file(this->options.get_path());
|
||||
|
||||
for (int i = 0; i < ui->tableWidget->rowCount(); i++) {
|
||||
int position = ui->tableWidget->item(i, 0)->text().toInt();
|
||||
std::string name = ui->tableWidget->item(i, 1)->text().toStdString();
|
||||
print_header(&output_file);
|
||||
|
||||
Column c;
|
||||
c.type = static_cast<ColumnType>(i);
|
||||
c.position = position;
|
||||
c.name = name;
|
||||
|
||||
this->options.add_or_update_column(c);
|
||||
}
|
||||
|
||||
std::sort(this->options.get_columns().begin(),
|
||||
this->options.get_columns().end(), compare_position);
|
||||
|
||||
if (options.get_print_header()) {
|
||||
// output_file << "date,"
|
||||
for (auto &column : this->options.get_columns()) {
|
||||
output_file << column.name
|
||||
<< (column.position == this->options.get_columns().size()
|
||||
? ""
|
||||
: ",");
|
||||
}
|
||||
output_file << std::endl;
|
||||
}
|
||||
for (Check &check : *checks) {
|
||||
int i = 0;
|
||||
// auto &goods : check.get_goods()
|
||||
for (auto it = check.get_goods().begin(); it != check.get_goods().end(); i++, it++) {
|
||||
for (auto &column : this->options.get_columns()) {
|
||||
switch (column.type) {
|
||||
case ColumnType::date:
|
||||
if (i == 0) output_file << check.get_date();
|
||||
break;
|
||||
case ColumnType::goods_name:
|
||||
output_file << it->get_name();
|
||||
break;
|
||||
case ColumnType::goods_price_per_unit:
|
||||
output_file << std::fixed << std::setprecision(2) << it->get_price_per_unit();
|
||||
break;
|
||||
case ColumnType::goods_quantity:
|
||||
output_file << std::fixed << std::setprecision(2) << it->get_quantity();
|
||||
break;
|
||||
case ColumnType::goods_net_weight:
|
||||
output_file << it->get_net_weight();
|
||||
break;
|
||||
case ColumnType::goods_total:
|
||||
output_file << std::fixed << std::setprecision(2) << it->calculate_total_price();
|
||||
break;
|
||||
}
|
||||
int row_number = 0;
|
||||
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();
|
||||
break;
|
||||
case ColumnType::goods_name:
|
||||
output_file << it->get_name();
|
||||
break;
|
||||
case ColumnType::goods_price_per_unit:
|
||||
output_file << std::fixed << std::setprecision(2) << it->get_price_per_unit();
|
||||
break;
|
||||
case ColumnType::goods_quantity:
|
||||
output_file << std::fixed << std::setprecision(2) << it->get_quantity();
|
||||
break;
|
||||
case ColumnType::goods_net_weight:
|
||||
output_file << it->get_net_weight();
|
||||
break;
|
||||
case ColumnType::goods_total:
|
||||
output_file << std::fixed << std::setprecision(2) << it->calculate_total_price();
|
||||
break;
|
||||
}
|
||||
|
||||
if (column.position != this->options.get_columns().size()) {
|
||||
if (i < columns->size() - 1) {
|
||||
output_file << ",";
|
||||
} else {
|
||||
output_file << "\n";
|
||||
|
@ -119,19 +104,19 @@ void OutputDialog::on_buttonBox_accepted() {
|
|||
output_file.close();
|
||||
}
|
||||
|
||||
void update_settings(OutputOptions &options, ColumnType t, std::string name,
|
||||
int value) {
|
||||
Column column;
|
||||
column.type = t;
|
||||
column.name = name;
|
||||
column.position = value;
|
||||
// void update_settings(OutputOptions &options, ColumnType t, std::string name,
|
||||
// int value) {
|
||||
// Column column;
|
||||
// column.type = t;
|
||||
// column.name = name;
|
||||
// column.position = value;
|
||||
|
||||
if (value) {
|
||||
options.add_or_update_column(column);
|
||||
} else {
|
||||
options.remove_column(t);
|
||||
}
|
||||
}
|
||||
// if (value) {
|
||||
// options.add_or_update_column(column);
|
||||
// } else {
|
||||
// options.remove_column(t);
|
||||
// }
|
||||
// }
|
||||
|
||||
void OutputDialog::on_chooseFileButton_clicked() {
|
||||
QString filename = QFileDialog::getSaveFileName();
|
||||
|
@ -146,3 +131,16 @@ void OutputDialog::on_printHeaderCheckBox_stateChanged(int value) {
|
|||
void OutputDialog::on_printTotalCheckBox_stateChanged(int value) {
|
||||
this->options.set_print_total(value);
|
||||
}
|
||||
|
||||
void OutputDialog::print_header(std::ofstream *output_file) {
|
||||
if (options.get_print_header()) {
|
||||
for (unsigned int i = 0; i < columns->size(); i ++) {
|
||||
OutputColumn column = columns->at(i);
|
||||
(*output_file) << column.get_text().toStdString()
|
||||
<< (i == columns->size() - 1
|
||||
? ""
|
||||
: ",");
|
||||
}
|
||||
*output_file << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "output/output_options.h"
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <outputcolumn.h>
|
||||
|
||||
namespace Ui {
|
||||
class OutputDialog;
|
||||
|
@ -15,6 +16,7 @@ class OutputDialog : public QDialog {
|
|||
|
||||
OutputOptions options;
|
||||
std::vector<Check> *checks;
|
||||
std::vector<OutputColumn> *columns;
|
||||
|
||||
public:
|
||||
explicit OutputDialog(QWidget *parent = nullptr, std::vector<Check> *checks = nullptr);
|
||||
|
@ -31,6 +33,8 @@ private slots:
|
|||
|
||||
private:
|
||||
Ui::OutputDialog *ui;
|
||||
|
||||
void print_header(std::ofstream *output_file);
|
||||
};
|
||||
|
||||
#endif // OUTPUTDIALOG_H
|
||||
|
|
|
@ -21,20 +21,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="chooseFileButton">
|
||||
<property name="text">
|
||||
<string>Choose</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="printHeaderCheckBox">
|
||||
<property name="text">
|
||||
<string>Print header</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="printTotalCheckBox">
|
||||
<property name="text">
|
||||
|
@ -42,30 +28,15 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
|
||||
<item row="0" column="3">
|
||||
<widget class="QPushButton" name="chooseFileButton">
|
||||
<property name="text">
|
||||
<string>Choose</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="3">
|
||||
<widget class="TableWidgetMovable" name="tableWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="acceptDrops">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QAbstractScrollArea::SizeAdjustPolicy::AdjustToContentsOnFirstShow</enum>
|
||||
</property>
|
||||
<widget class="QListView" name="listView">
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
@ -76,137 +47,35 @@
|
|||
<enum>QAbstractItemView::DragDropMode::InternalMove</enum>
|
||||
</property>
|
||||
<property name="defaultDropAction">
|
||||
<enum>Qt::DropAction::MoveAction</enum>
|
||||
<enum>Qt::DropAction::TargetMoveAction</enum>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SelectionMode::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectionBehavior::SelectRows</enum>
|
||||
</property>
|
||||
<property name="gridStyle">
|
||||
<enum>Qt::PenStyle::SolidLine</enum>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>false</bool>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="printHeaderCheckBox">
|
||||
<property name="text">
|
||||
<string>Print header</string>
|
||||
</property>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Date</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Goods name</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Goods price</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Goods quantity</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Goods net weight</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Goods total</string>
|
||||
</property>
|
||||
</row>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>position</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>name</string>
|
||||
</property>
|
||||
</column>
|
||||
<item row="0" column="0">
|
||||
<property name="text">
|
||||
<string>1</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<property name="text">
|
||||
<string>Date</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<property name="text">
|
||||
<string>2</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<property name="text">
|
||||
<string>3</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<property name="text">
|
||||
<string>Price</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<property name="text">
|
||||
<string>4</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<property name="text">
|
||||
<string>Quantity</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<property name="text">
|
||||
<string>5</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<property name="text">
|
||||
<string>Net weight</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<property name="text">
|
||||
<string>6</string>
|
||||
</property>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<property name="text">
|
||||
<string>Total price</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>TableWidgetMovable</class>
|
||||
<extends>QTableWidget</extends>
|
||||
<header>widgets/tablewidgetmovable.hpp</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
|
|
|
@ -527,113 +527,103 @@
|
|||
<translation>Path to export: </translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="27"/>
|
||||
<location filename="../scenes/outputdialog.ui" line="34"/>
|
||||
<source>Choose</source>
|
||||
<translation>Choose</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="34"/>
|
||||
<location filename="../scenes/outputdialog.ui" line="73"/>
|
||||
<source>Print header</source>
|
||||
<translation>Print header</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="101"/>
|
||||
<location filename="../scenes/outputdialog.ui" line="146"/>
|
||||
<location filename="../outputdialog.cpp" line="24"/>
|
||||
<source>Date</source>
|
||||
<translation>Date</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="106"/>
|
||||
<location filename="../outputdialog.cpp" line="25"/>
|
||||
<source>Goods name</source>
|
||||
<translation>Goods name</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="111"/>
|
||||
<source>Goods price</source>
|
||||
<translation>Goods price</translation>
|
||||
<translation type="vanished">Goods price</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="116"/>
|
||||
<location filename="../outputdialog.cpp" line="26"/>
|
||||
<source>Goods price per unit</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../outputdialog.cpp" line="27"/>
|
||||
<source>Goods quantity</source>
|
||||
<translation>Goods quantity</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="121"/>
|
||||
<location filename="../outputdialog.cpp" line="28"/>
|
||||
<source>Goods net weight</source>
|
||||
<translation>Goods net weight</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="126"/>
|
||||
<location filename="../outputdialog.cpp" line="29"/>
|
||||
<source>Goods total</source>
|
||||
<translation>Goods total</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="131"/>
|
||||
<source>position</source>
|
||||
<translation>position</translation>
|
||||
<translation type="vanished">position</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="136"/>
|
||||
<source>name</source>
|
||||
<translation>name</translation>
|
||||
<translation type="vanished">name</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="141"/>
|
||||
<source>1</source>
|
||||
<translation>1</translation>
|
||||
<translation type="vanished">1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="156"/>
|
||||
<source>Name</source>
|
||||
<translation>Name</translation>
|
||||
<translation type="vanished">Name</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="151"/>
|
||||
<source>2</source>
|
||||
<translation>2</translation>
|
||||
<translation type="vanished">2</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="166"/>
|
||||
<source>Price</source>
|
||||
<translation>Price</translation>
|
||||
<translation type="vanished">Price</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="161"/>
|
||||
<source>3</source>
|
||||
<translation>3</translation>
|
||||
<translation type="vanished">3</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="176"/>
|
||||
<source>Quantity</source>
|
||||
<translation>Quantity</translation>
|
||||
<translation type="vanished">Quantity</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="171"/>
|
||||
<source>4</source>
|
||||
<translation>4</translation>
|
||||
<translation type="vanished">4</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="186"/>
|
||||
<source>Net weight</source>
|
||||
<translation>Net Weight</translation>
|
||||
<translation type="vanished">Net Weight</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="181"/>
|
||||
<source>5</source>
|
||||
<translation>5</translation>
|
||||
<translation type="vanished">5</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="191"/>
|
||||
<source>6</source>
|
||||
<translation>6</translation>
|
||||
<translation type="vanished">6</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="196"/>
|
||||
<source>Total price</source>
|
||||
<translation>Total price</translation>
|
||||
<translation type="vanished">Total price</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="41"/>
|
||||
<location filename="../scenes/outputdialog.ui" line="27"/>
|
||||
<source>Print total</source>
|
||||
<translation>Print total</translation>
|
||||
</message>
|
||||
|
@ -641,7 +631,7 @@
|
|||
<context>
|
||||
<name>QObject</name>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="63"/>
|
||||
<location filename="../main.cpp" line="64"/>
|
||||
<source>Using locale: </source>
|
||||
<translation>Using locale: </translation>
|
||||
</message>
|
||||
|
|
|
@ -515,121 +515,111 @@
|
|||
<translation>Путь для экспорта: </translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="27"/>
|
||||
<location filename="../scenes/outputdialog.ui" line="34"/>
|
||||
<source>Choose</source>
|
||||
<translation>Выбрать</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="34"/>
|
||||
<location filename="../scenes/outputdialog.ui" line="73"/>
|
||||
<source>Print header</source>
|
||||
<translation>Печатать заголовок</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="101"/>
|
||||
<location filename="../scenes/outputdialog.ui" line="146"/>
|
||||
<source>Date</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="106"/>
|
||||
<location filename="../outputdialog.cpp" line="25"/>
|
||||
<source>Goods name</source>
|
||||
<translation>Имя товара</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="111"/>
|
||||
<source>Goods price</source>
|
||||
<translation>Цена товара</translation>
|
||||
<translation type="vanished">Цена товара</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="116"/>
|
||||
<location filename="../outputdialog.cpp" line="26"/>
|
||||
<source>Goods price per unit</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../outputdialog.cpp" line="27"/>
|
||||
<source>Goods quantity</source>
|
||||
<translation>Количество товара</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="121"/>
|
||||
<location filename="../outputdialog.cpp" line="28"/>
|
||||
<source>Goods net weight</source>
|
||||
<translation>Масса нетто товара</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="126"/>
|
||||
<location filename="../outputdialog.cpp" line="29"/>
|
||||
<source>Goods total</source>
|
||||
<translation>Всего за товар</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="131"/>
|
||||
<source>position</source>
|
||||
<translation>позиция</translation>
|
||||
<translation type="vanished">позиция</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="136"/>
|
||||
<source>name</source>
|
||||
<translation>алиас</translation>
|
||||
<translation type="vanished">алиас</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="141"/>
|
||||
<source>1</source>
|
||||
<translation>1</translation>
|
||||
<translation type="vanished">1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="156"/>
|
||||
<source>Name</source>
|
||||
<translation>Имя</translation>
|
||||
<translation type="vanished">Имя</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="151"/>
|
||||
<source>2</source>
|
||||
<translation>2</translation>
|
||||
<translation type="vanished">2</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="166"/>
|
||||
<source>Price</source>
|
||||
<translation>Цена</translation>
|
||||
<translation type="vanished">Цена</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="161"/>
|
||||
<source>3</source>
|
||||
<translation>3</translation>
|
||||
<translation type="vanished">3</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="176"/>
|
||||
<source>Quantity</source>
|
||||
<translation>Количество</translation>
|
||||
<translation type="vanished">Количество</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="171"/>
|
||||
<source>4</source>
|
||||
<translation>4</translation>
|
||||
<translation type="vanished">4</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="186"/>
|
||||
<source>Net weight</source>
|
||||
<translation>Масса нетто</translation>
|
||||
<translation type="vanished">Масса нетто</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="181"/>
|
||||
<source>5</source>
|
||||
<translation>5</translation>
|
||||
<translation type="vanished">5</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="191"/>
|
||||
<source>6</source>
|
||||
<translation type="unfinished">6</translation>
|
||||
<translation type="obsolete">6</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="196"/>
|
||||
<source>Total price</source>
|
||||
<translation>Всего</translation>
|
||||
<translation type="vanished">Всего</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scenes/outputdialog.ui" line="41"/>
|
||||
<location filename="../scenes/outputdialog.ui" line="27"/>
|
||||
<source>Print total</source>
|
||||
<translation>Печатать Итого</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../outputdialog.cpp" line="24"/>
|
||||
<source>Date</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QObject</name>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="63"/>
|
||||
<location filename="../main.cpp" line="64"/>
|
||||
<source>Using locale: </source>
|
||||
<translation>Использую локаль: </translation>
|
||||
</message>
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
CheckListViewWidget::CheckListViewWidget(QWidget *parent, Check check) : QWidget(parent), check(check) {
|
||||
mw = (MainWindow*) parent;
|
||||
|
||||
std::cout << "I was created with check with date " << check.get_date() << std::endl;
|
||||
QHBoxLayout *layout = new QHBoxLayout;
|
||||
|
||||
QLabel *date_label = new QLabel(QString::fromStdString(check.get_date()));
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#include "outputcolumn.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
|
||||
OutputColumn::OutputColumn() { }
|
||||
|
||||
OutputColumn::OutputColumn(QString text, ColumnType type)
|
||||
: text(text), type(type) { }
|
||||
|
||||
void OutputColumn::set_column_type(ColumnType type) { this->type = type; }
|
||||
ColumnType OutputColumn::get_column_type() { return type; }
|
||||
|
||||
void OutputColumn::set_text(const QString &text) { this->text = text; }
|
||||
QString OutputColumn::get_text() { return text; }
|
||||
|
||||
|
||||
Q_DECLARE_METATYPE(OutputColumn)
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef OUTPUTCOLUMN_H
|
||||
#define OUTPUTCOLUMN_H
|
||||
|
||||
#include "output/output_options.h"
|
||||
#include <QLineEdit>
|
||||
#include <QStandardItem>
|
||||
|
||||
class OutputColumn
|
||||
{
|
||||
QString text;
|
||||
ColumnType type;
|
||||
public:
|
||||
OutputColumn();
|
||||
OutputColumn(QString text, ColumnType type);
|
||||
|
||||
void set_column_type(ColumnType type);
|
||||
ColumnType get_column_type();
|
||||
|
||||
void set_text(const QString &text);
|
||||
QString get_text();
|
||||
};
|
||||
|
||||
#endif // OUTPUTCOLUMN_H
|
|
@ -0,0 +1,151 @@
|
|||
#include "outputcolumnmodel.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <outputcolumn.h>
|
||||
#include <QJsonObject>
|
||||
#include <QMimeData>
|
||||
#include <QIODevice>
|
||||
|
||||
OutputColumnModel::OutputColumnModel(std::vector<OutputColumn> *columns, QObject *parent)
|
||||
: columns(columns), QAbstractListModel{parent} { }
|
||||
|
||||
int OutputColumnModel::rowCount(const QModelIndex &parent) const {
|
||||
return columns->size();
|
||||
}
|
||||
|
||||
QVariant OutputColumnModel::data(const QModelIndex &index, int role) const {
|
||||
if (!index.isValid() || index.row() >= columns->size())
|
||||
return QVariant();
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
return QVariant::fromValue(columns->at(index.row()).get_text());
|
||||
else if (role == 0x0101)
|
||||
return QVariant::fromValue(columns->at(index.row()).get_column_type());
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant OutputColumnModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
if (orientation == Qt::Horizontal)
|
||||
return QObject::tr("Column type alias");
|
||||
else
|
||||
return QStringLiteral("Position %1").arg(section);
|
||||
}
|
||||
|
||||
bool OutputColumnModel::setData(const QModelIndex &index, const QVariant &value, int role) {
|
||||
if (index.isValid()) {
|
||||
OutputColumn &column = columns->at(index.row());
|
||||
if (role == 0x102) {
|
||||
OutputColumn data = value.value<OutputColumn>();
|
||||
column.set_text(data.get_text());
|
||||
column.set_column_type(data.get_column_type());
|
||||
} else {
|
||||
QString data = value.value<QString>();
|
||||
column.set_text(data);
|
||||
}
|
||||
|
||||
(*columns)[index.row()] = column;
|
||||
emit dataChanged(index, index, {role});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Qt::DropActions OutputColumnModel::supportedDropActions() const {
|
||||
return Qt::MoveAction;
|
||||
}
|
||||
|
||||
bool OutputColumnModel::insertRows(int position, int rows, const QModelIndex &index) {
|
||||
beginInsertRows(QModelIndex(), position, position+rows-1);
|
||||
|
||||
for (int row = 0; row < rows; ++row)
|
||||
columns->emplace(columns->begin() + position, OutputColumn("Чё зыришь глаза пузыришь?", ColumnType::date));
|
||||
|
||||
endInsertRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OutputColumnModel::removeRows(int position, int rows, const QModelIndex &parent) {
|
||||
beginRemoveRows(QModelIndex(), position, position+rows-1);
|
||||
|
||||
for (int row = 0; row < rows; ++row)
|
||||
columns->erase(std::next(columns->begin(), position));
|
||||
|
||||
endRemoveRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList OutputColumnModel::mimeTypes() const {
|
||||
QStringList types;
|
||||
types << OutputColumnModel::MimeType;
|
||||
return types;
|
||||
}
|
||||
|
||||
bool OutputColumnModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int, int, const QModelIndex &) {
|
||||
if ( action != Qt::MoveAction || !data->hasFormat(OutputColumnModel::MimeType))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
Qt::ItemFlags OutputColumnModel::flags (const QModelIndex & index) const {
|
||||
Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index);
|
||||
|
||||
if (index.isValid())
|
||||
return Qt::ItemIsDragEnabled | Qt::ItemIsEditable | defaultFlags;
|
||||
else
|
||||
return Qt::ItemIsDropEnabled | defaultFlags;
|
||||
}
|
||||
|
||||
QMimeData* OutputColumnModel::mimeData(const QModelIndexList &indexes) const {
|
||||
QMimeData* mimeData = new QMimeData;
|
||||
QByteArray encodedData;
|
||||
|
||||
QDataStream stream(&encodedData, QIODevice::WriteOnly);
|
||||
|
||||
for (const QModelIndex &index : indexes) {
|
||||
if (index.isValid()) {
|
||||
QString text = data(index, Qt::DisplayRole).toString();
|
||||
ColumnType type = ColumnType(data(index, 0x0101).toInt());
|
||||
stream << text << type;
|
||||
}
|
||||
}
|
||||
mimeData->setData(OutputColumnModel::MimeType, encodedData);
|
||||
return mimeData;
|
||||
}
|
||||
|
||||
bool OutputColumnModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) {
|
||||
if (!canDropMimeData(data, action, row, column, parent))
|
||||
return false;
|
||||
|
||||
if (action == Qt::IgnoreAction)
|
||||
return true;
|
||||
else if (action != Qt::MoveAction)
|
||||
return false;
|
||||
|
||||
QByteArray encodedData = data->data(OutputColumnModel::MimeType);
|
||||
QDataStream stream(&encodedData, QIODevice::ReadOnly);
|
||||
std::vector<OutputColumn> newItems;
|
||||
int rows = 0;
|
||||
|
||||
while (!stream.atEnd()) {
|
||||
QString text;
|
||||
ColumnType type;
|
||||
stream >> text >> type;
|
||||
newItems.push_back(OutputColumn(text, type));
|
||||
++rows;
|
||||
}
|
||||
|
||||
insertRows(row, rows, QModelIndex());
|
||||
for (const OutputColumn &column : newItems)
|
||||
{
|
||||
QModelIndex idx = index(row, 0, QModelIndex());
|
||||
setData(idx, QVariant::fromValue(column), 0x102);
|
||||
row++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef OUTPUTCOLUMNMODEL_H
|
||||
#define OUTPUTCOLUMNMODEL_H
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QAbstractListModel>
|
||||
#include <outputcolumn.h>
|
||||
|
||||
class OutputColumnModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
static constexpr const char* MimeType = "application/output.column.model";
|
||||
std::vector<OutputColumn> *columns;
|
||||
|
||||
public:
|
||||
OutputColumnModel(std::vector<OutputColumn> *columns, QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
|
||||
Qt::ItemFlags flags (const QModelIndex& index) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole) override;
|
||||
|
||||
Qt::DropActions supportedDropActions() const override;
|
||||
|
||||
bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()) override;
|
||||
bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()) override;
|
||||
|
||||
QStringList mimeTypes() const override;
|
||||
bool canDropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex&);
|
||||
QMimeData* mimeData(const QModelIndexList &indexes) const;
|
||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
||||
};
|
||||
|
||||
#endif // OUTPUTCOLUMNMODEL_H
|
Loading…
Reference in New Issue