scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

TableDoubleHeaderView.cpp
Go to the documentation of this file.
1 
11 
30 #include "TableDoubleHeaderView.h"
32 #include <QApplication>
33 #include <QEvent>
34 #include <QLayout>
35 
37  : QHeaderView(Qt::Horizontal, parent)
38 {
39 }
40 
42 {
43  delete model();
44 }
45 
46 void TableCommentsHeaderView::setModel(QAbstractItemModel * model)
47 {
48  Q_ASSERT(model->inherits("TableModel"));
49  QAbstractItemModel *old_model = QHeaderView::model();
50  TableCommentsHeaderModel *new_model = new TableCommentsHeaderModel(static_cast<TableModel *>(model));
51  QHeaderView::setModel(new_model);
52  QObject::disconnect(new_model, SIGNAL(columnsInserted(QModelIndex,int,int)),
53  this, SLOT(sectionsInserted(QModelIndex,int,int))); // We have to make sure sectionsInserted is called in the right order
54  delete old_model;
55 }
56 
58 : QHeaderView(Qt::Horizontal, parent)
59 {
60  setDefaultAlignment(Qt::AlignLeft | Qt::AlignTop);
62  d_slave->setDefaultAlignment(Qt::AlignLeft | Qt::AlignTop);
63  d_show_comments = true;
64 }
65 
67 {
68  delete d_slave;
69 }
70 
72 {
73  QSize master_size, slave_size;
74  master_size = QHeaderView::sizeHint();
75  slave_size = d_slave->sizeHint();
76  if(d_show_comments)
77  master_size.setHeight(master_size.height() + slave_size.height());
78  return master_size;
79 }
80 
81 void TableDoubleHeaderView::setModel(QAbstractItemModel * model)
82 {
83  Q_ASSERT(model->inherits("TableModel"));
84  d_slave->setModel(model);
85  QHeaderView::setModel(model);
86  connect(model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), this, SLOT(headerDataChanged(Qt::Orientation,int,int)));
87 }
88 
89 void TableDoubleHeaderView::paintSection ( QPainter * painter, const QRect & rect, int logicalIndex ) const
90 {
91  QRect master_rect = rect;
92  if(d_show_comments)
93  master_rect = rect.adjusted(0, 0, 0, -d_slave->sizeHint().height());
94  QHeaderView::paintSection(painter, master_rect, logicalIndex);
95  if(d_show_comments && rect.height() > QHeaderView::sizeHint().height())
96  {
97  QRect slave_rect = rect.adjusted(0, QHeaderView::sizeHint().height(), 0, 0);
98  d_slave->paintSection(painter, slave_rect, logicalIndex);
99  }
100 }
101 
103 {
104  return d_show_comments;
105 }
106 
108 {
109  d_show_comments = on;
110  refresh();
111 }
112 
114 {
115  // adjust geometry and repaint header (still looking for a more elegant solution)
116  d_slave->setStretchLastSection(true); // ugly hack (flaw in Qt? Does anyone know a better way?)
117  d_slave->updateGeometry();
118  d_slave->setStretchLastSection(false); // ugly hack part 2
119  setStretchLastSection(true); // ugly hack (flaw in Qt? Does anyone know a better way?)
120  updateGeometry();
121  setStretchLastSection(false); // ugly hack part 2
122  update();
123 }
124 
125 void TableDoubleHeaderView::headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast)
126 {
127  Q_UNUSED(logicalFirst);
128  Q_UNUSED(logicalLast);
129  if(orientation == Qt::Horizontal)
130  refresh();
131 }
132 
133 void TableDoubleHeaderView::sectionsInserted(const QModelIndex & parent, int logicalFirst, int logicalLast )
134 {
135  d_slave->sectionsInserted(parent, logicalFirst, logicalLast);
136  QHeaderView::sectionsInserted(parent, logicalFirst, logicalLast);
137  Q_ASSERT(d_slave->count() == QHeaderView::count());
138 }
139 
TableCommentsHeaderModel
Model class wrapping a TableModel to display column comments in a TableCommentsHeaderView.
Definition: TableCommentsHeaderModel.h:39
TableModel
Model for the access to a Table.
Definition: TableModel.h:54
TableDoubleHeaderView::sizeHint
virtual QSize sizeHint() const
Definition: TableDoubleHeaderView.cpp:71
TableDoubleHeaderView::sectionsInserted
void sectionsInserted(const QModelIndex &parent, int logicalFirst, int logicalLast)
Definition: TableDoubleHeaderView.cpp:133
TableCommentsHeaderView::TableCommentsHeaderView
TableCommentsHeaderView(QWidget *parent=0)
Definition: TableDoubleHeaderView.cpp:36
TableDoubleHeaderView::d_show_comments
bool d_show_comments
Flag: show/high column comments.
Definition: TableDoubleHeaderView.h:101
TableDoubleHeaderView::setModel
virtual void setModel(QAbstractItemModel *model)
Definition: TableDoubleHeaderView.cpp:81
TableCommentsHeaderModel.h
TableDoubleHeaderView.h
TableDoubleHeaderView::areCommentsShown
bool areCommentsShown() const
Return whether comments are show currently.
Definition: TableDoubleHeaderView.cpp:102
TableCommentsHeaderView::setModel
virtual void setModel(QAbstractItemModel *model)
Definition: TableDoubleHeaderView.cpp:46
TableDoubleHeaderView::TableDoubleHeaderView
TableDoubleHeaderView(QWidget *parent=0)
Definition: TableDoubleHeaderView.cpp:57
TableDoubleHeaderView::showComments
void showComments(bool on=true)
Show or hide (if on = false) the column comments.
Definition: TableDoubleHeaderView.cpp:107
TableCommentsHeaderView::~TableCommentsHeaderView
virtual ~TableCommentsHeaderView()
Definition: TableDoubleHeaderView.cpp:41
TableDoubleHeaderView::paintSection
virtual void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
Definition: TableDoubleHeaderView.cpp:89
TableDoubleHeaderView::~TableDoubleHeaderView
~TableDoubleHeaderView()
Definition: TableDoubleHeaderView.cpp:66
TableDoubleHeaderView::refresh
void refresh()
Definition: TableDoubleHeaderView.cpp:113
TableDoubleHeaderView::headerDataChanged
void headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast)
Definition: TableDoubleHeaderView.cpp:125
TableCommentsHeaderView
Slave header for TableDoubleHeaderView.
Definition: TableDoubleHeaderView.h:47
TableDoubleHeaderView::d_slave
TableCommentsHeaderView * d_slave
Definition: TableDoubleHeaderView.h:75