Skip to content

Commit

Permalink
Allow empty rows and columns
Browse files Browse the repository at this point in the history
by default in form view, with new setting to enable auto pruning of unused space, see giowck#120
  • Loading branch information
joshirio committed Jan 29, 2020
1 parent 067f9ee commit 27ac8b9
Show file tree
Hide file tree
Showing 9 changed files with 1,182 additions and 1,058 deletions.
8 changes: 6 additions & 2 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ Contributor and current maintainer
joshirio@protonmail.com
https://github.com/joshirio
PGP: 9964 C7DD 2020 5D4F 2E53 2BA5 0545 ACE7 38A1 08EF
2017-2019
2017-2020

jtMUMT
One time contributor
https://github.com/jtMUMT
2020


Translations
Expand All @@ -30,4 +35,3 @@ Founder
www.giowisys.com
Germany
2012-2014

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,5 @@ You can use Symphytum for free and for any purprose.
## Donate
If you find Symphytum useful. please consider [donating](https://github.com/giowck/symphytum/blob/master/doc/donate.md) to support this project, thanks.

Copyright (c) 2014-2019 Symphytum Developers
Copyright (c) 2014-2020 Symphytum Developers
Copyright (c) 2012-2014 GIOWISYS Software UG
133 changes: 95 additions & 38 deletions components/formlayoutmatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
//-----------------------------------------------------------------------------

#include "formlayoutmatrix.h"
#include "settingsmanager.h"
#include "../widgets/form_widgets/abstractformwidget.h"

#include <QtCore/QString>
#include <QtCore/QVariant>


//-----------------------------------------------------------------------------
Expand All @@ -18,7 +20,9 @@

FormLayoutMatrix::FormLayoutMatrix() : m_rows(0), m_columns(0)
{

//load settings
SettingsManager sm;
m_pruneEmptyRowsCols = sm.restoreProperty("pruneEmptyRowsCols", "formView").toBool(); //default false
}

FormLayoutMatrix::FormLayoutMatrix(const FormLayoutMatrix &other) :
Expand Down Expand Up @@ -202,7 +206,7 @@ void FormLayoutMatrix::formWidgetMovement(AbstractFormWidget *fw, int newRow, in
}

//remove empty rows/cols if they exist
simplifyMatrix();
simplifyMatrix(m_pruneEmptyRowsCols);
}

void FormLayoutMatrix::formWidgetResize(AbstractFormWidget *fw, int newWidthUnits, int newHeightUnits)
Expand Down Expand Up @@ -261,7 +265,7 @@ void FormLayoutMatrix::formWidgetResize(AbstractFormWidget *fw, int newWidthUnit
}

//remove empty rows/cols if they exist
simplifyMatrix();
simplifyMatrix(m_pruneEmptyRowsCols);
}

bool FormLayoutMatrix::findFormWidgetIndex(AbstractFormWidget *fw, int &row, int &column)
Expand All @@ -281,18 +285,14 @@ bool FormLayoutMatrix::findFormWidgetIndex(AbstractFormWidget *fw, int &row, int
return found;
}

void FormLayoutMatrix::simplifyMatrix()
void FormLayoutMatrix::simplifyMatrix(const bool aggressive)
{
bool rowRemoved = false;
bool scanningEdge = true;

//This used to prune out all empty rows/columns
//New functionality only prunes away extra rows/columns
// ie., those on the edges of the layout.
//prune away ALL empty rows/columns if aggro mode
if (aggressive) {
bool rowRemoved = false;

//check for empty rows, from outside in
for (int i = m_rows-1; i >= 0; i--) {
if (scanningEdge == true) { //only test for removal if we're on the edge.
//check for empty rows
for (int i = 0; i < m_rows; i++) {
bool markedRow = false; //current row removal flag
QList<AbstractFormWidget*>& currentColumn = m_matrix[i];

Expand All @@ -308,40 +308,97 @@ void FormLayoutMatrix::simplifyMatrix()
}
}

//if we find an empty row, we remove it and then re-try with the next-to-last row.
if (markedRow) {
removeRow(i);
//removing an edge row will not affect the indexing of subsequent loops
} else {
//this row is not empty, then we have found all the empty edges, no more removals.
scanningEdge = false;
rowRemoved = true;
simplifyMatrix(m_pruneEmptyRowsCols); //repeat for all rows but now with one row less
break; //break cycle because after removal the indexes are not coherent anymore
}
}
}

//if no row was deleted the indexes are still valid, so we can check columns
//check for empty columns
scanningEdge = true;
for (int i = m_columns-1; i >= 0; i--) {
if (scanningEdge == true) {
bool markedColumn = true; //current column removal flag
int j = 0;
while (j < m_rows) {
AbstractFormWidget* p = m_matrix[j].at(i);
if ((p == (void*)NO_FORM_WIDGET) || (p == NULL)) {
j++;
//if no row was deleted the indexes are still valid, so we can check columns
if (!rowRemoved) {
//check for empty columns
for (int i = 0; i < m_columns; i++) {
bool markedColumn = true; //current column removal flag
int j = 0;
while (j < m_rows) {
AbstractFormWidget* p = m_matrix[j].at(i);
if ((p == (void*)NO_FORM_WIDGET) || (p == NULL)) {
j++;
} else {
markedColumn = false;
break; //there is an item that is valid so exit cycle
}
}

if (markedColumn) {
removeColumn(i);
simplifyMatrix(m_pruneEmptyRowsCols); //repeat for all columns but now with one column less
break; //break cycle because after removal the indexes are not coherent anymore
}
}
}
} else { //allow empty rows/columns inside the matrix just remove those at the edges of the layout
bool scanningEdge = true;

//instead of pruning out all empty rows/columns
//only prune away extra rows/columns
//ie., those on the edges of the layout

//check for empty rows, from outside in
for (int i = m_rows-1; i >= 0; i--) {
if (scanningEdge == true) { //only test for removal if we're on the edge
bool markedRow = false; //current row removal flag
QList<AbstractFormWidget*>& currentColumn = m_matrix[i];

if (currentColumn.isEmpty()) {
markedRow = true;
} else {
markedRow = true; //init value
//check if all elements of the row are empty
for (int c = 0; c < m_columns; c++) {
AbstractFormWidget* p = currentColumn.at(c);
//markedRow is only true if all previous and current cell is empty
markedRow = markedRow && ((p == NULL) || (p == (void*)NO_FORM_WIDGET));
}
}

//if we find an empty row, we remove it and then re-try with the next-to-last row
if (markedRow) {
removeRow(i);
//removing an edge row will not affect the indexing of subsequent loops
} else {
markedColumn = false;
break; //there is an item that is valid so exit cycle
//this row is not empty, then we have found all the empty edges, no more removals
scanningEdge = false;
}
}
}

if (markedColumn) {
removeColumn(i);
//removing an edge column will not affect the indexing of subsequent loops
} else {
//this row is not empty, then we have found all the empty edges, no more removals.
scanningEdge = false;
//if no row was deleted the indexes are still valid, so we can check columns
//check for empty columns
scanningEdge = true;
for (int i = m_columns-1; i >= 0; i--) {
if (scanningEdge == true) {
bool markedColumn = true; //current column removal flag
int j = 0;
while (j < m_rows) {
AbstractFormWidget* p = m_matrix[j].at(i);
if ((p == (void*)NO_FORM_WIDGET) || (p == NULL)) {
j++;
} else {
markedColumn = false;
break; //there is an item that is valid so exit cycle
}
}

if (markedColumn) {
removeColumn(i);
//removing an edge column will not affect the indexing of subsequent loops
} else {
//this row is not empty, then we have found all the empty edges, no more removals
scanningEdge = false;
}
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion components/formlayoutmatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ class FormLayoutMatrix

/** Look if there are some improvements to do like
* removing unused (empty) matrix rows or columns
* @param aggressive - if true all empty rows/columns will be pruned away,
* if false, only empty rows/columns at the edges will be removed
*/
void simplifyMatrix();
void simplifyMatrix(const bool aggressive);

/** Create a QString representation of the layout matrix */
QString toString();
Expand Down Expand Up @@ -182,6 +184,10 @@ class FormLayoutMatrix
* the key (int) represents the row and the
* list of FW represents current row's columns.
*/
bool m_pruneEmptyRowsCols; /**< If true, empty rows/columns are pruned
* from the matrix, @see simplifyMastrix()
* for additional info and context
*/
};

#endif // FORMLAYOUTMATRIX_H
Loading

0 comments on commit 27ac8b9

Please sign in to comment.