Skip to content
Snippets Groups Projects
Commit 9b33e127 authored by stefan's avatar stefan
Browse files

New SequenceViewer, use sequencedelegate to render

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2161 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent ef04b57c
No related branches found
No related tags found
No related merge requests found
...@@ -67,4 +67,9 @@ bool Row::IsPosValid(int pos) ...@@ -67,4 +67,9 @@ bool Row::IsPosValid(int pos)
return false; return false;
} }
const PainterList& Row::GetPainters() const
{
return painter_;
}
}} }}
...@@ -44,6 +44,8 @@ public: ...@@ -44,6 +44,8 @@ public:
Painter* GetPainter(int pos); Painter* GetPainter(int pos);
int GetPainterCount(); int GetPainterCount();
const PainterList& GetPainters() const;
private: private:
bool IsPosValid(int pos); bool IsPosValid(int pos);
PainterList painter_; PainterList painter_;
... ...
......
...@@ -29,22 +29,15 @@ namespace ost { namespace gui { ...@@ -29,22 +29,15 @@ namespace ost { namespace gui {
SequenceDelegate::SequenceDelegate(SequenceModel* seq_model, QObject *parent) SequenceDelegate::SequenceDelegate(SequenceModel* seq_model, QObject *parent)
: QItemDelegate(parent), seq_model_(seq_model) : QItemDelegate(parent), seq_model_(seq_model)
{ {}
QFontMetrics metrics = QFontMetrics(QFont("Courier",10));
default_size = QSize(metrics.width(QString("_"))+2,metrics.height()+2);
}
void SequenceDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, void SequenceDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const const QModelIndex &index) const
{ {
/* Row* row = seq_model_->GetRow(index); const PainterList& painters = seq_model_->GetPainters(index);
for(int i=0; i < row->GetPainterCount(); i++){ for(int i=0; i < painters.size(); i++){
row->GetPainter(i)->Paint(painter, option, index); painters[i]->Paint(painter, option, index);
}*/
} }
QSize& SequenceDelegate::GetDefaultSize(){
return default_size;
} }
}} }}
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include <QItemDelegate> #include <QItemDelegate>
#include <QModelIndex> #include <QModelIndex>
#include "sequence_table_view.hh"
#include "sequence_model.hh" #include "sequence_model.hh"
namespace ost { namespace gui { namespace ost { namespace gui {
... ...
......
...@@ -35,7 +35,7 @@ SequenceModel::SequenceModel(QObject *parent) ...@@ -35,7 +35,7 @@ SequenceModel::SequenceModel(QObject *parent)
void SequenceModel::InsertSequence(QString& name, seq::SequenceHandle& seq){ void SequenceModel::InsertSequence(QString& name, seq::SequenceHandle& seq){
int cols = this->columnCount(); int cols = this->columnCount();
int new_cols = cols + seq.GetLength(); int new_cols = seq.GetLength();
this->beginInsertRows(QModelIndex(),this->rowCount(),this->rowCount()); this->beginInsertRows(QModelIndex(),this->rowCount(),this->rowCount());
objects_.append(new ViewObject(seq, name, this)); objects_.append(new ViewObject(seq, name, this));
if(new_cols > cols){ if(new_cols > cols){
...@@ -70,6 +70,11 @@ ViewObject* SequenceModel::GetObject(QString& name){ ...@@ -70,6 +70,11 @@ ViewObject* SequenceModel::GetObject(QString& name){
return NULL; return NULL;
} }
const PainterList& SequenceModel::GetPainters(const QModelIndex& index) const{
QPair<int, ViewObject*> pair = this->GetItem(index);
return pair.second->GetRow(pair.first)->GetPainters();
}
QPair<int, ViewObject*> SequenceModel::GetItem(const QModelIndex& index) const{ QPair<int, ViewObject*> SequenceModel::GetItem(const QModelIndex& index) const{
if(!objects_.isEmpty()){ if(!objects_.isEmpty()){
int ind_row = index.row(); int ind_row = index.row();
... ...
......
...@@ -45,6 +45,7 @@ public: ...@@ -45,6 +45,7 @@ public:
void RemoveSequence(QString& name); void RemoveSequence(QString& name);
ViewObject* GetObject(QString& name); ViewObject* GetObject(QString& name);
const PainterList& GetPainters(const QModelIndex& index) const;
QPair<int, ViewObject*> GetItem(const QModelIndex& index) const; QPair<int, ViewObject*> GetItem(const QModelIndex& index) const;
... ...
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <iostream> #include <iostream>
#include "sequence_table_view.hh" #include "sequence_table_view.hh"
#include "sequence_model.hh"
namespace ost { namespace gui { namespace ost { namespace gui {
...@@ -112,6 +113,8 @@ SequenceTableView::SequenceTableView(QAbstractItemModel * model) ...@@ -112,6 +113,8 @@ SequenceTableView::SequenceTableView(QAbstractItemModel * model)
connect(column_not_move_->verticalScrollBar(), SIGNAL(valueChanged(int)), this->verticalScrollBar(), SLOT(setValue(int))); connect(column_not_move_->verticalScrollBar(), SIGNAL(valueChanged(int)), this->verticalScrollBar(), SLOT(setValue(int)));
connect(verticalScrollBar(), SIGNAL(valueChanged(int)), column_not_move_->verticalScrollBar(), SLOT(setValue(int))); connect(verticalScrollBar(), SIGNAL(valueChanged(int)), column_not_move_->verticalScrollBar(), SLOT(setValue(int)));
delegate_ = new SequenceDelegate(qobject_cast<SequenceModel*>(this->model()),this);
} }
void SequenceTableView::ResizeWidth(int index, int, int size) void SequenceTableView::ResizeWidth(int index, int, int size)
...@@ -163,8 +166,9 @@ void SequenceTableView::updateNotMoveColumn() ...@@ -163,8 +166,9 @@ void SequenceTableView::updateNotMoveColumn()
void SequenceTableView::columnCountChanged(const QModelIndex& index, int old_count, int new_count){ void SequenceTableView::columnCountChanged(const QModelIndex& index, int old_count, int new_count){
if(old_count >= 0 && old_count <= new_count){ if(old_count >= 0 && old_count <= new_count){
if(old_count == 0)old_count = 1; if(old_count == 0)old_count = 1;
for(int col=old_count; col<new_count; col++){ for(int col=old_count; col<=new_count; col++){
column_not_move_->setColumnHidden(col, true); column_not_move_->setColumnHidden(col, true);
this->setItemDelegateForColumn(col, delegate_);
} }
} }
} }
... ...
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include <ost/gui/module_config.hh> #include <ost/gui/module_config.hh>
#include "sequence_delegate.hh"
namespace ost { namespace gui { namespace ost { namespace gui {
/// \brief QTableView with first column not moving /// \brief QTableView with first column not moving
...@@ -51,6 +53,7 @@ private slots: ...@@ -51,6 +53,7 @@ private slots:
private: private:
QTableView* column_not_move_; QTableView* column_not_move_;
SequenceDelegate* delegate_;
void updateNotMoveColumn(); void updateNotMoveColumn();
}; };
... ...
......
...@@ -54,10 +54,9 @@ SequenceViewerV2::SequenceViewerV2(QWidget* parent): Widget(NULL,parent) ...@@ -54,10 +54,9 @@ SequenceViewerV2::SequenceViewerV2(QWidget* parent): Widget(NULL,parent)
layout->addWidget(seq_table_view_); layout->addWidget(seq_table_view_);
this->setLayout(layout); this->setLayout(layout);
connect(model_,SIGNAL(columnsInserted(const QModelIndex&, int, int)),seq_table_view_,SLOT(columnCountChanged(const QModelIndex&, int, int))); connect(model_,SIGNAL(columnsInserted(const QModelIndex&, int, int)),seq_table_view_,SLOT(columnCountChanged(const QModelIndex&, int, int)));
/*
seq_table_view_->horizontalHeader()->setMinimumSectionSize(2); seq_table_view_->horizontalHeader()->setMinimumSectionSize(2);
seq_table_view_->verticalHeader()->setMinimumSectionSize(2); seq_table_view_->verticalHeader()->setMinimumSectionSize(2);
*/
} }
void SequenceViewerV2::NodeAdded(const gfx::GfxNodeP& n) void SequenceViewerV2::NodeAdded(const gfx::GfxNodeP& n)
... ...
......
...@@ -37,11 +37,20 @@ ViewObject::ViewObject(seq::SequenceList& sequences, const QString& name, QObjec ...@@ -37,11 +37,20 @@ ViewObject::ViewObject(seq::SequenceList& sequences, const QString& name, QObjec
seq::SequenceHandle seq = sequences[i]; seq::SequenceHandle seq = sequences[i];
this->AddSequence(seq); this->AddSequence(seq);
} }
this->Init();
} }
ViewObject::ViewObject(seq::SequenceHandle& sequence, const QString& name, QObject *parent): QObject(parent), name_(name) ViewObject::ViewObject(seq::SequenceHandle& sequence, const QString& name, QObject *parent): QObject(parent), name_(name)
{ {
this->AddSequence(sequence); this->AddSequence(sequence);
this->Init();
}
void ViewObject::Init()
{
font_ = QFont("Courier",10);
QFontMetrics metrics = QFontMetrics(font_);
default_size_ = QSize(metrics.width(QString("_"))+2,metrics.height()+2);
} }
void ViewObject::InsertRow(int pos, Row* row) void ViewObject::InsertRow(int pos, Row* row)
...@@ -103,6 +112,12 @@ QVariant ViewObject::GetData(int row, int column, int role) ...@@ -103,6 +112,12 @@ QVariant ViewObject::GetData(int row, int column, int role)
if (role==Qt::DisplayRole) { if (role==Qt::DisplayRole) {
return QVariant(QString(rows_[row].second.GetOneLetterCode(column - 1))); return QVariant(QString(rows_[row].second.GetOneLetterCode(column - 1)));
} }
if (role==Qt::FontRole){
return QVariant(font_);
}
if (role==Qt::SizeHintRole){
return QVariant(default_size_);
}
} }
return QVariant(); return QVariant();
} }
... ...
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include <QObject> #include <QObject>
#include <QPair> #include <QPair>
#include <QList> #include <QList>
#include <QFont>
#include <QSize>
#include <ost/seq/sequence_list.hh> #include <ost/seq/sequence_list.hh>
...@@ -62,8 +64,11 @@ public: ...@@ -62,8 +64,11 @@ public:
private: private:
void Init();
QString name_; QString name_;
QList<QPair<Row*, seq::SequenceHandle> > rows_; QList<QPair<Row*, seq::SequenceHandle> > rows_;
QFont font_;
QSize default_size_;
}; };
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment