diff --git a/modules/gui/src/CMakeLists.txt b/modules/gui/src/CMakeLists.txt index d58e43808d8b7d4db0e6fa3a850ccbc90093a2dd..83cc8752a4415f283e25add69b1e00e45cb167df 100644 --- a/modules/gui/src/CMakeLists.txt +++ b/modules/gui/src/CMakeLists.txt @@ -21,9 +21,14 @@ sequence_search_bar.hh ) set(OST_GUI_SEQUENCE_VIEW_HEADERS +painter.hh +row.hh +seq_text_painter.hh +sequence_delegate.hh +sequence_model.hh sequence_table_view.hh sequence_viewer.hh -sequence_delegate.hh +view_object.hh ) set(OST_GUI_TOOLS_HEADERS @@ -199,9 +204,13 @@ sequence_viewer/sequence_viewer_base.cc sequence_viewer/sequence_viewer.cc sequence_viewer/sequence_scene.cc sequence_viewer/sequence_search_bar.cc +sequence/row.cc +sequence/seq_text_painter.cc +sequence/sequence_delegate.cc +sequence/sequence_model.cc sequence/sequence_table_view.cc sequence/sequence_viewer.cc -sequence/sequence_delegate.cc +sequence/view_object.cc gosty_app.cc change_process_name.cc main_area.cc @@ -318,9 +327,14 @@ sequence_viewer/sequence_viewer_base.hh sequence_viewer/sequence_viewer.hh sequence_viewer/sequence_scene.hh sequence_viewer/sequence_search_bar.hh +sequence/painter.hh +sequence/row.hh +sequence/seq_text_painter.hh +sequence/sequence_delegate.hh +sequence/sequence_model.hh sequence/sequence_table_view.hh sequence/sequence_viewer.hh -sequence/sequence_delegate.hh +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/main.cpp b/modules/gui/src/sequence/main.cpp deleted file mode 100644 index 108814dbe0545a64f0af73f3f9d3e321f45c55e6..0000000000000000000000000000000000000000 --- a/modules/gui/src/sequence/main.cpp +++ /dev/null @@ -1,86 +0,0 @@ - /**************************************************************************** - ** - ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). - ** All rights reserved. - ** Contact: Nokia Corporation (qt-info@nokia.com) - ** - ** This file is part of the examples of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:LGPL$ - ** Commercial Usage - ** Licensees holding valid Qt Commercial licenses may use this file in - ** accordance with the Qt Commercial License Agreement provided with the - ** Software or, alternatively, in accordance with the terms contained in - ** a written agreement between you and Nokia. - ** - ** GNU Lesser General Public License Usage - ** Alternatively, this file may be used under the terms of the GNU Lesser - ** General Public License version 2.1 as published by the Free Software - ** Foundation and appearing in the file LICENSE.LGPL included in the - ** packaging of this file. Please review the following information to - ** ensure the GNU Lesser General Public License version 2.1 requirements - ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. - ** - ** In addition, as a special exception, Nokia gives you certain additional - ** rights. These rights are described in the Nokia Qt LGPL Exception - ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. - ** - ** GNU General Public License Usage - ** Alternatively, this file may be used under the terms of the GNU - ** General Public License version 3.0 as published by the Free Software - ** Foundation and appearing in the file LICENSE.GPL included in the - ** packaging of this file. Please review the following information to - ** ensure the GNU General Public License version 3.0 requirements will be - ** met: http://www.gnu.org/copyleft/gpl.html. - ** - ** If you have questions regarding the use of this file, please contact - ** Nokia at qt-info@nokia.com. - ** $QT_END_LICENSE$ - ** - ****************************************************************************/ - - #include <QApplication> - #include <QStandardItemModel> - #include <QFile> - - #include "freezetablewidget.h" - - int main( int argc, char** argv ) - { - - Q_INIT_RESOURCE(grades); - - QApplication app( argc, argv ); - QStandardItemModel *model=new QStandardItemModel(); - - QFile file(":/grades.txt"); - QString line; - QStringList list; - if (file.open(QFile::ReadOnly)) { - line = file.readLine(200); - list= line.simplified().split(","); - model->setHorizontalHeaderLabels(list); - - int row=0; - QStandardItem *newItem=0; - while(file.canReadLine()){ - line = file.readLine(200); - if(!line.startsWith("#") && line.contains(",")){ - list= line.simplified().split(","); - for(int col=0; col<list.length(); col++){ - newItem = new QStandardItem(list.at(col)); - model->setItem(row ,col, newItem); - } - row++; - } - } - } - file.close(); - - FreezeTableWidget *tableView = new FreezeTableWidget(model); - - tableView->setWindowTitle(QObject::tr("Frozen Column Example")); - tableView->resize(560,680); - tableView->show(); - return app.exec(); - } diff --git a/modules/gui/src/sequence/painter.hh b/modules/gui/src/sequence/painter.hh new file mode 100644 index 0000000000000000000000000000000000000000..4c84fd61edb34b808a4119587692b6ab9884b913 --- /dev/null +++ b/modules/gui/src/sequence/painter.hh @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// 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_PAINTER +#define OST_SEQUENCE_VIEWER_PAINTER + +/* + Author: Stefan Scheuber + */ + +#include <QObject> +#include <QPainter> +#include <QStyleOptionViewItem> +#include <QModelIndex> +#include <QList> + +namespace ost { namespace gui { + +class Painter : public QObject +{ + Q_OBJECT + +public: + Painter(QObject* parent = 0):QObject(parent){}; + virtual void Paint(QPainter* painter, const QStyleOptionViewItem& option, + const QModelIndex& index) = 0; + +}; + +typedef QList<Painter*> PainterList; + +}} + +#endif diff --git a/modules/gui/src/sequence/row.cc b/modules/gui/src/sequence/row.cc new file mode 100644 index 0000000000000000000000000000000000000000..8846f1913224d5bd42b7be4ce47f2ac88f65512a --- /dev/null +++ b/modules/gui/src/sequence/row.cc @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// 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 "row.hh" + +namespace ost { namespace gui { + +Row::Row(QObject *parent) : QObject(parent) +{ } + +void Row::InsertPainter(Painter* painter, int pos) +{ + if(pos == -1 || pos == painter_.size()){ + painter_.append(painter); + } + else if(this->IsPosValid(pos)){ + painter_.insert(pos, painter); + } +} + +void Row::RemovePainter(Painter* painter) +{ + painter_.removeAll(painter); +} + +Painter* Row::GetPainter(int pos) +{ + if(this->IsPosValid(pos)){ + return painter_[pos]; + } + return NULL; +} + +int Row::GetPainterCount() +{ + return painter_.size(); +} + +bool Row::IsPosValid(int pos) +{ + if(pos >= 0 && pos < painter_.size()){ + return true; + } + return false; +} + +}} diff --git a/modules/gui/src/sequence/row.hh b/modules/gui/src/sequence/row.hh new file mode 100644 index 0000000000000000000000000000000000000000..161e251a601c81810f9e53b504bf25be3c57547d --- /dev/null +++ b/modules/gui/src/sequence/row.hh @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// 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_ROW +#define OST_SEQUENCE_VIEWER_ROW + +/* + Author: Stefan Scheuber + */ + +#include <QObject> +#include <QModelIndex> +#include <QList> + +#include "painter.hh" + +namespace ost { namespace gui { + +class Row : public QObject +{ + Q_OBJECT + +public: + Row(QObject *parent = 0); + + void InsertPainter(Painter* painter, int pos = -1); + void RemovePainter(Painter* painter); + + Painter* GetPainter(int pos); + int GetPainterCount(); + +private: + bool IsPosValid(int pos); + PainterList painter_; +}; + +typedef QList<Row*> RowList; + +}} + +#endif diff --git a/modules/gui/src/sequence/seq_text_painter.cc b/modules/gui/src/sequence/seq_text_painter.cc new file mode 100644 index 0000000000000000000000000000000000000000..9ac48a688cdd8baf5b3dcfbf374d35bf63988353 --- /dev/null +++ b/modules/gui/src/sequence/seq_text_painter.cc @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// 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 "seq_text_painter.hh" + +namespace ost { namespace gui { + +SeqTextPainter::SeqTextPainter(QObject* parent) + : Painter(parent) +{} + +void SeqTextPainter::Paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index){ + painter->save(); + painter->setPen(QPen(Qt::black)); + QVariant value = index.data(Qt::DisplayRole); + if (value.isValid()){ + QString text = value.toString(); + painter->setFont(QFont("Courier",10)); + painter->drawText(option.rect, Qt::AlignLeft|Qt::AlignVCenter, text); + } + painter->restore(); +} + +}} diff --git a/modules/gui/src/sequence/seq_text_painter.hh b/modules/gui/src/sequence/seq_text_painter.hh new file mode 100644 index 0000000000000000000000000000000000000000..429394cb4bca349b3bc67a9269fbda2048954223 --- /dev/null +++ b/modules/gui/src/sequence/seq_text_painter.hh @@ -0,0 +1,43 @@ +//------------------------------------------------------------------------------ +// 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_SEQ_TEXT_PAINTER +#define OST_SEQUENCE_VIEWER_SEQ_TEXT_PAINTER + +/* + Author: Stefan Scheuber + */ + +#include <QObject> + +#include "painter.hh" + +namespace ost { namespace gui { + +class SeqTextPainter : public Painter +{ + Q_OBJECT +public: + SeqTextPainter(QObject* parent = 0); + void Paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index); +}; + +}} + +#endif diff --git a/modules/gui/src/sequence/sequence_delegate.cc b/modules/gui/src/sequence/sequence_delegate.cc index 6e5a7a5cb64b6b6cb39ed7cf29d2e22c28b545e1..a152298e7e375ce61afa867a74156d2d9fd44112 100644 --- a/modules/gui/src/sequence/sequence_delegate.cc +++ b/modules/gui/src/sequence/sequence_delegate.cc @@ -23,56 +23,28 @@ #include <QtGui> -#include <iostream> #include "sequence_delegate.hh" namespace ost { namespace gui { -SequenceDelegate::SequenceDelegate(SequenceTableView* view, QObject *parent) - : QItemDelegate(parent), view_(view) +SequenceDelegate::SequenceDelegate(SequenceModel* seq_model, QObject *parent) + : QItemDelegate(parent), seq_model_(seq_model) { - + QFontMetrics metrics = QFontMetrics(QFont("Courier",10)); + default_size = QSize(metrics.width(QString("_"))+2,metrics.height()+2); } -/* -QWidget *SequenceDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const -{ - QSpinBox *editor = new QSpinBox(parent); - editor->setMinimum(0); - editor->setMaximum(100); - - return editor; -} -*/ - void SequenceDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - painter->save(); - - painter->setPen(QPen(Qt::NoPen)); - if(option.state & QStyle::State_Selected){ - painter->setBrush(option.palette.highlight()); - } - else{ - painter->setBrush(QBrush(Qt::white)); - } - painter->drawRect(option.rect); +/* Row* row = seq_model_->GetRow(index); + for(int i=0; i < row->GetPainterCount(); i++){ + row->GetPainter(i)->Paint(painter, option, index); + }*/ +} - painter->setPen(QPen(Qt::lightGray)); - if(index.column()%2){ - painter->drawLine(option.rect.topLeft(),option.rect.bottomRight()); - } - else{ - painter->drawLine(option.rect.bottomLeft(),option.rect.topRight()); - } - painter->setPen(QPen(Qt::black)); - QVariant value = index.data(Qt::DisplayRole); - if (value.isValid()){ - QString text = value.toString(); - painter->setFont(QFont("Courier",10)); - painter->drawText(option.rect, Qt::AlignLeft|Qt::AlignVCenter, text); - } - painter->restore(); +QSize& SequenceDelegate::GetDefaultSize(){ + return default_size; } + }} diff --git a/modules/gui/src/sequence/sequence_delegate.hh b/modules/gui/src/sequence/sequence_delegate.hh index da820e5cd5c05e80c65ffcfdda00c337635ca258..5629a355bf6809c4641d5550db7a6c9dbffff1c6 100644 --- a/modules/gui/src/sequence/sequence_delegate.hh +++ b/modules/gui/src/sequence/sequence_delegate.hh @@ -25,11 +25,9 @@ #include <QItemDelegate> #include <QModelIndex> -#include <QObject> -#include <QSize> -#include <QSpinBox> #include "sequence_table_view.hh" +#include "sequence_model.hh" namespace ost { namespace gui { @@ -38,15 +36,14 @@ class SequenceDelegate : public QItemDelegate Q_OBJECT public: - SequenceDelegate(SequenceTableView* view, QObject *parent = 0); - - /* QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, - const QModelIndex &index) const;*/ + SequenceDelegate(SequenceModel* seq_model, QObject *parent = 0); void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + QSize& GetDefaultSize(); private: - SequenceTableView* view_; + SequenceModel* seq_model_; + QSize default_size; }; diff --git a/modules/gui/src/sequence/sequence_model.cc b/modules/gui/src/sequence/sequence_model.cc new file mode 100644 index 0000000000000000000000000000000000000000..1fdf5730d654532d47dab48d64764c1dd791a6e5 --- /dev/null +++ b/modules/gui/src/sequence/sequence_model.cc @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// 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 "sequence_model.hh" + +namespace ost { namespace gui { + +SequenceModel::SequenceModel(QObject *parent) + : QAbstractTableModel(parent) +{ +} + +void SequenceModel::InsertSequence(QString& name, seq::SequenceHandle& seq){ + int cols = this->columnCount(); + int new_cols = cols + seq.GetLength(); + this->beginInsertRows(QModelIndex(),this->rowCount(),this->rowCount()); + objects_.append(new ViewObject(seq, name, this)); + if(new_cols > cols){ + this->beginInsertColumns(QModelIndex(), cols, new_cols); + this->endInsertColumns(); + } + this->endInsertRows(); +} + +void SequenceModel::InsertSequences(QString& name, seq::SequenceList& list){ + this->beginInsertRows(this->index(this->rowCount(),0),this->rowCount(),this->rowCount()+list.GetCount()); + objects_.append(new ViewObject(list, name, this)); + this->endInsertRows(); +} + +void SequenceModel::RemoveSequence(QString& name){ + ViewObject* obj = this->GetObject(name); + if(obj){ + int index = objects_.indexOf(obj); + this->beginRemoveRows(QModelIndex(),index,index); + objects_.removeAt(index); + this->endRemoveRows(); + } +} + +ViewObject* SequenceModel::GetObject(QString& name){ + for (int i = 0 ; i< objects_.size(); i++){ + if(name == objects_[i]->GetName()){ + return objects_[i]; + } + } + return NULL; +} + +QPair<int, ViewObject*> SequenceModel::GetItem(const QModelIndex& index) const{ + if(!objects_.isEmpty()){ + int ind_row = index.row(); + int rows = 0; + int i = 0; + while (i < objects_.size() && rows < ind_row){ + i++; + rows += objects_[i]->GetRowCount(); + } + int sub_index = ind_row - rows; + return QPair<int, ViewObject*>(sub_index, objects_[i]); + } + return QPair<int, ViewObject*>(-1, NULL); +} + +int SequenceModel::rowCount(const QModelIndex& parent) const +{ + int rows = 0; + for (int i = 0; i<objects_.size(); i++){ + rows += objects_[i]->GetRowCount(); + } + return rows; +} + +int SequenceModel::columnCount(const QModelIndex& parent) const +{ + int cols = 0; + for (int i = 0; i<objects_.size(); i++){ + int max_col = objects_[i]->GetMaxColumnCount(); + if(max_col >= cols) + cols = max_col+1; + } + return cols; +} + +QVariant SequenceModel::data(const QModelIndex& index, int role) const +{ + QPair<int, ViewObject*> item = this->GetItem(index); + if(!item.second) return QVariant(); + QVariant data = item.second->GetData(item.first,index.column(),role); + return data; +} + +QVariant SequenceModel::headerData(int section, Qt::Orientation orientation, + int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + return QVariant(""); + } + return QVariant(); +} + +Qt::ItemFlags SequenceModel::flags(const QModelIndex& index) const +{ + QPair<int, ViewObject*> item = GetItem(index); + if(item.second){ + return item.second->Flags(item.first, index.column()); + } + + return QAbstractItemModel::flags(index); +} + +}} diff --git a/modules/gui/src/sequence/sequence_model.hh b/modules/gui/src/sequence/sequence_model.hh new file mode 100644 index 0000000000000000000000000000000000000000..e025b0ddadabd1f5d8af286c9baed1435b5abd0a --- /dev/null +++ b/modules/gui/src/sequence/sequence_model.hh @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// 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_MODEL +#define OST_SEQUENCE_VIEWER_SEQUENCE_MODEL + +/* + Author: Stefan Scheuber + */ + +#include <QAbstractTableModel> + +#include <ost/seq/sequence_list.hh> + +#include "sequence_model.hh" +#include "view_object.hh" + +namespace ost { namespace gui { + +class SequenceModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + SequenceModel(QObject *parent = 0); + + void InsertSequence(QString& name, seq::SequenceHandle& seq); + void InsertSequences(QString& name, seq::SequenceList& list); + + void RemoveSequence(QString& name); + + ViewObject* GetObject(QString& name); + + QPair<int, ViewObject*> GetItem(const QModelIndex& index) const; + + // abstract item model interface + 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; + + virtual Qt::ItemFlags flags(const QModelIndex& index=QModelIndex()) const; + +private: + QList<ViewObject*> objects_; +}; + + +}} + +#endif diff --git a/modules/gui/src/sequence/sequence_table_view.cc b/modules/gui/src/sequence/sequence_table_view.cc index ff7655bc53f0eaacde11d08a705e33aba81bb1a2..10e16a597a7faa19dfec664d1c86ba6b4d21caef 100644 --- a/modules/gui/src/sequence/sequence_table_view.cc +++ b/modules/gui/src/sequence/sequence_table_view.cc @@ -60,6 +60,17 @@ SequenceTableView::SequenceTableView(QAbstractItemModel * model) "background-color: #47ce27;" "}"); + this->verticalHeader()->hide(); + this->horizontalHeader()->setStyleSheet( + "QHeaderView::section {" + "padding-bottom: 0px;" + "padding-top: 0px;" + "padding-left: 0px;" + "padding-right: 0px;" + "margin: 0px;" + "}" + ); + column_not_move_ = new QTableView(this); column_not_move_->setModel(this->model()); @@ -86,15 +97,7 @@ SequenceTableView::SequenceTableView(QAbstractItemModel * model) "padding: 0px; border-width: 0px; margin: 0px;}"); column_not_move_->setShowGrid(false); - column_not_move_->horizontalHeader()->setStyleSheet( - "QHeaderView::section {" - "padding-bottom: 0px;" - "padding-top: 0px;" - "padding-left: 0px;" - "padding-right: 0px;" - "margin: 0px;" - "}" - ); + column_not_move_->horizontalHeader()->setStyleSheet(this->horizontalHeader()->styleSheet()); this->setShowGrid(false); @@ -158,8 +161,9 @@ void SequenceTableView::updateNotMoveColumn() } void SequenceTableView::columnCountChanged(const QModelIndex& index, int old_count, int new_count){ - if(old_count > 1 && old_count <= new_count){ - for(int col=old_count-1; col<this->model()->columnCount(); col++){ + if(old_count >= 0 && old_count <= new_count){ + if(old_count == 0)old_count = 1; + for(int col=old_count; col<new_count; col++){ column_not_move_->setColumnHidden(col, true); } } diff --git a/modules/gui/src/sequence/sequence_viewer.cc b/modules/gui/src/sequence/sequence_viewer.cc index db2aca7eb8b386f8261e9c71e5ac915cd4f1a4a0..378c6f1813cdd7b0390cd1a8e46584b037d0a48a 100644 --- a/modules/gui/src/sequence/sequence_viewer.cc +++ b/modules/gui/src/sequence/sequence_viewer.cc @@ -22,7 +22,6 @@ */ #include <boost/pointer_cast.hpp> -#include <QStandardItem> #include <QVBoxLayout> #include <QPushButton> #include <QHeaderView> @@ -35,6 +34,8 @@ #include <ost/gfx/entity.hh> #include <ost/gfx/entity_fw.hh> +#include "sequence_model.hh" + #include "sequence_viewer.hh" #include "sequence_delegate.hh" @@ -45,31 +46,18 @@ namespace ost { namespace gui { SequenceViewerV2::SequenceViewerV2(QWidget* parent): Widget(NULL,parent) { gfx::Scene::Instance().AttachObserver(this); - QStandardItemModel* model=new QStandardItemModel(); + model_ = new SequenceModel(this); QVBoxLayout* layout = new QVBoxLayout(this); - seq_table_view_ = new SequenceTableView(model); + seq_table_view_ = new SequenceTableView(model_); layout->addWidget(seq_table_view_); - //seq_table_view_->setItemDelegateForColumn(2,new SequenceDelegate(seq_table_view_)); this->setLayout(layout); - connect(model,SIGNAL(columnsInserted(const QModelIndex&, int, int)),seq_table_view_,SLOT(columnCountChanged(const QModelIndex&, int, int))); - //QPushButton* pb = new QPushButton("BLABLA"); - //seq_table_view_->setIndexWidget(model->index(0,2),pb); - seq_table_view_->verticalHeader()->hide(); - seq_table_view_->horizontalHeader()->setStyleSheet( - "QHeaderView::section {" - "padding-bottom: 0px;" - "padding-top: 0px;" - "padding-left: 0px;" - "padding-right: 0px;" - "margin: 0px;" - "}" - ); - seq_table_view_->horizontalHeader()->setMinimumSectionSize(8); - seq_table_view_->horizontalHeader()->setDefaultSectionSize(10); - seq_table_view_->verticalHeader()->setMinimumSectionSize(8); - seq_table_view_->verticalHeader()->setDefaultSectionSize(10); + 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_->verticalHeader()->setMinimumSectionSize(2); + */ } void SequenceViewerV2::NodeAdded(const gfx::GfxNodeP& n) @@ -90,33 +78,15 @@ void SequenceViewerV2::NodeAdded(const gfx::GfxNodeP& n) if (seq_str.empty()) { continue; } - String name=o->GetName(); + QString name = QString(o->GetName().c_str()); if (chain.GetName()!="" && chain.GetName()!=" ") { - name+=" ("+chain.GetName()+")"; + name= name + " ("+chain.GetName().c_str()+")"; } - seq::SequenceHandle seq=seq::CreateSequence(name, seq_str); + seq::SequenceHandle sequence=seq::CreateSequence(name.toStdString(), seq_str); mol::EntityView v_one_chain=v.GetHandle().CreateEmptyView(); v_one_chain.AddChain(chain, mol::ViewAddFlag::INCLUDE_ALL); - seq.AttachView(v_one_chain); - QStandardItem* item = new QStandardItem(name.c_str()); - QStandardItemModel* model = qobject_cast<QStandardItemModel*>(seq_table_view_->model()); - SequenceDelegate* del = new SequenceDelegate(seq_table_view_,this); - if(model){ - int row = model->rowCount(); - model->setHeaderData(0, Qt::Horizontal, QObject::tr("") ); - model->setHeaderData(row, Qt::Vertical, QObject::tr("") ); - model->setItem(row, 0, item); - for(int i = 0; i< seq.GetLength(); i++){ - item = new QStandardItem(QString(seq.GetOneLetterCode(i))); - item->setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter); - item->setFont(QFont("Courier",10)); - QFontMetrics m = QFontMetrics(QFont("Courier",10)); - item->setSizeHint(QSize(m.width(QString(seq.GetOneLetterCode(i)))+2,m.height()+2)); - model->setItem(row, i+1, item); - model->setHeaderData(i+1, Qt::Horizontal, QObject::tr("") ); - seq_table_view_->setItemDelegateForColumn(i+1,del); - } - } + sequence.AttachView(v_one_chain); + model_->InsertSequence(name,sequence); } seq_table_view_->resizeColumnsToContents(); seq_table_view_->resizeRowsToContents(); diff --git a/modules/gui/src/sequence/sequence_viewer.hh b/modules/gui/src/sequence/sequence_viewer.hh index d81f887f93d474a1e4b94b75e4ad367520f4f018..494e477e99727868ef5efb01c097227c28b372a0 100644 --- a/modules/gui/src/sequence/sequence_viewer.hh +++ b/modules/gui/src/sequence/sequence_viewer.hh @@ -32,6 +32,7 @@ #include <ost/gui/module_config.hh> +#include "sequence_model.hh" #include "sequence_table_view.hh" namespace ost { namespace gui { @@ -50,6 +51,7 @@ public: virtual bool Save(const QString&){return true;}; private: + SequenceModel* model_; SequenceTableView* seq_table_view_; }; diff --git a/modules/gui/src/sequence/view_object.cc b/modules/gui/src/sequence/view_object.cc new file mode 100644 index 0000000000000000000000000000000000000000..bff516edc4491396ee060905af35bfa6559aae58 --- /dev/null +++ b/modules/gui/src/sequence/view_object.cc @@ -0,0 +1,152 @@ +//------------------------------------------------------------------------------ +// 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 "painter.hh" +#include "seq_text_painter.hh" + +#include "view_object.hh" + +namespace ost { namespace gui { + +ViewObject::ViewObject(seq::SequenceList& sequences, const QString& name, QObject *parent): QObject(parent), name_(name) +{ + for(int i=0; i<sequences.GetCount(); i++){ + seq::SequenceHandle seq = sequences[i]; + this->AddSequence(seq); + } +} + +ViewObject::ViewObject(seq::SequenceHandle& sequence, const QString& name, QObject *parent): QObject(parent), name_(name) +{ + this->AddSequence(sequence); +} + +void ViewObject::InsertRow(int pos, Row* row) +{ + if(pos >= 0 && pos <= rows_.size()){ + seq::SequenceHandle sequence = seq::SequenceHandle(); + QPair<Row*, seq::SequenceHandle> pair(row,sequence); + rows_.insert(pos,pair); + } +} + +void ViewObject::RemoveRow(Row* row) +{ + QList<int> rows_to_delete; + for (int i = 0; i < rows_.size(); ++i){ + if(rows_[i].first == row){ + rows_to_delete.append(i); + } + } + for (int i= 0; i < rows_to_delete.size(); ++i){ + rows_.removeAt(rows_to_delete[i]); + } +} + +Row* ViewObject::GetRow(int pos) +{ + if(pos >= 0 && pos < rows_.size()){ + return rows_[pos].first; + } + return NULL; +} + +int ViewObject::GetRowCount() +{ + return rows_.size(); +} + +void ViewObject::AddSequence(seq::SequenceHandle& sequence) +{ + Row* new_row = new Row(this); + Painter* p = new SeqTextPainter(this); + new_row->InsertPainter(p,0); + QPair<Row*, seq::SequenceHandle> pair(new_row,sequence); + rows_.append(pair); +} + +QVariant ViewObject::GetData(int row, int column, int role) +{ + if(row<0 || row >= rows_.size())return QVariant(); + + if(column<0 || column >= this->GetMaxColumnCount())return QVariant(); + + if(column == 0 && row == 0) { + if (role == Qt::DisplayRole){ + return QVariant(this->GetName()); + } + } + else if(column > 0) { + if (role==Qt::DisplayRole) { + return QVariant(QString(rows_[row].second.GetOneLetterCode(column - 1))); + } + } + return QVariant(); +} + +int ViewObject::GetMaxColumnCount() const +{ + int columns = 0; + for(int i = 0; i < rows_.size(); i++){ + int col_length = rows_[i].second.GetLength(); + if(columns < col_length){ + columns = rows_[i].second.GetLength() + 1; + } + } + return columns; +} + +bool ViewObject::SetData(int column, const QVariant& value, int role) +{ + return false; +} + +Qt::ItemFlags ViewObject::Flags(int row, int column) const +{ + if(row<0 || row >= rows_.size())return Qt::NoItemFlags; + + if(column<0 || column >= this->GetMaxColumnCount())return Qt::NoItemFlags; + + if(column==0){ + return Qt::ItemIsSelectable|Qt::ItemIsEnabled; + } + else if(column>0){ + return Qt::ItemIsSelectable|Qt::ItemIsEnabled; + } + return Qt::NoItemFlags; +} + +const QString& ViewObject::GetName() const +{ + return name_; +} + +void ViewObject::SetName(const QString& name) +{ + name_ = name; +} + +}} diff --git a/modules/gui/src/sequence/view_object.hh b/modules/gui/src/sequence/view_object.hh new file mode 100644 index 0000000000000000000000000000000000000000..e3d4dcc5a887772ab30c3d50b4a2cb897a8b3219 --- /dev/null +++ b/modules/gui/src/sequence/view_object.hh @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// 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_VIEW_OBJECT +#define OST_SEQUENCE_VIEWER_VIEW_OBJECT + +/* + Author: Stefan Scheuber + */ + +#include <QObject> +#include <QPair> +#include <QList> + +#include <ost/seq/sequence_list.hh> + +#include "row.hh" + + +namespace ost { namespace gui { + +class ViewObject : public QObject +{ + Q_OBJECT + +public: + ViewObject(seq::SequenceList& sequences, const QString& name, QObject* parent = 0); + ViewObject(seq::SequenceHandle& sequence, const QString& name, QObject* parent = 0); + + void InsertRow(int pos, Row* row); + void RemoveRow(Row* row); + + const QString& GetName() const; + void SetName(const QString& name); + + Row* GetRow(int pos); + int GetRowCount(); + int GetMaxColumnCount() const; + + void AddSequence(seq::SequenceHandle& sequence); + + QVariant GetData(int row, int column, int role); + + bool SetData(int column, const QVariant& value, int role); + + Qt::ItemFlags Flags(int row, int column) const; + + +private: + QString name_; + QList<QPair<Row*, seq::SequenceHandle> > rows_; +}; + + +}} + +#endif