Update SequenceDescription to have signal/slots
authorDiane Trout <diane@caltech.edu>
Fri, 11 Aug 2006 01:23:28 +0000 (01:23 +0000)
committerDiane Trout <diane@caltech.edu>
Fri, 11 Aug 2006 01:23:28 +0000 (01:23 +0000)
I'm trying to figure out how to make the sequence name editable and it
seemed like it would be useful to have a sequence description be able
to emit if its name changed.

qui/seqbrowser/SequenceBrowserSidebar.cpp
qui/seqbrowser/SequenceDescription.cpp
qui/seqbrowser/SequenceDescription.hpp

index 275b3b4b5bd0b3b592ad92cca980d4948872f0f6..f63a5001481e22dcbf8a55999335d8d8d852e7f8 100644 (file)
@@ -30,7 +30,6 @@ void SequenceBrowserSidebar::setSequences(vector<GlSequence>& sequences)
     SequenceDescription *desc = new SequenceDescription(this);
     desc->setName(track_i->sequence().get_species());
     desc->setLength(track_i->sequence().length());
-    //desc->setPosition(track_i->sequence().length());
     descriptions.push_back(desc);
     layout.addWidget(desc);
     if ((track_i+1) != sequences.end()) {
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);
+  }
+}
index f8a16782a34c226bcc58097598f7cefff76715d6..ff449ee1240c931552e0a989433133735b954ca0 100644 (file)
@@ -13,17 +13,26 @@ class SequenceDescription : public QFrame
 
 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