using namespace std;
SequenceDescription::SequenceDescription(QWidget *parent)
- : QFrame(parent)
+ : QFrame(parent),
+ pos(-1) // set pos to an invalid value so the setPos function will call
+ // setText
{
createWidget();
}
-SequenceDescription::SequenceDescription(string& name, float length,
+SequenceDescription::SequenceDescription(string name, int length,
QWidget *parent)
- : QFrame(parent)
+ : QFrame(parent),
+ pos(-1) // set pos to an invalid value so the setPos function will call
+ // setText
{
setName(name);
setLength(length);
setLayout(layout);
}
-void SequenceDescription::setLength(float length)
+void SequenceDescription::setName(std::string name)
+{
+ if (name != name_label.text().toStdString()) {
+ name_label.setText(name.c_str());
+ emit nameChanged(name);
+ }
+}
+
+void SequenceDescription::setLength(int length_)
{
QString s;
- if (length > 1000000) {
- length /= 1000000;
- s.setNum(length, 'f', 2);
- s += "mb";
- } if (length > 1000) {
- length /= 1000;
- s.setNum(length, 'f', 2);
- s += "kb";
- } else {
- s.setNum(length);
- s += "b";
+ float short_length = length_;
+ if (length_ != length) {
+ if (short_length > 1000000) {
+ short_length /= 1000000;
+ s.setNum(short_length, 'f', 2);
+ s += "mb";
+ } if (short_length > 1000) {
+ short_length /= 1000;
+ s.setNum(short_length, 'f', 2);
+ s += "kb";
+ } else {
+ s.setNum(short_length);
+ s += "b";
+ }
+ length_label.setText(s);
+ length = length_;
+ emit lengthChanged(length);
}
- length_label.setText(s);
}
+void SequenceDescription::setPosition(int pos_)
+{
+ QString s;
+ if (pos != pos_) {
+ pos = pos_;
+ position_label.setText(s.setNum(pos_));
+ emit positionChanged(pos);
+ }
+}
public:
SequenceDescription(QWidget *parent=0);
- SequenceDescription(std::string& name, float length, QWidget *parent=0);
+ SequenceDescription(std::string name, int length, QWidget *parent=0);
- void setName(const std::string& name) { name_label.setText(name.c_str()); }
- void setLength(float length);
- void setPosition(int pos) { QString s; position_label.setText(s.setNum(pos));}
+public slots:
+ void setName(std::string name);
+ void setLength(int length);
+ void setPosition(int pos);
+
+signals:
+ void nameChanged(std::string name);
+ void lengthChanged(float length);
+ void positionChanged(int pos);
private:
QLabel name_label;
QLabel length_label;
QLabel position_label;
+ int length;
+ int pos;
+
void createWidget();
};
#endif