saving output settings
This commit is contained in:
parent
33ea7ff459
commit
b67d575645
|
@ -16,7 +16,7 @@
|
|||
OutputDialog::OutputDialog(QWidget *parent, std::vector<Check> *checks)
|
||||
: QDialog(parent), ui(new Ui::OutputDialog), checks(checks),
|
||||
options(OutputOptions()) {
|
||||
Settings settings(get_path_relative_to_home(".local/share/checks_parser/settings.json"));
|
||||
settings = new Settings(get_path_relative_to_home(".local/share/checks_parser/settings.json"));
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
|
@ -26,29 +26,24 @@ OutputDialog::OutputDialog(QWidget *parent, std::vector<Check> *checks)
|
|||
|
||||
ui->listView->setModel(model);
|
||||
|
||||
const std::map<std::string, ColumnType> 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"];
|
||||
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"]);
|
||||
ui->printHeaderCheckBox->setChecked(settings->get_all_settings()["print_header"]);
|
||||
ui->printTotalCheckBox->setChecked(settings->get_all_settings()["print_total"]);
|
||||
}
|
||||
|
||||
OutputDialog::~OutputDialog() { delete ui; }
|
||||
OutputDialog::~OutputDialog() {
|
||||
delete settings;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void OutputDialog::on_buttonBox_accepted() {
|
||||
std::ofstream output_file(this->options.get_path());
|
||||
|
@ -94,22 +89,9 @@ void OutputDialog::on_buttonBox_accepted() {
|
|||
}
|
||||
}
|
||||
output_file.close();
|
||||
save_settings();
|
||||
}
|
||||
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
|
||||
void OutputDialog::on_chooseFileButton_clicked() {
|
||||
QString filename = QFileDialog::getSaveFileName();
|
||||
this->options.set_path(filename.toStdString());
|
||||
|
@ -136,3 +118,13 @@ void OutputDialog::print_header(std::ofstream *output_file) {
|
|||
*output_file << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void OutputDialog::save_settings() {
|
||||
for (int i = 0; i < columns->size(); i ++) {
|
||||
OutputColumn &column = columns->at(i);
|
||||
std::string key = find_key_by_value(column_names, column.get_column_type());
|
||||
settings->get_all_settings()["output_order"][key]["name"] = column.get_text().toStdString();
|
||||
settings->get_all_settings()["output_order"][key]["position"] = i + 1;
|
||||
}
|
||||
settings->flush();
|
||||
}
|
||||
|
|
|
@ -17,6 +17,16 @@ class OutputDialog : public QDialog {
|
|||
OutputOptions options;
|
||||
std::vector<Check> *checks;
|
||||
std::vector<OutputColumn> *columns;
|
||||
Settings *settings;
|
||||
|
||||
const std::map<std::string, ColumnType> 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}
|
||||
};
|
||||
|
||||
public:
|
||||
explicit OutputDialog(QWidget *parent = nullptr, std::vector<Check> *checks = nullptr);
|
||||
|
@ -35,6 +45,8 @@ private:
|
|||
Ui::OutputDialog *ui;
|
||||
|
||||
void print_header(std::ofstream *output_file);
|
||||
|
||||
void save_settings();
|
||||
};
|
||||
|
||||
#endif // OUTPUTDIALOG_H
|
||||
|
|
|
@ -618,7 +618,7 @@
|
|||
<translation>Print total</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../outputdialog.cpp" line="38"/>
|
||||
<location filename="../outputdialog.cpp" line="30"/>
|
||||
<source>Кто здесь?</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
|
|
@ -602,7 +602,7 @@
|
|||
<translation>Печатать Итого</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../outputdialog.cpp" line="38"/>
|
||||
<location filename="../outputdialog.cpp" line="30"/>
|
||||
<source>Кто здесь?</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "output/output_options.h"
|
||||
#include <utils/utils.h>
|
||||
#ifdef BUILD_OFD_BINARYEYE_SCAN
|
||||
# include <arpa/inet.h>
|
||||
|
@ -80,11 +81,31 @@ bool areAllSizesEqual(const std::vector<T>& v1, const std::vector<T>& v2,
|
|||
return (v1.size() == v2.size() && v2.size() == v3.size() && v3.size() == v4.size());
|
||||
}
|
||||
|
||||
// template<typename K, typename V>
|
||||
// K find_key_by_value(std::map<K, V> &m, V value) {
|
||||
// for (auto& entry : m) {
|
||||
// if (value == entry.second) {
|
||||
// return entry.first;
|
||||
// }
|
||||
// }
|
||||
// return K();
|
||||
// }
|
||||
|
||||
std::string find_key_by_value(const std::map<std::string, ColumnType> &m, ColumnType value) {
|
||||
for (auto& entry : m) {
|
||||
if (value == entry.second) {
|
||||
return entry.first;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//ужас
|
||||
template bool vector_contains_element<std::string>(const std::vector<std::string>& vector, const std::string& to_find);
|
||||
template bool areAllSizesEqual(const std::vector<std::string>& v1, const std::vector<std::string>& v2,
|
||||
const std::vector<std::string>& v3, const std::vector<std::string>& v4);
|
||||
// template std::string find_key_by_value(std::map<std::string, ColumnType> &, ColumnType);
|
||||
|
||||
std::vector<std::string> split(std::string s, std::string delimiter) {
|
||||
std::vector<std::string> result;
|
||||
size_t pos = 0;
|
||||
|
@ -321,3 +342,4 @@ std::vector<std::string> read_file(std::string path) {
|
|||
return lines;
|
||||
}
|
||||
#endif // ifdef BUILD_EMAIL_MODE
|
||||
|
||||
|
|
|
@ -3,13 +3,19 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "../check/check.h"
|
||||
#include "output/output_options.h"
|
||||
|
||||
std::string to_utf8(std::wstring wide_string);
|
||||
std::wstring from_utf8(std::string string);
|
||||
|
||||
std::string get_path_relative_to_home(std::string path);
|
||||
|
||||
// template <typename K, typename V>
|
||||
// K find_key_by_value(std::map<K, V> &m, V value);
|
||||
std::string find_key_by_value(const std::map<std::string, ColumnType> &m, ColumnType value);
|
||||
|
||||
template <typename T>
|
||||
bool vector_contains_element(const std::vector<T> &vector, const T &to_find);
|
||||
template <class T>
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#include "outputcolumnmodel.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <outputcolumn.h>
|
||||
#include <QJsonObject>
|
||||
#include <QMimeData>
|
||||
#include <QIODevice>
|
||||
#include <outputcolumn.h>
|
||||
|
||||
OutputColumnModel::OutputColumnModel(std::vector<OutputColumn> *columns, QObject *parent)
|
||||
: columns(columns), QAbstractListModel{parent} { }
|
||||
|
|
Loading…
Reference in New Issue