From: Diane Trout Date: Tue, 3 Oct 2006 20:48:37 +0000 (+0000) Subject: Use pointers in ThresholdWidget X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=commitdiff_plain;h=3071b168a3bae4947dbda407ce73d2b06007e134 Use pointers in ThresholdWidget Change threshold widget to use dynamically allocated objects instead of statically allocated objects. I think Qt prefers this, but now I'm less sure. --- diff --git a/qui/ThresholdWidget.cpp b/qui/ThresholdWidget.cpp index 98b7ba0..c1ca76c 100644 --- a/qui/ThresholdWidget.cpp +++ b/qui/ThresholdWidget.cpp @@ -1,4 +1,3 @@ -#include #include #include @@ -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 diff --git a/qui/ThresholdWidget.hpp b/qui/ThresholdWidget.hpp index 61d8900..319175a 100644 --- a/qui/ThresholdWidget.hpp +++ b/qui/ThresholdWidget.hpp @@ -1,6 +1,7 @@ #ifndef _THRESHOLD_WIDGET_H_ #define _THRESHOLD_WIDGET_H_ +#include #include #include #include @@ -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;