Change threshold widget to use dynamically allocated objects
instead of statically allocated objects. I think Qt prefers this, but
now I'm less sure.
#include <QSlider>
#include <QString>
#include <QSlider>
#include <QString>
// This is completely and totally derived from the Qt example
// LCDRange.cpp
ThresholdWidget::ThresholdWidget(QWidget *parent, int min, int max)
// This is completely and totally derived from the Qt example
// LCDRange.cpp
ThresholdWidget::ThresholdWidget(QWidget *parent, int min, int max)
+ : 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");
- connect(&basepair_spinner, SIGNAL(valueChanged(int)),
+ connect(basepair_spinner, SIGNAL(valueChanged(int)),
this, SLOT(setBasepairThreshold(int)));
this, SLOT(setBasepairThreshold(int)));
- basepair_spinner.setValue(min);
+ basepair_spinner->setValue(min);
updatePercentThreshold();
updatePercentThreshold();
- QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(new QLabel("Threshold"));
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)
{
setLayout(layout);
}
void ThresholdWidget::setRange(int min, int max)
{
- basepair_spinner.setRange(min, max);
+ basepair_spinner->setRange(min, max);
- basepair_spinner.setValue(min);
+ basepair_spinner->setValue(min);
QString num;
num.setNum(max);
QString num;
num.setNum(max);
- window_size_label.setText("/"+num);
+ window_size_label->setText("/"+num);
updatePercentThreshold();
}
double ThresholdWidget::min_ratio() const
{
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 ratio;
}
double ThresholdWidget::ratio() const
{
- return ((float)threshold())/((float)basepair_spinner.maximum());
+ return ((float)threshold())/((float)basepair_spinner->maximum());
}
void ThresholdWidget::setBasepairThreshold(int threshold)
}
void ThresholdWidget::setBasepairThreshold(int threshold)
{
cur_bp_threshold = threshold;
cur_percent_threshold = (int)(roundl(ratio() * 100));
{
cur_bp_threshold = threshold;
cur_percent_threshold = (int)(roundl(ratio() * 100));
- basepair_spinner.setValue(threshold);
+ basepair_spinner->setValue(threshold);
updatePercentThreshold();
emit thresholdChanged(threshold);
}
updatePercentThreshold();
emit thresholdChanged(threshold);
}
QString label;
label.setNum(min_percent);
label += "%";
QString label;
label.setNum(min_percent);
label += "%";
- percent_label.setText(label);
+ percent_label->setText(label);
}
int ThresholdWidget::threshold() const
}
int ThresholdWidget::threshold() const
#ifndef _THRESHOLD_WIDGET_H_
#define _THRESHOLD_WIDGET_H_
#ifndef _THRESHOLD_WIDGET_H_
#define _THRESHOLD_WIDGET_H_
#include <QLabel>
#include <QSpinBox>
#include <QWidget>
#include <QLabel>
#include <QSpinBox>
#include <QWidget>
void thresholdChanged(int new_threshold);
protected:
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;
int cur_bp_threshold;
int cur_percent_threshold;