[Kst] branches/work/kst/view2dplotdialog/kst/src/libkstapp

George Staikos staikos at kde.org
Fri Sep 29 03:22:43 CEST 2006


SVN commit 589949 by staikos:

final cleanups and fixes including:
1) make New Plot work when there is no window
2) fix a huge kst2dplot const mess that solves most of the const problem
3) push that const issue into the widget for now.  it might actually be the
   right thing conceptually there anyway.


 M  +7 -2      kst.cpp  
 M  +8 -23     kst2dplot.cpp  
 M  +9 -9      kst2dplot.h  
 M  +2 -2      view2dplotwidget.ui  
 M  +8 -10     view2dplotwidget.ui.h  


--- branches/work/kst/view2dplotdialog/kst/src/libkstapp/kst.cpp #589948:589949
@@ -1970,13 +1970,18 @@
 #endif
 }
 
+
 void KstApp::newPlot() {
   KstViewWindow *w = dynamic_cast<KstViewWindow*>(activeWindow());
-  if (w) {
-    w->createObject<Kst2DPlot>(KST::suggestPlotName(), false);
+  if (!w) {
+    newWindow(false);
+    w = dynamic_cast<KstViewWindow*>(activeWindow());
+    assert(w);
   }
+  w->createObject<Kst2DPlot>(KST::suggestPlotName(), false);
 }
 
+
 void KstApp::showDataManager() {
   dataManager->show_I();
 }
--- branches/work/kst/view2dplotdialog/kst/src/libkstapp/kst2dplot.cpp #589948:589949
@@ -2278,15 +2278,8 @@
 
 
 void Kst2DPlot::edit() {
-  KstApp *app = KstApp::inst();
-  KMdiChildView *c = app->activeWindow();
-
-  if (c) {
-    KstTopLevelViewPtr tlv = kst_cast<KstTopLevelView>(topLevelParent());
-    showDialog(tlv, false);
-  } else {
-    //app->showPlotDialog();
-  }
+  KstTopLevelViewPtr tlv = kst_cast<KstTopLevelView>(topLevelParent());
+  showDialog(tlv, false);
 }
 
 
@@ -5485,7 +5478,7 @@
 }
 */
 
-const KstMarkerList Kst2DPlot::plotMarkers(const double minX, const double maxX) {
+const KstMarkerList Kst2DPlot::plotMarkers(const double minX, const double maxX) const {
   KstMarkerList foundMarkers;
   KstMarkerList::ConstIterator marks_iter = _plotMarkers.begin();
   while (marks_iter != _plotMarkers.end()) {
@@ -5498,7 +5491,7 @@
 }
 
 
-const KstMarkerList& Kst2DPlot::plotMarkers() {
+const KstMarkerList& Kst2DPlot::plotMarkers() const {
   return _plotMarkers;
 }
 
@@ -6392,13 +6385,13 @@
 }
 
 
-void Kst2DPlot::getXScaleExps(QString& minExp, QString& maxExp) {
+void Kst2DPlot::getXScaleExps(QString& minExp, QString& maxExp) const {
   minExp = _xMinExp;
   maxExp = _xMaxExp;
 }
 
 
-void Kst2DPlot::getYScaleExps(QString& minExp, QString& maxExp) {
+void Kst2DPlot::getYScaleExps(QString& minExp, QString& maxExp) const {
   minExp = _yMinExp;
   maxExp = _yMaxExp;
 }
@@ -6830,7 +6823,7 @@
 
 
 /** find the first legend owned by the plot, or return NULL if there is none */
-KstViewLegendPtr Kst2DPlot::legend() {
+KstViewLegendPtr Kst2DPlot::legend() const {
   for (KstViewObjectList::ConstIterator i = _children.begin(); i != _children.end(); ++i) {
     KstViewLegendPtr vl = kst_cast<KstViewLegend>(*i);
     if (vl) {
@@ -6910,15 +6903,7 @@
     return false;
   }
   
-  // FIXME: there must be a better way to get a Kst2DPlotPtr to 'this'!
-  // or maybe not - fillConfigWidget is const, and we are breaking constness
-  // because we have to iterate through the 2dplot's lists....
-  // and, not only that, but the widget has to hold a pointer to
-  // this to allow 'default labels' to work...
-  // though some might argue it doesn't work right.
-  Kst2DPlotPtr thisPlot = findPlotByName(this->tagName());
-  widget->fillWidget(thisPlot);
-
+  widget->fillWidget(this);
   widget->TabWidget->setCurrentPage(_tabToShow);
   return false;
 }
--- branches/work/kst/view2dplotdialog/kst/src/libkstapp/kst2dplot.h #589948:589949
@@ -173,8 +173,8 @@
   void getScale(double& xmin, double& ymin, double& xmax, double& ymax) const;
 
   // get expressions for the scale
-  void getXScaleExps(QString& minExp, QString& maxExp);
-  void getYScaleExps(QString& minExp, QString& maxExp);
+  void getXScaleExps(QString& minExp, QString& maxExp) const;
+  void getYScaleExps(QString& minExp, QString& maxExp) const;
 
   void getLScale(double& xmin, double& ymin, double& xmax, double& ymax) const;
 
@@ -258,8 +258,8 @@
   bool setPlotMarker(const double xValue, bool isRisng = false, bool isFalling = false, bool isVectorValue = false);
   bool removePlotMarker(const double xValue);
   void setPlotMarkerList(const KstMarkerList& newMarkers);
-  const KstMarkerList plotMarkers(const double minX, const double maxX);
-  const KstMarkerList& plotMarkers();
+  const KstMarkerList plotMarkers(const double minX, const double maxX) const;
+  const KstMarkerList& plotMarkers() const;
   bool nextMarker(const double currentPosition, double& marker);
   bool prevMarker(const double currentPosition, double& marker);
   void moveToNextMarker(KstViewWidget*);
@@ -318,13 +318,13 @@
   int axisPenWidth() const { return _axisPenWidth; }
 
   void setColorMarkers(QColor color) { _colorMarkers = color; }
-  QColor colorMarkers() { return _colorMarkers; }
+  QColor colorMarkers() const { return _colorMarkers; }
   void setLineWidthMarkers(int lineWidth) { _lineWidthMarkers = lineWidth; }
-  int lineWidthMarkers() { return _lineWidthMarkers; }
+  int lineWidthMarkers() const { return _lineWidthMarkers; }
   void setLineStyleMarkers(int lineStyle) { _lineStyleMarkers = lineStyle; }
-  int lineStyleMarkers() { return _lineStyleMarkers; }
+  int lineStyleMarkers() const { return _lineStyleMarkers; }
   void setDefaultColorMarker(bool defaultColor) { _defaultMarkerColor = defaultColor; }
-  bool defaultColorMarker( ) { return _defaultMarkerColor; }
+  bool defaultColorMarker() const { return _defaultMarkerColor; }
   
   // set and get tick mark display options
   void setXTicksInPlot(bool yes);
@@ -373,7 +373,7 @@
   bool undoChangeToMonochrome(int pointStylePriority, int lineStylePriority, int lineWidthPriority);
 
   //convenience routines for working with viewLegends
-  KstViewLegendPtr legend();
+  KstViewLegendPtr legend() const;
 
   KstViewLegendPtr getOrCreateLegend();
   
--- branches/work/kst/view2dplotdialog/kst/src/libkstapp/view2dplotwidget.ui #589948:589949
@@ -3261,8 +3261,8 @@
     <slot>fillMarkerLineCombo()</slot>
     <slot>updateAxesButtons()</slot>
     <slot>updateScalarCombo()</slot>
-    <slot>updatePlotMarkers( Kst2DPlotPtr plot )</slot>
-    <slot>fillWidget( Kst2DPlotPtr plot )</slot>
+    <slot>updatePlotMarkers( const Kst2DPlot *plot )</slot>
+    <slot>fillWidget( const Kst2DPlot *plot )</slot>
     <slot>applyAppearance( Kst2DPlotPtr plot )</slot>
     <slot>applyXAxis( Kst2DPlotPtr plot )</slot>
     <slot>applyYAxis( Kst2DPlotPtr plot )</slot>
--- branches/work/kst/view2dplotdialog/kst/src/libkstapp/view2dplotwidget.ui.h #589948:589949
@@ -411,7 +411,7 @@
   }
 }
 
-void View2DPlotWidget::updatePlotMarkers(Kst2DPlotPtr plot) {
+void View2DPlotWidget::updatePlotMarkers(const Kst2DPlot *plot) {
   for (KstMarkerList::ConstIterator it = plot->plotMarkers().begin(); it != plot->plotMarkers().end(); ++it) {
     if ((*it).isRising) {
       PlotMarkerList->insertItem(i18n("%1 [rising]").arg(QString::number((*it).value, 'g', MARKER_LABEL_PRECISION)));
@@ -427,7 +427,7 @@
   // update the auto-generation settings
   KstBaseCurveList curves = kstObjectSubList<KstDataObject, KstBaseCurve>(KST::dataObjectList);
   CurveCombo->clear();
-  for (KstBaseCurveList::iterator curves_iter = curves.begin(); curves_iter != curves.end(); ++curves_iter) {
+  for (KstBaseCurveList::ConstIterator curves_iter = curves.begin(); curves_iter != curves.end(); ++curves_iter) {
     (*curves_iter)->readLock();
     CurveCombo->insertItem((*curves_iter)->tagName());
     (*curves_iter)->unlock();
@@ -447,13 +447,12 @@
     } else {
       Rising->setChecked(true);
     }
-    int curveComboIndex;
-    for (curveComboIndex = 0; curveComboIndex < CurveCombo->count(); curveComboIndex++) {
+    for (int curveComboIndex = 0; curveComboIndex < CurveCombo->count(); curveComboIndex++) {
       if (CurveCombo->text(curveComboIndex) == plot->curveToMarkers()->tagName()) {
+        CurveCombo->setCurrentItem(curveComboIndex);
         break;
       }
     }
-    CurveCombo->setCurrentItem(curveComboIndex);
   } else {
     UseCurve->setChecked(false);
   }
@@ -467,9 +466,8 @@
 
 }
 
-void View2DPlotWidget::fillWidget(Kst2DPlotPtr plot) {
-
-  _plot = plot;
+void View2DPlotWidget::fillWidget(const Kst2DPlot *plot) {
+  _plot = Kst2DPlot::findPlotByName(plot->tagName());
   _vectorForMarkers->update();
   scalarSelectorX1->update();
   scalarSelectorY1->update();
@@ -482,12 +480,12 @@
   AvailableCurveList->clear();
 
   // add curves while retaining the order in the plot
-  for (KstBaseCurveList::iterator it = plot->Curves.begin(); it != plot->Curves.end(); ++it) {
+  for (KstBaseCurveList::ConstIterator it = plot->Curves.begin(); it != plot->Curves.end(); ++it) {
     (*it)->readLock();
     DisplayedCurveList->insertItem((*it)->tagName());
     (*it)->unlock();
   }
-  for (KstBaseCurveList::iterator it = curves.begin(); it != curves.end(); ++it) {
+  for (KstBaseCurveList::ConstIterator it = curves.begin(); it != curves.end(); ++it) {
     (*it)->readLock();
     if (plot->Curves.find(*it) == plot->Curves.end()) {
       AvailableCurveList->insertItem((*it)->tagName());


More information about the Kst mailing list