version 2.27.0

Graphic legend checks context menu rework
This commit is contained in:
2024-04-08 11:25:46 +03:00
parent 073d483381
commit bee9bd12d5
7 changed files with 192 additions and 83 deletions

View File

@@ -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<double>::max(),
-std::numeric_limits<double>::max(),
std::numeric_limits<double>::max(),
std::numeric_limits<double>::max());
eminx = eminy = std::numeric_limits<double>::max();
emaxx = emaxy = -std::numeric_limits<double>::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<QCheckBox *>(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<double>::max();
minY = minX = std::numeric_limits<double>::max();
maxY = maxX = -std::numeric_limits<double>::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<QCheckBox *>(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);
}