Graphic setCustomGridMarkFuncs, select decimal point when export to CSV
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <QActionGroup>
|
||||
#include <QScrollArea>
|
||||
#include <QTimer>
|
||||
#include <QInputDialog>
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
# include <QRandomGenerator>
|
||||
#endif
|
||||
@@ -72,6 +73,7 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
func_gridMarkX = func_gridMarkY = nullptr;
|
||||
ui = new Ui::Graphic();
|
||||
ui->setupUi(this);
|
||||
ui->scrollLegend->layout()->addWidget(new LegendScrollArea(ui->widgetLegend));
|
||||
@@ -189,6 +191,7 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
||||
updateLegend();
|
||||
setRectToLines();
|
||||
conf = new GraphicConf(graphics, this);
|
||||
connect(conf, SIGNAL(exportClicked()), this, SLOT(on_graphic_buttonExport_clicked()));
|
||||
}
|
||||
|
||||
|
||||
@@ -916,7 +919,7 @@ void Graphic::saveImage(QString filename) {
|
||||
}
|
||||
|
||||
|
||||
void Graphic::exportGraphics(QString filename) {
|
||||
void Graphic::exportGraphics(QString filename, QChar decimal_point) {
|
||||
ppath = filename;
|
||||
QFile f(filename);
|
||||
if (!f.open(QIODevice::ReadWrite)) {
|
||||
@@ -930,7 +933,7 @@ void Graphic::exportGraphics(QString filename) {
|
||||
for (int i = 0; i < graphics.size(); ++i) {
|
||||
GraphicType & g(graphics[i]);
|
||||
if (!g.visible) continue;
|
||||
ts << ";" << (g.name + "_X") << ";" << (g.name + "_Y");
|
||||
ts << ";" << (g.name + " " + (label_x.isEmpty() ? "X" : label_x)) << ";" << (g.name + " " + (label_y.isEmpty() ? "Y" : label_y));
|
||||
}
|
||||
ts << "\n";
|
||||
bool has_data = true;
|
||||
@@ -949,9 +952,9 @@ void Graphic::exportGraphics(QString filename) {
|
||||
}
|
||||
has_data = true;
|
||||
line += ";";
|
||||
line += QString::number(g.polyline[ind].x(), 'g', 9);
|
||||
line += QString::number(g.polyline[ind].x(), 'g', 9).replace('.', decimal_point);
|
||||
line += ";";
|
||||
line += QString::number(g.polyline[ind].y(), 'g', 9);
|
||||
line += QString::number(g.polyline[ind].y(), 'g', 9).replace('.', decimal_point);
|
||||
}
|
||||
++ind;
|
||||
line += "\n";
|
||||
@@ -1028,6 +1031,12 @@ void Graphic::removeGraphic(int arg, bool update) {
|
||||
}
|
||||
|
||||
|
||||
void Graphic::setCustomGridMarkFuncs(std::function<QString (double)> fx, std::function<QString (double)> fy) {
|
||||
func_gridMarkX = fx;
|
||||
func_gridMarkY = fy;
|
||||
}
|
||||
|
||||
|
||||
void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, double end_y) {
|
||||
double cx, cy, maxX, minX, maxY, minY, vx;
|
||||
bool isRangeX = (start_x != end_x), isRangeY = (start_y != end_y);
|
||||
@@ -1174,15 +1183,20 @@ void Graphic::drawGrid() {
|
||||
if (cy > hei + 5) break;
|
||||
painter->setPen(grid_pen);
|
||||
painter->drawLine(gbx, cy, cwid, cy);
|
||||
str = gridMark(py * grid_numbers_y);
|
||||
painter->setPen(text_color);
|
||||
cy += font_sz.height() / 4.;
|
||||
int dx = font_sz.height() / 8.;
|
||||
if (!str.second.isEmpty()) {
|
||||
rect = sfm.boundingRect(str.second);
|
||||
painter->setFont(sf);
|
||||
painter->drawText(cx - rect.width() - dx, cy - font_sz.height() / 2.5, str.second);
|
||||
dx += rect.width() + font_sz.height() / 6.;
|
||||
if (func_gridMarkY) {
|
||||
str.first = func_gridMarkY(py * grid_numbers_y);
|
||||
str.second.clear();
|
||||
} else {
|
||||
str = gridMark(py * grid_numbers_y);
|
||||
if (!str.second.isEmpty()) {
|
||||
rect = sfm.boundingRect(str.second);
|
||||
painter->setFont(sf);
|
||||
painter->drawText(cx - rect.width() - dx, cy - font_sz.height() / 2.5, str.second);
|
||||
dx += rect.width() + font_sz.height() / 6.;
|
||||
}
|
||||
}
|
||||
rect = fm.boundingRect(str.first);
|
||||
painter->setFont(nf);
|
||||
@@ -1227,11 +1241,16 @@ void Graphic::drawGrid() {
|
||||
painter->setPen(text_color);
|
||||
int dx = -font_sz.height() / 4.;
|
||||
painter->setFont(nf);
|
||||
str = gridMark(px * grid_numbers_x);
|
||||
if (func_gridMarkX) {
|
||||
str.first = func_gridMarkX(px * grid_numbers_x);
|
||||
str.second.clear();
|
||||
} else {
|
||||
str = gridMark(px * grid_numbers_x);
|
||||
}
|
||||
rect = fm.boundingRect(str.first);
|
||||
painter->drawText(cx + dx, cy, str.first);
|
||||
dx += rect.width() + font_sz.height() / 6.;
|
||||
if (!str.second.isEmpty()) {
|
||||
dx += rect.width() + font_sz.height() / 6.;
|
||||
rect = sfm.boundingRect(str.second);
|
||||
painter->setFont(sf);
|
||||
painter->drawText(cx + dx, cy - font_sz.height() / 4., str.second);
|
||||
@@ -1886,7 +1905,11 @@ void Graphic::on_graphic_buttonSave_clicked() {
|
||||
void Graphic::on_graphic_buttonExport_clicked() {
|
||||
QString f = QFileDialog::getSaveFileName(this, tr("Export graphics"), ppath, "CSV(*.csv)");
|
||||
if (f.isEmpty()) return;
|
||||
exportGraphics(f);
|
||||
QStringList items;
|
||||
items << "." << ",";
|
||||
bool ok;
|
||||
QString item = QInputDialog::getItem(this, tr("Select decimal point"), tr("Decimal point:"), items, 0, false, &ok);
|
||||
if (ok && !item.isEmpty()) exportGraphics(f, item.front());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user