Skip to content

Commit

Permalink
Change signature and usage
Browse files Browse the repository at this point in the history
Schematic::sizeOfSelection returns values back to the client
via four reference variables passed to it as arguments. This
is not very elegant and most important it doesn't convey return
values semantics.

This commit makes 'sizeOfSelection' return QRect as usual return
value of function.
  • Loading branch information
wawuwo committed Mar 8, 2024
1 parent 77aa94f commit 36f0bd9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
25 changes: 10 additions & 15 deletions qucs/schematic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,14 +934,10 @@ void Schematic::zoomToSelection() {
return;
}

// Coordinates of top-left and bottom-right corners of the selected
// elements bounding rectangle
int selectedX1, selectedX2, selectedY1, selectedY2 = 0;
sizeOfSelection(selectedX1, selectedY1, selectedX2, selectedY2);
const QRect selectedBoundingRect{ sizeOfSelection() };

// Working with raw coordinates is clumsy, abstract them out
const QRect usedBoundingRect{UsedX1, UsedY1, UsedX2 - UsedX1, UsedY2 - UsedY1};
const QRect selectedBoundingRect{selectedX1, selectedY1, selectedX2 - selectedX1, selectedY2 - selectedY1};

if (selectedBoundingRect.width() == 0 || selectedBoundingRect.height() == 0) {
// If nothing is selected, then what should be shown? Probably it's best
Expand Down Expand Up @@ -1284,22 +1280,20 @@ void Schematic::sizeOfAll(int &xmin, int &ymin, int &xmax, int &ymax)
}
}

void Schematic::sizeOfSelection(int &xmin, int &ymin, int &xmax, int &ymax)
QRect Schematic::sizeOfSelection() const
{
xmin = INT_MAX;
ymin = INT_MAX;
xmax = INT_MIN;
ymax = INT_MIN;
int xmin = INT_MAX;
int ymin = INT_MAX;
int xmax = INT_MIN;
int ymax = INT_MIN;

bool isAnySelected = false;

if (Components->isEmpty())
if (Wires->isEmpty())
if (Diagrams->isEmpty())
if (Paintings->isEmpty()) {
xmin = xmax = 0;
ymin = ymax = 0;
return;
return QRect{};
}

int x1, y1, x2, y2;
Expand Down Expand Up @@ -1417,9 +1411,10 @@ void Schematic::sizeOfSelection(int &xmin, int &ymin, int &xmax, int &ymax)
}

if (!isAnySelected) {
xmin = xmax = 0;
ymin = ymax = 0;
return QRect{};
}

return QRect{xmin, ymin, xmax - xmin, ymax - ymin};
}

// ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion qucs/schematic.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Schematic : public Q3ScrollView, public QucsDoc {
float textCorr();
bool sizeOfFrame(int&, int&);
void sizeOfAll(int&, int&, int&, int&);
void sizeOfSelection(int&, int&, int&, int&);
QRect sizeOfSelection() const;
bool rotateElements();
bool mirrorXComponents();
bool mirrorYComponents();
Expand Down

0 comments on commit 36f0bd9

Please sign in to comment.