Update SequenceDescription to have signal/slots
[mussa.git] / qui / seqbrowser / SequenceDescription.cpp
index 73efe361fae7f84e1b6b59c6dcce8e7ca4b597dd..d01ae5f7ab8d4a1f7313b7165a1215f07cf58af8 100644 (file)
@@ -5,14 +5,18 @@
 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);
@@ -30,21 +34,43 @@ void SequenceDescription::createWidget()
   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);
+  }
+}