Skip to content
Snippets Groups Projects
Commit 08b5ac12 authored by stefan's avatar stefan
Browse files

New SequenceViewer, added classes for secstr rows and normal sequence rows

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2176 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent f3ce5fc4
No related branches found
No related tags found
No related merge requests found
...@@ -21,13 +21,15 @@ sequence_search_bar.hh ...@@ -21,13 +21,15 @@ sequence_search_bar.hh
) )
set(OST_GUI_SEQUENCE_VIEW_HEADERS set(OST_GUI_SEQUENCE_VIEW_HEADERS
painter.hh
base_row.hh base_row.hh
painter.hh
secstr_row.hh
seq_secstr_painter.hh seq_secstr_painter.hh
seq_selection_painter.hh seq_selection_painter.hh
seq_text_painter.hh seq_text_painter.hh
sequence_delegate.hh sequence_delegate.hh
sequence_model.hh sequence_model.hh
sequence_row.hh
sequence_table_view.hh sequence_table_view.hh
sequence_viewer.hh sequence_viewer.hh
view_object.hh view_object.hh
...@@ -207,11 +209,13 @@ sequence_viewer/sequence_viewer.cc ...@@ -207,11 +209,13 @@ sequence_viewer/sequence_viewer.cc
sequence_viewer/sequence_scene.cc sequence_viewer/sequence_scene.cc
sequence_viewer/sequence_search_bar.cc sequence_viewer/sequence_search_bar.cc
sequence/base_row.cc sequence/base_row.cc
sequence/secstr_row.cc
sequence/seq_secstr_painter.cc sequence/seq_secstr_painter.cc
sequence/seq_selection_painter.cc sequence/seq_selection_painter.cc
sequence/seq_text_painter.cc sequence/seq_text_painter.cc
sequence/sequence_delegate.cc sequence/sequence_delegate.cc
sequence/sequence_model.cc sequence/sequence_model.cc
sequence/sequence_row.cc
sequence/sequence_table_view.cc sequence/sequence_table_view.cc
sequence/sequence_viewer.cc sequence/sequence_viewer.cc
sequence/view_object.cc sequence/view_object.cc
...@@ -331,13 +335,15 @@ sequence_viewer/sequence_viewer_base.hh ...@@ -331,13 +335,15 @@ sequence_viewer/sequence_viewer_base.hh
sequence_viewer/sequence_viewer.hh sequence_viewer/sequence_viewer.hh
sequence_viewer/sequence_scene.hh sequence_viewer/sequence_scene.hh
sequence_viewer/sequence_search_bar.hh sequence_viewer/sequence_search_bar.hh
sequence/painter.hh
sequence/base_row.hh sequence/base_row.hh
sequence/painter.hh
sequence/secstr_row.hh
sequence/seq_secstr_painter.hh sequence/seq_secstr_painter.hh
sequence/seq_selection_painter.hh sequence/seq_selection_painter.hh
sequence/seq_text_painter.hh sequence/seq_text_painter.hh
sequence/sequence_delegate.hh sequence/sequence_delegate.hh
sequence/sequence_model.hh sequence/sequence_model.hh
sequence/sequence_row.hh
sequence/sequence_table_view.hh sequence/sequence_table_view.hh
sequence/sequence_viewer.hh sequence/sequence_viewer.hh
sequence/view_object.hh sequence/view_object.hh
......
...@@ -29,7 +29,24 @@ ...@@ -29,7 +29,24 @@
namespace ost { namespace gui { namespace ost { namespace gui {
BaseRow::BaseRow(QObject *parent) : QObject(parent) BaseRow::BaseRow(QObject *parent) : QObject(parent)
{ } { this->SetFont(font_); }
BaseRow::BaseRow(QFont font, QObject *parent) : QObject(parent)
{
this->SetFont(font);
}
int BaseRow::GetColumnCount() const
{
return -1;
}
void BaseRow::Init()
{
QFontMetrics metrics = QFontMetrics(font_);
default_font_size_=QSize(metrics.boundingRect('W').width(),metrics.boundingRect('|').height());
default_cell_size_ = QSize(metrics.boundingRect('W').width()+2,metrics.boundingRect('|').height()*2);
}
void BaseRow::InsertPainter(Painter* painter, int pos) void BaseRow::InsertPainter(Painter* painter, int pos)
{ {
...@@ -67,6 +84,29 @@ bool BaseRow::IsPainterPosValid(int pos) ...@@ -67,6 +84,29 @@ bool BaseRow::IsPainterPosValid(int pos)
return false; return false;
} }
const QFont& BaseRow::GetFont() const
{
return font_;
}
void BaseRow::SetFont(const QFont& font)
{
font_ = font;
QFontMetrics metrics = QFontMetrics(font_);
default_font_size_=QSize(metrics.boundingRect('W').width(),metrics.boundingRect('|').height());
default_cell_size_ = QSize(metrics.boundingRect('W').width()+2,metrics.boundingRect('|').height()*2);
}
const QSize& BaseRow::GetFontSize() const
{
return default_font_size_;
}
const QSize& BaseRow::GetCellSize() const
{
return default_cell_size_;
}
const PainterList& BaseRow::GetPainters() const const PainterList& BaseRow::GetPainters() const
{ {
return painter_; return painter_;
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
// along with this library; if not, write to the Free Software Foundation, Inc., // along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#ifndef OST_SEQUENCE_VIEWER_ROW #ifndef OST_SEQUENCE_VIEWER_BASE_ROW
#define OST_SEQUENCE_VIEWER_ROW #define OST_SEQUENCE_VIEWER_BASE_ROW
/* /*
Author: Stefan Scheuber Author: Stefan Scheuber
...@@ -37,15 +37,24 @@ class BaseRow : public QObject ...@@ -37,15 +37,24 @@ class BaseRow : public QObject
public: public:
BaseRow(QObject *parent = 0); BaseRow(QObject *parent = 0);
BaseRow(QFont font, QObject *parent = 0);
void Init();
virtual int GetColumnCount() const;
void InsertPainter(Painter* painter, int pos = -1); void InsertPainter(Painter* painter, int pos = -1);
void RemovePainter(Painter* painter); void RemovePainter(Painter* painter);
Painter* GetPainter(int pos); Painter* GetPainter(int pos);
int GetPainterCount(); int GetPainterCount();
const PainterList& GetPainters() const; const PainterList& GetPainters() const;
const QFont& GetFont() const;
void SetFont(const QFont& font);
const QSize& GetFontSize() const;
virtual const QSize& GetCellSize() const;
virtual QVariant GetData(int column, int role) const; virtual QVariant GetData(int column, int role) const;
virtual bool SetData(int column, const QVariant& value, int role); virtual bool SetData(int column, const QVariant& value, int role);
virtual Qt::ItemFlags Flags(int column) const; virtual Qt::ItemFlags Flags(int column) const;
...@@ -54,6 +63,9 @@ public: ...@@ -54,6 +63,9 @@ public:
private: private:
bool IsPainterPosValid(int pos); bool IsPainterPosValid(int pos);
PainterList painter_; PainterList painter_;
QFont font_;
QSize default_font_size_;
QSize default_cell_size_;
}; };
typedef QList<BaseRow*> BaseRowList; typedef QList<BaseRow*> BaseRowList;
......
//------------------------------------------------------------------------------
// 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 <ost/mol/mol.hh>
#include <ost/mol/view_op.hh>
#include <ost/gfx/entity.hh>
#include "secstr_row.hh"
namespace ost { namespace gui {
SecStrRow::SecStrRow(const QString& name, mol::ChainView& chain, ViewObject* parent) : SequenceRow(name,parent)
{ this->SetChain(chain); }
void SecStrRow::SetSequence(seq::SequenceHandle& sequence)
{
//Do nothing
}
void SecStrRow::SetChain(mol::ChainView& chain)
{
String seq_str;
seq_str.reserve(chain.GetResidueCount());
for (mol::ResidueViewList::const_iterator r=chain.GetResidueList().begin(),
e2=chain.GetResidueList().end(); r!=e2; ++r) {
mol::ResidueView res=*r;
seq_str.append(1, res.GetOneLetterCode());
}
if (!seq_str.empty()) {
seq::SequenceHandle sequence=seq::CreateSequence(this->GetName().toStdString(), seq_str);
mol::EntityView v_one_chain=chain.GetEntity().GetHandle().CreateEmptyView();
v_one_chain.AddChain(chain, mol::ViewAddFlag::INCLUDE_ALL);
sequence.AttachView(v_one_chain);
mol::alg::SecStructureSegments sec = mol::alg::ExtractSecStructureSegments(chain);
secstr_ = QVarLengthArray<mol::SecStructure>(chain.GetResidueCount());
for (mol::alg::SecStructureSegments::iterator i=sec.begin(),
e=sec.end(); i!=e; ++i) {
mol::alg::SecStructureSegment s=*i;
for(int i = s.first; i <= s.last ;i++){
secstr_[i] = s.ss_type;
}
}
this->chain_ = chain;
this->SetSequence(sequence);
}
}
QVariant SecStrRow::GetData(int column, int role) const
{
if(column > 0 && column < this->GetSequence().GetLength()){
if (role==Qt::UserRole){
QVariant variant;
variant.setValue(secstr_);
return variant;
}
if (role==Qt::UserRole+1){
return QVariant(this->GetFontSize());
}
}
return SequenceRow::GetData(column, role);
}
void SecStrRow::DoubleClicked(int column)
{
if(column>0){
column-=1;
if(this->secstr_.size()>0 && column < this->secstr_.size()){
mol::SecStructure& src_str = this->secstr_[column];
QVarLengthArray<bool> src_type(3);
src_type[0] = src_str.IsHelical();
src_type[1] = src_str.IsExtended();
src_type[2] = src_str.IsCoil();
int i = column;
QSet<int> cols_to_add;
mol::SecStructure& col_str = this->secstr_[i];
while(i >= 0 && (col_str = this->secstr_[i])){
if(src_type[0] == col_str.IsHelical()
&& src_type[1] == col_str.IsExtended()
&& src_type[2] == col_str.IsCoil()){
cols_to_add.insert(i+1);
--i;
}
else{break;}
}
i = column + 1;
if(i < this->secstr_.size()){
while(i < this->secstr_.size() && (col_str = this->secstr_[i])){
if(src_type[0] == col_str.IsHelical()
&& src_type[1] == col_str.IsExtended()
&& src_type[2] == col_str.IsCoil()){
cols_to_add.insert(i+1);
++i;
}
else{
break;
}
}
}
this->SetSelection(cols_to_add, QSet<int>());
}
}
else{
SequenceRow::DoubleClicked(column);
}
}
}}
//------------------------------------------------------------------------------
// 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_SECSTR_ROW
#define OST_SEQUENCE_VIEWER_SECSTR_ROW
/*
Author: Stefan Scheuber
*/
#include <QObject>
#include <QVarLengthArray>
#include <ost/mol/chain_view.hh>
#include <ost/mol/alg/sec_structure_segments.hh>
#include "sequence_row.hh"
namespace ost { namespace gui {
class SecStrRow : public SequenceRow
{
Q_OBJECT
public:
SecStrRow(const QString& name, mol::ChainView& chain, ViewObject* parent);
virtual QVariant GetData(int column, int role) const;
virtual void DoubleClicked(int column);
void SetSequence(seq::SequenceHandle& sequence);
void SetChain(mol::ChainView& chain);
private:
mol::ChainView chain_;
QVarLengthArray<mol::SecStructure> secstr_;
};
typedef QList<BaseRow*> BaseRowList;
}}
Q_DECLARE_METATYPE(QVarLengthArray<ost::mol::SecStructure>)
#endif
//------------------------------------------------------------------------------
// 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 <ost/mol/mol.hh>
#include <ost/mol/view_op.hh>
#include <ost/gfx/entity.hh>
#include "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), sequence_(sequence)
{ }
SequenceRow::SequenceRow(const QString& name, ViewObject* parent) : BaseRow(QFont("Courier",11),parent), name_(name)
{ }
int SequenceRow::GetColumnCount() const
{
return sequence_.GetLength()+1;
}
void SequenceRow::SetName(const QString& name)
{
this->name_ = name;
}
const QString& SequenceRow::GetName()
{
return this->name_;
}
void SequenceRow::SetSequence(seq::SequenceHandle& sequence)
{
this->sequence_ = sequence;
}
const seq::SequenceHandle& SequenceRow::GetSequence() const
{
return this->sequence_;
}
QVariant SequenceRow::GetData(int column, int role) const
{
if(column<0 || column > sequence_.GetLength())return QVariant();
if(column == 0) {
if (role == Qt::DisplayRole){
return QVariant(this->name_);
}
}
else if(column > 0) {
if (role==Qt::DisplayRole) {
return QVariant(QString(this->sequence_.GetOneLetterCode(column - 1)));
}
if (role==Qt::FontRole){
return QVariant(this->GetFont());
}
if (role==Qt::SizeHintRole){
return QVariant(this->GetCellSize());
}
}
return QVariant();
}
Qt::ItemFlags SequenceRow::Flags(int column) const
{
if(column<0 || column > this->GetColumnCount())return Qt::NoItemFlags;
if(column==0){
return Qt::ItemIsSelectable|Qt::ItemIsEnabled;
}
else if(column>0){
return Qt::ItemIsSelectable|Qt::ItemIsEnabled;
}
return BaseRow::Flags(column);
}
void SequenceRow::DoubleClicked(int column)
{
QSet<int> all;
int seq_length = this->sequence_.GetLength();
for(int i = 0; i < seq_length; i++){
all.insert(i+1);
}
this->SetSelection(all,QSet<int>());
}
void SequenceRow::SetSelection(const QSet<int>& added, const QSet<int>& removed)
{
ViewObject* view_object = qobject_cast<ViewObject*>(this->parent());
if(view_object){
if(gfx::EntityP entity = view_object->GetGfxObject()){
mol::EntityView sel = entity->GetSelection();
mol::EntityView view = this->sequence_.GetAttachedView().GetHandle().CreateEmptyView();
QSetIterator<int> i(removed);
while (i.hasNext()){
int column = i.next()-1;
if(column >= 0 && column < this->sequence_.GetLength()){
if (mol::ResidueView rv = this->sequence_.GetResidue(this->sequence_.GetResidueIndex(column))) {
view.AddResidue(rv, mol::ViewAddFlag::INCLUDE_ATOMS);
}
}
}
sel = mol::Difference(sel,view);
view = this->sequence_.GetAttachedView().GetHandle().CreateEmptyView();
i = QSetIterator<int>(added);
while (i.hasNext()){
int column = i.next()-1;
if(column >= 0 && column < this->sequence_.GetLength()){
if (mol::ResidueView rv=this->sequence_.GetResidue(this->sequence_.GetResidueIndex(column))) {
view.AddResidue(rv, mol::ViewAddFlag::INCLUDE_ATOMS);
}
}
}
sel = mol::Union(sel,view);
sel.AddAllInclusiveBonds();
entity->SetSelection(sel);
}
}
}
}}
//------------------------------------------------------------------------------
// 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_SEQUENCE_ROW
#define OST_SEQUENCE_VIEWER_SEQUENCE_ROW
/*
Author: Stefan Scheuber
*/
#include <QObject>
#include <ost/seq/sequence_handle.hh>
#include "base_row.hh"
namespace ost { namespace gui {
class ViewObject;
class SequenceRow : public BaseRow
{
Q_OBJECT
public:
SequenceRow(const QString& name, seq::SequenceHandle& sequence, ViewObject* parent);
SequenceRow(const QString& name, ViewObject* parent);
virtual int GetColumnCount() const;
virtual QVariant GetData(int column, int role) const;
virtual Qt::ItemFlags Flags(int column) const;
virtual void DoubleClicked(int column);
void SetName(const QString& name);
const QString& GetName();
virtual void SetSequence(seq::SequenceHandle& sequence);
const seq::SequenceHandle& GetSequence() const;
void SetSelection(const QSet<int>& added, const QSet<int>& removed);
private:
QString name_;
seq::SequenceHandle sequence_;
};
typedef QList<BaseRow*> BaseRowList;
}}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment