Bug 140520 - Font size for newly created plot is incorrect
Summary: Font size for newly created plot is incorrect
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: kst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-23 22:42 UTC by Andrew Walker
Modified: 2007-02-17 04:03 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Proposed fix (11.81 KB, patch)
2007-02-16 16:09 UTC, Netterfield
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Walker 2007-01-23 22:42:57 UTC
Version:           HEAD (using KDE KDE 3.5.1)
OS:                Linux

PROBLEM:
Under certain conditions when a new plot is created the associated font is too small relative to the existing plots.

STEPS TO REPRODUCE:
Start Kst
Maximize it
Using the data wizard to plot all 4 variables from gyrodata.dat in separate plots, on a 2x2 grid
Using the data wizard again plot 1 variable from gyrodata.dat in a new plot in the existing window
Ensure that the regrid to 2 columns option is checked in the data wizard

RESULTS:
The font size of the newly created plot is smaller than the font size of the existing plots

EXPECTED RESULTS:
The font size of the newly created plot is the same as the font size of the existing plots
Comment 1 Andrew Walker 2007-01-25 22:43:27 UTC
The problem was introduced with changes to datawizard.ui.h in revision 597630. 

In short this change sets the base font size of a plot based on the new grid layout of plots in a window (number of rows and columns). However, already existing plots are left untouched and so the described discrepancy in font size results.

A partial revert of this revision would fix the problem.

Comment 2 Andrew Walker 2007-02-08 02:19:12 UTC
Barth, could you add a note about the intent of revision 597630 so that when this bug report is fixed the effect of the revision is maintained.
Comment 3 Andrew Walker 2007-02-12 21:57:15 UTC
SVN commit 632990 by arwalker:

BUG:140520 don't modify font size on plots created with data wizard as it results in too many inconsistencies

 M  +2 -1      datawizard.ui.h  


--- trunk/extragear/graphics/kst/src/libkstapp/datawizard.ui.h #632989:632990
@@ -928,7 +928,8 @@
                 pp->getOrCreateLegend();
 	    }
 	}
-        pp->setPlotLabelFontSizes(fontSize);
+//      see bug report 140520 before enabling the following line.
+//      pp->setPlotLabelFontSizes(fontSize);
 
 	++pit;
     }
Comment 4 Netterfield 2007-02-12 23:43:51 UTC
I would like to discuss this before this fix...

The code which was commented out prevents the data wizard from guessing at a good font size when creating plots...  

It was guessing wrong when there were already plots in the window.

Telling it to not guess at all seems... worse.  The proper fix is get the wizard to do a better job of guessing.  So lets leave the bug opened until we have done this.

In the mean time, I think the sometimes bad guess behavior is better than always having the font too small... thoughts?
Comment 5 Andrew Walker 2007-02-13 00:14:51 UTC
I don't think the datawizard should be guessing at font sizes.

This results in inconsistencies between plots created at different times with the data wizard and plots not created with the data wizard.

If you're worried about font sizes being too small then perhaps this could be fixed in KstPlotLabel::updateAbsFontSize().
Comment 6 Netterfield 2007-02-13 12:36:54 UTC
From the point of view of a user: it is a wizard.  Its job is to guess.

On Monday 12 February 2007 6:14:52 pm Andrew Walker wrote:
> ------- I don't think the datawizard should be guessing at font sizes.

Comment 7 Andrew Walker 2007-02-13 19:16:58 UTC
When the user creates plots (through the wizard or not) they should end up with a default font size that is reasonable. They should get the same font size whether they use the wizard or not. Hence my asertion that it is not the wizard that should be guessing at this font size. Instead this should be done in code that is common to plot creation via the wizard or menu.
Comment 8 Netterfield 2007-02-13 19:43:05 UTC
I understand and agree with your point that any automagic new-plot generation 
should use a good guess for font size.

The situations that the wizard and command line face (simultaneous creation of 
multiple plots) are different than the other situations (creation of 1 plot, 
sometimes in the presence of existing plots) so whatever we do has to deal 
with that.

In the mean time, I like the pre-fix situation better than the current 
situation.
Comment 9 Andrew Walker 2007-02-14 00:00:11 UTC
Can you not get what you are after by increasing the value of the "base font size" in the "Kst Settings" dialog?
Comment 10 Netterfield 2007-02-14 04:50:51 UTC
No.
Lots of plots -> bigger font (relative to the window).

We find the previous behavior very convenient.

cbn

On Tuesday 13 February 2007 6:00:12 pm Andrew Walker wrote:
[bugs.kde.org quoted mail]
Comment 11 Andrew Walker 2007-02-14 19:18:12 UTC
So if I understand correctly the problem you are trying to solve is that the font size is too small for relatively few plots and too large for relatively many plots. 

Does that sound about right?
Comment 12 Netterfield 2007-02-16 16:09:05 UTC
Created attachment 19709 [details]
Proposed fix

The proposed patch retains the previous behavior (enlarged fonts when creating
multiple plots) only in the case where there are no other plots in the window.

If there are are other plots in the window already, the font size of the first
plot in the window is used for the new plots (this applies to all dialogs).

To do this for everthing but the Wizard, a createPlot method was added to
kstViewWindow.	The wizard, as it deals with multiple plot creation, can't use
it.

The patch also includes a variable name change: a 2dplot list in the
datawizard.ui.h is changed from 'l' to 'vlist' for several unimportant but
obvious reasons.
Comment 13 Netterfield 2007-02-17 04:03:21 UTC
SVN commit 634383 by netterfield:

BUG: 140520
New plots in windows that already have plots take the font size of the
first plot in the window.



 M  +3 -2      datawizard.ui  
 M  +19 -13    datawizard.ui.h  
 M  +1 -1      kst.cpp  
 M  +1 -1      kstcsddialog_i.cpp  
 M  +2 -1      kstcurvedialog_i.cpp  
 M  +1 -1      ksteqdialog_i.cpp  
 M  +1 -1      ksthsdialog_i.cpp  
 M  +1 -1      kstimagedialog_i.cpp  
 M  +1 -1      kstpsddialog_i.cpp  
 M  +14 -0     kstviewwindow.cpp  
 M  +6 -0      kstviewwindow.h  


--- trunk/extragear/graphics/kst/src/libkstapp/datawizard.ui #634382:634383
@@ -1528,7 +1528,7 @@
     <include location="global" impldecl="in implementation">math.h</include>
     <include location="global" impldecl="in implementation">defaultprimitivenames.h</include>
     <include location="local" impldecl="in implementation">kstvectordefaults.h</include>
-    <include location="local" impldecl="in implementation">kstviewwindow.h</include>
+    <include location="local" impldecl="in declaration">kstviewwindow.h</include>
     <include location="local" impldecl="in implementation">kstcombobox.h</include>
     <include location="local" impldecl="in implementation">kst2dplot.h</include>
     <include location="global" impldecl="in implementation">qdeepcopy.h</include>
@@ -1542,6 +1542,7 @@
     <include location="global" impldecl="in implementation">kdebug.h</include>
     <include location="global" impldecl="in implementation">vectorlistview.h</include>
     <include location="local" impldecl="in implementation">datawizard.ui.h</include>
+    <include location="local" impldecl="in implementation">kstplotlabel.h</include>
 </includes>
 <variables>
     <variable access="private">static const QString&amp; defaultTag;</variable>
@@ -1587,7 +1588,7 @@
 <functions>
     <function returnType="bool">xVectorOk()</function>
     <function returnType="bool">yVectorsOk()</function>
-    <function returnType="double">getFontSize(int count)</function>
+    <function returnType="double">getFontSize(int count, KstViewWindow *w)</function>
     <function>showPage( QWidget * page )</function>
     <function>saveSettings()</function>
     <function>loadSettings()</function>
--- trunk/extragear/graphics/kst/src/libkstapp/datawizard.ui.h #634382:634383
@@ -46,7 +46,7 @@
     _url->setURL(default_source);
     _url->completionObject()->setDir(QDir::currentDirPath());
     _url->setFocus();
-    
+
     // x vector selection
     connect(_xAxisCreateFromField, SIGNAL(toggled(bool)), _xVector, SLOT(setEnabled(bool)));
     connect(_xAxisUseExisting, SIGNAL(toggled(bool)), _xVectorExisting, SLOT(setEnabled(bool)));
@@ -471,7 +471,7 @@
 void DataWizard::finished()
 {
     KstApp *app = KstApp::inst();
-    KstVectorList l;
+    KstVectorList vlist;
     QString name = KST::suggestVectorName(_xVector->currentText());
     QValueList<QColor> colors;
     QColor color;
@@ -642,7 +642,7 @@
 		    _kstDataRange->DoSkip->isChecked() ? _kstDataRange->Skip->value() : 0, 
 		    _kstDataRange->DoSkip->isChecked(),
 		    _kstDataRange->DoFilter->isChecked());
-	    l.append(v);
+	    vlist.append(v);
 	    ++n_curves;
 	    app->slotUpdateProgress(n_steps, ++prg, i18n("Creating vectors..."));
 	    ++it;
@@ -680,7 +680,7 @@
 	return;
     }
 
-    fontSize = qRound(getFontSize(l.count()));
+    fontSize = qRound(getFontSize(vlist.count(), w));
 
     // create the necessary plots
     app->slotUpdateProgress(n_steps, prg, i18n("Creating plots..."));
@@ -702,7 +702,7 @@
 	}
     } else if (_multiplePlots->isChecked()) {
 	Kst2DPlotPtr p;
-	for (uint i = 0; i < l.count(); ++i) {
+	for (uint i = 0; i < vlist.count(); ++i) {
 	    p = kst_cast<Kst2DPlot>(w->view()->findChild(w->createObject<Kst2DPlot>(KST::suggestPlotName(), false)));
 	    plots.append(p.data());
 	}
@@ -713,7 +713,7 @@
 		QString n = app->newWindow(newName);
 		w = static_cast<KstViewWindow*>(app->findWindow(n));
 	    }
-	    for (uint i = 0; i < l.count(); ++i) {
+	    for (uint i = 0; i < vlist.count(); ++i) {
 		p = kst_cast<Kst2DPlot>(w->view()->findChild(w->createObject<Kst2DPlot>(KST::suggestPlotName(), false)));
 		plots.append(p.data());
 	        p->setXAxisInterpretation(false, KstAxisInterpretation(), KstAxisDisplay());
@@ -753,14 +753,14 @@
 
     // Reorder the vectors if the user wants it
     if (_orderInColumns->isChecked()) {
-	const KstVectorList lOld = l;
+	const KstVectorList lOld = vlist;
 	const int count = lOld.count();
 	const int cols = signed(sqrt(plots.count()));
 	const int rows = cols + (count - cols * cols) / cols;
 	int overflow = count % cols;
 	int row = 0, col = 0;
 	for (int i = 0; i < count; ++i) {
-	    l[row * cols + col] = lOld[i];
+	    vlist[row * cols + col] = lOld[i];
 	    ++row;
 	    if (row >= rows) {
 		if (overflow > 0) {
@@ -776,7 +776,7 @@
     // create the data curves
     app->slotUpdateProgress(n_steps, prg, i18n("Creating curves..."));
     KstViewObjectList::Iterator pit = plots.begin();
-    for (KstVectorList::Iterator it = l.begin(); it != l.end(); ++it) {
+    for (KstVectorList::Iterator it = vlist.begin(); it != vlist.end(); ++it) {
 	if (_radioButtonPlotData->isChecked() || _radioButtonPlotDataPSD->isChecked()) {
 	    name = KST::suggestCurveName((*it)->tag(), false);
 	    Kst2DPlotPtr plot = kst_cast<Kst2DPlot>(*pit);
@@ -837,7 +837,7 @@
 	ptype = 0;
 	app->slotUpdateProgress(n_steps, prg, i18n("Creating PSDs..."));
 	
-	for (KstVectorList::Iterator it = l.begin(); it != l.end(); ++it) {
+	for (KstVectorList::Iterator it = vlist.begin(); it != vlist.end(); ++it) {
 	    if ((*it)->length() > 0) {
 		Kst2DPlotPtr plot;
 		KstViewObjectList::Iterator startPlot = pit;
@@ -928,9 +928,9 @@
                 pp->getOrCreateLegend();
 	    }
 	}
-//      see bug report 140520 before enabling the following line.
-//      pp->setPlotLabelFontSizes(fontSize);
 
+	pp->setPlotLabelFontSizes(fontSize);
+
 	++pit;
     }
 
@@ -1334,10 +1334,16 @@
     updateVectorPageButtons();
 }
 
-double DataWizard::getFontSize(int count) {
+double DataWizard::getFontSize(int count, KstViewWindow *w) {
   double size;
   double rows, cols;
 
+  // if there are already plots in the window, use the the first one's font size.
+  Kst2DPlotList plotList = w->view()->findChildrenType<Kst2DPlot>(false);
+  if (!plotList.isEmpty()) {
+    return(plotList[0]->xTickLabel()->fontSize());
+  }
+
   if (_cycleThrough->isChecked()) {
     count = _plotNumber->value();
   } else if (!_multiplePlots->isChecked()) {
--- trunk/extragear/graphics/kst/src/libkstapp/kst.cpp #634382:634383
@@ -2004,7 +2004,7 @@
     w = dynamic_cast<KstViewWindow*>(activeWindow());
     assert(w);
   }
-  w->createObject<Kst2DPlot>(KST::suggestPlotName(), false);
+  w->createPlot(KST::suggestPlotName(), false);
 }
 
 
--- trunk/extragear/graphics/kst/src/libkstapp/kstcsddialog_i.cpp #634382:634383
@@ -218,7 +218,7 @@
 
     if (_w->_curvePlacement->newPlot()) {
       /* assign image to plot */
-      QString name = w->createObject<Kst2DPlot>(KST::suggestPlotName());
+      QString name = w->createPlot(KST::suggestPlotName());
       if (_w->_curvePlacement->reGrid()) {
         w->view()->cleanup(_w->_curvePlacement->columns());
       }
--- trunk/extragear/graphics/kst/src/libkstapp/kstcurvedialog_i.cpp #634382:634383
@@ -39,6 +39,7 @@
 #include "kstviewwindow.h"
 #include "kstuinames.h"
 #include "vectorselector.h"
+#include "kstplotlabel.h"
 
 const QString& KstCurveDialogI::defaultTag = KGlobal::staticQString("<Auto Name>");
 
@@ -316,7 +317,7 @@
 
       if (_w->_curvePlacement->newPlot()) {
         // assign curve to plot
-        QString name = w->createObject<Kst2DPlot>(KST::suggestPlotName());
+	QString name = w->createPlot(KST::suggestPlotName());
         plot = kst_cast<Kst2DPlot>(w->view()->findChild(name));
         if (_w->_curvePlacement->reGrid()) {
           w->view()->cleanup(_w->_curvePlacement->columns());
--- trunk/extragear/graphics/kst/src/libkstapp/ksteqdialog_i.cpp #634382:634383
@@ -226,7 +226,7 @@
 
     if (_w->_curvePlacement->newPlot()) {
       /* assign curve to plot */
-      QString name = w->createObject<Kst2DPlot>(KST::suggestPlotName());
+      QString name = w->createPlot(KST::suggestPlotName());
       if (_w->_curvePlacement->reGrid()) {
         w->view()->cleanup(_w->_curvePlacement->columns());
       }
--- trunk/extragear/graphics/kst/src/libkstapp/ksthsdialog_i.cpp #634382:634383
@@ -259,7 +259,7 @@
 
     if (_w->_curvePlacement->newPlot()) {
       /* assign curve to plot */
-      QString name = w->createObject<Kst2DPlot>(KST::suggestPlotName());
+      QString name = w->createPlot(KST::suggestPlotName());
       if (_w->_curvePlacement->reGrid()) {
         w->view()->cleanup(_w->_curvePlacement->columns());
       }
--- trunk/extragear/graphics/kst/src/libkstapp/kstimagedialog_i.cpp #634382:634383
@@ -517,7 +517,7 @@
 
     if (_w->_curvePlacement->newPlot()) {
       /* assign image to plot */
-      QString name = w->createObject<Kst2DPlot>(KST::suggestPlotName());
+      QString name = w->createPlot(KST::suggestPlotName());
       if (_w->_curvePlacement->reGrid()) {
         w->view()->cleanup(_w->_curvePlacement->columns());
       }
--- trunk/extragear/graphics/kst/src/libkstapp/kstpsddialog_i.cpp #634382:634383
@@ -223,7 +223,7 @@
 
       if (_w->_curvePlacement->newPlot()) {
         // assign curve to plot
-        QString name = w->createObject<Kst2DPlot>(KST::suggestPlotName());
+        QString name = w->createPlot(KST::suggestPlotName());
         if (_w->_curvePlacement->reGrid()) {
           w->view()->cleanup(_w->_curvePlacement->columns());
         }
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewwindow.cpp #634382:634383
@@ -27,6 +27,7 @@
 
 // application specific includes
 #include "kst2dplot.h"
+#include "kstplotlabel.h"
 #include "kstdoc.h"
 #include "kstsettings.h"
 #include "kstviewwindow.h"
@@ -428,5 +429,18 @@
   KMdiChildView::closeEvent(e);
 }
 
+QString KstViewWindow::createPlot(const QString& suggestedName, bool prompt) {
+  Kst2DPlotList plotList = view()->findChildrenType<Kst2DPlot>(false);
+  QString name = createObject<Kst2DPlot>(suggestedName, prompt);
+  Kst2DPlotPtr plot = kst_cast<Kst2DPlot>(view()->findChild(name));
+
+  // if there are already plots in the window, use the the first one's font size.
+  if (!plotList.isEmpty()) {
+    plot->setPlotLabelFontSizes(plotList[0]->xTickLabel()->fontSize());
+  }
+  return (name);
+}
+
+
 #include "kstviewwindow.moc"
 // vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewwindow.h #634382:634383
@@ -99,7 +99,9 @@
 
   public:
     template<class T> QString createObject(const QString& suggestedName = QString::null, bool prompt = false);
+    QString createPlot(const QString& suggestedName = QString::null, bool prompt = false);
 
+
   private:
     void commonConstructor();
 
@@ -109,6 +111,10 @@
 };
 
 
+//FIXME: while this purports to be a general createObject, it presumes
+// in a couple cases that it is creating a plot, As, afaikt it is currently only
+// used to create plots, doing anything about it is not urgent, but if
+// you decide to use this to create anything else, keep it in mind.
 template<class T>
 QString KstViewWindow::createObject(const QString& suggestedName, bool prompt) {