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