Przeglądaj źródła

Minor refactor for creation of sub-windows

This refactors the sub-window code a bit so that instead of deleting the
window pointers, it calls QWidget::close() on them to safely trigger a
normal close on them instead (which will also delete them).
Moves setting the DeleteOnClose flag from inside of the Dialog classes
into the OBSBasic class, to make that behaviour more obvious.
BtbN 11 lat temu
rodzic
commit
34b67db50f

+ 23 - 13
obs/window-basic-main.cpp

@@ -588,8 +588,11 @@ OBSBasic::~OBSBasic()
 	delete cpuUsageTimer;
 	os_cpu_usage_info_destroy(cpuUsageInfo);
 
-	delete properties;
-	delete transformWindow;
+	if (properties)
+		delete properties;
+
+	if (transformWindow)
+		delete transformWindow;
 
 	ClearVolumeControls();
 	ui->sources->clear();
@@ -648,11 +651,18 @@ void OBSBasic::InsertSceneItem(obs_sceneitem_t item)
 	ui->sources->setCurrentRow(0);
 
 	/* if the source was just created, open properties dialog */
-	if (sourceSceneRefs[source] == 0 && loaded) {
-		delete properties;
-		properties = new OBSBasicProperties(this, source);
-		properties->Init();
-	}
+	if (sourceSceneRefs[source] == 0 && loaded)
+		CreatePropertiesWindow(source);
+}
+
+void OBSBasic::CreatePropertiesWindow(obs_source_t source)
+{
+	if (properties)
+		properties->close();
+
+	properties = new OBSBasicProperties(this, source);
+	properties->Init();
+	properties->setAttribute(Qt::WA_DeleteOnClose, true);
 }
 
 /* Qt callbacks for invokeMethod */
@@ -1674,11 +1684,8 @@ void OBSBasic::on_actionSourceProperties_triggered()
 	OBSSceneItem item = GetCurrentSceneItem();
 	OBSSource source = obs_sceneitem_getsource(item);
 
-	if (source) {
-		delete properties;
-		properties = new OBSBasicProperties(this, source);
-		properties->Init();
-	}
+	if (source)
+		CreatePropertiesWindow(source);
 }
 
 void OBSBasic::on_actionSourceUp_triggered()
@@ -2112,9 +2119,12 @@ config_t OBSBasic::Config() const
 
 void OBSBasic::on_actionEditTransform_triggered()
 {
-	delete transformWindow;
+	if (transformWindow)
+		transformWindow->close();
+
 	transformWindow = new OBSBasicTransform(this);
 	transformWindow->show();
+	transformWindow->setAttribute(Qt::WA_DeleteOnClose, true);
 }
 
 void OBSBasic::on_actionResetTransform_triggered()

+ 2 - 0
obs/window-basic-main.hpp

@@ -140,6 +140,8 @@ private:
 	void TempStreamOutput(const char *url, const char *key,
 			int vBitrate, int aBitrate);
 
+	void CreatePropertiesWindow(obs_source_t source);
+
 public slots:
 	void StreamingStart();
 	void StreamingStop(int errorcode);

+ 0 - 2
obs/window-basic-properties.cpp

@@ -36,8 +36,6 @@ OBSBasicProperties::OBSBasicProperties(QWidget *parent, OBSSource source_)
 	  removedSignal (obs_source_signalhandler(source), "remove",
 	                 OBSBasicProperties::SourceRemoved, this)
 {
-	setAttribute(Qt::WA_DeleteOnClose);
-
 	ui->setupUi(this);
 
 	OBSData settings = obs_source_getsettings(source);

+ 0 - 2
obs/window-basic-transform.cpp

@@ -37,8 +37,6 @@ OBSBasicTransform::OBSBasicTransform(OBSBasic *parent)
 	  ui      (new Ui::OBSBasicTransform),
 	  main    (parent)
 {
-	setAttribute(Qt::WA_DeleteOnClose);
-
 	ui->setupUi(this);
 
 	HookWidget(ui->positionX,    DSCROLL_CHANGED, SLOT(OnControlChanged()));