BCESolve
bceobjweightstablemodel.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 BCEOBJWEIGHTSTABLEMODEL_HPP
24#define BCEOBJWEIGHTSTABLEMODEL_HPP
25
26#include <QtWidgets>
27#include <QAbstractTableModel>
28#include <QTableView>
29#include "bcegame.hpp"
30#include "bceenumeration.hpp"
31
33
45class BCEObjWeightsTableModel : public QAbstractTableModel
46{
47 Q_OBJECT
48
49private:
51 vector<double> mainObjWeights;
53 vector<double> secondaryObjWeights;
55 void setWeightData(vector<int> cellLocation,double value) {
56 if (cellLocation[1]==0)
57 mainObjWeights[cellLocation[0]] = value;
58 else
59 secondaryObjWeights[cellLocation[0]] = value;
60 }
62 vector<string> objectiveLabels;
63
64public:
66
72 game(_game)
73 {
74
75 mainObjWeights = vector<double>(game->getNumObjectives(),0);
76 secondaryObjWeights = vector<double>(game->getNumObjectives(),0);
77
78 mainObjWeights[0] = 1;
80
82
83 if (objectiveLabels.size() < game->getNumObjectives()) {
84 int currLabelIndex = objectiveLabels.size();
85 while (currLabelIndex < game->getNumObjectives() + 1) {
86 objectiveLabels.push_back(string());
87 currLabelIndex++;
88 }
89 }
90 }
91
93
95 Qt::ItemFlags flags(const QModelIndex & index) const
96 { return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; }
97
99 int rowCount(const QModelIndex & parent = QModelIndex()) const Q_DECL_OVERRIDE
100 { return game->getNumObjectives(); }
102 int columnCount(const QModelIndex & parent = QModelIndex()) const Q_DECL_OVERRIDE
103 { return 2; }
104
107 { emit layoutChanged(); }
108
110
112 QVariant data(const QModelIndex & index,
113 int role) const Q_DECL_OVERRIDE;
114
116
117 bool setData(const QModelIndex & index, const QVariant & value, int role);
118
120
122 QVariant headerData(int section,
123 Qt::Orientation orientation,
124 int role) const Q_DECL_OVERRIDE;
125
127 void addObjective(int position) {
128 mainObjWeights.insert(mainObjWeights.begin()+position,0);
129 secondaryObjWeights.insert(secondaryObjWeights.begin()+position,0);
130 objectiveLabels.insert(objectiveLabels.begin()+position,
131 game->getObjLabels(position));
132 }
133
135
137 void removeObjective(int position) {
138 mainObjWeights.erase(mainObjWeights.begin() + position);
139 secondaryObjWeights.erase(secondaryObjWeights.begin() + position);
140 objectiveLabels.erase(objectiveLabels.begin() + position);
141 }
142
144 const vector<double> getSolverData() {
145 return mainObjWeights;
146 }
147
149 const vector<vector<double> > getMapBoundaryData() {
150 vector<vector<double> > weightData;
151 weightData.push_back(mainObjWeights);
152 weightData.push_back(secondaryObjWeights);
153 return weightData;
154 }
155
158 mainObjWeights.clear();
159 secondaryObjWeights.clear();
162
163 mainObjWeights[0] = 1;
164 secondaryObjWeights[1] = 1;
165 }
166
167protected:
170
171
172};
173
174
175#endif
int getNumObjectives() const
Returns the number of objectives.
Definition: bceabstractgame.hpp:245
string getObjLabels(int obj)
Gets an entry from objective label vector.
Definition: bceabstractgame.hpp:213
The base class for games of incomplete information.
Definition: bcegame.hpp:40
Model for Objective Weights in the BCEViewer.
Definition: bceobjweightstablemodel.hpp:46
void resetObjectiveWeights()
Resets weights on objectives.
Definition: bceobjweightstablemodel.hpp:157
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE
Reimplements the data method.
Definition: bceobjweightstablemodel.cpp:25
const vector< double > getSolverData()
Returns a reference to the weight data vector.
Definition: bceobjweightstablemodel.hpp:144
void setWeightData(vector< int > cellLocation, double value)
Sets data in the objective weights vectors.
Definition: bceobjweightstablemodel.hpp:55
vector< double > mainObjWeights
Vector storing weights on main objective.
Definition: bceobjweightstablemodel.hpp:51
int columnCount(const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
Returns the number of column player actions.
Definition: bceobjweightstablemodel.hpp:102
BCEGame * game
Pointer to the associated game.
Definition: bceobjweightstablemodel.hpp:169
void emitLayoutChanged()
Emits layoutChanged signal.
Definition: bceobjweightstablemodel.hpp:106
Qt::ItemFlags flags(const QModelIndex &index) const
Returns flags.
Definition: bceobjweightstablemodel.hpp:95
void removeObjective(int position)
Removes an objective from the weight data and label vectors.
Definition: bceobjweightstablemodel.hpp:137
bool setData(const QModelIndex &index, const QVariant &value, int role)
Reimplements the setData method.
Definition: bceobjweightstablemodel.cpp:47
BCEObjWeightsTableModel(BCEGame *_game)
Constructor.
Definition: bceobjweightstablemodel.hpp:71
vector< double > secondaryObjWeights
Vector storing weights on secondary objective.
Definition: bceobjweightstablemodel.hpp:53
int rowCount(const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
Returns the number of row player actions.
Definition: bceobjweightstablemodel.hpp:99
QVariant headerData(int section, Qt::Orientation orientation, int role) const Q_DECL_OVERRIDE
Returns formatted header data.
Definition: bceobjweightstablemodel.cpp:66
const vector< vector< double > > getMapBoundaryData()
Returns a reference to the weight data vector.
Definition: bceobjweightstablemodel.hpp:149
vector< string > objectiveLabels
Vector storing objective labels.
Definition: bceobjweightstablemodel.hpp:62
void addObjective(int position)
Adds an objective to the weight data vector.
Definition: bceobjweightstablemodel.hpp:127