QTfrontend/model/MapModel.cpp
author antonc27 <antonc27@mail.ru>
Fri, 06 Nov 2015 03:21:00 +0100
branchios-revival
changeset 11313 4701700276f5
parent 11046 47a8c19ecb60
child 11749 ac58a063d26a
permissions -rw-r--r--
- 'iOS Deployment Target' bump to 8.0 - Xcode projects updated to recommended settings - 'Bundle Identifier' changed back to old one
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6939
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
     1
/*
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10391
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
6939
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
     4
 *
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
     8
 *
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
    12
 * GNU General Public License for more details.
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
    13
 *
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
    14
 * You should have received a copy of the GNU General Public License
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 9998
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
6939
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
    17
 */
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
    18
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
    19
/**
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
    20
 * @file
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
    21
 * @brief MapModel class implementation
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
    22
 */
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    23
8385
9e8924ff9813 Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents: 8377
diff changeset
    24
#include <QSettings>
9e8924ff9813 Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents: 8377
diff changeset
    25
8419
d99f46b676b5 Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents: 8393
diff changeset
    26
#include "physfs.h"
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    27
#include "MapModel.h"
8385
9e8924ff9813 Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents: 8377
diff changeset
    28
#include "HWApplication.h"
8464
c708b4f5cffc check datadir instead
nemo
parents: 8419
diff changeset
    29
#include "hwconsts.h"
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    30
9736
d2b01d350035 add missing initializers for 'dlc' variables for the 3 default generated map types (fixes 3 clang warnings)
sheepluva
parents: 9080
diff changeset
    31
MapModel::MapInfo MapModel::MapInfoRandom = {MapModel::GeneratedMap, "+rnd+", "", 0, "", "", "", false};
d2b01d350035 add missing initializers for 'dlc' variables for the 3 default generated map types (fixes 3 clang warnings)
sheepluva
parents: 9080
diff changeset
    32
MapModel::MapInfo MapModel::MapInfoMaze = {MapModel::GeneratedMaze, "+maze+", "", 0, "", "", "", false};
10391
ce3ccc45d790 Add separate option for perlin gen
unc0rr
parents: 10108
diff changeset
    33
MapModel::MapInfo MapModel::MapInfoPerlin = {MapModel::GeneratedMaze, "+perlin+", "", 0, "", "", "", false};
9736
d2b01d350035 add missing initializers for 'dlc' variables for the 3 default generated map types (fixes 3 clang warnings)
sheepluva
parents: 9080
diff changeset
    34
MapModel::MapInfo MapModel::MapInfoDrawn = {MapModel::HandDrawnMap, "+drawn+", "", 0, "", "", "", false};
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
    35
9744
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    36
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    37
MapModel::MapModel(MapType maptype, QObject *parent) : QStandardItemModel(parent)
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    38
{
9744
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    39
    m_maptype = maptype;
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    40
    m_loaded = false;
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    41
}
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    42
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    43
bool MapModel::loadMaps()
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    44
{
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    45
    if(m_loaded)
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    46
        return false;
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    47
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    48
    m_loaded = true;
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    49
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    50
    qDebug("[LAZINESS] MapModel::loadMaps()");
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    51
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    52
    // this method resets the contents of this model (important to know for views).
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    53
    beginResetModel();
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    54
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    55
    // we'll need the DataManager a few times, so let's get a reference to it
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    56
    DataManager & datamgr = DataManager::instance();
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    57
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    58
    // fetch list of available maps
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    59
    QStringList maps =
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    60
        datamgr.entryList("Maps", QDir::AllDirs | QDir::NoDotAndDotDot);
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    61
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    62
    // empty list, so that we can (re)fill it
6939
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
    63
    QStandardItemModel::clear();
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    64
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
    65
    //QList<QStandardItem *> staticMaps;
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
    66
    //QList<QStandardItem *> missionMaps;
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
    67
    QList<QStandardItem *> mapList;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    68
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    69
    // add mission/static maps to lists
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    70
    foreach (QString map, maps)
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    71
    {
8386
2aaa2995a32e - Fix another ton of bugs and misbehavior
unc0rr
parents: 8385
diff changeset
    72
        // only 2 map relate files are relevant:
2aaa2995a32e - Fix another ton of bugs and misbehavior
unc0rr
parents: 8385
diff changeset
    73
        // - the cfg file that contains the settings/info of the map
2aaa2995a32e - Fix another ton of bugs and misbehavior
unc0rr
parents: 8385
diff changeset
    74
        // - the lua file - if it exists it's a mission, otherwise it isn't
2aaa2995a32e - Fix another ton of bugs and misbehavior
unc0rr
parents: 8385
diff changeset
    75
        QFile mapLuaFile(QString("physfs://Maps/%1/map.lua").arg(map));
2aaa2995a32e - Fix another ton of bugs and misbehavior
unc0rr
parents: 8385
diff changeset
    76
        QFile mapCfgFile(QString("physfs://Maps/%1/map.cfg").arg(map));
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    77
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    78
        if (mapCfgFile.open(QFile::ReadOnly))
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    79
        {
6939
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
    80
            QString caption;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    81
            QString theme;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    82
            quint32 limit = 0;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    83
            QString scheme;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    84
            QString weapons;
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
    85
            QString desc;
8419
d99f46b676b5 Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents: 8393
diff changeset
    86
            bool dlc;
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
    87
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    88
            // if there is a lua file for this map, then it's a mission
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    89
            bool isMission = mapLuaFile.exists();
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
    90
            MapType type = isMission ? MissionMap : StaticMap;
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
    91
8419
d99f46b676b5 Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents: 8393
diff changeset
    92
            // if we're supposed to ignore this type, continue
9744
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
    93
            if (type != m_maptype) continue;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    94
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    95
            // load map info from file
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    96
            QTextStream input(&mapCfgFile);
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
    97
            theme = input.readLine();
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
    98
            limit = input.readLine().toInt();
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    99
            if (isMission) { // scheme and weapons are only relevant for missions
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   100
                scheme = input.readLine();
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   101
                weapons = input.readLine();
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   102
            }
6939
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   103
            mapCfgFile.close();
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   104
8419
d99f46b676b5 Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents: 8393
diff changeset
   105
            // load description (if applicable)
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   106
            if (isMission)
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   107
            {
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   108
                QString locale = HWApplication::keyboardInputLocale().name();
8386
2aaa2995a32e - Fix another ton of bugs and misbehavior
unc0rr
parents: 8385
diff changeset
   109
2aaa2995a32e - Fix another ton of bugs and misbehavior
unc0rr
parents: 8385
diff changeset
   110
                QSettings descSettings(QString("physfs://Maps/%1/desc.txt").arg(map), QSettings::IniFormat);
8393
85bd6c7b2641 Can now change theme for static and mission maps.
dag10 <gottlieb.drew@gmail.com>
parents: 8386
diff changeset
   111
                desc = descSettings.value(locale, QString()).toString().replace("|", "\n").replace("\\,", ",");
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   112
            }
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   113
8419
d99f46b676b5 Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents: 8393
diff changeset
   114
            // detect if map is dlc
d99f46b676b5 Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents: 8393
diff changeset
   115
            QString mapDir = PHYSFS_getRealDir(QString("Maps/%1/map.cfg").arg(map).toLocal8Bit().data());
8464
c708b4f5cffc check datadir instead
nemo
parents: 8419
diff changeset
   116
            dlc = !mapDir.startsWith(datadir->absolutePath());
8419
d99f46b676b5 Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents: 8393
diff changeset
   117
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   118
            // let's use some semi-sane hedgehog limit, rather than none
6939
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   119
            if (limit == 0)
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   120
                limit = 18;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   121
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   122
            // the default scheme/weaponset for missions.
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   123
            // if empty we assume the map sets these internally -> locked
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   124
            if (isMission)
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   125
            {
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   126
                if (scheme.isEmpty())
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   127
                    scheme = "locked";
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   128
                else
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   129
                    scheme.replace("_", " ");
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   130
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   131
                if (weapons.isEmpty())
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   132
                    weapons = "locked";
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   133
                else
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   134
                    weapons.replace("_", " ");
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   135
            }
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   136
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   137
            // caption
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   138
            caption = map;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   139
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   140
            // we know everything there is about the map, let's get am item for it
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   141
            QStandardItem * item = MapModel::infoToItem(
8419
d99f46b676b5 Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents: 8393
diff changeset
   142
                QIcon(), caption, type, map, theme, limit, scheme, weapons, desc, dlc);
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   143
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   144
            // append item to the list
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   145
            mapList.append(item);
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   146
        }
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   147
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   148
    }
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   149
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   150
    // Create column-index lookup table
6983
ede55af89e78 roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents: 6952
diff changeset
   151
ede55af89e78 roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents: 6952
diff changeset
   152
    m_mapIndexes.clear();
ede55af89e78 roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents: 6952
diff changeset
   153
ede55af89e78 roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents: 6952
diff changeset
   154
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   155
    int count = mapList.size();
6983
ede55af89e78 roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents: 6952
diff changeset
   156
    for (int i = 0; i < count; i++)
ede55af89e78 roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents: 6952
diff changeset
   157
    {
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   158
        QStandardItem * si = mapList.at(i);
6983
ede55af89e78 roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents: 6952
diff changeset
   159
        QVariant v = si->data(Qt::UserRole + 1);
ede55af89e78 roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents: 6952
diff changeset
   160
        if (v.canConvert<MapInfo>())
ede55af89e78 roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents: 6952
diff changeset
   161
            m_mapIndexes.insert(v.value<MapInfo>().name, i);
ede55af89e78 roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents: 6952
diff changeset
   162
    }
ede55af89e78 roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents: 6952
diff changeset
   163
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   164
    QStandardItemModel::appendColumn(mapList);
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   165
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   166
    endResetModel();
9744
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
   167
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
   168
    return true;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   169
}
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   170
9744
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
   171
bool MapModel::mapExists(const QString & map)
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   172
{
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   173
    return findMap(map) >= 0;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   174
}
6939
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   175
9744
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
   176
int MapModel::findMap(const QString & map)
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   177
{
9744
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
   178
    loadMaps();
1ee4842a9c86 Be lazy in loading maps list
unc0rr
parents: 9736
diff changeset
   179
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   180
    return m_mapIndexes.value(map, -1);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   181
}
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   182
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   183
QStandardItem * MapModel::getMap(const QString & map)
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   184
{
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   185
    int loc = findMap(map);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   186
    if (loc < 0) return NULL;
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   187
    return item(loc);
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   188
}
6939
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   189
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   190
QStandardItem * MapModel::infoToItem(
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   191
    const QIcon & icon,
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   192
    const QString caption,
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   193
    MapType type,
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   194
    QString name,
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   195
    QString theme,
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   196
    quint32 limit,
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   197
    QString scheme,
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   198
    QString weapons,
8419
d99f46b676b5 Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents: 8393
diff changeset
   199
    QString desc,
d99f46b676b5 Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents: 8393
diff changeset
   200
    bool dlc)
6939
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   201
{
8419
d99f46b676b5 Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents: 8393
diff changeset
   202
    QStandardItem * item = new QStandardItem(icon, (dlc ? "*" : "") + caption);
6939
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   203
    MapInfo mapInfo;
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   204
    QVariant qvar(QVariant::UserType);
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   205
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   206
    mapInfo.type = type;
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   207
    mapInfo.name = name;
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   208
    mapInfo.theme = theme;
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   209
    mapInfo.limit = limit;
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   210
    mapInfo.scheme = scheme;
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   211
    mapInfo.weapons = weapons;
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents: 8049
diff changeset
   212
    mapInfo.desc = desc.isEmpty() ? tr("No description available.") : desc;
8419
d99f46b676b5 Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents: 8393
diff changeset
   213
    mapInfo.dlc = dlc;
6939
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   214
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   215
    qvar.setValue(mapInfo);
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   216
    item->setData(qvar, Qt::UserRole + 1);
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   217
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   218
    return item;
970389573788 MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents: 6938
diff changeset
   219
}