1 /* ColorCode, a free MasterMind clone with built in solver 2 * Copyright (C) 2009 Dirk Laebisch 3 * http://www.laebisch.com/ 4 * 5 * ColorCode is free software: you can redistribute it and/or modify 6 * it 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 * ColorCode is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with ColorCode. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef GAMESLISTMODEL_H 20 #define GAMESLISTMODEL_H 21 22 #include <QAbstractTableModel> 23 #include <QTableView> 24 #include <QHeaderView> 25 #include <QStringList> 26 #include "ccgame.h" 27 #include "buttonscell.h" 28 #include "gametableview.h" 29 30 class GamesListModel : public QAbstractTableModel 31 { 32 Q_OBJECT 33 34 public: 35 GamesListModel(QObject* parent = 0); 36 37 static const int MODEL_ID_DEFAULT; 38 static const int MODEL_ID_PREV; 39 static const int MODEL_ID_SAVED; 40 static const int MODEL_ID_HIGH; 41 42 static const int COL_RANKING; 43 static const int COL_SCORE; 44 static const int COL_USERNAME; 45 static const int COL_DELETE; 46 static const int COL_GAMENO; 47 static const int COL_DATE; 48 static const int COL_TIME; 49 static const int COL_CCNT; 50 static const int COL_PCNT; 51 static const int COL_DOUBLES; 52 53 static bool SortListScore(CCGame a, CCGame b); 54 static bool SortListTime(CCGame a, CCGame b); 55 56 virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); 57 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; 58 virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; 59 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 60 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 61 virtual Qt::ItemFlags flags(const QModelIndex &index) const; 62 virtual bool setData(const QModelIndex &index, const QVariant &value, int role); 63 64 int GetId(); 65 QString GetListStr() const; 66 void SetView(GameTableView* view); 67 void SetMaxSize(const int max); 68 void SetRowHColors(QString fg, QString bg); 69 virtual void InsertRow(CCGame g); 70 void EditField(); 71 void ReadList(const QString &str); 72 void SetEditIndex(QModelIndex ix); 73 QModelIndex GetEditIndex() const; 74 QString GetEditValue() const; 75 const CCGame* GetGameAt(const int row) const; 76 77 virtual int GetColIx(const int ix) const = 0; 78 virtual int GetMaxColCnt() const = 0; 79 80 public slots: 81 void HoverRowSlot(int row); 82 83 signals: 84 void CloseEditorSignal(const QModelIndex &index); 85 void SaveListGameSignal(CCGame* g); 86 void NewGameInputSignal(CCGame* g); 87 void ValidNameCommitSignal(); 88 89 protected: 90 QString GetHHeaderLabel(const int col) const; 91 virtual void DoSort(QList<CCGame> &list) = 0; 92 void LimitGamesListSize(); 93 94 int mId; 95 int mMaxSize; 96 int mHoverRow; 97 GameTableView* mView; 98 QList<CCGame> mGamesList; 99 QModelIndex mEditIndex; 100 QColor mRowHFg; 101 QColor mRowHBg; 102 103 }; 104 105 #endif // GAMESLISTMODEL_H 106