-#include <QVBoxLayout>
-
#include "qui/seqbrowser/SequenceDescription.hpp"
using namespace std;
SequenceDescription::SequenceDescription(QWidget *parent)
- : QFrame(parent),
+ : QFrame(parent),
+ layout(0),
+ name_label(0),
+ position_label(0),
+ length_label(0),
pos(-1) // set pos to an invalid value so the setPos function will call
// setText
{
- createWidget();
+ setupWidgets();
}
-SequenceDescription::SequenceDescription(string name, int length,
- QWidget *parent)
- : QFrame(parent),
- pos(-1) // set pos to an invalid value so the setPos function will call
- // setText
+SequenceDescription::SequenceDescription(
+ boost::shared_ptr<GlSequence> glseq,
+ QWidget *parent
+) : QFrame(parent)
{
- setName(name);
- setLength(length);
- createWidget();
+ setupWidgets();
+ setGlSequence(glseq);
}
-void SequenceDescription::createWidget()
+void SequenceDescription::setupWidgets()
{
+ layout = new QVBoxLayout;
+ name_label = new QLineEdit;
+ position_label = new QLabel;
+ length_label = new QLabel;
+
setFrameStyle(QFrame::Panel | QFrame::Sunken);
setLineWidth(1);
- QLayout *layout = new QVBoxLayout;
- layout->addWidget(&name_label);
- layout->addWidget(&length_label);
- layout->addWidget(&position_label);
+
+ // What's this feature descriptions
+ // FIXME: The '*' is added because for some reason
+ // Qt's whatsthis feature is chopping off the last word
+ // If the '*' eventually shows up in a whatsthis pop-up
+ // then the '*' should be removed.
+ name_label->setWhatsThis("Name of sequence *");
+ position_label->setWhatsThis("Edge of viewport base pair position *");
+ length_label->setWhatsThis("Total length of sequence *");
+
+ 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& )),
+ this, SLOT(setName(const QString& )));
+}
+
+void SequenceDescription::setGlSequence(
+ boost::shared_ptr<GlSequence> glseq )
+{
+ if (glseq != glsequence_) {
+ glsequence_ = glseq;
+ setName(glsequence_->sequence()->get_species());
+ setLength(glsequence_->sequence()->length());
+ emit glsequenceChanged(glsequence_);
+ }
+}
+
+boost::shared_ptr<GlSequence> SequenceDescription::glsequence()
+{
+ return glsequence_;
}
void SequenceDescription::setName(std::string name)
{
- if (name != name_label.text().toStdString()) {
- name_label.setText(name.c_str());
- emit nameChanged(name);
+ setName(QString(name.c_str()));
+}
+
+void SequenceDescription::setName(const QString& name_)
+{
+ std::string std_name_ = name_.toStdString();
+
+ if (std_name_ != glsequence_->sequence()->get_species()) {
+ glsequence_->sequence()->set_species(std_name_);
+ emit nameChanged(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);
}
}
-void SequenceDescription::setLength(int length_)
+std::string SequenceDescription::name() const
+{
+ if (glsequence_)
+ return glsequence_->sequence()->get_species();
+ else
+ return string("");
+}
+
+void SequenceDescription::setLength(int length)
{
QString s;
- 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);
+ float short_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);
+}
+
+int SequenceDescription::length() const
+{
+ return 0;
+
+ if (glsequence_)
+ return glsequence_->sequence()->size();
+ else
+ return 0;
}
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);
}
}
+
+int SequenceDescription::position() const
+{
+ return pos;
+}