Fix grid and guide startup behavior and update german translation

This commit is contained in:
Kellermorph
2026-06-16 17:41:03 +02:00
parent 918db632ed
commit 4e0c075575
39 changed files with 5479 additions and 420 deletions
+75 -13
View File
@@ -39,7 +39,7 @@
#include "qetxml.h"
#include "undocommand/addelementtextcommand.h"
#include "qetinformation.h"
#include "qetproject.h"
#include <cassert>
#include <math.h>
@@ -65,7 +65,6 @@ QColor Diagram::background_color = Qt::white;
Diagram::Diagram(QETProject *project) :
QGraphicsScene (project),
m_project (project),
draw_grid_ (true),
use_border_ (true),
draw_terminals_ (true),
draw_colored_conductors_ (true),
@@ -73,6 +72,11 @@ Diagram::Diagram(QETProject *project) :
m_freeze_new_elements (false),
m_freeze_new_conductors_ (false)
{
QSettings settings;
draw_grid_ = settings.value(QStringLiteral("diagrameditor/grid_display_startup"), true).toBool();
draw_guides_ = settings.value(QStringLiteral("diagrameditor/guides_display_startup"), false).toBool();
setItemIndexMethod(QGraphicsScene::NoIndex);
/* Set to no index,
* because they can be the source of the crash with conductor and shape ghost.
@@ -121,8 +125,30 @@ Diagram::Diagram(QETProject *project) :
connect(this, &Diagram::diagramActivated,
this, &Diagram::loadCndFolioSeq);
adjustSceneRect();
}
m_guides_list.clear();
if (m_project) {
for (const auto &pg : m_project->defaultGuides()) {
Diagram::Guide g;
g.orientation = static_cast<Diagram::Guide::Orientation>(pg.orientation);
g.position = pg.position;
g.color = pg.color;
m_guides_list.append(g);
}
} else {
QSettings settings;
int size = settings.beginReadArray(QStringLiteral("diagrameditor/defaultguides"));
for (int i = 0; i < size; ++i) {
settings.setArrayIndex(i);
Diagram::Guide g;
g.orientation = static_cast<Diagram::Guide::Orientation>(settings.value(QStringLiteral("orientation"), 0).toInt());
g.position = settings.value(QStringLiteral("position"), 0.0).toReal();
g.color = QColor(settings.value(QStringLiteral("color"), QStringLiteral("#ff0000")).toString());
m_guides_list.append(g);
}
settings.endArray();
}
}
/**
@brief Diagram::~Diagram
Destructor
@@ -186,6 +212,14 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) {
p -> setBrush(Diagram::background_color);
p -> drawRect(r);
QSettings settings;
QRectF rect = settings.value(
QStringLiteral("diagrameditor/zoom-out-beyond-of-folio"),
false).toBool() ? r
: border_and_titleblock
.insideBorderRect()
.intersected(r);
if (draw_grid_) {
/* Draw the points of the grid
* if background color is black,
@@ -200,19 +234,10 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) {
p -> setBrush(Qt::NoBrush);
// If user allow zoom out beyond of folio,
// we draw grid outside of border.
QSettings settings;
int xGrid = settings.value(QStringLiteral("diagrameditor/Xgrid"),
Diagram::xGrid).toInt();
int yGrid = settings.value(QStringLiteral("diagrameditor/Ygrid"),
Diagram::yGrid).toInt();
QRectF rect = settings.value(
QStringLiteral("diagrameditor/zoom-out-beyond-of-folio"),
false).toBool() ? r
: border_and_titleblock
.insideBorderRect()
.intersected(r);
qreal limit_x = rect.x() + rect.width();
qreal limit_y = rect.y() + rect.height();
@@ -252,7 +277,23 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) {
p -> drawPoints(points);
}
if (use_border_) border_and_titleblock.draw(p);
if (draw_guides_) {
for (const Diagram::Guide &guide : m_guides_list) {
QPen guidePen(guide.color, 1, Qt::DashLine);
guidePen.setCosmetic(true);
p->setPen(guidePen);
if (guide.orientation == Diagram::Guide::Vertical) {
p->drawLine(guide.position, rect.top(), guide.position, rect.bottom());
} else {
p->drawLine(rect.left(), guide.position, rect.right(), guide.position);
}
}
}
if (use_border_) {
border_and_titleblock.draw(p);
}
p -> restore();
}
@@ -2635,3 +2676,24 @@ void Diagram::restoreText(Element* elmt)
}
}
}
QUndoStack &Diagram::undoStack() {
return *(project()->undoStack());
}
/**
* @brief Diagram::updateProjectGuides
* Aktualisiert die internen Hilfslinien dieses Schaltplans
* basierend auf den Projekt-Einstellungen und erzwingt ein Neuzeichnen.
*/
void Diagram::updateProjectGuides(const QList<GuideProperties> &guides) {
m_guides_list.clear();
for (const GuideProperties &pg : guides) {
Diagram::Guide g;
g.orientation = static_cast<Diagram::Guide::Orientation>(pg.orientation);
g.position = pg.position;
g.color = pg.color;
m_guides_list.append(g);
}
update();
}