Merge pull request #387 from plc-user/master

only calculate grid-point-size, when min != max
This commit is contained in:
Laurent Trinques
2025-03-15 18:45:16 +01:00
committed by GitHub
7 changed files with 44 additions and 26 deletions

View File

@@ -186,7 +186,7 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) {
p -> drawRect(r);
if (draw_grid_) {
/* Draw the point of the grid
/* Draw the points of the grid
* if background color is black,
* then grid spots shall be white,
* else they shall be black in color.
@@ -232,19 +232,20 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) {
int minWidthPen = settings.value(QStringLiteral("diagrameditor/grid_pointsize_min"), 1).toInt();
int maxWidthPen = settings.value(QStringLiteral("diagrameditor/grid_pointsize_max"), 1).toInt();
pen.setWidth(minWidthPen);
qreal stepPen = (maxWidthPen - minWidthPen) / (qreal)maxWidthPen;
qreal stepZoom = (5.0 - 1.0) / maxWidthPen;
for (int n=0; n<maxWidthPen; n++) {
if ((zoom_factor > (1.0 + n * stepZoom)) && (zoom_factor <= (1.0 + (n+1) * stepZoom))) {
int widthPen = minWidthPen + qRound(n * stepPen);
pen.setWidth(widthPen);
if (minWidthPen != maxWidthPen) {
qreal stepPen = (maxWidthPen - minWidthPen) / (qreal)maxWidthPen;
qreal stepZoom = (5.0 - 1.0) / maxWidthPen;
for (int n=0; n<maxWidthPen; n++) {
if ((zoom_factor > (1.0 + n * stepZoom)) && (zoom_factor <= (1.0 + (n+1) * stepZoom))) {
int widthPen = minWidthPen + qRound(n * stepPen);
pen.setWidth(widthPen);
}
}
if (zoom_factor <= 1.0)
pen.setWidth(minWidthPen);
else if (zoom_factor > (1.0 + stepZoom * maxWidthPen))
pen.setWidth(maxWidthPen);
}
if (zoom_factor <= 1.0)
pen.setWidth(minWidthPen);
else if (zoom_factor > (1.0 + stepZoom * maxWidthPen))
pen.setWidth(maxWidthPen);
p -> setPen(pen);
if (zoom_factor > 0.5) // no grid below ... !
p -> drawPoints(points);

View File

@@ -1153,7 +1153,7 @@ void DiagramView::editSelection()
QGraphicsItem *item = m_diagram->selectedItems().first();
//We use dynamic_cast instead of qgraphicsitem_cast for QetGraphicsItem
//because they haven't got they own type().
//because they haven't got their own type().
//Use qgraphicsitem_cast will have weird behavior for this class.
if (IndependentTextItem *iti = qgraphicsitem_cast<IndependentTextItem *>(item))
iti -> edit();

View File

@@ -559,19 +559,20 @@ void ElementView::drawBackground(QPainter *p, const QRectF &r) {
int minWidthPen = settings.value(QStringLiteral("elementeditor/grid_pointsize_min"), 1).toInt();
int maxWidthPen = settings.value(QStringLiteral("elementeditor/grid_pointsize_max"), 1).toInt();
pen.setWidth(minWidthPen);
qreal stepPen = (maxWidthPen - minWidthPen) / (qreal)maxWidthPen;
qreal stepZoom = (25.0 - 1.0) / maxWidthPen;
for (int n=0; n<maxWidthPen; n++) {
if ((zoom_factor > (1.0 + n * stepZoom)) && (zoom_factor <= (1.0 + (n+1) * stepZoom))) {
int widthPen = minWidthPen + qRound(n * stepPen);
pen.setWidth(widthPen);
if (minWidthPen != maxWidthPen) {
qreal stepPen = (maxWidthPen - minWidthPen) / (qreal)maxWidthPen;
qreal stepZoom = (25.0 - 1.0) / maxWidthPen;
for (int n=0; n<maxWidthPen; n++) {
if ((zoom_factor > (1.0 + n * stepZoom)) && (zoom_factor <= (1.0 + (n+1) * stepZoom))) {
int widthPen = minWidthPen + qRound(n * stepPen);
pen.setWidth(widthPen);
}
}
if (zoom_factor <= 1.0)
pen.setWidth(minWidthPen);
else if (zoom_factor > (1.0 + stepZoom * maxWidthPen))
pen.setWidth(maxWidthPen);
}
if (zoom_factor <= 1.0)
pen.setWidth(minWidthPen);
else if (zoom_factor > (1.0 + stepZoom * maxWidthPen))
pen.setWidth(maxWidthPen);
p -> setPen(pen);
p -> setBrush(Qt::NoBrush);
qreal limit_x = r.x() + r.width();

View File

@@ -32,6 +32,10 @@
en orientation. Si la chaine fait plusieurs caracteres, seul le
premier est pris en compte. En cas d'incoherence, Qet::North est
retourne.
Used to convert a string of characters (n, s, e or w)
into orientation. If the string is made up of several characters,
only the only the first is taken into account. In the event of an
inconsistency, Qet::North is returned.
@param s Chaine de caractere cense representer une orientation
@return l'orientation designee par la chaine de caractere
*/
@@ -60,6 +64,7 @@ QString Qet::orientationToString(Qet::Orientation o) {
/**
Indique si deux orientations de Borne sont sur le meme axe (Vertical / Horizontal).
Indicates whether two terminal orientations are on the same axis (Vertical / Horizontal).
@param a La premiere orientation de Borne
@param b La seconde orientation de Borne
@return Un booleen a true si les deux orientations de bornes sont sur le meme axe

View File

@@ -1597,7 +1597,7 @@ void QETDiagramEditor::slot_updateUndoStack()
/**
@brief QETDiagramEditor::slot_updateComplexActions
Manage the actions who need some conditions to be enable or not.
Manage the actions that need some conditions to be enabled or not.
This method does nothing if there is no project opened
*/
void QETDiagramEditor::slot_updateComplexActions()
@@ -1633,7 +1633,7 @@ void QETDiagramEditor::slot_updateComplexActions()
int selected_elements_count = dc.count(DiagramContent::Elements);
m_find_element->setEnabled(selected_elements_count == 1);
//Action that need items (elements, conductors, texts...) selected, to be enabled
//Actions that need items (elements, conductors, texts...) selected, to be enabled
bool copiable_items = dc.hasCopiableItems();
bool deletable_items = dc.hasDeletableItems();
m_cut -> setEnabled(!ro && copiable_items);

View File

@@ -384,9 +384,11 @@ void Conductor::generateConductorPath(const QPointF &p1, Qet::Orientation o1, co
points << depart0;
// prolongement de la borne de depart
// extend start terminal
points << depart;
// commence le vrai trajet
// starts the real path
if (depart.y() < arrivee.y()) {
// trajet descendant
if ((ori_depart == Qet::North && (ori_arrivee == Qet::South || ori_arrivee == Qet::West)) || (ori_depart == Qet::East && ori_arrivee == Qet::West)) {

View File

@@ -37,6 +37,7 @@ const qreal Terminal::Z = 1000;
/**
@brief Terminal::init
Methode privee pour initialiser la borne.
Private method to initialize the terminal.
@param number of terminal
@param name of terminal
@param hiddenName
@@ -92,17 +93,25 @@ Terminal::~Terminal() {
est bien un Element, cette fonction renvoie l'orientation par rapport a
la scene de la borne, en tenant compte du fait que l'element ait pu etre
pivote. Sinon elle renvoie son sens normal.
Used to find out the orientation of the terminal. If the terminal's parent
is in fact an Element, this function returns the orientation of the
terminal with respect to the scene, taking into account the angle of
rotation. scene, taking into account the fact that the element may have
been rotated. Otherwise it returns its normal direction.
@return L'orientation actuelle de la Terminal.
*/
Qet::Orientation Terminal::orientation() const
{
if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) {
// orientations actuelle et par defaut de l'element
// current and default element orientations
int ori_cur = elt -> orientation();
if (ori_cur == 0) return(d->m_orientation);
else {
// calcul l'angle de rotation implique par l'orientation de l'element parent
// angle de rotation de la borne sur la scene, divise par 90
// calculates the angle of rotation implied by the orientation of the parent
// element angle of rotation of the terminal on the scene, divided by 90
int angle = ori_cur + d->m_orientation;
while (angle >= 4) angle -= 4;
return((Qet::Orientation)angle);