QTfrontend/model/MapModel.cpp
author sheepluva
Sat, 28 Apr 2012 00:24:37 +0200
changeset 6943 1fe601a2761b
parent 6939 970389573788
child 6947 1be3e48e1d53
permissions -rw-r--r--
MapModel: comments/docs, small tweaks
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
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
     3
 * Copyright (c) 2006-2007 Igor Ulyanov <iulyanov@gmail.com>
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
 * Copyright (c) 2007-2012 Andrey Korotaev <unC0Rr@gmail.com>
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
 *
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
 * 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
     7
 * 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
     8
 * 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
     9
 *
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
 * 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
    11
 * 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
    12
 * 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
    13
 * 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
    14
 *
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
 * 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
    16
 * along with this program; if not, write to the Free Software
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
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
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
/**
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
 * @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
    22
 * @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
    23
 */
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    24
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    25
#include "MapModel.h"
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    26
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    27
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    28
void MapModel::loadMaps()
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    29
{
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    30
    // 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
    31
    beginResetModel();
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    32
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    33
    // 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
    34
    DataManager & datamgr = DataManager::instance();
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    35
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    36
    // fetch list of available maps
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    37
    QStringList maps =
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    38
        datamgr.entryList("Maps", QDir::AllDirs | QDir::NoDotAndDotDot);
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    39
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    40
    // 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
    41
    QStandardItemModel::clear();
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    42
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
    43
    QList<QStandardItem *> genMaps;
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
    44
    QList<QStandardItem *> missionMaps;
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
    45
    QList<QStandardItem *> staticMaps;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    46
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    47
    // add generated/handdrawn maps to list
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    48
    // TODO: icons for these
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    49
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
    50
    genMaps.append(
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
    51
        infoToItem(QIcon(), QComboBox::tr("generated map..."), GeneratedMap, "+rnd+"));
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
    52
    genMaps.append(
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
    53
        infoToItem(QIcon(), QComboBox::tr("generated maze..."), GeneratedMaze, "+maze+"));
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
    54
    genMaps.append(
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
    55
        infoToItem(QIcon(), QComboBox::tr("hand drawn map..."), HandDrawnMap, "+drawn+"));
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    56
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    57
    // only 2 map relate files are relevant:
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    58
    // - the cfg file that contains the settings/info of the map
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    59
    // - the lua file - if it exists it's a mission, otherwise it isn't
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    60
    QFile mapLuaFile;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    61
    QFile mapCfgFile;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    62
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    63
    // add mission/static maps to lists
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    64
    foreach (QString map, maps)
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    65
    {
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    66
        mapCfgFile.setFileName(
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    67
            datamgr.findFileForRead(QString("Maps/%1/map.cfg").arg(map)));
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    68
        mapLuaFile.setFileName(
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    69
            datamgr.findFileForRead(QString("Maps/%1/map.lua").arg(map)));
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    70
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    71
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    72
        if (mapCfgFile.open(QFile::ReadOnly))
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    73
        {
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
    74
            QString caption;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    75
            QString theme;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    76
            quint32 limit = 0;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    77
            QString scheme;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    78
            QString weapons;
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    79
            // 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
    80
            bool isMission = mapLuaFile.exists();
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
    81
            MapType type = isMission?MissionMap:StaticMap;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    82
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    83
            // load map info from file
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    84
            QTextStream input(&mapCfgFile);
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    85
            input >> theme;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    86
            input >> limit;
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    87
            if (isMission) { // scheme and weapons are only relevant for missions
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    88
                input >> scheme;
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    89
                input >> weapons;
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    90
            }
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
    91
            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
    92
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    93
            // 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
    94
            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
    95
                limit = 18;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    96
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    97
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    98
            // the default scheme/weaponset for missions.
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
    99
            // if empty we assume the map sets these internally -> locked
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   100
            if (isMission)
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   101
            {
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   102
                if (scheme.isEmpty())
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   103
                    scheme = "locked";
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   104
                else
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   105
                    scheme.replace("_", " ");
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   106
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   107
                if (weapons.isEmpty())
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   108
                    weapons = "locked";
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   109
                else
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   110
                    weapons.replace("_", " ");
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   111
            }
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   112
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   113
            // add a mission caption prefix to missions
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
   114
            if (isMission)
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   115
            {
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   116
                // TODO: icon
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
   117
                caption = QComboBox::tr("Mission") + ": " + map;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   118
                m_nMissions++;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   119
            }
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
   120
            else
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
   121
                caption = map;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   122
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   123
            // we know everything there is about the map, let's get am item for 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
   124
            QStandardItem * item = 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
   125
                QIcon(), caption, type, map, theme, limit, scheme, weapons);
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   126
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   127
            // append item to the list
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
   128
            if (isMission)
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
   129
                missionMaps.append(item);
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   130
            else
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
   131
                staticMaps.append(item);
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   132
        
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   133
        }
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   134
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   135
    }
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   136
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   137
    // update mission count member
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
   138
    m_nMissions = missionMaps.size();
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
   139
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   140
    // define a separator item
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
   141
    QStandardItem separator("---");
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
   142
    separator.setData(QLatin1String("separator"), Qt::AccessibleDescriptionRole);
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
   143
    separator.setFlags(separator.flags() & ~( Qt::ItemIsEnabled | Qt::ItemIsSelectable ) );
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
   144
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   145
    // create list:
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   146
    // generated+handdrawn maps, 2 saperators, missions, 1 separator, static maps
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
   147
    QList<QStandardItem * > items;
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
   148
    items.append(genMaps);
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
   149
    items.append(separator.clone());
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
   150
    items.append(separator.clone());
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
   151
    items.append(missionMaps);
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
   152
    items.append(separator.clone());
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
   153
    items.append(staticMaps);
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
   154
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   155
    // store list contents in the item model
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
   156
    QStandardItemModel::appendColumn(items);
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
   157
6943
1fe601a2761b MapModel: comments/docs, small tweaks
sheepluva
parents: 6939
diff changeset
   158
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   159
    endResetModel();
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   160
}
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   161
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   162
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   163
int MapModel::missionCount() const
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   164
{
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   165
    return m_nMissions;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   166
}
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
   167
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
   168
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
   169
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
   170
    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
   171
    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
   172
    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
   173
    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
   174
    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
   175
    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
   176
    QString 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
   177
    QString weapons)
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
   178
const
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
   179
{
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
   180
    QStandardItem * item = new QStandardItem(icon, 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
   181
    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
   182
    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
   183
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
   184
    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
   185
    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
   186
    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
   187
    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
   188
    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
   189
    mapInfo.weapons = weapons;
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
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
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
    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
   193
    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
   194
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
    if (mapInfo.type == Invalid)
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
            Q_ASSERT(false);
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
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
   198
    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
   199
}