瀏覽代碼

UI: Add QDataStream opreators for OBSSource

Allows serializing/deserializing sources in and out of QDataStreams via
their UUID
cg2121 2 年之前
父節點
當前提交
e863bea7fb
共有 3 個文件被更改,包括 20 次插入0 次删除
  1. 17 0
      UI/qt-wrappers.cpp
  2. 2 0
      UI/qt-wrappers.hpp
  3. 1 0
      UI/window-basic-main.cpp

+ 17 - 0
UI/qt-wrappers.cpp

@@ -207,6 +207,23 @@ QDataStream &operator>>(QDataStream &in, OBSScene &scene)
 	return in;
 }
 
+QDataStream &operator<<(QDataStream &out, const OBSSource &source)
+{
+	return out << QString(obs_source_get_uuid(source));
+}
+
+QDataStream &operator>>(QDataStream &in, OBSSource &source)
+{
+	QString uuid;
+
+	in >> uuid;
+
+	OBSSourceAutoRelease source_ = obs_get_source_by_uuid(QT_TO_UTF8(uuid));
+	source = source_;
+
+	return in;
+}
+
 void DeleteLayout(QLayout *layout)
 {
 	if (!layout)

+ 2 - 0
UI/qt-wrappers.hpp

@@ -71,6 +71,8 @@ QDataStream &operator>>(QDataStream &in,
 			std::vector<std::shared_ptr<OBSSignal>> &signal_vec);
 QDataStream &operator<<(QDataStream &out, const OBSScene &scene);
 QDataStream &operator>>(QDataStream &in, OBSScene &scene);
+QDataStream &operator<<(QDataStream &out, const OBSSource &source);
+QDataStream &operator>>(QDataStream &in, OBSSource &source);
 
 QThread *CreateQThread(std::function<void()> func);
 

+ 1 - 0
UI/window-basic-main.cpp

@@ -344,6 +344,7 @@ OBSBasic::OBSBasic(QWidget *parent)
 	qRegisterMetaTypeStreamOperators<std::vector<std::shared_ptr<OBSSignal>>>(
 		"std::vector<std::shared_ptr<OBSSignal>>");
 	qRegisterMetaTypeStreamOperators<OBSScene>("OBSScene");
+	qRegisterMetaTypeStreamOperators<OBSSource>("OBSSource");
 #endif
 
 	ui->scenes->setAttribute(Qt::WA_MacShowFocusRect, false);