- Move colorsModel to appropriate place
authorunc0rr
Sun, 17 Jun 2012 21:45:49 +0400
changeset 7258 722e8a0d89dc
parent 7256 5b97b9946cde
child 7260 c3584a3ab730
- Move colorsModel to appropriate place - Less includes in DataManager.h
QTfrontend/game.cpp
QTfrontend/hwconsts.cpp.in
QTfrontend/hwconsts.h
QTfrontend/main.cpp
QTfrontend/model/GameStyleModel.cpp
QTfrontend/model/roomslistmodel.cpp
QTfrontend/team.cpp
QTfrontend/ui/page/pageeditteam.cpp
QTfrontend/ui/widget/frameTeam.cpp
QTfrontend/ui/widget/gamecfgwidget.cpp
QTfrontend/ui/widget/mapContainer.cpp
QTfrontend/ui/widget/mapContainer.h
QTfrontend/ui/widget/teamselhelper.cpp
QTfrontend/util/DataManager.cpp
QTfrontend/util/DataManager.h
--- a/QTfrontend/game.cpp	Sun Jun 17 16:32:44 2012 +0200
+++ b/QTfrontend/game.cpp	Sun Jun 17 21:45:49 2012 +0400
@@ -21,6 +21,7 @@
 #include <QUuid>
 #include <QColor>
 #include <QStringListModel>
+#include <QTextStream>
 
 #include "game.h"
 #include "hwconsts.h"
@@ -29,8 +30,7 @@
 #include "teamselect.h"
 #include "KB.h"
 #include "proto.h"
-
-#include <QTextStream>
+#include "ThemeModel.h"
 
 QString training, campaign; // TODO: Cleaner solution?
 
--- a/QTfrontend/hwconsts.cpp.in	Sun Jun 17 16:32:44 2012 +0200
+++ b/QTfrontend/hwconsts.cpp.in	Sun Jun 17 21:45:49 2012 +0400
@@ -72,19 +72,3 @@
 
 int season = SEASON_NONE;
 int years_since_foundation = 0;
-
-QStandardItemModel * colorsModel;
-
-void hwConstsInit()
-{
-    colorsModel = new QStandardItemModel();
-
-    int i = 0;
-    while(colors[i])
-    {
-        QStandardItem * item = new QStandardItem();
-        item->setData(QColor(colors[i]));
-        colorsModel->appendRow(item);
-        ++i;
-    }
-}
--- a/QTfrontend/hwconsts.h	Sun Jun 17 16:32:44 2012 +0200
+++ b/QTfrontend/hwconsts.h	Sun Jun 17 21:45:49 2012 +0400
@@ -44,8 +44,7 @@
 extern int cAmmoNumber;
 extern QList< QPair<QString, QString> > cDefaultAmmos;
 
-//extern unsigned int colors[];
-extern QStandardItemModel * colorsModel;
+extern unsigned int colors[];
 
 extern QString * netHost;
 extern quint16 netPort;
@@ -60,8 +59,6 @@
 //Could be used to implement a text/graphic like "This is the xxth birthday of hedgewars" or similar
 extern int years_since_foundation;
 
-void hwConstsInit();
-
 #endif
 
 #define HEDGEHOGS_PER_TEAM           8
--- a/QTfrontend/main.cpp	Sun Jun 17 16:32:44 2012 +0200
+++ b/QTfrontend/main.cpp	Sun Jun 17 21:45:49 2012 +0400
@@ -104,8 +104,6 @@
 {
     HWApplication app(argc, argv);
 
-    hwConstsInit();
-
     app.setAttribute(Qt::AA_DontShowIconsInMenus,false);
 
     QStringList arguments = app.arguments();
--- a/QTfrontend/model/GameStyleModel.cpp	Sun Jun 17 16:32:44 2012 +0200
+++ b/QTfrontend/model/GameStyleModel.cpp	Sun Jun 17 21:45:49 2012 +0400
@@ -21,6 +21,8 @@
  * @brief GameStyleModel class implementation
  */
 
+#include <QTextStream>
+
 #include "GameStyleModel.h"
 
 
--- a/QTfrontend/model/roomslistmodel.cpp	Sun Jun 17 16:32:44 2012 +0200
+++ b/QTfrontend/model/roomslistmodel.cpp	Sun Jun 17 21:45:49 2012 +0400
@@ -21,12 +21,13 @@
  * @brief RoomsListModel class implementation
  */
 
-#include "roomslistmodel.h"
-
 #include <QBrush>
 #include <QColor>
 #include <QIcon>
 
+#include "roomslistmodel.h"
+#include "MapModel.h"
+
 RoomsListModel::RoomsListModel(QObject *parent) :
     QAbstractTableModel(parent),
     c_nColumns(8)
--- a/QTfrontend/team.cpp	Sun Jun 17 16:32:44 2012 +0200
+++ b/QTfrontend/team.cpp	Sun Jun 17 21:45:49 2012 +0400
@@ -26,6 +26,7 @@
 
 #include "team.h"
 #include "hwform.h"
+#include "DataManager.h"
 
 HWTeam::HWTeam(const QString & teamname) :
     QObject(0)
@@ -351,12 +352,12 @@
 
 QColor HWTeam::qcolor() const
 {
-    return colorsModel->item(m_color)->data().value<QColor>();
+    return DataManager::instance().colorsModel()->item(m_color)->data().value<QColor>();
 }
 
 void HWTeam::setColor(int color)
 {
-    m_color = color % colorsModel->rowCount();
+    m_color = color % DataManager::instance().colorsModel()->rowCount();
 }
 
 
--- a/QTfrontend/ui/page/pageeditteam.cpp	Sun Jun 17 16:32:44 2012 +0200
+++ b/QTfrontend/ui/page/pageeditteam.cpp	Sun Jun 17 21:45:49 2012 +0400
@@ -32,6 +32,7 @@
 #include "HWApplication.h"
 
 #include "DataManager.h"
+#include "HatModel.h"
 
 #include "pageeditteam.h"
 
--- a/QTfrontend/ui/widget/frameTeam.cpp	Sun Jun 17 16:32:44 2012 +0200
+++ b/QTfrontend/ui/widget/frameTeam.cpp	Sun Jun 17 21:45:49 2012 +0400
@@ -25,6 +25,7 @@
 #include "frameTeam.h"
 #include "teamselhelper.h"
 #include "hwconsts.h"
+#include "DataManager.h"
 
 FrameTeams::FrameTeams(QWidget* parent) :
     QFrame(parent), maxHedgehogsPerGame(48), overallHedgehogs(0), mainLayout(this), nonInteractive(false)
@@ -54,12 +55,12 @@
 
 void FrameTeams::resetColors()
 {
-    currentColor = colorsModel->rowCount() - 1; // ensure next color is the first one
+    currentColor = DataManager::instance().colorsModel()->rowCount() - 1; // ensure next color is the first one
 }
 
 int FrameTeams::getNextColor()
 {
-    currentColor = (currentColor + 1) % colorsModel->rowCount();
+    currentColor = (currentColor + 1) % DataManager::instance().colorsModel()->rowCount();
     return currentColor;
 }
 
--- a/QTfrontend/ui/widget/gamecfgwidget.cpp	Sun Jun 17 16:32:44 2012 +0200
+++ b/QTfrontend/ui/widget/gamecfgwidget.cpp	Sun Jun 17 21:45:49 2012 +0400
@@ -32,6 +32,7 @@
 #include "hwconsts.h"
 #include "ammoSchemeModel.h"
 #include "proto.h"
+#include "GameStyleModel.h"
 
 GameCFGWidget::GameCFGWidget(QWidget* parent) :
     QGroupBox(parent)
--- a/QTfrontend/ui/widget/mapContainer.cpp	Sun Jun 17 16:32:44 2012 +0200
+++ b/QTfrontend/ui/widget/mapContainer.cpp	Sun Jun 17 21:45:49 2012 +0400
@@ -36,6 +36,7 @@
 #include "mapContainer.h"
 #include "igbox.h"
 #include "HWApplication.h"
+#include "ThemeModel.h"
 
 HWMapContainer::HWMapContainer(QWidget * parent) :
     QWidget(parent),
--- a/QTfrontend/ui/widget/mapContainer.h	Sun Jun 17 16:32:44 2012 +0200
+++ b/QTfrontend/ui/widget/mapContainer.h	Sun Jun 17 21:45:49 2012 +0400
@@ -31,6 +31,7 @@
 
 #include "hwmap.h"
 #include "drawmapscene.h"
+#include "MapModel.h"
 
 class QPushButton;
 class IconedGroupBox;
--- a/QTfrontend/ui/widget/teamselhelper.cpp	Sun Jun 17 16:32:44 2012 +0200
+++ b/QTfrontend/ui/widget/teamselhelper.cpp	Sun Jun 17 21:45:49 2012 +0400
@@ -28,6 +28,7 @@
 #include "hwconsts.h"
 #include "frameTeam.h"
 #include "colorwidget.h"
+#include "DataManager.h"
 
 void TeamLabel::teamButtonClicked()
 {
@@ -69,7 +70,7 @@
     if(m_isPlaying)
     {
         // team color
-        colorWidget = new ColorWidget(colorsModel, this);
+        colorWidget = new ColorWidget(DataManager::instance().colorsModel(), this);
         colorWidget->setMinimumWidth(26);
         colorWidget->setMaximumWidth(26);
         colorWidget->setMinimumHeight(26);
--- a/QTfrontend/util/DataManager.cpp	Sun Jun 17 16:32:44 2012 +0200
+++ b/QTfrontend/util/DataManager.cpp	Sun Jun 17 21:45:49 2012 +0400
@@ -23,13 +23,17 @@
 
 #include <QMap>
 #include <QStringList>
-
+#include <QStandardItemModel>
 #include <QFileInfo>
 
 #include "hwconsts.h"
 
 #include "DataManager.h"
 
+#include "GameStyleModel.h"
+#include "HatModel.h"
+#include "MapModel.h"
+#include "ThemeModel.h"
 
 DataManager::DataManager()
 {
@@ -42,6 +46,7 @@
     m_hatModel = NULL;
     m_mapModel = NULL;
     m_themeModel = NULL;
+    m_colorsModel = NULL;
 }
 
 
@@ -154,6 +159,25 @@
     return m_themeModel;
 }
 
+QStandardItemModel * DataManager::colorsModel()
+{
+    if(m_colorsModel == NULL)
+    {
+        m_colorsModel = new QStandardItemModel();
+
+        int i = 0;
+        while(colors[i])
+        {
+            QStandardItem * item = new QStandardItem();
+            item->setData(QColor(colors[i]));
+            m_colorsModel->appendRow(item);
+            ++i;
+        }
+    }
+
+    return m_colorsModel;
+}
+
 void DataManager::reload()
 {
     m_gameStyleModel->loadGameStyles();
--- a/QTfrontend/util/DataManager.h	Sun Jun 17 16:32:44 2012 +0200
+++ b/QTfrontend/util/DataManager.h	Sun Jun 17 21:45:49 2012 +0400
@@ -26,21 +26,13 @@
 
 #include <QDir>
 #include <QFile>
-
 #include <QStringList>
 
-#include "GameStyleModel.h"
-#include "HatModel.h"
-#include "MapModel.h"
-#include "ThemeModel.h"
-
-class QDir;
-class QFile;
-class QStringList;
 class GameStyleModel;
 class HatModel;
 class MapModel;
 class ThemeModel;
+class QStandardItemModel;
 
 /**
  * @brief Offers access to the data files of hedgewars.
@@ -135,6 +127,8 @@
          */
         ThemeModel * themeModel();
 
+        QStandardItemModel * colorsModel();
+
     public slots:
         /// Reloads data from storage.
         void reload();
@@ -163,6 +157,7 @@
         HatModel * m_hatModel; ///< hat model instance
         MapModel * m_mapModel; ///< map model instance
         ThemeModel * m_themeModel; ///< theme model instance
+        QStandardItemModel * m_colorsModel;
 };
 
 #endif // HEDGEWARS_DATAMANAGER_H