QTfrontend/model/MapModel.cpp
author sheepluva
Fri, 27 Apr 2012 22:22:04 +0200
changeset 6939 970389573788
parent 6938 217ed62e872c
child 6943 1fe601a2761b
permissions -rw-r--r--
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)
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
{
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    30
    beginResetModel();
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    31
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    32
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    33
    DataManager & datamgr = DataManager::instance();
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    34
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    35
    QStringList maps =
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    36
        datamgr.entryList("Maps", QDir::AllDirs | QDir::NoDotAndDotDot);
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    37
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
    38
    QStandardItemModel::clear();
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    39
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
    40
    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
    41
    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
    42
    QList<QStandardItem *> staticMaps;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    43
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    44
    // TODO: icons for these
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    45
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
    46
    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
    47
        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
    48
    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
    49
        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
    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("hand drawn map..."), HandDrawnMap, "+drawn+"));
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    52
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    53
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    54
    QFile mapLuaFile;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    55
    QFile mapCfgFile;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    56
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    57
    foreach (QString map, maps)
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    58
    {
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    59
        mapCfgFile.setFileName(
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    60
            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
    61
        mapLuaFile.setFileName(
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    62
            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
    63
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    64
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    65
        if (mapCfgFile.open(QFile::ReadOnly))
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    66
        {
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
    67
            QString caption;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    68
            QString theme;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    69
            quint32 limit = 0;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    70
            QString scheme;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    71
            QString weapons;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    72
            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
    73
            MapType type = isMission?MissionMap:StaticMap;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    74
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    75
            QTextStream input(&mapCfgFile);
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    76
            input >> theme;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    77
            input >> limit;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    78
            input >> scheme;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    79
            input >> weapons;
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
            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
    81
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
    82
            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
    83
                limit = 18;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    84
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    85
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    86
            if (scheme.isEmpty())
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    87
                scheme = "locked";
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
    88
            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
    89
                scheme.replace("_", " ");
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    90
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    91
            if (weapons.isEmpty())
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    92
                weapons = "locked";
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
    93
            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
    94
                weapons.replace("_", " ");
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    95
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
    96
            if (isMission)
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    97
            {
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
    98
                // 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
    99
                caption = QComboBox::tr("Mission") + ": " + map;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   100
                m_nMissions++;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   101
            }
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
   102
            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
   103
                caption = map;
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   104
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
   105
            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
   106
                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
   107
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
   108
            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
   109
                missionMaps.append(item);
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   110
            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
   111
                staticMaps.append(item);
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   112
        
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   113
        }
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   114
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
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
    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
   118
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
    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
   120
    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
   121
    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
   122
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
   123
    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
   124
    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
   125
    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
   126
    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
   127
    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
   128
    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
   129
    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
   130
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
    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
   132
6938
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   133
    endResetModel();
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
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   137
int MapModel::missionCount() const
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   138
{
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   139
    return m_nMissions;
217ed62e872c MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff changeset
   140
}
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
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
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
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
   144
    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
   145
    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
   146
    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
   147
    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
   148
    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
   149
    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
   150
    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
   151
    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
   152
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
   153
{
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
    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
   155
    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
   156
    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
   157
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
   158
    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
   159
    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
   160
    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
   161
    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
   162
    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
   163
    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
   164
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
   165
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
   166
    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
   167
    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
   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
    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
   170
            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
   171
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
    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
   173
}