From bee9bd12d508324047cca6bcd6d4b730364d028d Mon Sep 17 00:00:00 2001 From: peri4 Date: Mon, 8 Apr 2024 11:25:46 +0300 Subject: [PATCH] version 2.27.0 Graphic legend checks context menu rework --- CMakeLists.txt | 2 +- libs/graphic/graphic.cpp | 105 +++++++++++++++++++--------- libs/graphic/graphic.h | 9 ++- libs/graphic/graphic.ui | 31 ++++++++ libs/graphic/lang/qad_graphic_en.ts | 62 ++++++++++------ libs/graphic/lang/qad_graphic_ru.ts | 64 ++++++++++------- libs/graphic/qad_graphic.qrc | 2 + 7 files changed, 192 insertions(+), 83 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 678ef50..d3fcc57 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 26) +set(QAD_MINOR 27) set(QAD_REVISION 0) set(QAD_SUFFIX ) set(QAD_COMPANY SHS) diff --git a/libs/graphic/graphic.cpp b/libs/graphic/graphic.cpp index bba9dbb..98aa24c 100644 --- a/libs/graphic/graphic.cpp +++ b/libs/graphic/graphic.cpp @@ -159,9 +159,12 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), aupdate = grid = isFit = navigation = true; aalias = bufferActive = isOGL = cancel = guides = hasLblX = hasLblY = isHover = false; pause_ = only_expand_x = only_expand_y = m_LODOptimization = was_trace = false; - limit_.setCoords(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX); - eminx = eminy = DBL_MAX; - emaxx = emaxy = DBL_MIN; + limit_.setCoords(-std::numeric_limits::max(), + -std::numeric_limits::max(), + std::numeric_limits::max(), + std::numeric_limits::max()); + eminx = eminy = std::numeric_limits::max(); + emaxx = emaxy = -std::numeric_limits::max(); grad_x = grad_y = Auto; axis_type_x = Numeric; floating_axis_type = Trace; @@ -307,6 +310,9 @@ bool Graphic::eventFilter(QObject * o, QEvent * e) { default: break; } } + if (e->type() == QEvent::ContextMenu) { + action_source = qobject_cast(o); + } return QFrame::eventFilter(o, e); } @@ -1292,6 +1298,7 @@ void Graphic::setGraphicsCount(int count, bool update) { changed = true; } while (graphics.size() > count) { + if (action_source == graphics.back().pb) action_source = nullptr; graphics.back().destroy(); graphics.pop_back(); changed = true; @@ -1326,9 +1333,9 @@ void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, dou bool isRangeX = (start_x != end_x), isRangeY = (start_y != end_y); bool can_fast = (start_x == 0 && end_x == 0 && start_y == 0 && end_y == 0); bool anyVisible = false, isTimeLimit = (visible_time > 0.) && !(isRangeX || isRangeY); - vx = -DBL_MAX; - minY = minX = DBL_MAX; - maxY = maxX = -DBL_MAX; + vx = -std::numeric_limits::max(); + minY = minX = std::numeric_limits::max(); + maxY = maxX = -std::numeric_limits::max(); foreach(const GraphicType & t, graphics) { if (!t.visible) continue; if (vx < (pause_ ? t.max_x_pause : t.max_x)) vx = (pause_ ? t.max_x_pause : t.max_x); @@ -1738,6 +1745,16 @@ bool Graphic::checkGraphicIndex(int index) const { } +void Graphic::graphicVisibleChanged() { + if (isFit) + autofit(); + else { + repaintCanvas(); + } + emit graphicSettingsChanged(); +} + + void Graphic::drawGraphics() { if (isHover && ui->status->isVisible()) { ui->status->setText(tr("Cursor: ") + pointCoords(canvas2real(QPointF(curpos)))); @@ -2458,11 +2475,9 @@ void Graphic::updateLegend(bool es) { ui->layoutLegend->invalidate(); for (int i = 0; i < graphics.size(); i++) { if (graphics[i].init()) { - QAction * act = new QAction(tr("Check all"), 0); - act->setCheckable(true); - act->setChecked(true); - graphics[i].pb->addAction(act); - connect(act, SIGNAL(triggered(bool)), this, SLOT(graphicAllVisibleChange(bool))); + graphics[i].pb->addActions( + {ui->actionCheck_all, ui->actionUncheck_all, ui->actionInvert_selection, ui->actionSelect_only_this}); + graphics[i].pb->installEventFilter(this); connect(graphics[i].pb, SIGNAL(toggled(bool)), this, SLOT(graphicVisibleChange(bool))); graphics[i].pb->setContextMenuPolicy(Qt::ActionsContextMenu); } @@ -2515,28 +2530,7 @@ void Graphic::graphicVisibleChange(bool checked) { QCheckBox * cb = qobject_cast(sender()); int i = cb->property("graphic_num").toInt(); graphics[i].visible = checked; - if (isFit) - autofit(); - else { - repaintCanvas(); - } - emit graphicSettingsChanged(); -} - - -void Graphic::graphicAllVisibleChange(bool checked) { - visible_update = true; - for (int i = 0; i < graphics.size(); i++) { - graphics[i].visible = checked; - graphics[i].pb->setChecked(checked); - } - visible_update = false; - if (isFit) - autofit(); - else { - repaintCanvas(); - } - emit graphicSettingsChanged(); + graphicVisibleChanged(); } @@ -2564,6 +2558,51 @@ void Graphic::lineYMaxChanged(double value) { } +void Graphic::on_actionCheck_all_triggered() { + visible_update = true; + for (auto & g: graphics) { + g.visible = true; + g.pb->setChecked(true); + } + visible_update = false; + graphicVisibleChanged(); +} + + +void Graphic::on_actionUncheck_all_triggered() { + visible_update = true; + for (auto & g: graphics) { + g.visible = false; + g.pb->setChecked(false); + } + visible_update = false; + graphicVisibleChanged(); +} + + +void Graphic::on_actionInvert_selection_triggered() { + visible_update = true; + for (auto & g: graphics) { + g.visible = !g.visible; + g.pb->setChecked(g.visible); + } + visible_update = false; + graphicVisibleChanged(); +} + + +void Graphic::on_actionSelect_only_this_triggered() { + visible_update = true; + for (auto & g: graphics) { + g.visible = (g.pb == action_source); + g.pb->setChecked(g.visible); + } + visible_update = false; + graphicVisibleChanged(); + action_source = nullptr; +} + + void Graphic::on_graphic_buttonClose_clicked() { emit closeRequest(this); } diff --git a/libs/graphic/graphic.h b/libs/graphic/graphic.h index 166bd2d..f0592f1 100644 --- a/libs/graphic/graphic.h +++ b/libs/graphic/graphic.h @@ -435,6 +435,7 @@ protected: void fillDateFormats(); void askForExport(bool view_only); bool checkGraphicIndex(int index) const; + void graphicVisibleChanged(); Ui::Graphic * ui; UGLWidget * canvas_gl; @@ -458,7 +459,8 @@ protected: GraphicConf * conf; EvalSpinBox line_x_min, line_x_max, line_y_min, line_y_max; QElapsedTimer tm; - QMenu * buttons_menu = nullptr; + QMenu * buttons_menu = nullptr; + QCheckBox * action_source = nullptr; #ifdef Q_OS_ANDROID QElapsedTimer tm_fscr; #endif @@ -489,11 +491,14 @@ protected slots: void canvasWheelEvent(QWheelEvent *); void canvasLeaveEvent(QEvent *); void graphicVisibleChange(bool checked); - void graphicAllVisibleChange(bool checked); void lineXMinChanged(double value); void lineXMaxChanged(double value); void lineYMinChanged(double value); void lineYMaxChanged(double value); + void on_actionCheck_all_triggered(); + void on_actionUncheck_all_triggered(); + void on_actionInvert_selection_triggered(); + void on_actionSelect_only_this_triggered(); void on_graphic_buttonClose_clicked(); void on_graphic_buttonClear_clicked(); void on_graphic_buttonAutofit_clicked(); diff --git a/libs/graphic/graphic.ui b/libs/graphic/graphic.ui index ed9676b..e8cc62e 100644 --- a/libs/graphic/graphic.ui +++ b/libs/graphic/graphic.ui @@ -506,6 +506,37 @@ Esc + + + + :/icons/layer-visible-on.png:/icons/layer-visible-on.png + + + Check all + + + + + + :/icons/layer-visible-off.png:/icons/layer-visible-off.png + + + Uncheck all + + + + + Invert selection + + + + + Select only this + + + Select only this + + diff --git a/libs/graphic/lang/qad_graphic_en.ts b/libs/graphic/lang/qad_graphic_en.ts index 50fb69e..1711e33 100644 --- a/libs/graphic/lang/qad_graphic_en.ts +++ b/libs/graphic/lang/qad_graphic_en.ts @@ -89,6 +89,22 @@ Esc + + + Uncheck all + + + + + Invert selection + + + + + + Select only this + + Record graphic @@ -116,97 +132,97 @@ - - + + Cursor: - + Selection - + Size - - + + Range - - + + Length - - + + Cursor - - + + Export graphics - + Can`t open file "%1"! - + ms - + s - + m - + h - + Save Image - + y(x) - + Select decimal point - + Decimal point: - + Save GIF - + Check all diff --git a/libs/graphic/lang/qad_graphic_ru.ts b/libs/graphic/lang/qad_graphic_ru.ts index 46346e7..f70deef 100644 --- a/libs/graphic/lang/qad_graphic_ru.ts +++ b/libs/graphic/lang/qad_graphic_ru.ts @@ -71,6 +71,22 @@ Configure ... Настроить ... + + + Uncheck all + Скрыть все + + + + Invert selection + Инвертировать выбор + + + + + Select only this + Выбрать только этот + Save image ... Сохранить изображение ... @@ -148,99 +164,99 @@ Свободная трассировка - - + + Cursor: Курсор: - + Selection Выделение - + Size Размер - - + + Range Диапазон - - + + Length Длина - - + + Cursor Курсор - - + + Export graphics Экспорт графиков - + Can`t open file "%1"! Невозможно открыть файл "%1"! - + ms мс - + s сек - + m мин - + h ч - + Save Image Сохранить изображение - + y(x) - + Select decimal point Выберите десятичный разделитель - + Decimal point: Десятичный разделитель: - + Save GIF Сохранить GIF - + Check all - Выбрать все + Показать все diff --git a/libs/graphic/qad_graphic.qrc b/libs/graphic/qad_graphic.qrc index 710874b..6b638e1 100644 --- a/libs/graphic/qad_graphic.qrc +++ b/libs/graphic/qad_graphic.qrc @@ -19,5 +19,7 @@ ../../icons/border-line.png ../../icons/legend.png ../../icons/graphic.png + ../../icons/layer-visible-off.png + ../../icons/layer-visible-on.png