don't use staticly allocated widgets
authorDiane Trout <diane@caltech.edu>
Sat, 28 Oct 2006 01:53:48 +0000 (01:53 +0000)
committerDiane Trout <diane@caltech.edu>
Sat, 28 Oct 2006 01:53:48 +0000 (01:53 +0000)
dynamically create the widgets used in SequenceDescription

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

index 8bf36e6c6911cb47f944b7fdfd009beddf551312..4b2f66bf6da1546bf66627e1fafd843db5219afe 100644 (file)
@@ -1,10 +1,13 @@
-#include <QVBoxLayout>
 #include "qui/seqbrowser/SequenceDescription.hpp"
 
 using namespace std;
 
 SequenceDescription::SequenceDescription(QWidget *parent)
-  : QFrame(parent), 
+  : QFrame(parent),
+    layout(new QVBoxLayout), 
+    name_label(new QLineEdit),
+    position_label(new QLabel),
+    length_label(new QLabel),
     pos(-1) // set pos to an invalid value so the setPos function will call
             // setText
 {
@@ -23,14 +26,13 @@ void SequenceDescription::createWidget()
 {
   setFrameStyle(QFrame::Panel | QFrame::Sunken);
   setLineWidth(1);
-  QLayout *layout = new QVBoxLayout;
-  layout->addWidget(&name_label);
-  layout->addWidget(&length_label);
-  layout->addWidget(&position_label);
-  name_label.setMaximumWidth(length_label.fontMetrics().width("01234567"));
+  
+  layout->addWidget(name_label);
+  layout->addWidget(position_label);
+  layout->addWidget(length_label);
+  name_label->setMaximumWidth(length_label->fontMetrics().width("01234567"));
   setLayout(layout);
-
-  connect(&name_label, SIGNAL(textChanged(const QString& )),
+  connect(name_label, SIGNAL(textChanged(const QString& )),
           this, SLOT(setName(const QString& )));
 }
 
@@ -65,9 +67,9 @@ void SequenceDescription::setName(const QString& name_)
   }
 
     // no need to setText again if its because of user editing
-  if (name_ != name_label.text()) {
-    name_label.setText(name_);
-    name_label.setCursorPosition(0);
+  if (name_ != name_label->text()) {
+    name_label->setText(name_);
+    name_label->setCursorPosition(0);
   }
 }
 
@@ -95,7 +97,7 @@ void SequenceDescription::setLength(int length)
     s.setNum(short_length);
     s += "b";
   }
-  length_label.setText(s);
+  length_label->setText(s);
 }
 
 int SequenceDescription::length() const 
@@ -113,7 +115,7 @@ void SequenceDescription::setPosition(int pos_)
   QString s; 
   if (pos != pos_) {
     pos = pos_;
-    position_label.setText(s.setNum(pos_));
+    position_label->setText(s.setNum(pos_));
     emit positionChanged(pos);
   }
 }
index 929a999ccff3a9b9e21dfa8061936b46962b5510..1a8077939ab9ff452f51ceb0bd614920fdc4aa58 100644 (file)
@@ -9,6 +9,7 @@
 #include <QLabel>
 #include <QLineEdit>
 #include <QFrame>
+#include <QVBoxLayout>
 
 #include "alg/glsequence.hpp"
 
@@ -19,8 +20,8 @@ class SequenceDescription : public QFrame
 public:
   SequenceDescription(QWidget *parent=0);
   SequenceDescription(boost::shared_ptr<GlSequence>, QWidget *);
+  
   void setName(std::string name);
-
   boost::shared_ptr<GlSequence> glsequence();
   std::string name() const; 
   int length() const;
@@ -39,9 +40,10 @@ signals:
   void positionChanged(int pos);
 
 private:
-  QLineEdit name_label;
-  QLabel length_label;
-  QLabel position_label;
+  QVBoxLayout *layout;
+  QLineEdit *name_label;
+  QLabel *length_label;
+  QLabel *position_label;
 
   boost::shared_ptr<GlSequence> glsequence_;
   int pos;