diff --git a/modules/gui/src/CMakeLists.txt b/modules/gui/src/CMakeLists.txt index ea38cf4c0ad9fe88403b10777f51bfd2d16813bf..b4ca43ed392d7f8088acc611f71ce05dec3b5ed0 100644 --- a/modules/gui/src/CMakeLists.txt +++ b/modules/gui/src/CMakeLists.txt @@ -36,7 +36,8 @@ sequence_table_view.hh sequence_viewer.hh tick_painter.hh title_row.hh -view_object.hh +base_view_object.hh +sequence_view_object.hh ) set(OST_GUI_TOOLS_HEADERS @@ -226,7 +227,8 @@ sequence/sequence_table_view.cc sequence/sequence_viewer.cc sequence/tick_painter.cc sequence/title_row.cc -sequence/view_object.cc +sequence/base_view_object.cc +sequence/sequence_view_object.cc gosty_app.cc change_process_name.cc main_area.cc @@ -358,7 +360,8 @@ sequence/sequence_table_view.hh sequence/sequence_viewer.hh sequence/tick_painter.hh sequence/title_row.hh -sequence/view_object.hh +sequence/base_view_object.hh +sequence/sequence_view_object.hh plot_viewer/plot_axis_base.hh plot_viewer/plot_data_graphics_item_base.hh plot_viewer/plot_function_info.hh diff --git a/modules/gui/src/sequence/base_row.cc b/modules/gui/src/sequence/base_row.cc index e2a57450bba50b67f65f9c8c32d5eed2706d0a8f..16dfb0af3831eda02d11e32f964374b5298c5247 100644 --- a/modules/gui/src/sequence/base_row.cc +++ b/modules/gui/src/sequence/base_row.cc @@ -130,6 +130,9 @@ Qt::ItemFlags BaseRow::Flags(int column) const void BaseRow::DoubleClicked(int column) { } +void BaseRow::SetSelection(const QSet<int>& added, const QSet<int>& removed) +{ } + void BaseRow::ZoomIn() { QFont font = this->GetFont(); diff --git a/modules/gui/src/sequence/base_row.hh b/modules/gui/src/sequence/base_row.hh index 3a69ca0e6b62fb0f1b7678ce9eab10e57f2cf47a..6f20d872b7ff431bb4ba3799e7f5af66c6f52d20 100644 --- a/modules/gui/src/sequence/base_row.hh +++ b/modules/gui/src/sequence/base_row.hh @@ -59,6 +59,7 @@ public: virtual bool SetData(int column, const QVariant& value, int role); virtual Qt::ItemFlags Flags(int column) const; virtual void DoubleClicked(int column); + virtual void SetSelection(const QSet<int>& added, const QSet<int>& removed); virtual void ZoomIn(); virtual void ZoomOut(); diff --git a/modules/gui/src/sequence/base_view_object.cc b/modules/gui/src/sequence/base_view_object.cc new file mode 100644 index 0000000000000000000000000000000000000000..6c882761bd82dba5ccbc891016ff0c640326bafc --- /dev/null +++ b/modules/gui/src/sequence/base_view_object.cc @@ -0,0 +1,120 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2010 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ + +/* + Author: Stefan Scheuber + */ + + +#include <QtGui> + +#include "base_view_object.hh" + +namespace ost { namespace gui { + +BaseViewObject::BaseViewObject(QObject* parent): QObject(parent) +{ } + +void BaseViewObject::InsertRow(int pos, BaseRow* row) +{ + if(pos >= 0 && pos <= rows_.size()){ + rows_.insert(pos,row); + } +} + +void BaseViewObject::RemoveRow(BaseRow* row) +{ + rows_.removeAll(row); +} + +BaseRow* BaseViewObject::GetRow(int pos) +{ + if(pos >= 0 && pos < rows_.size()){ + return rows_[pos]; + } + return NULL; +} + +int BaseViewObject::GetRowCount() +{ + return rows_.size(); +} + +void BaseViewObject::SetSelection(int row, const QSet<int>& added, const QSet<int>& removed) +{ + if(row<0 || row >= rows_.size()){ + rows_[row]->SetSelection(added,removed); + } +} + +QVariant BaseViewObject::GetData(int row, int column, int role) +{ + if(row<0 || row >= rows_.size())return QVariant(); + + return rows_[row]->GetData(column,role); +} + +int BaseViewObject::GetMaxColumnCount() const +{ + int columns = 0; + for(int i = 0; i < rows_.size(); i++){ + int col_length = rows_[i]->GetColumnCount(); + if(columns < col_length){ + columns = col_length; + } + } + return columns; +} + +bool BaseViewObject::SetData(int row, int column, const QVariant& value, int role) +{ + if(row<0 || row >= rows_.size())return false; + + return rows_[row]->SetData(column, value, role); +} + +void BaseViewObject::DoubleClicked(int row, int column) +{ + if(row>=0 || row < rows_.size()){ + rows_[row]->DoubleClicked(column); + } +} + +void BaseViewObject::ZoomIn() +{ + for(int i=0; i< rows_.size(); i++){ + rows_[i]->ZoomIn(); + } +} + +void BaseViewObject::ZoomOut() +{ + for(int i=0; i< rows_.size(); i++){ + rows_[i]->ZoomOut(); + } +} + +Qt::ItemFlags BaseViewObject::Flags(int row, int column) const +{ + if(row<0 || row >= rows_.size())return Qt::NoItemFlags; + + return rows_[row]->Flags(column); +} + +}} diff --git a/modules/gui/src/sequence/base_view_object.hh b/modules/gui/src/sequence/base_view_object.hh new file mode 100644 index 0000000000000000000000000000000000000000..b751244627216fcddb683cfd1635e44bdbc9e0fa --- /dev/null +++ b/modules/gui/src/sequence/base_view_object.hh @@ -0,0 +1,65 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2010 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ +#ifndef OST_SEQUENCE_VIEWER_BASE_VIEW_OBJECT +#define OST_SEQUENCE_VIEWER_BASE_VIEW_OBJECT + +/* + Author: Stefan Scheuber + */ + +#include <QObject> +#include <QList> + +#include "base_row.hh" + + +namespace ost { namespace gui { + +class BaseViewObject : public QObject +{ + Q_OBJECT + + +public: + BaseViewObject(QObject* parent = 0); + + void InsertRow(int pos, BaseRow* row); + void RemoveRow(BaseRow* row); + BaseRow* GetRow(int pos); + int GetRowCount(); + int GetMaxColumnCount() const; + + void SetSelection(int row, const QSet<int>& added, const QSet<int>& removed); + + QVariant GetData(int row, int column, int role); + bool SetData(int row, int column, const QVariant& value, int role); + Qt::ItemFlags Flags(int row, int column) const; + + void DoubleClicked(int row, int column); + void ZoomIn(); + void ZoomOut(); + +protected: + QList<BaseRow*> rows_; +}; + + +}} + +#endif diff --git a/modules/gui/src/sequence/secstr_row.cc b/modules/gui/src/sequence/secstr_row.cc index e6017f35724e1f059b952bab68bf0078522e34f9..180a47469bc97f931ce713e74574ee20be3083a7 100644 --- a/modules/gui/src/sequence/secstr_row.cc +++ b/modules/gui/src/sequence/secstr_row.cc @@ -33,7 +33,7 @@ namespace ost { namespace gui { -SecStrRow::SecStrRow(const QString& name, mol::ChainView& chain, ViewObject* parent) : SequenceRow(name,parent) +SecStrRow::SecStrRow(const QString& name, mol::ChainView& chain, SequenceViewObject* parent) : SequenceRow(name,parent) { this->SetChain(chain); } void SecStrRow::SetSequence(seq::SequenceHandle& sequence) diff --git a/modules/gui/src/sequence/secstr_row.hh b/modules/gui/src/sequence/secstr_row.hh index f52766032ef531d5583f38c621fb22477d446143..4b6bd2762457b2545807b344f1953362543f0347 100644 --- a/modules/gui/src/sequence/secstr_row.hh +++ b/modules/gui/src/sequence/secstr_row.hh @@ -38,7 +38,7 @@ class SecStrRow : public SequenceRow Q_OBJECT public: - SecStrRow(const QString& name, mol::ChainView& chain, ViewObject* parent); + SecStrRow(const QString& name, mol::ChainView& chain, SequenceViewObject* parent); virtual QVariant GetData(int column, int role) const; virtual void DoubleClicked(int column); diff --git a/modules/gui/src/sequence/sequence_model.cc b/modules/gui/src/sequence/sequence_model.cc index fc55fe0188f1a3bb32cf89ddf09571d55cb354a4..7622af1d4225c3f1e96b2351217325653e9aa7c6 100644 --- a/modules/gui/src/sequence/sequence_model.cc +++ b/modules/gui/src/sequence/sequence_model.cc @@ -26,6 +26,13 @@ #include <QtGui> +#include "sequence_view_object.hh" + +#include "title_row.hh" + +#include "background_painter.hh" +#include "tick_painter.hh" + #include "sequence_model.hh" namespace ost { namespace gui { @@ -34,7 +41,14 @@ SequenceModel::SequenceModel(QObject *parent) : QAbstractTableModel(parent), max_columns(0) { this->beginInsertRows(QModelIndex(),this->rowCount(),this->rowCount()); - objects_.append(new ViewObject(this)); + BaseViewObject* title = new BaseViewObject(this); + TitleRow* title_row = new TitleRow(this); + Painter* p = new BackgroundPainter(this); + title_row->InsertPainter(p); + p = new TickPainter(this); + title_row->InsertPainter(p); + title->InsertRow(0,title_row); + objects_.append(title); this->endInsertRows(); } @@ -42,7 +56,7 @@ void SequenceModel::InsertSequence(QString& name, seq::SequenceHandle& seq){ int cols = this->columnCount(); int new_cols = seq.GetLength(); this->beginInsertRows(QModelIndex(),this->rowCount(),this->rowCount()); - objects_.append(new ViewObject(seq, name, this)); + objects_.append(new SequenceViewObject(seq, name, this)); if(new_cols > cols){ this->max_columns = new_cols; this->beginInsertColumns(QModelIndex(), cols, new_cols); @@ -55,7 +69,7 @@ void SequenceModel::InsertChain(QString& name, mol::ChainView& view){ int cols = this->columnCount(); int new_cols = view.GetResidueCount(); this->beginInsertRows(QModelIndex(),this->rowCount(),this->rowCount()); - objects_.append(new ViewObject(view, name, this)); + objects_.append(new SequenceViewObject(view, name, this)); if(new_cols > cols){ this->max_columns = new_cols; this->beginInsertColumns(QModelIndex(), cols, new_cols); @@ -66,7 +80,7 @@ void SequenceModel::InsertChain(QString& name, mol::ChainView& view){ void SequenceModel::InsertSequences(const QList<QString>& names, seq::SequenceList& list){ this->beginInsertRows(this->index(this->rowCount(),0),this->rowCount(),this->rowCount()+list.GetCount()); - objects_.append(new ViewObject(list, names, this)); + objects_.append(new SequenceViewObject(list, names, this)); this->endInsertRows(); } @@ -75,7 +89,7 @@ void SequenceModel::InsertGfxEntity(gfx::EntityP& ent){ int size = view.GetChainList().size(); int cols = this->columnCount(); this->beginInsertRows(QModelIndex(),this->rowCount(),this->rowCount()+size); - ViewObject* obj = new ViewObject(ent, this); + SequenceViewObject* obj = new SequenceViewObject(ent, this); objects_.append(obj); int new_cols = obj->GetMaxColumnCount(); if(new_cols > cols){ @@ -87,7 +101,7 @@ void SequenceModel::InsertGfxEntity(gfx::EntityP& ent){ } void SequenceModel::RemoveGfxEntity(gfx::EntityP& entity){ - if(ViewObject* obj = this->GetItem(entity)){ + if(SequenceViewObject* obj = this->GetItem(entity)){ int index = this->GetGlobalRow(obj,0); this->beginRemoveRows(QModelIndex(),index,index+obj->GetRowCount()-1); int cols_before = this->columnCount(); @@ -102,11 +116,13 @@ void SequenceModel::RemoveGfxEntity(gfx::EntityP& entity){ } } -ViewObject* SequenceModel::GetItem(gfx::EntityP& entity){ +SequenceViewObject* SequenceModel::GetItem(gfx::EntityP& entity){ if(entity != NULL){ for (int i = 0 ; i< objects_.size(); i++){ - if(entity == objects_[i]->GetGfxObject()){ - return objects_[i]; + if(SequenceViewObject* seq_view_object = qobject_cast<SequenceViewObject*>(objects_[i])){ + if(entity == seq_view_object->GetGfxObject()){ + return seq_view_object; + } } } } @@ -114,14 +130,14 @@ ViewObject* SequenceModel::GetItem(gfx::EntityP& entity){ } const PainterList& SequenceModel::GetPainters(const QModelIndex& index) const{ - QPair<int, ViewObject*> pair = this->GetRowWithItem(index); + QPair<int, BaseViewObject*> pair = this->GetRowWithItem(index); if(pair.second){ return pair.second->GetRow(pair.first)->GetPainters(); } return empty_list_; } -QPair<int, ViewObject*> SequenceModel::GetRowWithItem(int row) const{ +QPair<int, BaseViewObject*> SequenceModel::GetRowWithItem(int row) const{ if(!objects_.isEmpty()){ int rows = 0; int i = -1; @@ -132,21 +148,21 @@ QPair<int, ViewObject*> SequenceModel::GetRowWithItem(int row) const{ rows += last_row; } int sub_index = row - (rows-last_row); - return QPair<int, ViewObject*>(sub_index, objects_[i]); + return QPair<int, BaseViewObject*>(sub_index, objects_[i]); } - return QPair<int, ViewObject*>(-1, NULL); + return QPair<int, BaseViewObject*>(-1, NULL); } -QPair<int, ViewObject*> SequenceModel::GetRowWithItem(const QModelIndex& index) const{ +QPair<int, BaseViewObject*> SequenceModel::GetRowWithItem(const QModelIndex& index) const{ return this->GetRowWithItem(index.row()); } -ViewObject* SequenceModel::GetItem(const QModelIndex& index) const +BaseViewObject* SequenceModel::GetItem(const QModelIndex& index) const { return this->GetRowWithItem(index).second; } -int SequenceModel::GetGlobalRow(ViewObject* obj, int row) const +int SequenceModel::GetGlobalRow(BaseViewObject* obj, int row) const { int glob_row = -1; int index = objects_.indexOf(obj); @@ -163,15 +179,17 @@ int SequenceModel::GetGlobalRow(ViewObject* obj, int row) const QModelIndexList SequenceModel::GetModelIndexes(gfx::EntityP& entity, const mol::EntityView& view) { QModelIndexList list; - if(ViewObject* object = this->GetItem(entity)){ - QMap<int, QList<int> > indexes = object->GetIndexesForView(view); - QMapIterator< int, QList<int> > i(indexes); - while (i.hasNext()) { - i.next(); - int row = this->GetGlobalRow(object, i.key()); - const QList<int>& index_list = i.value(); - for(int i=0; i<index_list.size(); i++){ - list.append(this->index(row,index_list[i])); + if(BaseViewObject* object = this->GetItem(entity)){ + if(SequenceViewObject* seq_view_object = qobject_cast<SequenceViewObject*>(object)){ + QMap<int, QList<int> > indexes = seq_view_object->GetIndexesForView(view); + QMapIterator< int, QList<int> > i(indexes); + while (i.hasNext()) { + i.next(); + int row = this->GetGlobalRow(seq_view_object, i.key()); + const QList<int>& index_list = i.value(); + for(int i=0; i<index_list.size(); i++){ + list.append(this->index(row,index_list[i])); + } } } } @@ -182,15 +200,16 @@ QModelIndexList SequenceModel::GetModelIndexes(const QString& subject, const QSt { QModelIndexList list; for (int i = 0; i<objects_.size(); i++){ - ViewObject* object = objects_[i]; - QMap<int, QList<int> > indexes = object->GetIndexesForSubject(subject,sequence_name); - QMapIterator< int, QList<int> > iter(indexes); - while (iter.hasNext()) { - iter.next(); - int row = this->GetGlobalRow(object, iter.key()); - const QList<int>& index_list = iter.value(); - for(int j=0; j<index_list.size(); j++){ - list.append(this->index(row,index_list[j])); + if(SequenceViewObject* seq_view_object = qobject_cast<SequenceViewObject*>(objects_[i])){ + QMap<int, QList<int> > indexes = seq_view_object->GetIndexesForSubject(subject,sequence_name); + QMapIterator< int, QList<int> > iter(indexes); + while (iter.hasNext()) { + iter.next(); + int row = this->GetGlobalRow(seq_view_object, iter.key()); + const QList<int>& index_list = iter.value(); + for(int j=0; j<index_list.size(); j++){ + list.append(this->index(row,index_list[j])); + } } } } @@ -213,14 +232,14 @@ void SequenceModel::SelectionChanged(const QItemSelection& sel, const QItemSelec QMapIterator< int,QPair<QSet<int>,QSet<int> > > i(sel_map); while (i.hasNext()) { i.next(); - QPair<int, ViewObject*> item = this->GetRowWithItem(i.key()); + QPair<int, BaseViewObject*> item = this->GetRowWithItem(i.key()); item.second->SetSelection(item.first,i.value().first, i.value().second); } } void SequenceModel::DoubleClicked(const QModelIndex& index) { - QPair<int, ViewObject*> item = this->GetRowWithItem(index); + QPair<int, BaseViewObject*> item = this->GetRowWithItem(index); if(item.second){ item.second->DoubleClicked(item.first,index.column()); } @@ -242,7 +261,7 @@ int SequenceModel::columnCount(const QModelIndex& parent) const QVariant SequenceModel::data(const QModelIndex& index, int role) const { - QPair<int, ViewObject*> item = this->GetRowWithItem(index); + QPair<int, BaseViewObject*> item = this->GetRowWithItem(index); if(!item.second) return QVariant(); QVariant data = item.second->GetData(item.first,index.column(),role); return data; @@ -259,7 +278,7 @@ QVariant SequenceModel::headerData(int section, Qt::Orientation orientation, Qt::ItemFlags SequenceModel::flags(const QModelIndex& index) const { - QPair<int, ViewObject*> item = GetRowWithItem(index); + QPair<int, BaseViewObject*> item = GetRowWithItem(index); if(item.second){ return item.second->Flags(item.first, index.column()); } diff --git a/modules/gui/src/sequence/sequence_model.hh b/modules/gui/src/sequence/sequence_model.hh index ea42f348fbb0df21d0d590c1f990f7c4bff7545c..2bf6f9fd41fcf50a4e7baa40396403d62f6b3476 100644 --- a/modules/gui/src/sequence/sequence_model.hh +++ b/modules/gui/src/sequence/sequence_model.hh @@ -30,8 +30,10 @@ #include <ost/seq/sequence_list.hh> -#include "sequence_model.hh" -#include "view_object.hh" +#include <ost/gfx/entity.hh> + +#include "base_view_object.hh" +#include "sequence_view_object.hh" namespace ost { namespace gui { @@ -52,7 +54,7 @@ public: QModelIndexList GetModelIndexes(gfx::EntityP& entity, const mol::EntityView& view); QModelIndexList GetModelIndexes(const QString& subject, const QString& sequence_name=QString()); - int GetGlobalRow(ViewObject* obj, int row) const; + int GetGlobalRow(BaseViewObject* obj, int row) const; const PainterList& GetPainters(const QModelIndex& index) const; @@ -76,12 +78,12 @@ public slots: void SelectionChanged(const QItemSelection& sel, const QItemSelection& desel); private: - ViewObject* GetItem(gfx::EntityP& entity); - ViewObject* GetItem(const QModelIndex& index) const; - QPair<int, ViewObject*> GetRowWithItem(int row) const; - QPair<int, ViewObject*> GetRowWithItem(const QModelIndex& index) const; + SequenceViewObject* GetItem(gfx::EntityP& entity); + BaseViewObject* GetItem(const QModelIndex& index) const; + QPair<int, BaseViewObject*> GetRowWithItem(int row) const; + QPair<int, BaseViewObject*> GetRowWithItem(const QModelIndex& index) const; - QList<ViewObject*> objects_; + QList<BaseViewObject*> objects_; int max_columns; PainterList empty_list_; }; diff --git a/modules/gui/src/sequence/sequence_row.cc b/modules/gui/src/sequence/sequence_row.cc index c1daa1e69ff8f0404c129d5bb56d3f22b3dc5dc4..517a86eeeb779d7d5cafced51ead05232c61afaf 100644 --- a/modules/gui/src/sequence/sequence_row.cc +++ b/modules/gui/src/sequence/sequence_row.cc @@ -29,18 +29,18 @@ #include <ost/gfx/entity.hh> -#include "view_object.hh" +#include "sequence_view_object.hh" #include "sequence_row.hh" namespace ost { namespace gui { -SequenceRow::SequenceRow(const QString& name, seq::SequenceHandle& sequence, ViewObject* parent) : BaseRow(QFont("Courier",11),parent), name_(name), name_font_(QFont("Courier",11)), sequence_(sequence) +SequenceRow::SequenceRow(const QString& name, seq::SequenceHandle& sequence, SequenceViewObject* parent) : BaseRow(QFont("Courier",11),parent), name_(name), name_font_(QFont("Courier",11)), sequence_(sequence) { name_font_.setBold(true); name_font_.setItalic(true); } -SequenceRow::SequenceRow(const QString& name, ViewObject* parent) : BaseRow(QFont("Courier",11),parent), name_(name), name_font_(QFont("Courier",11)) +SequenceRow::SequenceRow(const QString& name, SequenceViewObject* parent) : BaseRow(QFont("Courier",11),parent), name_(name), name_font_(QFont("Courier",11)) { name_font_.setBold(true); name_font_.setItalic(true); @@ -135,7 +135,7 @@ void SequenceRow::DoubleClicked(int column) void SequenceRow::SetSelection(const QSet<int>& added, const QSet<int>& removed) { - ViewObject* view_object = qobject_cast<ViewObject*>(this->parent()); + SequenceViewObject* view_object = qobject_cast<SequenceViewObject*>(this->parent()); if(view_object){ if(gfx::EntityP entity = view_object->GetGfxObject()){ mol::EntityView sel = entity->GetSelection(); diff --git a/modules/gui/src/sequence/sequence_row.hh b/modules/gui/src/sequence/sequence_row.hh index 58c0a2dad280d19e36f2f00808998646677a613a..029fe26e4579ed92c14d9c0be1134d332fb40192 100644 --- a/modules/gui/src/sequence/sequence_row.hh +++ b/modules/gui/src/sequence/sequence_row.hh @@ -31,15 +31,15 @@ namespace ost { namespace gui { -class ViewObject; +class SequenceViewObject; class SequenceRow : public BaseRow { Q_OBJECT public: - SequenceRow(const QString& name, seq::SequenceHandle& sequence, ViewObject* parent); - SequenceRow(const QString& name, ViewObject* parent); + SequenceRow(const QString& name, seq::SequenceHandle& sequence, SequenceViewObject* parent); + SequenceRow(const QString& name, SequenceViewObject* parent); virtual int GetColumnCount() const; diff --git a/modules/gui/src/sequence/view_object.cc b/modules/gui/src/sequence/sequence_view_object.cc similarity index 61% rename from modules/gui/src/sequence/view_object.cc rename to modules/gui/src/sequence/sequence_view_object.cc index 88dfede657186f09ebef54ba712c8d1c10ca5396..d3e53093a6e06357b9c2d019e570e0c9c0518b5a 100644 --- a/modules/gui/src/sequence/view_object.cc +++ b/modules/gui/src/sequence/sequence_view_object.cc @@ -29,20 +29,18 @@ #include "sequence_row.hh" #include "secstr_row.hh" -#include "title_row.hh" #include "painter.hh" #include "background_painter.hh" #include "seq_secstr_painter.hh" #include "seq_selection_painter.hh" #include "seq_text_painter.hh" -#include "tick_painter.hh" -#include "view_object.hh" +#include "sequence_view_object.hh" namespace ost { namespace gui { -ViewObject::ViewObject(seq::SequenceList& sequences, const QList<QString>& names, QObject *parent): QObject(parent) +SequenceViewObject::SequenceViewObject(seq::SequenceList& sequences, const QList<QString>& names, QObject *parent): BaseViewObject(parent), entity_(gfx::EntityP()) { if(names.size() == sequences.GetCount()){ for(int i=0; i<sequences.GetCount(); i++){ @@ -52,17 +50,17 @@ ViewObject::ViewObject(seq::SequenceList& sequences, const QList<QString>& names } } -ViewObject::ViewObject(seq::SequenceHandle& sequence, const QString& name, QObject *parent): QObject(parent), entity_(gfx::EntityP()) +SequenceViewObject::SequenceViewObject(seq::SequenceHandle& sequence, const QString& name, QObject *parent): BaseViewObject(parent), entity_(gfx::EntityP()) { this->AddSequence(sequence, name); } -ViewObject::ViewObject(mol::ChainView& chain, const QString& name, QObject *parent): QObject(parent), entity_(gfx::EntityP()) +SequenceViewObject::SequenceViewObject(mol::ChainView& chain, const QString& name, QObject *parent): BaseViewObject(parent), entity_(gfx::EntityP()) { this->AddChain(chain, name); } -ViewObject::ViewObject(gfx::EntityP& entity, QObject* parent): QObject(parent), entity_(entity) +SequenceViewObject::SequenceViewObject(gfx::EntityP& entity, QObject* parent): BaseViewObject(parent), entity_(entity) { mol::EntityView view =entity->GetView(); for (mol::ChainViewList::const_iterator c=view.GetChainList().begin(), @@ -76,42 +74,7 @@ ViewObject::ViewObject(gfx::EntityP& entity, QObject* parent): QObject(parent), } } -ViewObject::ViewObject(QObject* parent): QObject(parent) -{ - TitleRow* new_row = new TitleRow(this); - Painter* p = new BackgroundPainter(this); - new_row->InsertPainter(p); - p = new TickPainter(this); - new_row->InsertPainter(p); - rows_.append(new_row); -} - -void ViewObject::InsertRow(int pos, BaseRow* row) -{ - if(pos >= 0 && pos <= rows_.size()){ - rows_.insert(pos,row); - } -} - -void ViewObject::RemoveRow(BaseRow* row) -{ - rows_.removeAll(row); -} - -BaseRow* ViewObject::GetRow(int pos) -{ - if(pos >= 0 && pos < rows_.size()){ - return rows_[pos]; - } - return NULL; -} - -int ViewObject::GetRowCount() -{ - return rows_.size(); -} - -void ViewObject::AddSequence(seq::SequenceHandle& sequence, const QString& name) +void SequenceViewObject::AddSequence(seq::SequenceHandle& sequence, const QString& name) { SequenceRow* new_row = new SequenceRow(name, sequence, this); Painter* p = new BackgroundPainter(this); @@ -123,7 +86,7 @@ void ViewObject::AddSequence(seq::SequenceHandle& sequence, const QString& name) rows_.append(new_row); } -void ViewObject::AddChain(mol::ChainView& chain, const QString& name) +void SequenceViewObject::AddChain(mol::ChainView& chain, const QString& name) { SecStrRow* new_row = new SecStrRow(name, chain, this); Painter* p = new BackgroundPainter(this); @@ -137,71 +100,17 @@ void ViewObject::AddChain(mol::ChainView& chain, const QString& name) rows_.append(new_row); } -void ViewObject::AttachGfxObject(gfx::EntityP& ent) +void SequenceViewObject::AttachGfxObject(gfx::EntityP& ent) { entity_ = ent; } -gfx::EntityP& ViewObject::GetGfxObject() +gfx::EntityP& SequenceViewObject::GetGfxObject() { return entity_; } -void ViewObject::SetSelection(int row, const QSet<int>& added, const QSet<int>& removed) -{ - if(SequenceRow* sequence_row = qobject_cast<SequenceRow*>(rows_[row])){ - sequence_row->SetSelection(added,removed); - } -} - -QVariant ViewObject::GetData(int row, int column, int role) -{ - if(row<0 || row >= rows_.size())return QVariant(); - - return rows_[row]->GetData(column,role); -} - -int ViewObject::GetMaxColumnCount() const -{ - int columns = 0; - for(int i = 0; i < rows_.size(); i++){ - int col_length = rows_[i]->GetColumnCount(); - if(columns < col_length){ - columns = col_length; - } - } - return columns; -} - -bool ViewObject::SetData(int row, int column, const QVariant& value, int role) -{ - if(row<0 || row >= rows_.size())return false; - - return rows_[row]->SetData(column, value, role); -} - -void ViewObject::DoubleClicked(int row, int column) -{ - if(row>=0 || row < rows_.size()){ - rows_[row]->DoubleClicked(column); - } -} - -void ViewObject::ZoomIn() -{ - for(int i=0; i< rows_.size(); i++){ - rows_[i]->ZoomIn(); - } -} - -void ViewObject::ZoomOut() -{ - for(int i=0; i< rows_.size(); i++){ - rows_[i]->ZoomOut(); - } -} - -QMap<int, QList<int> > ViewObject::GetIndexesForView(const mol::EntityView& view) +QMap<int, QList<int> > SequenceViewObject::GetIndexesForView(const mol::EntityView& view) { if(view.GetChainCount()==0){ return QMap<int, QList<int> >(); @@ -229,7 +138,7 @@ QMap<int, QList<int> > ViewObject::GetIndexesForView(const mol::EntityView& view } } -QMap<int, QList<int> > ViewObject::GetIndexesForSubject(const QString& subject, const QString& sequence_name) +QMap<int, QList<int> > SequenceViewObject::GetIndexesForSubject(const QString& subject, const QString& sequence_name) { if(subject.size()==0){ return QMap<int, QList<int> >(); @@ -258,11 +167,4 @@ QMap<int, QList<int> > ViewObject::GetIndexesForSubject(const QString& subject, return selected_indexes; } -Qt::ItemFlags ViewObject::Flags(int row, int column) const -{ - if(row<0 || row >= rows_.size())return Qt::NoItemFlags; - - return rows_[row]->Flags(column); -} - }} diff --git a/modules/gui/src/sequence/view_object.hh b/modules/gui/src/sequence/sequence_view_object.hh similarity index 60% rename from modules/gui/src/sequence/view_object.hh rename to modules/gui/src/sequence/sequence_view_object.hh index 4e88d9eb6e919b7d222b5ecc075522022417f64c..9d85f85b839908c2ae469087e4f06cce2bd47aca 100644 --- a/modules/gui/src/sequence/view_object.hh +++ b/modules/gui/src/sequence/sequence_view_object.hh @@ -16,50 +16,33 @@ // along with this library; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //------------------------------------------------------------------------------ -#ifndef OST_SEQUENCE_VIEWER_VIEW_OBJECT -#define OST_SEQUENCE_VIEWER_VIEW_OBJECT +#ifndef OST_SEQUENCE_VIEWER_SEQUENCE_VIEW_OBJECT +#define OST_SEQUENCE_VIEWER_SEQUENCE_VIEW_OBJECT /* Author: Stefan Scheuber */ -#include <QObject> -#include <QPair> -#include <QList> -#include <QVarLengthArray> -#include <QFont> -#include <QSize> -#include <ost/mol/alg/sec_structure_segments.hh> #include <ost/mol/entity_handle.hh> #include <ost/gfx/entity.hh> #include <ost/seq/sequence_list.hh> -#include "base_row.hh" - +#include "base_view_object.hh" namespace ost { namespace gui { -class ViewObject : public QObject +class SequenceViewObject : public BaseViewObject { Q_OBJECT - public: - ViewObject(seq::SequenceList& sequences, const QList<QString>& names, QObject* parent = 0); - ViewObject(seq::SequenceHandle& sequence, const QString& name, QObject* parent = 0); - ViewObject(mol::ChainView& chain, const QString& name, QObject* parent = 0); - ViewObject(gfx::EntityP& entity, QObject* parent = 0); - ViewObject(QObject* parent = 0); - - void InsertRow(int pos, BaseRow* row); - void RemoveRow(BaseRow* row); - - BaseRow* GetRow(int pos); - int GetRowCount(); - int GetMaxColumnCount() const; + SequenceViewObject(seq::SequenceList& sequences, const QList<QString>& names, QObject* parent = 0); + SequenceViewObject(seq::SequenceHandle& sequence, const QString& name, QObject* parent = 0); + SequenceViewObject(mol::ChainView& chain, const QString& name, QObject* parent = 0); + SequenceViewObject(gfx::EntityP& entity, QObject* parent = 0); void AddSequence(seq::SequenceHandle& sequence, const QString& name=QString()); void AddChain(mol::ChainView& chain, const QString& name=QString()); @@ -67,21 +50,10 @@ public: void AttachGfxObject(gfx::EntityP& ent); gfx::EntityP& GetGfxObject(); - void SetSelection(int row, const QSet<int>& added, const QSet<int>& removed); - - QVariant GetData(int row, int column, int role); - bool SetData(int row, int column, const QVariant& value, int role); - Qt::ItemFlags Flags(int row, int column) const; - - void DoubleClicked(int row, int column); - void ZoomIn(); - void ZoomOut(); - QMap<int, QList<int> > GetIndexesForView(const mol::EntityView& view); QMap<int, QList<int> > GetIndexesForSubject(const QString& subject, const QString& sequence_name=QString()); private: - QList<BaseRow*> rows_; gfx::EntityP entity_; };