Browse Source

remove chains of `parent()->parent()`

godric3 10 months ago
parent
commit
c1413b9368

+ 1 - 0
mapeditor/mapcontroller.h

@@ -69,6 +69,7 @@ public:
 	void redo();
 	
 	PlayerColor defaultPlayer;
+	QDialog * settingsDialog = nullptr;
 	
 private:
 	std::unique_ptr<CMap> _map;

+ 2 - 2
mapeditor/mapsettings/loseconditions.cpp

@@ -310,12 +310,12 @@ void LoseConditions::onObjectSelect()
 		QObject::connect(&l, &ObjectPickerLayer::selectionMade, this, &LoseConditions::onObjectPicked);
 	}
 	
-	dynamic_cast<QWidget*>(parent()->parent()->parent()->parent()->parent()->parent()->parent())->hide();
+	controller->settingsDialog->hide();
 }
 
 void LoseConditions::onObjectPicked(const CGObjectInstance * obj)
 {
-	dynamic_cast<QWidget*>(parent()->parent()->parent()->parent()->parent()->parent()->parent())->show();
+	controller->settingsDialog->show();
 	
 	for(int lvl : {0, 1})
 	{

+ 2 - 1
mapeditor/mapsettings/mapsettings.cpp

@@ -27,7 +27,7 @@ MapSettings::MapSettings(MapController & ctrl, QWidget *parent) :
 	ui->setupUi(this);
 
 	assert(controller.map());
-	
+	controller.settingsDialog = this;
 	show();
 
 	for(auto const & objectPtr : VLC->skillh->objects)
@@ -73,6 +73,7 @@ MapSettings::MapSettings(MapController & ctrl, QWidget *parent) :
 
 MapSettings::~MapSettings()
 {
+	controller.settingsDialog = nullptr;
 	delete ui;
 }
 

+ 2 - 2
mapeditor/mapsettings/timedevent.cpp

@@ -122,7 +122,7 @@ void TimedEvent::on_addObjectToDelete_clicked()
 		QObject::connect(&l, &ObjectPickerLayer::selectionMade, this, &TimedEvent::onObjectPicked);
 	}
 	hide();
-	dynamic_cast<QWidget *>(parent()->parent()->parent()->parent()->parent()->parent()->parent())->hide();
+	controller.settingsDialog->hide();
 }
 
 void TimedEvent::on_removeObjectToDelete_clicked()
@@ -133,7 +133,7 @@ void TimedEvent::on_removeObjectToDelete_clicked()
 void TimedEvent::onObjectPicked(const CGObjectInstance * obj)
 {
 	show();
-	dynamic_cast<QWidget *>(parent()->parent()->parent()->parent()->parent()->parent()->parent())->show();
+	controller.settingsDialog->show();
 
 	for(int lvl : {0, 1})
 	{

+ 2 - 2
mapeditor/mapsettings/victoryconditions.cpp

@@ -528,12 +528,12 @@ void VictoryConditions::onObjectSelect()
 		QObject::connect(&l, &ObjectPickerLayer::selectionMade, this, &VictoryConditions::onObjectPicked);
 	}
 	
-	dynamic_cast<QWidget*>(parent()->parent()->parent()->parent()->parent()->parent()->parent())->hide();
+	controller->settingsDialog->hide();
 }
 
 void VictoryConditions::onObjectPicked(const CGObjectInstance * obj)
 {
-	dynamic_cast<QWidget*>(parent()->parent()->parent()->parent()->parent()->parent()->parent())->show();
+	controller->settingsDialog->show();
 	
 	for(int lvl : {0, 1})
 	{

+ 2 - 2
mapeditor/playerparams.cpp

@@ -202,12 +202,12 @@ void PlayerParams::on_townSelect_clicked()
 		QObject::connect(&l, &ObjectPickerLayer::selectionMade, this, &PlayerParams::onTownPicked);
 	}
 	
-	dynamic_cast<QWidget*>(parent()->parent()->parent()->parent())->hide();
+	controller.settingsDialog->hide();
 }
 
 void PlayerParams::onTownPicked(const CGObjectInstance * obj)
 {
-	dynamic_cast<QWidget*>(parent()->parent()->parent()->parent())->show();
+	controller.settingsDialog->show();
 	
 	for(int lvl : {0, 1})
 	{

+ 2 - 0
mapeditor/playersettings.cpp

@@ -22,6 +22,7 @@ PlayerSettings::PlayerSettings(MapController & ctrl, QWidget *parent) :
 	controller(ctrl)
 {
 	ui->setupUi(this);
+	controller.settingsDialog = this;
 	show();
 
 	int players = 0;
@@ -46,6 +47,7 @@ PlayerSettings::PlayerSettings(MapController & ctrl, QWidget *parent) :
 
 PlayerSettings::~PlayerSettings()
 {
+	controller.settingsDialog = nullptr;
 	delete ui;
 }