From: Diane Trout Date: Thu, 2 Nov 2006 21:35:41 +0000 (+0000) Subject: include sequence property editor source files X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=commitdiff_plain;h=12e8b617f16b5e5482bce0e8283ba910259b782d include sequence property editor source files sorry tristan, I forgot to add the files. --- diff --git a/qui/seqbrowser/seqproperties/PropertiesWindow.cpp b/qui/seqbrowser/seqproperties/PropertiesWindow.cpp new file mode 100644 index 0000000..24d1521 --- /dev/null +++ b/qui/seqbrowser/seqproperties/PropertiesWindow.cpp @@ -0,0 +1,88 @@ +#include "qui/seqbrowser/seqproperties/PropertiesWindow.hpp" + +#include "mussa_exceptions.hpp" +#include "alg/mussa.hpp" + +#include +#include +#include +#include + +PropertiesWindow::PropertiesWindow(/* MussaRef m, */ + SequencePropertiesModel::model_type glseqs, + QWidget *parent) + : QWidget(parent), + /* analysis(m), */ + table(0), + ok(0), + cancel(0), + model(glseqs) +{ + QGridLayout *parameterLayout = new QGridLayout; + + ok = new QPushButton(tr("&OK"), this); + ok->setEnabled( false ); + connect(ok, SIGNAL(clicked()), this, SLOT(apply())); + + cancel = new QPushButton(tr("Cancel"), this); + connect(cancel, SIGNAL(clicked()), this, SLOT(cancel())); + + table = new QTableView(this); + table->setModel(&model); + + // layout buttons + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addWidget(ok); + buttonLayout->addWidget(cancel); + + // layout verticle space + QVBoxLayout *verticalLayout = new QVBoxLayout; + verticalLayout->addWidget(table); + verticalLayout->addLayout(buttonLayout); + setLayout(verticalLayout); + + // now that we're all setup lets get notices when we're updated + connect(&model, SIGNAL(rowsInserted(const QModelIndex&, int, int)), + this, SLOT(modelUpdated(const QModelIndex&, int, int))); + connect(&model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), + this, SLOT(modelUpdated(const QModelIndex&, int, int))); + + updateTitle(); +} + +SequencePropertiesModel& PropertiesWindow::getModel() +{ + return model; +} + +void PropertiesWindow::abort() +{ + model.clear(); + hide(); +} + +void PropertiesWindow::apply() +{ + std::cout << "implement PropertiesWindow::apply" << std::endl; + + for(SequencePropertiesModel::iterator itor = model.begin(); + itor != model.end(); + ++itor) + { + } +} + +void PropertiesWindow::modelUpdated(const QModelIndex&, int, int ) +{ + // if the model is empty we shouldn't be able to click ok + if (ok) ok->setEnabled(not model.empty()); +} + +void PropertiesWindow::updateTitle() +{ + std::string title("Sequence Properites: "); + if (analysis) { + title += analysis->get_title(); + } + setWindowTitle(title.c_str()); +} diff --git a/qui/seqbrowser/seqproperties/PropertiesWindow.hpp b/qui/seqbrowser/seqproperties/PropertiesWindow.hpp new file mode 100644 index 0000000..638a45e --- /dev/null +++ b/qui/seqbrowser/seqproperties/PropertiesWindow.hpp @@ -0,0 +1,47 @@ +#ifndef _SUBANALYSIS_H_ +#define _SUBANALYSIS_H_ + +#include +#include +#include +#include +#include + +#include "qui/seqbrowser/seqproperties/SequencePropertiesModel.hpp" +#include "alg/mussa.hpp" + +class PropertiesWindow : public QWidget +{ + Q_OBJECT + +public: + PropertiesWindow(/* MussaRef m, */ + SequencePropertiesModel::model_type glseqs, + QWidget *parent = 0); + + //! return a modifiable reference to our SequenceLocationModel + SequencePropertiesModel& getModel(); + +public slots: + //! create a subanalysis and run it + void apply(); + //! clear our model and close the window + void abort(); + //! provide a way for the model to tell us to update our gui + void modelUpdated(const QModelIndex&, int, int); + //! update our title + void updateTitle(); + +private: + //! keep track of what analysis we're attached to + MussaRef analysis; + QTableView *table; + QPushButton *ok; + QPushButton *cancel; + + SequencePropertiesModel model; +}; + +//! reference to a subanalysis window +typedef boost::shared_ptr PropertiesWindowRef; +#endif diff --git a/qui/seqbrowser/seqproperties/SequencePropertiesModel.cpp b/qui/seqbrowser/seqproperties/SequencePropertiesModel.cpp new file mode 100644 index 0000000..b4fc3b2 --- /dev/null +++ b/qui/seqbrowser/seqproperties/SequencePropertiesModel.cpp @@ -0,0 +1,208 @@ +#include "qui/seqbrowser/seqproperties/SequencePropertiesModel.hpp" + +SequencePropertiesModel::SequencePropertiesModel(model_type& orig, QObject *parent) + : QAbstractTableModel(parent), + original_sequences(orig) +{ + for(const_iterator glseq_i = original_sequences.begin(); + glseq_i != original_sequences.end(); + ++glseq_i) + { + // manage to convert out of all of our pointers to call + // the glsequence copy constructor + model_item new_glseq(new GlSequence(*(glseq_i->get()))); + sequences.push_back(new_glseq); + } +} + +void SequencePropertiesModel::assign( + SequencePropertiesModel::size_type num, + const SequencePropertiesModel::model_item val +) +{ + sequences.assign(num, val); +} + +SequencePropertiesModel::model_item SequencePropertiesModel::at( + SequencePropertiesModel::size_type index +) +{ + return sequences.at(index); +} + +SequencePropertiesModel::model_item SequencePropertiesModel::back() +{ + return sequences.back(); +} + +SequencePropertiesModel::iterator SequencePropertiesModel::begin() +{ + return sequences.begin(); +} + +SequencePropertiesModel::const_iterator SequencePropertiesModel::begin() const +{ + return sequences.begin(); +} + +void SequencePropertiesModel::clear() +{ + if (sequences.size() != 0) { + beginRemoveRows(QModelIndex(), 0, sequences.size()-1); + sequences.clear(); + endRemoveRows(); + } +} + +SequencePropertiesModel::iterator SequencePropertiesModel::end() +{ + return sequences.end(); +} + +SequencePropertiesModel::const_iterator SequencePropertiesModel::end() const +{ + return sequences.end(); +} + +bool SequencePropertiesModel::empty() const +{ + return sequences.empty(); +} + +SequencePropertiesModel::model_item SequencePropertiesModel::operator[]( + SequencePropertiesModel::size_type index +) +{ + return sequences[index]; +} + +void SequencePropertiesModel::pop_back() +{ + int last_element = sequences.size()-1; + if (last_element >= 0) { + beginRemoveRows(QModelIndex(), last_element, last_element); + sequences.pop_back(); + endRemoveRows(); + } +} + +void SequencePropertiesModel::push_back( + SequencePropertiesModel::model_item item +) +{ + int last_element = sequences.size(); + beginInsertRows(QModelIndex(), last_element, last_element); + sequences.push_back(item); + endInsertRows(); +} + +SequencePropertiesModel::size_type SequencePropertiesModel::size() const +{ + return sequences.size(); +} + +int +SequencePropertiesModel::rowCount( const QModelIndex& parent) const +{ + return sequences.size(); +} + +int +SequencePropertiesModel::columnCount(const QModelIndex& parent) const +{ + return 2; +} + +QVariant +SequencePropertiesModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (index.row() >= sequences.size()) + return QVariant(); + + if (index.column() >= 3) + return QVariant(); + + if (role == Qt::DisplayRole) { + if (index.column() == 0 ) { + model_item glseq = sequences[index.row()]; + std::string name(glseq->sequence()->get_name()); + if (name.size() == 0) { + return QString(tr("Unnamed Sequence")); + } else { + return QVariant(QString(name.c_str())); + } + } else if (index.column() == 1) { + return QVariant(sequences[index.row()]->x()); + } + } + return QVariant(); +} + +QVariant +SequencePropertiesModel::headerData( + int section, + Qt::Orientation orientation, + int role +) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + if (orientation == Qt::Horizontal) { + switch(section) { + case 0: + return QString("Sequence"); + break; + case 1: + return QString("Offset to 0"); + break; + default: + return QVariant(); + break; + } + } + return QVariant(); +} + +bool SequencePropertiesModel::setData( + const QModelIndex& index, + const QVariant &value, + int role +) +{ + bool isInt; + int intValue(value.toInt(&isInt)); + if (index.isValid() and role == Qt::EditRole and isInt) { + model_item seq = sequences[index.row()]; + switch(index.column()) { + case 0: + return false; + break; + case 1: + seq->setX(intValue); + break; + default: + return false; + break; + } + emit dataChanged(index, index); + return true; + } else { + return false; + } +} + +Qt::ItemFlags SequencePropertiesModel::flags(const QModelIndex& index) const +{ + if (!index.isValid()) + return Qt::ItemIsEnabled; + + // first column is not editable + if (index.column() == 0) + return QAbstractItemModel::flags(index); + else + return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; +} \ No newline at end of file diff --git a/qui/seqbrowser/seqproperties/SequencePropertiesModel.hpp b/qui/seqbrowser/seqproperties/SequencePropertiesModel.hpp new file mode 100644 index 0000000..8980c13 --- /dev/null +++ b/qui/seqbrowser/seqproperties/SequencePropertiesModel.hpp @@ -0,0 +1,77 @@ +#ifndef _SEQUENCE_LOCATION_MODEL_HPP_ +#define _SEQUENCE_LOCATION_MODEL_HPP_ + +#include +#include +#include + +#include "alg/glsequence.hpp" + +class SequencePropertiesModel : public QAbstractTableModel +{ + Q_OBJECT + + public: + typedef boost::shared_ptr model_item; + typedef std::vector model_type; + typedef model_type::size_type size_type; + typedef model_type::iterator iterator; + typedef model_type::const_iterator const_iterator; + + SequencePropertiesModel(model_type& model, QObject *parent = 0); + + //! \defgroup VectorInterface + //! \addtogroup VectorInterface + //! \@{ + //! assign num copies of val to our vector + void assign(size_type num, const model_item val); + //! return a specific element + model_item at(size_type index); + //! return the last element + model_item back(); + //! return an iterator to the beginning of the model + iterator begin(); + //! return an iterator to the beginning of the model + const_iterator begin() const; + //! empty the model + void clear(); + //! return an iterator to the end of the model + iterator end(); + //! return an iterator to the end of the model + const_iterator end() const; + //! is the model empty? + bool empty() const; + //! return a specific element + model_item operator[](size_type index); + //! remove the last element from our model + void pop_back(); + //! add a sequence to the end of our model + void push_back(model_item); + //! how many elements are in our model. + size_type size() const; + //! \@} + + //! \defgroup QtModelInterface + //! \addtogroup QtModel + //! \@{ + int rowCount(const QModelIndex& parent=QModelIndex()) const; + int columnCount(const QModelIndex& parent=QModelIndex()) const; + QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const; + + QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const; + + bool setData(const QModelIndex& index, const QVariant &value, + int role=Qt::EditRole); + Qt::ItemFlags flags(const QModelIndex& index) const; + + //bool insertRows(int row, int count, + // const QModelIndex& parent=QModelIndex()); + //bool removeRows(int row, int count, + // const QModelIndex& parent=QModelIndex()); + //! \@} + private: + model_type sequences; + model_type& original_sequences; +}; + +#endif