UI: Fix signals for sub-items of groups

Because sub-items of groups can no longer reroute their signals to the
parent scenes of groups, delegates removal handling to SourceTreeItem
instead of OBSBasic.
master
jp9000 2018-07-16 18:57:17 -07:00
parent 256b7b793d
commit 573d5719d8
4 changed files with 41 additions and 34 deletions

View File

@ -112,7 +112,13 @@ void SourceTreeItem::ReconnectSignals()
obs_sceneitem_t *curItem = obs_sceneitem_t *curItem =
(obs_sceneitem_t*)calldata_ptr(cd, "item"); (obs_sceneitem_t*)calldata_ptr(cd, "item");
if (!curItem || curItem == this_->sceneitem) { if (curItem == this_->sceneitem) {
QMetaObject::invokeMethod(this_->tree,
"Remove",
Q_ARG(OBSSceneItem, curItem));
curItem = nullptr;
}
if (!curItem) {
this_->DisconnectSignals(); this_->DisconnectSignals();
this_->sceneitem = nullptr; this_->sceneitem = nullptr;
} }
@ -130,6 +136,12 @@ void SourceTreeItem::ReconnectSignals()
Q_ARG(bool, visible)); Q_ARG(bool, visible));
}; };
auto reorderGroup = [] (void *data, calldata_t*)
{
SourceTreeItem *this_ = reinterpret_cast<SourceTreeItem*>(data);
QMetaObject::invokeMethod(this_->tree, "ReorderItems");
};
obs_scene_t *scene = obs_sceneitem_get_scene(sceneitem); obs_scene_t *scene = obs_sceneitem_get_scene(sceneitem);
obs_source_t *sceneSource = obs_scene_get_source(scene); obs_source_t *sceneSource = obs_scene_get_source(scene);
signal_handler_t *signal = obs_source_get_signal_handler(sceneSource); signal_handler_t *signal = obs_source_get_signal_handler(sceneSource);
@ -138,6 +150,14 @@ void SourceTreeItem::ReconnectSignals()
itemRemoveSignal.Connect(signal, "item_remove", removeItem, this); itemRemoveSignal.Connect(signal, "item_remove", removeItem, this);
visibleSignal.Connect(signal, "item_visible", itemVisible, this); visibleSignal.Connect(signal, "item_visible", itemVisible, this);
if (obs_sceneitem_is_group(sceneitem)) {
obs_source_t *source = obs_sceneitem_get_source(sceneitem);
signal = obs_source_get_signal_handler(source);
groupReorderSignal.Connect(signal, "reorder", reorderGroup,
this);
}
/* --------------------------------------------------------- */ /* --------------------------------------------------------- */
auto renamed = [] (void *data, calldata_t *cd) auto renamed = [] (void *data, calldata_t *cd)
@ -1274,6 +1294,23 @@ bool SourceTree::GroupedItemsSelected() const
return false; return false;
} }
void SourceTree::Remove(OBSSceneItem item)
{
OBSBasic *main = reinterpret_cast<OBSBasic*>(App()->GetMainWindow());
GetStm()->Remove(item);
main->SaveProject();
if (!main->SavingDisabled()) {
obs_scene_t *scene = obs_sceneitem_get_scene(item);
obs_source_t *sceneSource = obs_scene_get_source(scene);
obs_source_t *itemSource = obs_sceneitem_get_source(item);
blog(LOG_INFO, "User Removed source '%s' (%s) from scene '%s'",
obs_source_get_name(itemSource),
obs_source_get_id(itemSource),
obs_source_get_name(sceneSource));
}
}
void SourceTree::GroupSelectedItems() void SourceTree::GroupSelectedItems()
{ {
QModelIndexList indices = selectedIndexes(); QModelIndexList indices = selectedIndexes();

View File

@ -62,6 +62,7 @@ private:
OBSSceneItem sceneitem; OBSSceneItem sceneitem;
OBSSignal sceneRemoveSignal; OBSSignal sceneRemoveSignal;
OBSSignal itemRemoveSignal; OBSSignal itemRemoveSignal;
OBSSignal groupReorderSignal;
OBSSignal visibleSignal; OBSSignal visibleSignal;
OBSSignal renameSignal; OBSSignal renameSignal;
OBSSignal removeSignal; OBSSignal removeSignal;
@ -143,11 +144,9 @@ public:
explicit SourceTree(QWidget *parent = nullptr); explicit SourceTree(QWidget *parent = nullptr);
inline bool IgnoreReorder() const {return ignoreReorder;} inline bool IgnoreReorder() const {return ignoreReorder;}
inline void ReorderItems() {GetStm()->ReorderItems();}
inline void Clear() {GetStm()->Clear();} inline void Clear() {GetStm()->Clear();}
inline void Add(obs_sceneitem_t *item) {GetStm()->Add(item);} inline void Add(obs_sceneitem_t *item) {GetStm()->Add(item);}
inline void Remove(obs_sceneitem_t *item) {GetStm()->Remove(item);}
inline OBSSceneItem Get(int idx) {return GetStm()->Get(idx);} inline OBSSceneItem Get(int idx) {return GetStm()->Get(idx);}
inline QString GetNewGroupName() {return GetStm()->GetNewGroupName();} inline QString GetNewGroupName() {return GetStm()->GetNewGroupName();}
@ -158,6 +157,8 @@ public:
bool GroupedItemsSelected() const; bool GroupedItemsSelected() const;
public slots: public slots:
inline void ReorderItems() {GetStm()->ReorderItems();}
void Remove(OBSSceneItem item);
void GroupSelectedItems(); void GroupSelectedItems();
void UngroupSelectedGroups(); void UngroupSelectedGroups();
void AddGroup(); void AddGroup();

View File

@ -2137,8 +2137,6 @@ void OBSBasic::AddScene(OBSSource source)
container.handlers.assign({ container.handlers.assign({
std::make_shared<OBSSignal>(handler, "item_add", std::make_shared<OBSSignal>(handler, "item_add",
OBSBasic::SceneItemAdded, this), OBSBasic::SceneItemAdded, this),
std::make_shared<OBSSignal>(handler, "item_remove",
OBSBasic::SceneItemRemoved, this),
std::make_shared<OBSSignal>(handler, "item_select", std::make_shared<OBSSignal>(handler, "item_select",
OBSBasic::SceneItemSelected, this), OBSBasic::SceneItemSelected, this),
std::make_shared<OBSSignal>(handler, "item_deselect", std::make_shared<OBSSignal>(handler, "item_deselect",
@ -2236,23 +2234,6 @@ void OBSBasic::AddSceneItem(OBSSceneItem item)
} }
} }
void OBSBasic::RemoveSceneItem(OBSSceneItem item)
{
ui->sources->Remove(item);
SaveProject();
if (!disableSaving) {
obs_scene_t *scene = obs_sceneitem_get_scene(item);
obs_source_t *sceneSource = obs_scene_get_source(scene);
obs_source_t *itemSource = obs_sceneitem_get_source(item);
blog(LOG_INFO, "User Removed source '%s' (%s) from scene '%s'",
obs_source_get_name(itemSource),
obs_source_get_id(itemSource),
obs_source_get_name(sceneSource));
}
}
void OBSBasic::UpdateSceneSelection(OBSSource source) void OBSBasic::UpdateSceneSelection(OBSSource source)
{ {
if (source) { if (source) {
@ -2853,16 +2834,6 @@ void OBSBasic::SceneItemAdded(void *data, calldata_t *params)
Q_ARG(OBSSceneItem, OBSSceneItem(item))); Q_ARG(OBSSceneItem, OBSSceneItem(item)));
} }
void OBSBasic::SceneItemRemoved(void *data, calldata_t *params)
{
OBSBasic *window = static_cast<OBSBasic*>(data);
obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
QMetaObject::invokeMethod(window, "RemoveSceneItem",
Q_ARG(OBSSceneItem, OBSSceneItem(item)));
}
void OBSBasic::SceneItemSelected(void *data, calldata_t *params) void OBSBasic::SceneItemSelected(void *data, calldata_t *params)
{ {
OBSBasic *window = static_cast<OBSBasic*>(data); OBSBasic *window = static_cast<OBSBasic*>(data);

View File

@ -416,7 +416,6 @@ public slots:
private slots: private slots:
void AddSceneItem(OBSSceneItem item); void AddSceneItem(OBSSceneItem item);
void RemoveSceneItem(OBSSceneItem item);
void AddScene(OBSSource source); void AddScene(OBSSource source);
void RemoveScene(OBSSource source); void RemoveScene(OBSSource source);
void RenameSources(OBSSource source, QString newName, QString prevName); void RenameSources(OBSSource source, QString newName, QString prevName);
@ -473,7 +472,6 @@ private:
/* OBS Callbacks */ /* OBS Callbacks */
static void SceneReordered(void *data, calldata_t *params); static void SceneReordered(void *data, calldata_t *params);
static void SceneItemAdded(void *data, calldata_t *params); static void SceneItemAdded(void *data, calldata_t *params);
static void SceneItemRemoved(void *data, calldata_t *params);
static void SceneItemSelected(void *data, calldata_t *params); static void SceneItemSelected(void *data, calldata_t *params);
static void SceneItemDeselected(void *data, calldata_t *params); static void SceneItemDeselected(void *data, calldata_t *params);
static void SourceCreated(void *data, calldata_t *params); static void SourceCreated(void *data, calldata_t *params);