QTfrontend/hwform.cpp
changeset 14623 14b295892fb7
parent 14622 1d3f8cf48831
child 14667 e3e6b0c6543f
--- a/QTfrontend/hwform.cpp	Wed Jan 16 03:40:05 2019 +0100
+++ b/QTfrontend/hwform.cpp	Wed Jan 16 06:02:56 2019 +0100
@@ -2088,12 +2088,13 @@
 {
     Q_UNUSED(index);
     HWTeam team(ui.pageCampaign->CBTeam->currentText());
-    QString campaignName = ui.pageCampaign->CBCampaign->itemData(ui.pageCampaign->CBCampaign->currentIndex()).toString();
+    QString campaignName = ui.pageCampaign->CBCampaign->currentData().toString();
     QString tName = team.name();
 
     campaignMissionInfo = getCampMissionList(campaignName,tName);
     ui.pageCampaign->CBMission->clear();
 
+    // Populate mission list
     for(int i=0;i<campaignMissionInfo.size();i++)
     {
         ui.pageCampaign->CBMission->addItem(QString(campaignMissionInfo[i].realName), QString(campaignMissionInfo[i].name));
@@ -2102,6 +2103,20 @@
         else
             ui.pageCampaign->CBMission->setItemIcon(i, notFinishedIcon);
     }
+
+    // Select first open mission
+    int missionIndex = ui.pageCampaign->CBMission->currentIndex();
+    if(isCampMissionWon(campaignName, missionIndex, tName))
+    {
+        for(int m = 0; m < ui.pageCampaign->CBMission->count(); m++)
+        {
+            if(!isCampMissionWon(campaignName, m, tName))
+            {
+                ui.pageCampaign->CBMission->setCurrentIndex(m);
+                break;
+            }
+        }
+    }
 }
 
 void HWForm::UpdateCampaignPageTeam(int index)
@@ -2118,6 +2133,7 @@
 
     unsigned int n = entries.count();
 
+    // Update campaign status
     for(unsigned int i = 0; i < n; i++)
     {
         QString campaignName = QString(entries[i]).replace(QString(" "),QString("_"));
@@ -2131,7 +2147,7 @@
 void HWForm::UpdateCampaignPageMission(int index)
 {
     // update thumbnail and description
-    QString campaignName = ui.pageCampaign->CBCampaign->itemData(ui.pageCampaign->CBCampaign->currentIndex()).toString();
+    QString campaignName = ui.pageCampaign->CBCampaign->currentData().toString();
     // when campaign changes the UpdateCampaignPageMission is triggered with wrong values
     // this will cause segfault. This check prevents illegal memory reads
     if(index > -1 && index < campaignMissionInfo.count()) {