[Kst] branches/work/kst/portto4/kst/src/libkstapp
Barth Netterfield
netterfield at astro.utoronto.ca
Thu Apr 28 20:01:52 CEST 2011
SVN commit 1229650 by netterfield:
CCBUG: 271786
Further improvements to the new autoformat system.
It is ready for testing and comments (use the bug entry).
M +13 -2 datawizard.cpp
M +12 -0 formatgridhelper.cpp
M +1 -1 formatgridhelper.h
M +35 -1 viewitem.cpp
--- branches/work/kst/portto4/kst/src/libkstapp/datawizard.cpp #1229649:1229650
@@ -1143,10 +1143,21 @@
}
}
+ CurvePlacement::Layout layout_type = _pagePlot->layout();
+ int num_columns = _pagePlot->gridColumns();
+ if (plotsInPage == 0) { // no format to protext
+ if (layout_type != CurvePlacement::Custom) {
+ layout_type = CurvePlacement::Custom;
+ if (_pagePlot->plotTabPlacement() == DataWizardPagePlot::SeparateTabs) {
+ num_columns = sqrt(plotList.size()/2);
+ } else {
+ num_columns = sqrt(plotList.size());
+ }
+ }
+ }
foreach (PlotItem* plot, plotList) {
plot->update();
- plot->view()->appendToLayout(_pagePlot->layout(), plot, _pagePlot->gridColumns());
-
+ plot->view()->appendToLayout(layout_type, plot, num_columns);
}
double fontScale;
fontScale = ApplicationSettings::self()->defaultFontScale();
--- branches/work/kst/portto4/kst/src/libkstapp/formatgridhelper.cpp #1229649:1229650
@@ -210,4 +210,16 @@
}
}
+int FormatGridHelper::numHoles() {
+ int n_holes = 0;
+ for (int i_row = 0; i_row<n_rows; i_row++) {
+ for (int i_col = 0; i_col<n_cols; i_col++) {
+ if (a[i_row][i_col] == 0) {
+ n_holes++;
}
+ }
+ }
+
+ return n_holes;
+}
+}
--- branches/work/kst/portto4/kst/src/libkstapp/formatgridhelper.h #1229649:1229650
@@ -44,7 +44,7 @@
QVector< QVector <int> > a;
int n_rows;
int n_cols;
- bool cleanGrid();
+ int numHoles();
};
}
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #1229649:1229650
@@ -2083,8 +2083,10 @@
FormatGridHelper grid(viewItems);
if (grid.n_cols == columns) {
+ if (grid.numHoles()<columns) {
columns = 0; // already in correct columns - just line stuff up
}
+ }
if (columns == 0) {
int n_views = viewItems.size();
@@ -2137,6 +2139,10 @@
Q_ASSERT(_item->view());
Q_ASSERT(item);
+ if (layout == CurvePlacement::Auto) {
+ columns = 0;
+ }
+
if (layout == CurvePlacement::Protect) {
_layout = new ViewGridLayout(_item);
@@ -2165,6 +2171,13 @@
FormatGridHelper grid(viewItems);
+ if (grid.n_cols == columns) {
+ if (grid.numHoles()<columns) {
+ columns = 0; // already in correct columns - just line stuff up
+ }
+ }
+
+ if (columns == 0) {
int row = -1;
int col = -1;
for (int i_col = 0; i_col<grid.n_cols; i_col++) {
@@ -2179,10 +2192,15 @@
}
}
}
- if (row<0) {
+ if (row<0) { // no empty slots
+ if (grid.n_rows>grid.n_cols+2) { // add a column
+ row = 0;
+ col = grid.n_cols;
+ } else { // add a row
row = grid.n_rows;
col = 0;
}
+ }
int n_views = viewItems.size();
for (int i_view = 0; i_view<n_views; i_view++) {
@@ -2192,7 +2210,23 @@
}
_item->view()->scene()->addItem(item);
_layout->addViewItem(item, row, col, 1,1);
+ } else {
+ int row = 0;
+ int col = 0;
+ int n_views = viewItems.size();
+ for (int i_view = 0; i_view<n_views; i_view++) {
+ ViewItem *v = viewItems.at(i_view);
+ _layout->addViewItem(v, row, col, 1, 1);
+ col++;
+ if (col>=columns) {
+ col = 0;
+ row++;
+ }
+ }
+ _item->view()->scene()->addItem(item);
+ _layout->addViewItem(item, row, col, 1,1);
+ }
if (qobject_cast<LayoutBoxItem*>(_item)) {
QObject::connect(_layout, SIGNAL(enabledChanged(bool)),
_item, SLOT(setEnabled(bool)));
More information about the Kst
mailing list