diff --git a/CMakeLists.txt b/CMakeLists.txt index 563b6df..5381975 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default project(QAD) set(QAD_MAJOR 2) -set(QAD_MINOR 13) +set(QAD_MINOR 14) set(QAD_REVISION 0) set(QAD_SUFFIX ) set(QAD_COMPANY SHS) diff --git a/libs/graphic/graphic.cpp b/libs/graphic/graphic.cpp index b82c72a..7c2c7ef 100644 --- a/libs/graphic/graphic.cpp +++ b/libs/graphic/graphic.cpp @@ -90,6 +90,7 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), func_gridMarkX = func_gridMarkY = nullptr; ui = new Ui::Graphic(); ui->setupUi(this); + ui->status->hide(); ui->scrollLegend->layout()->addWidget(new LegendScrollArea(ui->widgetLegend)); ui->scrollLegend->hide(); fillDateFormats(); @@ -122,20 +123,16 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), QActionGroup * agroup = new QActionGroup(this); agroup->addAction(ui->graphic_actionGuidesFree); agroup->addAction(ui->graphic_actionGuidesTrace); - agroup->addAction(ui->graphic_actionGuidesTraceX); - agroup->addAction(ui->graphic_actionGuidesTraceY); ui->graphic_actionGuidesFree->setProperty("_value", (int)Free); - ui->graphic_actionGuidesTrace->setProperty("_value", (int)TraceXY); - ui->graphic_actionGuidesTraceX->setProperty("_value", (int)TraceX); - ui->graphic_actionGuidesTraceY->setProperty("_value", (int)TraceY); + ui->graphic_actionGuidesTrace->setProperty("_value", (int)Trace); ui->graphic_actionGuidesFree->setChecked(true); connect(agroup, SIGNAL(triggered(QAction *)), this, SLOT(actionGuidesTriggered(QAction *))); ui->graphic_checkGuides->addAction(ui->graphic_actionGuidesFree); ui->graphic_checkGuides->addAction(ui->graphic_actionGuidesTrace); - ui->graphic_checkGuides->addAction(ui->graphic_actionGuidesTraceX); - ui->graphic_checkGuides->addAction(ui->graphic_actionGuidesTraceY); ui->graphic_buttonAutofit->addAction(ui->graphic_actionExpandX); ui->graphic_buttonAutofit->addAction(ui->graphic_actionExpandY); + ui->graphic_buttonSaveMenu->addAction(ui->graphic_actionSaveImage); + ui->graphic_buttonSaveMenu->addAction(ui->graphic_actionExportCSV); line_x_min.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); line_x_max.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); ((QBoxLayout *)ui->widgetLY->layout())->insertWidget(0, &line_y_min); @@ -169,8 +166,8 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), emaxx = emaxy = DBL_MIN; grad_x = grad_y = Auto; axis_type_x = Numeric; - floating_axis_type = Free; - min_repaint_int = 25; + floating_axis_type = Trace; + min_repaint_int = 25; // 40 Hz repaint interval lastw = lasth = 0; inc_x = 1.; // buffer = 0; @@ -191,8 +188,8 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), text_color = palette().color(QPalette::WindowText); grid_pen = QPen(palette().color(QPalette::Disabled, QPalette::WindowText), 0., Qt::DotLine); graphics.append(GraphicType()); - curGraphic = curTrace = 0; - selpen = palette().color(QPalette::WindowText); + curGraphic = 0; + selpen = palette().color(QPalette::WindowText); selpen.setStyle(Qt::DashLine); back_color = palette().color(QPalette::Base); buttons_ = AllButtons; @@ -206,7 +203,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())); + connect(conf, SIGNAL(exportClicked()), this, SLOT(on_graphic_actionExportCSV_triggered())); } @@ -258,7 +255,7 @@ void Graphic::timerEvent(QTimerEvent * e) { if (e->timerId() == timer_pause) { pause_phase += 0.02; if (pause_phase > 1.) pause_phase -= 1.; - update(); + repaintCanvas(); } if (e->timerId() == timer_record) { QPixmap im(canvas->size()); @@ -384,7 +381,7 @@ void Graphic::procZoom(QPointF view_center, double dzoom, Qt::KeyboardModifiers void Graphic::totalUpdate() { isFit = false; emit visualRectChanged(); - update(true); + repaintCanvas(true); setRectToLines(); } @@ -479,11 +476,10 @@ void Graphic::canvasMouseMoveEvent(QMouseEvent * e) { curpos = e->pos(); curpos_r = canvas2real(curpos); QPointF dp; - QString cursorstr = tr("Cursor: ") + pointCoords(curpos_r); emit graphicMouseMoveEvent(curpos_r, e->buttons()); if (e->buttons() == Qt::NoButton) { - ui->status->setText(cursorstr); - if (guides) update(); + if (ui->status->isVisible()) ui->status->setText(tr("Cursor: ") + pointCoords(curpos_r)); + if (guides) repaintCanvas(); return; } if (!navigation) return; @@ -494,18 +490,26 @@ void Graphic::canvasMouseMoveEvent(QMouseEvent * e) { return; switch (curaction) { case gaZoomInRect: - ui->status->setText(tr("Selection") + ": " + pointCoords(startpos_r) + " -> " + pointCoords(curpos_r) + ", " + tr("Size") + ": " + - pointCoords(absPoint(curpos_r - startpos_r))); + if (ui->status->isVisible()) { + ui->status->setText(tr("Selection") + ": " + pointCoords(startpos_r) + " -> " + pointCoords(curpos_r) + ", " + tr("Size") + + ": " + pointCoords(absPoint(curpos_r - startpos_r))); + } repaintCanvas(true); break; case gaZoomRangeX: - ui->status->setText(tr("Range") + ": " + QString::number(startpos_r.x(), 'f', 3) + " -> " + QString::number(curpos_r.x(), 'f', 3) + - ", " + tr("Length") + ": " + QString::number(qAbs(curpos_r.x() - startpos_r.x()), 'f', 3)); + if (ui->status->isVisible()) { + ui->status->setText(tr("Range") + ": " + QString::number(startpos_r.x(), 'f', 3) + " -> " + + QString::number(curpos_r.x(), 'f', 3) + ", " + tr("Length") + ": " + + QString::number(qAbs(curpos_r.x() - startpos_r.x()), 'f', 3)); + } repaintCanvas(true); break; case gaZoomRangeY: - ui->status->setText(tr("Range") + ": " + QString::number(startpos_r.y(), 'f', 3) + " -> " + QString::number(curpos_r.y(), 'f', 3) + - ", " + tr("Length") + ": " + QString::number(qAbs(curpos_r.y() - startpos_r.y()), 'f', 3)); + if (ui->status->isVisible()) { + ui->status->setText(tr("Range") + ": " + QString::number(startpos_r.y(), 'f', 3) + " -> " + + QString::number(curpos_r.y(), 'f', 3) + ", " + tr("Length") + ": " + + QString::number(qAbs(curpos_r.y() - startpos_r.y()), 'f', 3)); + } repaintCanvas(true); break; case gaMove: @@ -605,10 +609,11 @@ void Graphic::canvasMouseReleaseEvent(QMouseEvent * e) { } } swapToNormal(); - update(true); + repaintCanvas(true); + } + if (ui->status->isVisible()) { + ui->status->setText(tr("Cursor") + ": " + pointCoords(canvas2real(QPointF(e->pos())))); } - QPointF rp = canvas2real(QPointF(e->pos())); - ui->status->setText(tr("Cursor") + ": " + pointCoords(rp)); emit visualRectChanged(); } @@ -647,7 +652,7 @@ void Graphic::zoom(float factor) { selrect.width() * factor, selrect.height() * factor); isFit = false; - update(true); + repaintCanvas(true); setRectToLines(); } @@ -662,8 +667,8 @@ void Graphic::fullscreen() { void Graphic::canvasLeaveEvent(QEvent *) { isHover = false; - if (guides) update(true); - ui->status->setText(tr("Cursor") + ": ( ; )"); + if (guides) repaintCanvas(true); + if (ui->status->isVisible()) ui->status->setText(tr("Cursor") + ": ( ; )"); leaveFullscreen(); } @@ -685,14 +690,19 @@ void Graphic::clear() { graphics[i].max_x = 0.; graphics[i].cvrect = QRectF(); } - if (isFit) on_graphic_buttonAutofit_clicked(); + if (isFit) autofit(); } void Graphic::setAntialiasing(bool enabled) { if (aalias == enabled) return; aalias = enabled; - update(); + repaintCanvas(); +} + + +void Graphic::setAutoUpdate(bool enabled) { + aupdate = enabled; } @@ -706,7 +716,7 @@ void Graphic::setPaused(bool yes) { if (!pause_) { killTimer(timer_pause); timer_pause = 0; - update(true); + repaintCanvas(true); return; } for (int i = 0; i < graphics.size(); ++i) { @@ -739,7 +749,57 @@ void Graphic::setHistorySize(double val) { void Graphic::setMaxVisibleTime(double val) { visible_time = val; - if (isFit) on_graphic_buttonAutofit_clicked(); + if (isFit) autofit(); +} + + +void Graphic::setAutoXIncrement(double val) { + inc_x = val; +} + + +void Graphic::setLimit(const QRectF & val) { + limit_ = val; +} + + +void Graphic::setMargins(const QRect & val) { + margins_ = val; + repaintCanvas(); +} + + +void Graphic::setMargins(int left_, int right_, int top_, int bottom_) { + setMargins(QRect(left_, bottom_, right_, top_)); +} + + +void Graphic::setLeftMargin(int value) { + margins_.moveLeft(value); + setMargins(margins_); +} + + +void Graphic::setRightMargin(int value) { + margins_.setWidth(value); + setMargins(margins_); +} + + +void Graphic::setTopMargin(int value) { + margins_.setHeight(value); + setMargins(margins_); +} + + +void Graphic::setBottomMargin(int value) { + margins_.moveTop(value); + setMargins(margins_); +} + + +void Graphic::setMinimumRepaintInterval(const int & val) { + min_repaint_int = val; } @@ -777,8 +837,9 @@ QByteArray Graphic::graphicsDataRaw() const { void Graphic::setGraphicsData(const Graphic::GraphicsData & gd) { setGraphicsCount(gd.size()); - for (int i = 0; i < gd.size(); ++i) + for (int i = 0; i < gd.size(); ++i) { setGraphicData(gd[i], i, false); + } updateGraphics(); } @@ -795,6 +856,62 @@ void Graphic::setGraphicsDataRaw(const QByteArray & ba) { } +void Graphic::setGridNumbersMultiplierX(double value) { + grid_numbers_x = value; + updateGraphics(); +} + + +void Graphic::setGridNumbersMultiplierY(double value) { + grid_numbers_y = value; + updateGraphics(); +} + + +void Graphic::setGraduationX(Graduation value) { + grad_x = value; + updateGraphics(); +} + + +void Graphic::setGraduationY(Graduation value) { + grad_y = value; + updateGraphics(); +} + + +void Graphic::setGraduationStepX(double sx) { + gridx = sx; + updateGraphics(); +} + + +void Graphic::setGraduationStepY(double sy) { + gridy = sy; + if (aupdate) repaintCanvas(); +} + + +void Graphic::setGraduationSteps(double sx, double sy) { + gridx = sx; + gridy = sy; + if (aupdate) repaintCanvas(); +} + + +void Graphic::setAxisType(AxisType t) { + axis_type_x = t; + if (aupdate) repaintCanvas(); +} + + +void Graphic::setFloatingAxisType(FloatingAxisType t) { + floating_axis_type = t; + setGuidesCursor(); + if (aupdate) repaintCanvas(); +} + + void Graphic::setFloatingAxisEnabled(bool on) { ui->graphic_checkGuides->setChecked(on); } @@ -803,23 +920,24 @@ void Graphic::setFloatingAxisEnabled(bool on) { void Graphic::setButtons(Graphic::Buttons b) { buttons_ = b; ui->graphic_buttonAutofit->setVisible(b.testFlag(Autofit)); - ui->graphic_checkGrid->setVisible(b.testFlag(Grid)); ui->graphic_checkGuides->setVisible(b.testFlag(CursorAxis)); ui->graphic_buttonFullscreen->setVisible(b.testFlag(Fullscreen)); ui->graphic_checkBorderInputs->setVisible(b.testFlag(BorderInputs)); ui->graphic_checkLegend->setVisible(b.testFlag(Legend)); ui->graphic_buttonClear->setVisible(b.testFlag(Clear)); ui->graphic_buttonConfigure->setVisible(b.testFlag(Configure)); - ui->graphic_buttonSave->setVisible(b.testFlag(Save)); - ui->graphic_buttonExport->setVisible(b.testFlag(Export)); + ui->graphic_buttonSaveMenu->setVisible(b.testFlag(Save) || b.testFlag(Export)); + ui->graphic_actionExportCSV->setVisible(b.testFlag(Export)); + ui->graphic_actionSaveImage->setVisible(b.testFlag(Save)); ui->graphic_buttonClose->setVisible(b.testFlag(Close)); ui->graphic_checkPause->setVisible(b.testFlag(Pause)); ui->graphic_buttonRecord->setVisible(b.testFlag(Record)); - if (ui->graphic_buttonAutofit->isVisible() || ui->graphic_checkGrid->isVisible() || ui->graphic_checkGuides->isVisible() || - ui->graphic_buttonConfigure->isVisible() || ui->graphic_buttonSave->isVisible() || ui->graphic_checkPause->isVisible()) + if (ui->graphic_buttonAutofit->isVisible() || ui->graphic_checkGuides->isVisible() || ui->graphic_buttonConfigure->isVisible() || + ui->graphic_checkPause->isVisible()) { ui->verticalSpacer->changeSize(0, 30, QSizePolicy::Preferred, QSizePolicy::Preferred); - else + } else { ui->verticalSpacer->changeSize(0, 0, QSizePolicy::Preferred, QSizePolicy::Preferred); + } ui->layoutButtons->update(); } @@ -860,6 +978,35 @@ void Graphic::addPoint(const QPointF & p, int graphic, bool update_) { } +void Graphic::addPoint(const QPointF & p, bool update) { + addPoint(p, curGraphic, update); +} + + +void Graphic::addPoint(double x, double y, int graphic, bool update) { + addPoint(QPointF(x, y), graphic, update); +} + + +void Graphic::addPoint(double x, double y, bool update) { + addPoint(QPointF(x, y), update); +} + + +void Graphic::addPoint(double y, int graphic, bool update) { + if (graphics[graphic].polyline.isEmpty()) { + addPoint(QPointF(0.0, y), graphic, update); + } else { + addPoint(QPointF(graphics[graphic].max_x + inc_x, y), graphic, update); + } +} + + +void Graphic::addPoint(double y, bool update) { + addPoint(y, curGraphic, update); +} + + void Graphic::addPoints(const QPolygonF & pts, int graphic, bool update_) { if (graphic >= graphics.size() || graphic < 0 || pts.isEmpty()) return; GraphicType & t(graphics[graphic]); @@ -872,24 +1019,36 @@ void Graphic::addPoints(const QPolygonF & pts, int graphic, bool update_) { } } if (t.polyline.size() == 0) t.max_x = pts.at(0).x(); - for (const QPointF & p: pts) + for (const QPointF & p: pts) { if (t.max_x < p.x()) t.max_x = p.x(); + } t.polyline << pts; tick(graphic, true, update_); } +void Graphic::addPoints(const QPolygonF & pts, bool update) { + addPoints(pts, curGraphic, update); +} + + void Graphic::addPoints(const QVector & pts, int graphic, bool update_) { QPolygonF ps; ps.reserve(pts.size()); double stx = 0; if (!graphics[curGraphic].polyline.isEmpty()) stx = graphics[curGraphic].max_x; - for (int i = 0; i < pts.size(); ++i) + for (int i = 0; i < pts.size(); ++i) { ps << QPointF(stx + i * inc_x, pts[i]); + } addPoints(ps, graphic, update_); } +void Graphic::addPoints(const QVector & pts, bool update) { + addPoints(pts, curGraphic, update); +} + + void Graphic::setGraphicData(const QVector & g, int graphic, bool update_) { if (graphic >= graphics.size() || graphic < 0) return; GraphicType & t(graphics[graphic]); @@ -902,12 +1061,23 @@ void Graphic::setGraphicData(const QVector & g, int graphic, bool updat return; } t.max_x = t.polyline[0].x(); - for (int i = 1; i < t.polyline.size(); ++i) - if (t.max_x < t.polyline[i].x()) t.max_x = t.polyline[i].x(); + for (const auto & p: t.polyline) { + if (t.max_x < p.x()) t.max_x = p.x(); + } tick(graphic, false, update_); } +void Graphic::setGraphicData(const QVector & g) { + setGraphicData(g, curGraphic); +} + + +void Graphic::setGraphicProperties(const QString & name, const QColor & color, Qt::PenStyle style, double width, bool visible) { + setGraphicProperties(curGraphic, name, color, style, width, visible); +} + + void Graphic::setGraphicProperties(int graphic, const QString & name, const QColor & color, @@ -925,15 +1095,21 @@ void Graphic::setGraphicProperties(int graphic, void Graphic::addGraphic(const QString & name, const QColor & color, Qt::PenStyle style, double width, bool visible) { - graphics << GraphicType(name, color, style, width, visible); + addGraphic(GraphicType(name, color, style, width, visible)); +} + + +void Graphic::addGraphic(const GraphicType & gd) { + graphics << gd; updateLegend(); + repaintCanvas(); } void Graphic::setVisualRect(const QRectF & rect) { selrect = rect; isFit = false; - update(); + repaintCanvas(); } @@ -943,12 +1119,28 @@ void Graphic::setDefaultRect(const QRectF & rect) { } +void Graphic::autofit() { + isFit = true; + bool isEmpty = true; + for (const GraphicType & t: graphics) { + const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline); + if (!pol.isEmpty()) { + isEmpty = false; + break; + } + } + if (isEmpty) grect = def_rect; + selrect = grect; + findGraphicsRect(); + repaintCanvas(); +} + + void Graphic::saveImage(QString filename) { ppath = filename; QPixmap im(canvas->size()); canvas->render(&im); im.save(ppath); - update(true); } @@ -1036,12 +1228,23 @@ void Graphic::setOpenGL(bool on) { ui->canvas_raster->show(); canvas = ui->canvas_raster; #endif - update(); + repaintCanvas(); } -void Graphic::update(bool force) { - repaintCanvas(force); +void Graphic::update() { + repaintCanvas(); +} + +void Graphic::updateGraphics() { + findGraphicsRect(); + repaintCanvas(true); +} + + +void Graphic::setCurrentGraphic(int arg) { + if (arg < 0 || arg >= graphics.size()) return; + curGraphic = arg; } @@ -1478,7 +1681,9 @@ void Graphic::fillDateFormats() { void Graphic::drawGraphics() { - if (isHover) ui->status->setText(tr("Cursor: ") + pointCoords(canvas2real(QPointF(curpos)))); + if (isHover && ui->status->isVisible()) { + ui->status->setText(tr("Cursor: ") + pointCoords(canvas2real(QPointF(curpos)))); + } QPointF srp = -selrect.topLeft(); double sclx, scly, wid = canvas->width(), hei = canvas->height(); int cwid = (wid - gridborder.x() - margins_.left() - margins_.width()); @@ -1606,33 +1811,6 @@ void Graphic::drawGuides() { QString str; str = pointCoords(rpos) + fp_size; bool trace_found = false; - auto trace_axis_func = [&](bool on_x, double cursor) { - if (curTrace >= 0 && curTrace < graphics.size()) { - auto & t(graphics[curTrace]); - if (t.visible) { - QPolygonF & src_pol(pause_ ? t.polyline_pause : t.polyline); - QVector & src_lod(pause_ ? t._lod_pause : t._lod); - QPolygonF & pol(t.last_lod == 0 ? src_pol : src_lod[t.last_lod - 1]); - double min_dist = -1, dist = 0.; - int index = -1; - for (int i = 0; i < pol.size(); ++i) { - if (!selrect.contains(pol[i])) continue; - dist = qAbs((on_x ? pol[i].x() : pol[i].y()) - cursor); - if (min_dist > dist || min_dist < 0) { - min_dist = dist; - index = i; - } - } - if (index >= 0) { - rpos = pol[index]; - apos = real2canvas(rpos).toPoint(); - str = pointCoords(pol[index]) + fp_size; - trace_found = true; - emit graphicTraceEvent(curTrace, rpos); - } - } - } - }; auto trace_free_func = [&](QPointF cursor) { double min_dist = -1; int gr = -1, mag_dist = fontHeight(this) * 2; @@ -1667,11 +1845,8 @@ void Graphic::drawGuides() { emit graphicTraceEvent(gr, rpos); } }; - switch (floating_axis_type) { - case TraceXY: trace_free_func(rpos); break; - case TraceX: trace_axis_func(true, rpos.x()); break; - case TraceY: trace_axis_func(false, rpos.y()); break; - default: break; + if (floating_axis_type == Trace) { + trace_free_func(rpos); } if (was_trace && !trace_found) emit graphicTraceEvent(-1, QPointF()); was_trace = trace_found; @@ -1823,49 +1998,70 @@ void Graphic::addDateTime(QDateTime & dt, int * c, qint64 mul) { double Graphic::canvas2realX(double px) const { - int gbx = gridborder.x() + margins_.left(), cwid = lastw, wid = cwid - gbx - margins_.width(); - double cx = px - gbx, sclx = selrect.width() / (double)wid; + int gbx = gridborder.x() + margins_.left(); + int wid = lastw - gbx - margins_.width(); + double cx = px - gbx; + double sclx = selrect.width() / (double)wid; return cx * sclx + selrect.x(); } double Graphic::canvas2realY(double py) const { - int gby = gridborder.y() + margins_.top(), chei = lasth, hei = chei - gby - margins_.height(); - double cy = chei - py - gby, scly = selrect.height() / (double)hei; + int gby = gridborder.y() + margins_.top(); + int hei = lasth - gby - margins_.height(); + double cy = lasth - py - gby; + double scly = selrect.height() / (double)hei; return cy * scly + selrect.y(); } double Graphic::real2canvasX(double px) const { - int gbx = gridborder.x() + margins_.left(), cwid = lastw, wid = cwid - gbx - margins_.width(); + int gbx = gridborder.x() + margins_.left(); + int wid = lastw - gbx - margins_.width(); double sclx = selrect.width() / (double)wid; return (px - selrect.x()) / sclx + gbx; } double Graphic::real2canvasY(double py) const { - int gby = gridborder.y() + margins_.top(), chei = lasth, hei = chei - gby - margins_.height(); + int gby = gridborder.y() + margins_.top(); + int hei = lasth - gby - margins_.height(); double scly = selrect.height() / (double)hei; - return chei - gby - (py - selrect.y()) / scly; + return lasth - gby - (py - selrect.y()) / scly; } QPolygonF Graphic::real2canvas(const QPolygonF & real_polygon) const { QPolygonF ret; - for (int i = 0; i < real_polygon.size(); ++i) - ret << real2canvas(real_polygon[i]); + for (const auto & p: real_polygon) { + ret << real2canvas(p); + } return ret; } QPolygonF Graphic::canvas2real(const QPolygonF & canvas_polygon) const { QPolygonF ret; - for (int i = 0; i < canvas_polygon.size(); ++i) - ret << canvas2real(canvas_polygon[i]); + for (const auto & p: canvas_polygon) { + ret << canvas2real(p); + } return ret; } +double Graphic::getScaleX() const { + int gbx = gridborder.x() + margins_.left(); + int wid = lastw - gbx - margins_.width(); + return selrect.width() / (double)wid; +} + +double Graphic::getScaleY() const { + int gby = gridborder.y() + margins_.top(); + int hei = lasth - gby - margins_.height(); + return selrect.height() / (double)hei; +} + + void Graphic::setCurrentAction(GraphicAction action) { curaction = action; switch (action) { @@ -1939,10 +2135,10 @@ void Graphic::setRectToLines() { else line_y_max.setValue(selrect.top()); } - line_x_min.setDefaultText(QString::number(grect.left()).toUpper()); - line_x_max.setDefaultText(QString::number(grect.right()).toUpper()); - line_y_min.setDefaultText(QString::number(grect.bottom()).toUpper()); - line_y_max.setDefaultText(QString::number(grect.top()).toUpper()); + // line_x_min.setDefaultText(QString::number(grect.left()).toUpper()); + // line_x_max.setDefaultText(QString::number(grect.right()).toUpper()); + // line_y_min.setDefaultText(QString::number(grect.bottom()).toUpper()); + // line_y_max.setDefaultText(QString::number(grect.top()).toUpper()); line_x_min.blockSignals(false); line_x_max.blockSignals(false); line_y_min.blockSignals(false); @@ -1954,7 +2150,7 @@ void Graphic::setRectToLines() { void Graphic::checkLines() { isFit = (line_x_min.isCleared() && line_x_max.isCleared() && line_y_min.isCleared() && line_y_max.isCleared()); - update(true); + repaintCanvas(true); } @@ -1977,16 +2173,8 @@ void Graphic::tick(int index, bool slide, bool update_) { } else { calcLOD(index); } - if (!update_) { - if (isFit) findGraphicsRect(); - return; - } if (isFit) findGraphicsRect(); - if (!slide) { - if (aupdate) update(); - return; - } - if (aupdate) update(); + if (aupdate && update_) repaintCanvas(); } @@ -2036,20 +2224,15 @@ void Graphic::calcLOD(int index) { } +void Graphic::repaintCanvas(bool force) { + if (tm.elapsed() < min_repaint_int && !force) return; + tm.restart(); + canvas->update(); +} + + void Graphic::on_graphic_buttonAutofit_clicked() { - isFit = true; - bool isEmpty = true; - foreach(const GraphicType & t, graphics) { - const QPolygonF & pol(pause_ ? t.polyline_pause : t.polyline); - if (!pol.isEmpty()) { - isEmpty = false; - break; - } - } - if (isEmpty) grect = def_rect; - selrect = grect; - findGraphicsRect(); - update(); + autofit(); } @@ -2074,6 +2257,7 @@ void Graphic::on_graphic_buttonConfigure_clicked() { conf->ui->checkInputs->setChecked(borderInputsVisible()); conf->ui->checkStatus->setChecked(statusVisible()); conf->ui->checkLegend->setChecked(legendVisible()); + conf->ui->groupGrid->setChecked(grid); conf->ui->checkGridAutoX->setChecked(grad_x == Auto); conf->ui->checkGridAutoY->setChecked(grad_y == Auto); conf->ui->colorBackground->setColor(back_color); @@ -2102,12 +2286,18 @@ void Graphic::on_graphic_buttonConfigure_clicked() { conf->ui->spinMarginR->value(), conf->ui->spinMarginT->value(), conf->ui->spinMarginB->value()); + setGridEnabled(conf->ui->groupGrid->isChecked()); updateLegend(); - update(); + repaintCanvas(); } -void Graphic::on_graphic_buttonSave_clicked() { +void Graphic::on_graphic_buttonFullscreen_clicked() { + fullscreen(); +} + + +void Graphic::on_graphic_actionSaveImage_triggered() { QString f = QFileDialog::getSaveFileName(this, tr("Save Image"), ppath, @@ -2117,7 +2307,7 @@ void Graphic::on_graphic_buttonSave_clicked() { } -void Graphic::on_graphic_buttonExport_clicked() { +void Graphic::on_graphic_actionExportCSV_triggered() { QString f = QFileDialog::getSaveFileName(this, tr("Export graphics"), ppath, "CSV(*.csv)"); if (f.isEmpty()) return; QStringList items; @@ -2169,7 +2359,7 @@ void Graphic::on_graphic_buttonRecord_clicked(bool checked) { void Graphic::on_graphic_checkGuides_toggled(bool checked) { guides = checked; setGuidesCursor(); - update(); + repaintCanvas(); } @@ -2231,15 +2421,6 @@ void Graphic::updateLegend(bool es) { check->show(); if (leg_sa->minimum_hei == 0) { leg_sa->minimum_hei = ui->widgetLegend->sizeHint().height(); - /*#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - QTimer::singleShot(0, this, [this,leg_sa,check](){ - leg_sa->minimum_hei = check->sizeHint().height(); - leg_sa->updateGeometry(); - qDebug() << leg_sa->minimum_hei << ui->widgetLegend->sizeHint(); - }); - #else - leg_sa->minimum_hei = check->sizeHint().height(); - #endif*/ } col++; if (col > maxcol) { @@ -2250,7 +2431,6 @@ void Graphic::updateLegend(bool es) { ui->gridLayout->invalidate(); ui->scrollLegend->setVisible(lv); leg_sa->updateGeometry(); - // ui->gridLayout->invalidate(); leg_update = true; if (es) emit graphicSettingsChanged(); } @@ -2273,9 +2453,9 @@ void Graphic::graphicVisibleChange(bool checked) { int i = cb->property("graphic_num").toInt(); graphics[i].visible = checked; if (isFit) - on_graphic_buttonAutofit_clicked(); + autofit(); else { - update(); + repaintCanvas(); } emit graphicSettingsChanged(); } @@ -2289,14 +2469,49 @@ void Graphic::graphicAllVisibleChange(bool checked) { } visible_update = false; if (isFit) - on_graphic_buttonAutofit_clicked(); + autofit(); else { - update(); + repaintCanvas(); } emit graphicSettingsChanged(); } +void Graphic::lineXMinChanged(double value) { + selrect.setLeft(value); + checkLines(); +} + + +void Graphic::lineXMaxChanged(double value) { + selrect.setRight(value); + checkLines(); +} + + +void Graphic::lineYMinChanged(double value) { + selrect.setBottom(value); + checkLines(); +} + + +void Graphic::lineYMaxChanged(double value) { + selrect.setTop(value); + checkLines(); +} + + +void Graphic::on_graphic_buttonClose_clicked() { + emit closeRequest(this); +} + + +void Graphic::on_graphic_buttonClear_clicked() { + clear(); + emit cleared(); +} + + void Graphic::enterFullscreen() { if (fullscr) return; fullscr = true; @@ -2398,13 +2613,15 @@ QByteArray Graphic::save() { if (backgroundColor() == palette().color(QPalette::Base) && textColor() == palette().color(QPalette::WindowText) && gridColor() == palette().color(QPalette::Disabled, QPalette::WindowText)) cs.add(17, true); + cs.add(18, gridEnabled()); return cs.data().prepend('2'); } void Graphic::load(QByteArray ba) { if (ba.isEmpty()) return; - char ver = ba[0]; + char ver = ba[0]; + bool has_opengl = isOGL; switch (ver) { case '2': { // version '2': ba.remove(0, 1); @@ -2413,36 +2630,37 @@ void Graphic::load(QByteArray ba) { bool def_colors = false; while (!cs.atEnd()) { switch (cs.read()) { - case 1: setAntialiasing(cs.getData()); break; - case 2: setOpenGL(cs.getData()); break; + case 1: aalias = cs.getData(); break; + case 2: has_opengl = cs.getData(); break; case 3: setBorderInputsVisible(cs.getData()); break; case 4: setStatusVisible(cs.getData()); break; case 5: setLegendVisible(cs.getData()); break; case 6: - if (!def_colors) setBackgroundColor(cs.getData()); + if (!def_colors) back_color = cs.getData(); break; case 7: - if (!def_colors) setTextColor(cs.getData()); + if (!def_colors) text_color = cs.getData(); break; - case 8: setMargins(cs.getData()); break; + case 8: margins_ = cs.getData(); break; case 9: - if (!def_colors) setGridPen(cs.getData()); + if (!def_colors) grid_pen = cs.getData(); break; - case 10: setGraduationX(cs.getData()); break; - case 11: setGraduationY(cs.getData()); break; - case 12: setGraduationStepX(cs.getData()); break; - case 13: setGraduationStepY(cs.getData()); break; + case 10: grad_x = cs.getData(); break; + case 11: grad_y = cs.getData(); break; + case 12: gridx = cs.getData(); break; + case 13: gridy = cs.getData(); break; case 14: graphics = cs.getData>(); break; case 15: isFit = cs.getData(); break; case 16: vrect = cs.getData(); break; case 17: if (cs.getData()) { - setTextColor(palette().color(QPalette::WindowText)); - setGridPen(QPen(palette().color(QPalette::Disabled, QPalette::WindowText), 0., Qt::DotLine)); - setBackgroundColor(palette().color(QPalette::Base)); + text_color = palette().color(QPalette::WindowText); + grid_pen = QPen(palette().color(QPalette::Disabled, QPalette::WindowText), 0., Qt::DotLine); + back_color = palette().color(QPalette::Base); def_colors = true; } break; + case 18: grid = cs.getData(); break; default: break; } } @@ -2451,10 +2669,8 @@ void Graphic::load(QByteArray ba) { default: { // old version 0: QDataStream s(ba); bool a; - s >> a; - setOpenGL(a); - s >> a; - setAntialiasing(a); + s >> has_opengl; + s >> aalias; s >> a; setBorderInputsVisible(a); s >> a; @@ -2464,28 +2680,253 @@ void Graphic::load(QByteArray ba) { setLegendVisible(a); } break; } + if (has_opengl != isOGL) setOpenGL(has_opengl); + updateLegend(); + repaintCanvas(true); +} + + +GraphicType Graphic::graphic(int arg) { + if (arg < 0 || arg >= graphics.size()) return GraphicType(); + return graphics[arg]; +} + + +void Graphic::setAllGraphics(const QVector & g, bool update) { + graphics = g; + if (update) { + updateLegend(); + repaintCanvas(); + } } void Graphic::setCaption(const QString & str) { ui->labelCaption->setText(str); ui->labelCaption->setVisible(str.length() > 0); - if (aupdate) update(); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setLabelX(const QString & str) { + label_x = str; + hasLblX = (str.length() > 0); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setLabelY(const QString & str) { + label_y = str; + hasLblY = (str.length() > 0); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setGraphicName(const QString & str, int index) { + graphics[index].name = str; + updateLegend(); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setGraphicName(const QString & str) { + graphics[curGraphic].name = str; + updateLegend(); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setBackgroundColor(const QColor & color) { + back_color = color; + if (aupdate) repaintCanvas(); + updateLegend(); +} + + +void Graphic::setTextColor(const QColor & color) { + text_color = color; + if (aupdate) repaintCanvas(); +} + + +void Graphic::setGraphicColor(const QColor & color, int index) { + graphics[index].pen.setColor(color); + updateLegend(); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setGraphicColor(const QColor & color) { + setGraphicColor(color, curGraphic); +} + + +void Graphic::setGridColor(const QColor & color) { + grid_pen.setColor(color); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setSelectionColor(const QColor & color) { + selpen.setColor(color); +} + + +void Graphic::setGraphicStyle(const Qt::PenStyle & style, int index) { + graphics[index].pen.setStyle(style); + updateLegend(); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setGraphicStyle(const Qt::PenStyle & style) { + setGraphicStyle(style, curGraphic); +} + + +void Graphic::setGridStyle(const Qt::PenStyle & style) { + grid_pen.setStyle(style); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setSelectionStyle(const Qt::PenStyle & style) { + selpen.setStyle(style); } void Graphic::setGraphicVisible(bool visible, int index) { graphics[index].visible = visible; updateLegendChecks(); - if (isFit) - on_graphic_buttonAutofit_clicked(); - else if (aupdate) - update(); + if (isFit) { + autofit(); + } else if (aupdate) { + repaintCanvas(); + } +} + + +void Graphic::setGraphicVisible(bool visible) { + setGraphicVisible(visible, curGraphic); +} + + +void Graphic::setGraphicLineWidth(double w, int index) { + if (qRound(w) == w) + graphics[index].pen.setWidth(qRound(w)); + else + graphics[index].pen.setWidthF(w); + updateLegend(); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setGraphicLineWidth(double w) { + setGraphicLineWidth(w, curGraphic); +} + + +void Graphic::setGraphicPointWidth(double w, int index) { + graphics[index].pointWidth = w; + updateLegend(); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setGraphicPointWidth(double w) { + setGraphicPointWidth(w, curGraphic); +} + + +void Graphic::setGraphicFillColor(const QColor & w, int index) { + graphics[index].fill_color = w; + updateLegend(); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setGraphicFillColor(const QColor & w) { + setGraphicFillColor(w, curGraphic); +} + + +void Graphic::setGraphicLinesEnabled(bool w, int index) { + graphics[index].lines = w; + updateLegend(); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setGraphicLinesEnabled(bool w) { + setGraphicLinesEnabled(w, curGraphic); +} + + +void Graphic::setGraphicPointsEnabled(bool w, int index) { + graphics[index].points = w; + updateLegend(); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setGraphicPointsEnabled(bool w) { + setGraphicPointsEnabled(w, curGraphic); +} + + +void Graphic::setGraphicFillEnabled(bool w, int index) { + graphics[index].fill = w; + updateLegend(); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setGraphicFillEnabled(bool w) { + setGraphicFillEnabled(w, curGraphic); +} + + +void Graphic::setGraphicPen(const QPen & pen, int index) { + graphics[index].pen = pen; + updateLegend(); + if (aupdate) repaintCanvas(); +} + + +void Graphic::setGraphicPen(const QPen & pen) { + setGraphicPen(pen, curGraphic); +} + + +void Graphic::setGridPen(const QPen & pen) { + grid_pen = pen; + if (aupdate) repaintCanvas(); +} + + +void Graphic::setSelectionPen(const QPen & pen) { + selpen = pen; +} + + +void Graphic::setSelectionBrush(const QBrush & brush) { + selbrush = brush; +} + + +void Graphic::setNavigationEnabled(bool on) { + navigation = on; +} + + +void Graphic::setLODOptimization(bool yes) { + m_LODOptimization = yes; } void Graphic::setGridEnabled(bool enabled) { - ui->graphic_checkGrid->setChecked(enabled); + grid = enabled; + repaintCanvas(); } @@ -2525,6 +2966,21 @@ void Graphic::on_graphic_actionExpandY_triggered(bool checked) { } +void Graphic::on_graphic_checkBorderInputs_toggled(bool checked) { + setBorderInputsVisible(checked); +} + + +void Graphic::on_graphic_checkLegend_toggled(bool checked) { + setLegendVisible(checked); +} + + +void Graphic::on_graphic_checkPause_toggled(bool checked) { + setPaused(checked); +} + + void Graphic::actionGuidesTriggered(QAction * a) { ui->graphic_checkGuides->setChecked(true); setFloatingAxisType((FloatingAxisType)a->property("_value").toInt()); diff --git a/libs/graphic/graphic.h b/libs/graphic/graphic.h index 04f9b96..2f57dd9 100644 --- a/libs/graphic/graphic.h +++ b/libs/graphic/graphic.h @@ -167,9 +167,7 @@ public: }; enum FloatingAxisType { Free, - TraceXY, - TraceX, - TraceY + Trace }; Q_DECLARE_FLAGS(Buttons, Button) @@ -222,7 +220,6 @@ public: bool LODOptimization() const { return m_LODOptimization; } bool isAutofitted() const { return isFit; } int currentGraphic() const { return curGraphic; } - int currentTraceGraphic() const { return curTrace; } int graphicsCount() const { return graphics.size(); } Graphic::Buttons buttons() const { return buttons_; } Graphic::Alignment buttonsPosition() const { return align; } @@ -247,18 +244,13 @@ public: GraphicsData graphicsData() const; QByteArray graphicsDataRaw() const; QWidget * viewport() const { return canvas; } + QByteArray save(); void load(QByteArray ba); - GraphicType graphic(int arg) { - if (arg < 0 || arg >= graphics.size()) return GraphicType(); - return graphics[arg]; - } + GraphicType graphic(int arg); const QVector & allGraphics() const { return graphics; } - void setAllGraphics(const QVector & g, bool update = true) { - graphics = g; - if (update) updateLegend(); - } + void setAllGraphics(const QVector & g, bool update = true); double canvas2realX(double px) const; double canvas2realY(double py) const; @@ -268,121 +260,50 @@ public: QPointF real2canvas(QPointF real_point) const { return QPointF(real2canvasX(real_point.x()), real2canvasY(real_point.y())); } QPolygonF real2canvas(const QPolygonF & real_polygon) const; QPolygonF canvas2real(const QPolygonF & canvas_polygon) const; - double getScaleX() const { return real2canvasX(1.) - real2canvasX(0.); } - double getScaleY() const { return real2canvasY(1.) - real2canvasY(0.); } + double getScaleX() const; + double getScaleY() const; QPointF getScale() const { return QPointF(getScaleX(), getScaleY()); } public slots: void setCaption(const QString & str); - void setLabelX(const QString & str) { - label_x = str; - hasLblX = (str.length() > 0); - if (aupdate) update(); - } - void setLabelY(const QString & str) { - label_y = str; - hasLblY = (str.length() > 0); - if (aupdate) update(); - } - void setGraphicName(const QString & str, int index) { - graphics[index].name = str; - updateLegend(); - if (aupdate) update(); - } - void setGraphicName(const QString & str) { - graphics[curGraphic].name = str; - updateLegend(); - if (aupdate) update(); - } - void setBackgroundColor(const QColor & color) { - back_color = color; - if (aupdate) update(); - updateLegend(); - } - void setTextColor(const QColor & color) { - text_color = color; - if (aupdate) update(); - } - void setGraphicColor(const QColor & color, int index) { - graphics[index].pen.setColor(color); - updateLegend(); - if (aupdate) update(); - } - void setGraphicColor(const QColor & color) { setGraphicColor(color, curGraphic); } - void setGridColor(const QColor & color) { - grid_pen.setColor(color); - if (aupdate) update(); - } - void setSelectionColor(const QColor & color) { selpen.setColor(color); } - void setGraphicStyle(const Qt::PenStyle & style, int index) { - graphics[index].pen.setStyle(style); - updateLegend(); - if (aupdate) update(); - } - void setGraphicStyle(const Qt::PenStyle & style) { setGraphicStyle(style, curGraphic); } - void setGridStyle(const Qt::PenStyle & style) { - grid_pen.setStyle(style); - if (aupdate) update(); - } - void setSelectionStyle(const Qt::PenStyle & style) { selpen.setStyle(style); } + void setLabelX(const QString & str); + void setLabelY(const QString & str); + void setGraphicName(const QString & str, int index); + void setGraphicName(const QString & str); + void setBackgroundColor(const QColor & color); + void setTextColor(const QColor & color); + void setGraphicColor(const QColor & color, int index); + void setGraphicColor(const QColor & color); + void setGridColor(const QColor & color); + void setSelectionColor(const QColor & color); + void setGraphicStyle(const Qt::PenStyle & style, int index); + void setGraphicStyle(const Qt::PenStyle & style); + void setGridStyle(const Qt::PenStyle & style); + void setSelectionStyle(const Qt::PenStyle & style); void setGraphicVisible(bool visible, int index); - void setGraphicVisible(bool visible) { setGraphicVisible(visible, curGraphic); } - void setGraphicLineWidth(double w, int index) { - if (qRound(w) == w) - graphics[index].pen.setWidth(qRound(w)); - else - graphics[index].pen.setWidthF(w); - updateLegend(); - if (aupdate) update(); - } - void setGraphicLineWidth(double w) { setGraphicLineWidth(w, curGraphic); } - void setGraphicPointWidth(double w, int index) { - graphics[index].pointWidth = w; - updateLegend(); - if (aupdate) update(); - } - void setGraphicPointWidth(double w) { setGraphicPointWidth(w, curGraphic); } - void setGraphicFillColor(const QColor & w, int index) { - graphics[index].fill_color = w; - updateLegend(); - if (aupdate) update(); - } - void setGraphicFillColor(const QColor & w) { setGraphicFillColor(w, curGraphic); } - void setGraphicLinesEnabled(bool w, int index) { - graphics[index].lines = w; - updateLegend(); - if (aupdate) update(); - } - void setGraphicLinesEnabled(bool w) { setGraphicLinesEnabled(w, curGraphic); } - void setGraphicPointsEnabled(bool w, int index) { - graphics[index].points = w; - updateLegend(); - if (aupdate) update(); - } - void setGraphicPointsEnabled(bool w) { setGraphicPointsEnabled(w, curGraphic); } - void setGraphicFillEnabled(bool w, int index) { - graphics[index].fill = w; - updateLegend(); - if (aupdate) update(); - } - void setGraphicFillEnabled(bool w) { setGraphicFillEnabled(w, curGraphic); } - void setGraphicPen(const QPen & pen, int index) { - graphics[index].pen = pen; - updateLegend(); - if (aupdate) update(); - } - void setGraphicPen(const QPen & pen) { setGraphicPen(pen, curGraphic); } - void setGridPen(const QPen & pen) { - grid_pen = pen; - if (aupdate) update(); - } - void setSelectionPen(const QPen & pen) { selpen = pen; } - void setSelectionBrush(const QBrush & brush) { selbrush = brush; } - void setNavigationEnabled(bool on) { navigation = on; } - void setLODOptimization(bool yes) { m_LODOptimization = yes; } + void setGraphicVisible(bool visible); + void setGraphicLineWidth(double w, int index); + void setGraphicLineWidth(double w); + void setGraphicPointWidth(double w, int index); + void setGraphicPointWidth(double w); + void setGraphicFillColor(const QColor & w, int index); + void setGraphicFillColor(const QColor & w); + void setGraphicLinesEnabled(bool w, int index); + void setGraphicLinesEnabled(bool w); + void setGraphicPointsEnabled(bool w, int index); + void setGraphicPointsEnabled(bool w); + void setGraphicFillEnabled(bool w, int index); + void setGraphicFillEnabled(bool w); + void setGraphicPen(const QPen & pen, int index); + void setGraphicPen(const QPen & pen); + void setGridPen(const QPen & pen); + void setSelectionPen(const QPen & pen); + void setSelectionBrush(const QBrush & brush); + void setNavigationEnabled(bool on); + void setLODOptimization(bool yes); void setOpenGL(bool on); void setAntialiasing(bool enabled); - void setAutoUpdate(bool enabled) { aupdate = enabled; } + void setAutoUpdate(bool enabled); void setGridEnabled(bool enabled); void setBorderInputsVisible(bool visible); void setStatusVisible(bool visible); @@ -392,107 +313,49 @@ public slots: void setButtonsPosition(Graphic::Alignment a); void setHistorySize(double val); void setMaxVisibleTime(double val); - void setAutoXIncrement(double val) { inc_x = val; } - void setLimit(const QRectF & val) { limit_ = val; } - void setMargins(const QRect & val) { - margins_ = val; - update(); - } - void setMargins(int left_, int right_, int top_, int bottom_) { setMargins(QRect(left_, bottom_, right_, top_)); } - void setLeftMargin(int value) { - margins_.moveLeft(value); - setMargins(margins_); - } - void setRightMargin(int value) { - margins_.setWidth(value); - setMargins(margins_); - } - void setTopMargin(int value) { - margins_.setHeight(value); - setMargins(margins_); - } - void setBottomMargin(int value) { - margins_.moveTop(value); - setMargins(margins_); - } - void setMinimumRepaintInterval(const int & val) { min_repaint_int = val; } + void setAutoXIncrement(double val); + void setLimit(const QRectF & val); + void setMargins(const QRect & val); + void setMargins(int left_, int right_, int top_, int bottom_); + void setLeftMargin(int value); + void setRightMargin(int value); + void setTopMargin(int value); + void setBottomMargin(int value); + void setMinimumRepaintInterval(const int & val); void setOnlyExpandY(bool yes); void setOnlyExpandX(bool yes); void setGesturesNavigation(bool yes); void setGraphicsData(const GraphicsData & gd); void setGraphicsDataRaw(const QByteArray & ba); - void setGridNumbersMultiplierX(double value) { - grid_numbers_x = value; - updateGraphics(); - } - void setGridNumbersMultiplierY(double value) { - grid_numbers_y = value; - updateGraphics(); - } - void setGraduationX(Graduation value) { - grad_x = value; - if (aupdate) update(); - ; - } - void setGraduationY(Graduation value) { - grad_y = value; - if (aupdate) update(); - ; - } - void setGraduationStepX(double sx) { - gridx = sx; - if (aupdate) update(); - } - void setGraduationStepY(double sy) { - gridy = sy; - if (aupdate) update(); - } - void setGraduationSteps(double sx, double sy) { - gridx = sx; - gridy = sy; - if (aupdate) update(); - } - void setAxisType(AxisType t) { - axis_type_x = t; - if (aupdate) update(); - } - void setFloatingAxisType(FloatingAxisType t) { - floating_axis_type = t; - setGuidesCursor(); - if (aupdate) update(); - } + void setGridNumbersMultiplierX(double value); + void setGridNumbersMultiplierY(double value); + void setGraduationX(Graduation value); + void setGraduationY(Graduation value); + void setGraduationStepX(double sx); + void setGraduationStepY(double sy); + void setGraduationSteps(double sx, double sy); + void setAxisType(AxisType t); + void setFloatingAxisType(FloatingAxisType t); void setFloatingAxisEnabled(bool on); void addPoint(const QPointF & p, int graphic, bool update_ = true); - void addPoint(const QPointF & p, bool update = true) { addPoint(p, curGraphic, update); } - void addPoint(double x, double y, int graphic, bool update = true) { addPoint(QPointF(x, y), graphic, update); } - void addPoint(double x, double y, bool update = true) { addPoint(QPointF(x, y), update); } - void addPoint(double y, int graphic, bool update = true) { - if (graphics[graphic].polyline.isEmpty()) - addPoint(QPointF(0.0, y), graphic, update); - else - addPoint(QPointF(graphics[graphic].max_x + inc_x, y), graphic, update); - } - void addPoint(double y, bool update = true) { - if (graphics[curGraphic].polyline.isEmpty()) - addPoint(QPointF(0.0, y), update); - else - addPoint(QPointF(graphics[curGraphic].max_x + inc_x, y), update); - } + void addPoint(const QPointF & p, bool update = true); + void addPoint(double x, double y, int graphic, bool update = true); + void addPoint(double x, double y, bool update = true); + void addPoint(double y, int graphic, bool update = true); + void addPoint(double y, bool update = true); void addPoints(const QPolygonF & pts, int graphic, bool update_ = true); - void addPoints(const QPolygonF & pts, bool update = true) { addPoints(pts, curGraphic, update); } + void addPoints(const QPolygonF & pts, bool update = true); void addPoints(const QVector & pts, int graphic, bool update_ = true); - void addPoints(const QVector & pts, bool update = true) { addPoints(pts, curGraphic, update); } + void addPoints(const QVector & pts, bool update = true); void setGraphicData(const QVector & g, int graphic, bool update_ = true); - void setGraphicData(const QVector & g) { setGraphicData(g, curGraphic); } + void setGraphicData(const QVector & g); void setGraphicProperties(const QString & name, const QColor & color = Qt::darkRed, Qt::PenStyle style = Qt::SolidLine, double width = 0., - bool visible = true) { - setGraphicProperties(curGraphic, name, color, style, width, visible); - } + bool visible = true); void setGraphicProperties(int graphic, const QString & name, const QColor & color = Qt::darkRed, @@ -504,30 +367,16 @@ public slots: Qt::PenStyle style = Qt::SolidLine, double width = 0., bool visible = true); - void addGraphic(const GraphicType & gd, bool update = true) { - graphics << gd; - if (update) updateLegend(); - } + void addGraphic(const GraphicType & gd); void setVisualRect(const QRectF & rect); void setDefaultRect(const QRectF & rect); - void autofit() { on_graphic_buttonAutofit_clicked(); } + void autofit(); void saveImage(QString filename); void exportGraphics(QString filename, QChar decimal_point); void clear(); - void update(bool force); - void update() { update(false); } - void updateGraphics() { - findGraphicsRect(); - update(); - } - void setCurrentGraphic(int arg) { - if (arg < 0 || arg >= graphics.size()) return; - curGraphic = arg; - } - void setTraceGraphic(int arg) { - if (arg < 0 || arg >= graphics.size()) return; - curTrace = arg; - } + void update(); + void updateGraphics(); + void setCurrentGraphic(int arg); void setGraphicsCount(int arg, bool update = true); void removeGraphic(int arg, bool update = true); void setCustomGridMarkFuncs(std::function fx, std::function fy); @@ -560,11 +409,7 @@ protected: void findGraphicsRect(double start_x = 0., double end_x = 0., double start_y = 0., double end_y = 0.); void tick(int index, bool slide = true, bool update = true); void calcLOD(int index); - void repaintCanvas(bool force = false) { - if (tm.elapsed() < min_repaint_int && !force) return; - tm.restart(); - canvas->update(); - } + void repaintCanvas(bool force = false); void drawGraphics(); void drawGrid(); void drawGuides(); @@ -597,7 +442,7 @@ protected: QPen grid_pen, selpen; QColor back_color, text_color; QVector graphics; - int curGraphic, curTrace; + int curGraphic; GraphicAction curaction, prevaction; QRectF grect, selrect, limit_, def_rect; QRect margins_; @@ -642,43 +487,24 @@ protected slots: void canvasKeyPressEvent(QKeyEvent *); void graphicVisibleChange(bool checked); void graphicAllVisibleChange(bool checked); - void lineXMinChanged(double value) { - selrect.setLeft(value); - checkLines(); - } - void lineXMaxChanged(double value) { - selrect.setRight(value); - checkLines(); - } - void lineYMinChanged(double value) { - selrect.setBottom(value); - checkLines(); - } - void lineYMaxChanged(double value) { - selrect.setTop(value); - checkLines(); - } - void on_graphic_buttonClose_clicked() { emit closeRequest(this); } - void on_graphic_buttonClear_clicked() { - clear(); - emit cleared(); - } + void lineXMinChanged(double value); + void lineXMaxChanged(double value); + void lineYMinChanged(double value); + void lineYMaxChanged(double value); + void on_graphic_buttonClose_clicked(); + void on_graphic_buttonClear_clicked(); void on_graphic_buttonAutofit_clicked(); void on_graphic_buttonConfigure_clicked(); - void on_graphic_buttonFullscreen_clicked() { fullscreen(); } - void on_graphic_buttonSave_clicked(); - void on_graphic_buttonExport_clicked(); + void on_graphic_buttonFullscreen_clicked(); + void on_graphic_actionSaveImage_triggered(); + void on_graphic_actionExportCSV_triggered(); void on_graphic_buttonRecord_clicked(bool checked); - void on_graphic_checkGrid_toggled(bool checked) { - grid = checked; - update(); - } void on_graphic_checkGuides_toggled(bool checked); void on_graphic_actionExpandX_triggered(bool checked); void on_graphic_actionExpandY_triggered(bool checked); - void on_graphic_checkBorderInputs_toggled(bool checked) { setBorderInputsVisible(checked); } - void on_graphic_checkLegend_toggled(bool checked) { setLegendVisible(checked); } - void on_graphic_checkPause_toggled(bool checked) { setPaused(checked); } + void on_graphic_checkBorderInputs_toggled(bool checked); + void on_graphic_checkLegend_toggled(bool checked); + void on_graphic_checkPause_toggled(bool checked); void actionGuidesTriggered(QAction * a); void enterFullscreen(); void leaveFullscreen(); diff --git a/libs/graphic/graphic.ui b/libs/graphic/graphic.ui index c8ee72a..62a8e58 100644 --- a/libs/graphic/graphic.ui +++ b/libs/graphic/graphic.ui @@ -68,23 +68,6 @@ - - - - Grid - - - - :/icons/view-grid.png:/icons/view-grid.png - - - true - - - true - - - @@ -167,7 +150,7 @@ - + Save image ... @@ -175,16 +158,8 @@ :/icons/document-save.png:/icons/document-save.png - - - - - - Export graphics ... - - - - :/icons/document-edit.png:/icons/document-edit.png + + QToolButton::InstantPopup @@ -442,22 +417,6 @@ Free - - - true - - - Trace X - - - - - true - - - Trace Y - - true @@ -488,6 +447,24 @@ Snap trace + + + + :/icons/view-preview.png:/icons/view-preview.png + + + Save to Image... + + + + + + :/icons/document-edit.png:/icons/document-edit.png + + + Export to CSV... + + @@ -500,9 +477,6 @@ - - - diff --git a/libs/graphic/graphic_conf.cpp b/libs/graphic/graphic_conf.cpp index c875ec2..cbf86d4 100644 --- a/libs/graphic/graphic_conf.cpp +++ b/libs/graphic/graphic_conf.cpp @@ -8,14 +8,14 @@ GraphicConf::GraphicConf(QVector & graphics_, QWidget * parent): QD ui = new Ui::GraphicConf(); ui->setupUi(this); QStringList styles; - int fh = qMax(fontMetrics().size(0, "0").height(), 22); + int fh = qMax(fontMetrics().height(), 22); int thick = lineThickness(this); QSize sz(fh * 2.5, fh); styles << tr("NoPen") << tr("Solid") << tr("Dash") << tr("Dot") << tr("Dash-Dot") << tr("Dash-Dot-Dot"); ui->comboStyleGrid->setIconSize(sz); ui->comboStyleGraphic->setIconSize(sz); ui->cbGraphicNames->setIconSize(sz); - for (int i = 0; i < 6; i++) { + for (int i = 0; i < styles.size(); i++) { QPixmap pix(sz); pix.fill(); QPainter p(&pix); diff --git a/libs/graphic/graphic_conf.ui b/libs/graphic/graphic_conf.ui index edc28ec..0118387 100644 --- a/libs/graphic/graphic_conf.ui +++ b/libs/graphic/graphic_conf.ui @@ -10,7 +10,7 @@ 0 0 387 - 505 + 507 @@ -21,7 +21,7 @@ - + Appearance @@ -71,7 +71,7 @@ QFormLayout::AllNonFixedFieldsGrow - + 0 @@ -91,7 +91,7 @@ - + 0 @@ -116,7 +116,7 @@ - + Margins @@ -145,7 +145,7 @@ - + All: @@ -165,7 +165,7 @@ - + Right: @@ -175,7 +175,7 @@ - + Left: @@ -185,7 +185,7 @@ - + Bottom: @@ -205,7 +205,7 @@ - + Top: @@ -215,7 +215,7 @@ - + px @@ -230,16 +230,19 @@ - + Grid + + true + QFormLayout::AllNonFixedFieldsGrow - + Color: @@ -253,7 +256,7 @@ - + Style: @@ -263,7 +266,7 @@ - + Width: @@ -277,14 +280,14 @@ - + Step X: - + Step Y: @@ -340,7 +343,7 @@ - + Graphics @@ -359,7 +362,7 @@ - + Color: @@ -373,7 +376,7 @@ - + Style: @@ -518,7 +521,6 @@ - @@ -528,8 +530,8 @@ reject() - 255 - 641 + 376 + 495 245 @@ -544,12 +546,12 @@ setEnabled(bool) - 322 - 410 + 286 + 373 - 415 - 411 + 366 + 376 @@ -560,12 +562,12 @@ setEnabled(bool) - 322 - 434 + 291 + 399 - 415 - 435 + 366 + 402 @@ -576,8 +578,8 @@ accept() - 294 - 641 + 376 + 495 288 @@ -592,76 +594,76 @@ setEnabled(bool) - 322 - 458 + 245 + 425 - 415 - 460 + 366 + 431 - spinMarginT_2 + spinMarginAll valueChanged(int) spinMarginT setValue(int) - 259 - 221 + 237 + 209 - 249 - 191 + 237 + 183 - spinMarginT_2 + spinMarginAll valueChanged(int) spinMarginR setValue(int) - 268 - 220 + 237 + 209 - 371 - 220 + 367 + 209 - spinMarginT_2 + spinMarginAll valueChanged(int) spinMarginB setValue(int) - 233 - 230 + 237 + 209 - 234 - 252 + 237 + 235 - spinMarginT_2 + spinMarginAll valueChanged(int) spinMarginL setValue(int) - 213 - 230 + 237 + 209 - 133 - 229 + 106 + 209 diff --git a/utils/qpicalculator/mainwindow.cpp b/utils/qpicalculator/mainwindow.cpp index b5446b6..4a9a079 100644 --- a/utils/qpicalculator/mainwindow.cpp +++ b/utils/qpicalculator/mainwindow.cpp @@ -76,7 +76,7 @@ void MainWindow::redrawGraphics() { graphic->setGraphicData(pol, i); } graphic->setAutoUpdate(true); - graphic->update(true); + graphic->updateGraphics(); } diff --git a/utils/qpicalculator/mainwindow.ui b/utils/qpicalculator/mainwindow.ui index 5cf135c..93fab83 100644 --- a/utils/qpicalculator/mainwindow.ui +++ b/utils/qpicalculator/mainwindow.ui @@ -151,7 +151,7 @@ - + :/icons/list-add.png:/icons/list-add.png @@ -162,7 +162,7 @@ false - + :/icons/edit-delete.png:/icons/edit-delete.png @@ -192,7 +192,7 @@ false - + :/icons/edit-clear.png:/icons/edit-clear.png @@ -272,7 +272,7 @@ - + :/icons/list-add.png:/icons/list-add.png @@ -283,7 +283,7 @@ false - + :/icons/edit-delete.png:/icons/edit-delete.png @@ -313,7 +313,7 @@ false - + :/icons/edit-clear.png:/icons/edit-clear.png @@ -337,7 +337,7 @@ - Graphic::BorderInputs|Graphic::Configure|Graphic::CursorAxis|Graphic::Export|Graphic::Fullscreen|Graphic::Grid|Graphic::Save + Graphic::BorderInputs|Graphic::Configure|Graphic::CursorAxis|Graphic::Export|Graphic::Fullscreen|Graphic::Save true @@ -372,13 +372,7 @@ - - - - - - - +