OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
sequence_model.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_SEQUENCE_VIEWER_SEQUENCE_MODEL
20 #define OST_SEQUENCE_VIEWER_SEQUENCE_MODEL
21 
22 /*
23  Author: Stefan Scheuber
24  */
25 
26 
27 #include <ost/mol/chain_view.hh>
28 
29 #include <ost/seq/sequence_list.hh>
31 
32 #include <ost/gfx/entity.hh>
33 
34 #include "base_view_object.hh"
35 #include "alignment_view_object.hh"
36 #include "sequence_view_object.hh"
37 
38 #include <QAbstractTableModel>
39 #include <QItemSelection>
40 namespace ost { namespace gui {
41 
42 class SequenceModel : public QAbstractTableModel
43 {
44  Q_OBJECT
45 
46 public:
47  SequenceModel(QObject *parent = 0);
48 
49  void InsertAlignment(const seq::AlignmentHandle& alignment);
50  void InsertGfxEntity(const gfx::EntityP& entity);
51  void InsertChain(QString& name, mol::ChainView& view);
52  void InsertSequence(QString& name, seq::SequenceHandle& seq);
53  void InsertSequences(const QList<QString>& names, seq::SequenceList& list);
54 
55  void RemoveAlignment(const seq::AlignmentHandle& alignment);
56  void RemoveGfxEntity(const gfx::EntityP& entity);
57 
58  QModelIndexList GetModelIndexes(gfx::EntityP& entity, const mol::EntityView& view);
59  QModelIndexList GetModelIndexes(const QString& subject, const QString& sequence_name=QString());
60 
61  int GetGlobalRow(BaseViewObject* obj, int row) const;
62 
63  const QStringList& GetDisplayModes();
64  const QStringList& GetDisplayModes(const gfx::EntityP& entity);
65  const QStringList& GetDisplayModes(const seq::AlignmentHandle& alignment);
66  const QString& GetCurrentDisplayMode();
67  const QString& GetCurrentDisplayMode(const gfx::EntityP& entity);
68  const QString& GetCurrentDisplayMode(const seq::AlignmentHandle& alignment);
69  void SetDisplayMode(const QString& mode);
70  void SetDisplayMode(const gfx::EntityP& entity, const QString& mode);
71  void SetDisplayMode(const seq::AlignmentHandle& alignment, const QString& mode);
72 
73  const PainterList& GetPainters(const QModelIndex& index) const;
74 
75  // abstract item model interface
76  int rowCount(const QModelIndex& parent=QModelIndex()) const;
77 
78  int columnCount(const QModelIndex& parent=QModelIndex()) const;
79 
80  QVariant data(const QModelIndex& index, int role=Qt::DisplayRole) const;
81 
82  QVariant headerData(int section, Qt::Orientation orientation,
83  int role=Qt::DisplayRole) const;
84 
85  virtual Qt::ItemFlags flags(const QModelIndex& index=QModelIndex()) const;
86  QPair<seq::AlignmentHandle, int> GetAlignmentForRow(int row);
87 
88  void EmitRowChanged(int row);
89 
90  void Clear();
91 public slots:
92  void ZoomIn();
93  void ZoomOut();
94  void DoubleClicked(const QModelIndex& index);
95  void SelectionChanged(const QItemSelection& sel, const QItemSelection& desel);
96 private:
97  int GetColumnCount() const;
98  SequenceViewObject* GetItem(const gfx::EntityP& entity);
99  AlignmentViewObject* GetItem(const seq::AlignmentHandle& alignment);
100  BaseViewObject* GetItem(const QModelIndex& index) const;
101  QPair<int, BaseViewObject*> GetRowWithItem(int row) const;
102  QPair<int, BaseViewObject*> GetRowWithItem(const QModelIndex& index) const;
103 
104  QList<BaseViewObject*> objects_;
105  int max_columns;
106  PainterList empty_painter_list_;
107  QString empty_string_;
108  QStringList empty_string_list_;
109  QStringList display_modes_;
110  QString current_display_mode_;
111 };
112 
113 
114 }}
115 
116 #endif