From ef945d6ecac064dacc1a3ccaa5782ac22c06cd2b Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Fri, 11 Aug 2006 01:23:28 +0000 Subject: [PATCH] Update SequenceDescription to have signal/slots 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 | 1 - qui/seqbrowser/SequenceDescription.cpp | 58 ++++++++++++++++------- qui/seqbrowser/SequenceDescription.hpp | 17 +++++-- 3 files changed, 55 insertions(+), 21 deletions(-) diff --git a/qui/seqbrowser/SequenceBrowserSidebar.cpp b/qui/seqbrowser/SequenceBrowserSidebar.cpp index 275b3b4..f63a500 100644 --- a/qui/seqbrowser/SequenceBrowserSidebar.cpp +++ b/qui/seqbrowser/SequenceBrowserSidebar.cpp @@ -30,7 +30,6 @@ void SequenceBrowserSidebar::setSequences(vector& 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()) { diff --git a/qui/seqbrowser/SequenceDescription.cpp b/qui/seqbrowser/SequenceDescription.cpp index 73efe36..d01ae5f 100644 --- a/qui/seqbrowser/SequenceDescription.cpp +++ b/qui/seqbrowser/SequenceDescription.cpp @@ -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); + } +} diff --git a/qui/seqbrowser/SequenceDescription.hpp b/qui/seqbrowser/SequenceDescription.hpp index f8a1678..ff449ee 100644 --- a/qui/seqbrowser/SequenceDescription.hpp +++ b/qui/seqbrowser/SequenceDescription.hpp @@ -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 -- 2.30.2