# HG changeset patch # User Wuzzy # Date 1521643100 -3600 # Node ID 2c0779260e8a7040d28789fe347bfc4e5dacc78c # Parent e13777374583572a00c159d7a4e84d8bc132bff0 Partially fix wrong preview when joining host room with missing map diff -r e13777374583 -r 2c0779260e8a QTfrontend/ui/widget/mapContainer.cpp --- a/QTfrontend/ui/widget/mapContainer.cpp Wed Mar 21 14:36:26 2018 +0100 +++ b/QTfrontend/ui/widget/mapContainer.cpp Wed Mar 21 15:38:20 2018 +0100 @@ -337,6 +337,24 @@ changeMapType(MapModel::GeneratedMap); } +void HWMapContainer::onImageReceived(const QPixmap &newImage) +{ + // When image received from the engine. + switch (m_mapInfo.type) + { + case MapModel::GeneratedMap: + case MapModel::GeneratedMaze: + case MapModel::GeneratedPerlin: + case MapModel::HandDrawnMap: + case MapModel::FortsMap: + setImage(newImage); + break; + // Throw away image if we have switched the map mode in the meantime + default: + return; + } +} + void HWMapContainer::setImage(const QPixmap &newImage) { addInfoToPreview(newImage); @@ -399,7 +417,7 @@ void HWMapContainer::askForGeneratedPreview() { pMap = new HWMap(this); - connect(pMap, SIGNAL(ImageReceived(QPixmap)), this, SLOT(setImage(const QPixmap))); + connect(pMap, SIGNAL(ImageReceived(QPixmap)), this, SLOT(onImageReceived(const QPixmap))); connect(pMap, SIGNAL(HHLimitReceived(int)), this, SLOT(setHHLimit(int))); connect(pMap, SIGNAL(destroyed(QObject *)), this, SLOT(onPreviewMapDestroyed(QObject *))); pMap->getImage(m_seed, @@ -559,10 +577,15 @@ { qDebug() << "HWMapContainer::intSetMap: Map doesn't exist: " << map; m_missingMap = true; - setMapNameLabel(map); - if (m_mapInfo.type != MapModel::StaticMap && m_mapInfo.type != MapModel::MissionMap) + m_curMap = map; + if (m_mapInfo.type == MapModel::StaticMap) + setupStaticMapsView(); + else if (m_mapInfo.type == MapModel::MissionMap) + setupMissionMapsView(); + else { m_mapInfo.type = MapModel::StaticMap; + setupStaticMapsView(); changeMapType(m_mapInfo.type, QModelIndex()); } updatePreview(); @@ -773,7 +796,8 @@ void HWMapContainer::showEvent(QShowEvent * event) { - if (!m_previewEnabled) { + if (!m_previewEnabled) + { m_previewEnabled = true; setRandomTheme(); updatePreview(); @@ -789,8 +813,9 @@ if (pMap) { - disconnect(pMap, 0, this, SLOT(setImage(const QPixmap))); + disconnect(pMap, 0, this, SLOT(onImageReceived(const QPixmap))); disconnect(pMap, 0, this, SLOT(setHHLimit(int))); + disconnect(pMap, 0, this, SLOT(onPreviewMapDestroyed(QObject *))); pMap = 0; } @@ -1287,7 +1312,8 @@ SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(missionMapChanged(const QModelIndex &, const QModelIndex &))); - missionSelectionModel->setCurrentIndex(m_missionMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent); + if(!missionSelectionModel->hasSelection()) + missionSelectionModel->setCurrentIndex(m_missionMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent); } void HWMapContainer::setupStaticMapsView() @@ -1303,7 +1329,8 @@ SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(staticMapChanged(const QModelIndex &, const QModelIndex &))); - staticSelectionModel->setCurrentIndex(m_staticMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent); + if(!staticSelectionModel->hasSelection()) + staticSelectionModel->setCurrentIndex(m_staticMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent); } // Call this function instead of setting the text of the map name label diff -r e13777374583 -r 2c0779260e8a QTfrontend/ui/widget/mapContainer.h --- a/QTfrontend/ui/widget/mapContainer.h Wed Mar 21 14:36:26 2018 +0100 +++ b/QTfrontend/ui/widget/mapContainer.h Wed Mar 21 15:38:20 2018 +0100 @@ -100,7 +100,7 @@ void drawnMapChanged(const QByteArray & data); private slots: - void setImage(const QPixmap & newImage); + void onImageReceived(const QPixmap & newImage); void setHHLimit(int hhLimit); void setRandomSeed(); void setRandomTheme(); @@ -176,6 +176,7 @@ void intSetFeatureSize(int size); void setMissingTheme(const QString & name); void mapChanged(const QModelIndex & map, int type, const QModelIndex & old = QModelIndex()); + void setImage(const QPixmap & newImage); void setImage(const QPixmap & newImage, const QLinearGradient & linearGrad, bool showHHLimit); void addInfoToPreview(const QPixmap & image); void addInfoToPreview(const QPixmap & image, const QLinearGradient & linearGrad, bool drawHHLimit);