Use pointers in ThresholdWidget
authorDiane Trout <diane@caltech.edu>
Tue, 3 Oct 2006 20:48:37 +0000 (20:48 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 3 Oct 2006 20:48:37 +0000 (20:48 +0000)
Change threshold widget to use dynamically allocated objects
instead of statically allocated objects. I think Qt prefers this, but
now I'm less sure.

qui/ThresholdWidget.cpp
qui/ThresholdWidget.hpp

index 98b7ba01d41397a7fc696a97aef082bf338a494d..c1ca76c2ffae3474bbdf5666c8a7eccda372ea5f 100644 (file)
@@ -1,4 +1,3 @@
-#include <QHBoxLayout>
 #include <QSlider>
 #include <QString>
 
@@ -9,49 +8,52 @@
 // This is completely and totally derived from the Qt example
 // LCDRange.cpp
 ThresholdWidget::ThresholdWidget(QWidget *parent, int min, int max) 
-  : QWidget(parent)
+  : QWidget(parent),
+    layout(new QHBoxLayout(this)),
+    basepair_spinner(new QSpinBox(this)),
+    window_size_label(new QLabel(this)),
+    percent_label(new QLabel(this))
 {
-  basepair_spinner.setWhatsThis("How many base pairs need to be conserved in the window size");
+  basepair_spinner->setWhatsThis("How many base pairs need to be conserved in the window size");
 
   setRange(min, max);
 
-  connect(&basepair_spinner, SIGNAL(valueChanged(int)), 
+  connect(basepair_spinner, SIGNAL(valueChanged(int)), 
           this, SLOT(setBasepairThreshold(int)));
 
-  basepair_spinner.setValue(min);
+  basepair_spinner->setValue(min);
   updatePercentThreshold();
 
-  QHBoxLayout *layout = new QHBoxLayout;
   layout->addWidget(new QLabel("Threshold"));
-  layout->addWidget(&basepair_spinner);
-  layout->addWidget(&window_size_label);
-  layout->addWidget(&percent_label);
+  layout->addWidget(basepair_spinner);
+  layout->addWidget(window_size_label);
+  layout->addWidget(percent_label);
   setLayout(layout);
 }
 
 void ThresholdWidget::setRange(int min, int max)
 {
-  basepair_spinner.setRange(min, max);
+  basepair_spinner->setRange(min, max);
   cur_bp_threshold = min;
-  basepair_spinner.setValue(min);
+  basepair_spinner->setValue(min);
 
   QString num;
   num.setNum(max);
-  window_size_label.setText("/"+num);
+  window_size_label->setText("/"+num);
   updatePercentThreshold();
 }
 
 double ThresholdWidget::min_ratio() const
 {
-  double ratio=((double)basepair_spinner.minimum()/
-                (double)basepair_spinner.maximum());
+  double ratio=((double)basepair_spinner->minimum()/
+                (double)basepair_spinner->maximum());
 
   return ratio;
 }
 
 double ThresholdWidget::ratio() const
 {
-  return ((float)threshold())/((float)basepair_spinner.maximum()); 
+  return ((float)threshold())/((float)basepair_spinner->maximum()); 
 }
 
 void ThresholdWidget::setBasepairThreshold(int threshold)
@@ -60,7 +62,7 @@ void ThresholdWidget::setBasepairThreshold(int threshold)
   {
     cur_bp_threshold = threshold;
     cur_percent_threshold = (int)(roundl(ratio() * 100));
-    basepair_spinner.setValue(threshold);
+    basepair_spinner->setValue(threshold);
     updatePercentThreshold();
     emit thresholdChanged(threshold);
   }
@@ -72,7 +74,7 @@ void ThresholdWidget::updatePercentThreshold()
   QString label;
   label.setNum(min_percent);
   label += "%";
-  percent_label.setText(label);
+  percent_label->setText(label);
 }
 
 int ThresholdWidget::threshold() const
index 61d890042dc213f7d4694791d27e7ffdc9c4038d..319175a985f91527af48563c0e53be8aa55ef594 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef _THRESHOLD_WIDGET_H_ 
 #define _THRESHOLD_WIDGET_H_
 
+#include <QHBoxLayout>
 #include <QLabel>
 #include <QSpinBox>
 #include <QWidget>
@@ -32,9 +33,10 @@ signals:
   void thresholdChanged(int new_threshold);
 
 protected:
-  QSpinBox basepair_spinner;
-  QLabel window_size_label;
-  QLabel percent_label;
+  QHBoxLayout *layout;
+  QSpinBox *basepair_spinner;
+  QLabel *window_size_label;
+  QLabel *percent_label;
 
   int cur_bp_threshold;
   int cur_percent_threshold;