SGSolve
sgtableview.hpp
1 // This file is part of the SGSolve library for stochastic games
2 // Copyright (C) 2019 Benjamin A. Brooks
3 //
4 // SGSolve free software: you can redistribute it and/or modify it
5 // under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // SGSolve is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see
16 // <http://www.gnu.org/licenses/>.
17 //
18 // Benjamin A. Brooks
19 // ben@benjaminbrooks.net
20 // Chicago, IL
21 
22 #ifndef SGTABLEVIEW_HPP
23 #define SGTABLEVIEW_HPP
24 
25 #include <QtWidgets>
26 #include <QAbstractItemView>
27 
29 
34 class SGTableView : public QTableView
35 {
36  Q_OBJECT
37 
38 public:
41  {
42  setSelectionMode(QAbstractItemView::ContiguousSelection);
43  setEditTriggers(QAbstractItemView::AllEditTriggers);
44  setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding);
45  // horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
46  }
47 
49  int sizeHintForColumn(int col) const
50  {
51  return 65;
52  }
53 
55 
57  QSize minimumSizeHint() const
58  {
59  QSize hint(QTableView::sizeHint());
60 
61  double newWidth = 2; // Start with a little buffer
62  for (int col = 0; col < model()->columnCount(); col++)
63  newWidth += columnWidth(col);
64  newWidth += verticalHeader()->sizeHint().width();
65 
66  double newHeight = 2; // Start with a little buffer
67  for (int row = 0; row < model()->rowCount(); row++)
68  newHeight += rowHeight(row);
69 
70  newHeight += horizontalHeader()->sizeHint().height();
71 
72  hint.setHeight(newHeight);
73  hint.setWidth(newWidth);
74 
75  return hint;
76  }
77 
79  QSize sizeHint() const
80  {
81  return minimumSizeHint();
82  }
83 
84 };
85 
86 #endif
SGTableView::sizeHint
QSize sizeHint() const
Hint is equal to minimum size so table wont grow.
Definition: sgtableview.hpp:79
SGTableView::sizeHintForColumn
int sizeHintForColumn(int col) const
Reimplement column size to be slightly smaller.
Definition: sgtableview.hpp:49
SGTableView::minimumSizeHint
QSize minimumSizeHint() const
Reimplement minimumSizeHint.
Definition: sgtableview.hpp:57
SGTableView
Specialized table view for SGViewer.
Definition: sgtableview.hpp:35
SGTableView::SGTableView
SGTableView()
Constructor.
Definition: sgtableview.hpp:40