Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 43 additions & 49 deletions frontend/components/SourceTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,32 @@ SourceTree::SourceTree(QWidget *parent_) : QListView(parent_)
setItemDelegate(new SourceTreeDelegate(this));
}

void SourceTree::setModel(SourceTreeModel *model)
{
treeModel = model;
QListView::setModel(model);
}

void SourceTree::UpdateIcons()
{
SourceTreeModel *stm = GetStm();
stm->SceneChanged();
model()->SceneChanged();
}

void SourceTree::SetIconsVisible(bool visible)
{
SourceTreeModel *stm = GetStm();

iconsVisible = visible;
stm->SceneChanged();
model()->SceneChanged();
}

void SourceTree::ResetWidgets()
{
OBSScene scene = GetCurrentScene();

SourceTreeModel *stm = GetStm();
stm->UpdateGroupState(false);
model()->UpdateGroupState(false);

for (int i = 0; i < stm->items.count(); i++) {
QModelIndex index = stm->createIndex(i, 0, nullptr);
setIndexWidget(index, new SourceTreeItem(this, stm->items[i]));
for (int i = 0; i < model()->items.count(); i++) {
QModelIndex index = model()->createIndex(i, 0, nullptr);
setIndexWidget(index, new SourceTreeItem(this, model()->items[i]));
}
}

Expand All @@ -75,14 +77,12 @@ void SourceTree::UpdateWidget(const QModelIndex &idx, obs_sceneitem_t *item)

void SourceTree::UpdateWidgets(bool force)
{
SourceTreeModel *stm = GetStm();

for (int i = 0; i < stm->items.size(); i++) {
obs_sceneitem_t *item = stm->items[i];
for (int i = 0; i < model()->items.size(); i++) {
obs_sceneitem_t *item = model()->items[i];
SourceTreeItem *widget = GetItemWidget(i);

if (!widget) {
UpdateWidget(stm->createIndex(i, 0), item);
UpdateWidget(model()->createIndex(i, 0), item);
} else {
widget->Update(force);
}
Expand All @@ -91,18 +91,17 @@ void SourceTree::UpdateWidgets(bool force)

void SourceTree::SelectItem(obs_sceneitem_t *sceneitem, bool select)
{
SourceTreeModel *stm = GetStm();
int i = 0;

for (; i < stm->items.count(); i++) {
if (stm->items[i] == sceneitem)
for (; i < model()->items.count(); i++) {
if (model()->items[i] == sceneitem)
break;
}

if (i == stm->items.count())
if (i == model()->items.count())
return;

QModelIndex index = stm->createIndex(i, 0);
QModelIndex index = model()->createIndex(i, 0);
if (index.isValid() && select != selectionModel()->isSelected(index))
selectionModel()->select(index, select ? QItemSelectionModel::Select : QItemSelectionModel::Deselect);
}
Expand All @@ -124,8 +123,8 @@ void SourceTree::dropEvent(QDropEvent *event)

OBSScene scene = GetCurrentScene();
obs_source_t *scenesource = obs_scene_get_source(scene);
SourceTreeModel *stm = GetStm();
auto &items = stm->items;

auto &items = model()->items;
QModelIndexList indices = selectedIndexes();

DropIndicatorPosition indicator = dropIndicatorPosition();
Expand Down Expand Up @@ -172,7 +171,7 @@ void SourceTree::dropEvent(QDropEvent *event)
indicator == QAbstractItemView::OnViewport)
row++;

if (row < 0 || row > stm->items.count()) {
if (row < 0 || row > model()->items.count()) {
QListView::dropEvent(event);
return;
}
Expand All @@ -194,10 +193,10 @@ void SourceTree::dropEvent(QDropEvent *event)
/* below another group */

obs_sceneitem_t *itemBelow;
if (row == stm->items.count())
if (row == model()->items.count())
itemBelow = nullptr;
else
itemBelow = stm->items[row];
itemBelow = model()->items[row];

if (hasGroups) {
if (!itemBelow || obs_sceneitem_get_group(scene, itemBelow) != dropGroup) {
Expand Down Expand Up @@ -253,7 +252,7 @@ void SourceTree::dropEvent(QDropEvent *event)
obs_sceneitem_t *subitemGroup = obs_sceneitem_get_group(scene, subitem);

if (subitemGroup == item) {
QModelIndex idx = stm->createIndex(j, 0);
QModelIndex idx = model()->createIndex(j, 0);
indices.insert(i + 1, idx);
}
}
Expand Down Expand Up @@ -283,9 +282,9 @@ void SourceTree::dropEvent(QDropEvent *event)
itemTo--;

if (itemTo != from) {
stm->beginMoveRows(QModelIndex(), from, from, QModelIndex(), to);
model()->beginMoveRows(QModelIndex(), from, from, QModelIndex(), to);
MoveItem(items, from, itemTo);
stm->endMoveRows();
model()->endMoveRows();
}

r = persistentIdx.row() + 1;
Expand Down Expand Up @@ -397,9 +396,9 @@ void SourceTree::dropEvent(QDropEvent *event)
/* group */

if (dropOnCollapsed) {
stm->beginRemoveRows(QModelIndex(), firstIdx, lastIdx);
model()->beginRemoveRows(QModelIndex(), firstIdx, lastIdx);
items.remove(firstIdx, lastIdx - firstIdx + 1);
stm->endRemoveRows();
model()->endRemoveRows();
}

/* --------------------------------------- */
Expand All @@ -423,19 +422,18 @@ void SourceTree::selectionChanged(const QItemSelection &selected, const QItemSel

{
QSignalBlocker sourcesSignalBlocker(this);
SourceTreeModel *stm = GetStm();

QModelIndexList selectedIdxs = selected.indexes();
QModelIndexList deselectedIdxs = deselected.indexes();

for (int i = 0; i < selectedIdxs.count(); i++) {
int idx = selectedIdxs[i].row();
obs_sceneitem_select(stm->items[idx], true);
obs_sceneitem_select(model()->items[idx], true);
}

for (int i = 0; i < deselectedIdxs.count(); i++) {
int idx = deselectedIdxs[i].row();
obs_sceneitem_select(stm->items[idx], false);
obs_sceneitem_select(model()->items[idx], false);
}

OBSBasic::Get()->UpdateContextBarDeferred();
Expand Down Expand Up @@ -480,13 +478,13 @@ void SourceTree::NewGroupEdit(int row)

bool SourceTree::Edit(int row)
{
SourceTreeModel *stm = GetStm();
if (row < 0 || row >= stm->items.count())
if (row < 0 || row >= model()->items.count()) {
return false;
}

QModelIndex index = stm->createIndex(row, 0);
QModelIndex index = model()->createIndex(row, 0);
QWidget *widget = indexWidget(index);
SourceTreeItem *itemWidget = reinterpret_cast<SourceTreeItem *>(widget);
SourceTreeItem *itemWidget = static_cast<SourceTreeItem *>(widget);
if (itemWidget->IsEditing()) {
#ifdef __APPLE__
itemWidget->ExitEditMode(true);
Expand All @@ -501,7 +499,6 @@ bool SourceTree::Edit(int row)

bool SourceTree::MultipleBaseSelected() const
{
SourceTreeModel *stm = GetStm();
QModelIndexList selectedIndices = selectedIndexes();

OBSScene scene = GetCurrentScene();
Expand All @@ -511,7 +508,7 @@ bool SourceTree::MultipleBaseSelected() const
}

for (auto &idx : selectedIndices) {
obs_sceneitem_t *item = stm->items[idx.row()];
obs_sceneitem_t *item = model()->items[idx.row()];
if (obs_sceneitem_is_group(item)) {
return false;
}
Expand All @@ -527,7 +524,6 @@ bool SourceTree::MultipleBaseSelected() const

bool SourceTree::GroupsSelected() const
{
SourceTreeModel *stm = GetStm();
QModelIndexList selectedIndices = selectedIndexes();

OBSScene scene = GetCurrentScene();
Expand All @@ -537,7 +533,7 @@ bool SourceTree::GroupsSelected() const
}

for (auto &idx : selectedIndices) {
obs_sceneitem_t *item = stm->items[idx.row()];
obs_sceneitem_t *item = model()->items[idx.row()];
if (!obs_sceneitem_is_group(item)) {
return false;
}
Expand All @@ -548,7 +544,6 @@ bool SourceTree::GroupsSelected() const

bool SourceTree::GroupedItemsSelected() const
{
SourceTreeModel *stm = GetStm();
QModelIndexList selectedIndices = selectedIndexes();
OBSScene scene = GetCurrentScene();

Expand All @@ -557,7 +552,7 @@ bool SourceTree::GroupedItemsSelected() const
}

for (auto &idx : selectedIndices) {
obs_sceneitem_t *item = stm->items[idx.row()];
obs_sceneitem_t *item = model()->items[idx.row()];
obs_scene *itemScene = obs_sceneitem_get_scene(item);

if (itemScene != scene) {
Expand All @@ -571,7 +566,7 @@ bool SourceTree::GroupedItemsSelected() const
void SourceTree::Remove(OBSSceneItem item, OBSScene scene)
{
OBSBasic *main = OBSBasic::Get();
GetStm()->Remove(item);
model()->Remove(item);
main->SaveProject();

if (!main->SavingDisabled()) {
Expand All @@ -586,18 +581,18 @@ void SourceTree::GroupSelectedItems()
{
QModelIndexList indices = selectedIndexes();
std::sort(indices.begin(), indices.end());
GetStm()->GroupSelectedItems(indices);
model()->GroupSelectedItems(indices);
}

void SourceTree::UngroupSelectedGroups()
{
QModelIndexList indices = selectedIndexes();
GetStm()->UngroupSelectedGroups(indices);
model()->UngroupSelectedGroups(indices);
}

void SourceTree::AddGroup()
{
GetStm()->AddGroup();
model()->AddGroup();
}

void SourceTree::UpdateNoSourcesMessage()
Expand All @@ -615,8 +610,7 @@ void SourceTree::UpdateNoSourcesMessage()

void SourceTree::paintEvent(QPaintEvent *event)
{
SourceTreeModel *stm = GetStm();
if (stm && !stm->items.count()) {
if (model() && !model()->items.count()) {
QPainter p(viewport());

if (!textPrepared) {
Expand Down
23 changes: 13 additions & 10 deletions frontend/components/SourceTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class SourceTree : public QListView {

OBSData undoSceneData;

SourceTreeModel *treeModel;

bool iconsVisible = true;

void UpdateNoSourcesMessage();
Expand All @@ -29,23 +31,24 @@ class SourceTree : public QListView {
void UpdateWidget(const QModelIndex &idx, obs_sceneitem_t *item);
void UpdateWidgets(bool force = false);

inline SourceTreeModel *GetStm() const { return reinterpret_cast<SourceTreeModel *>(model()); }

public:
inline SourceTreeItem *GetItemWidget(int idx)
{
QWidget *widget = indexWidget(GetStm()->createIndex(idx, 0));
return reinterpret_cast<SourceTreeItem *>(widget);
QWidget *widget = indexWidget(model()->createIndex(idx, 0));
return static_cast<SourceTreeItem *>(widget);
}

explicit SourceTree(QWidget *parent = nullptr);

void setModel(SourceTreeModel *model);
SourceTreeModel *model() const { return treeModel; }

inline bool IgnoreReorder() const { return ignoreReorder; }
inline void Clear() { GetStm()->Clear(); }
inline void Clear() { model()->Clear(); }

inline void Add(obs_sceneitem_t *item) { GetStm()->Add(item); }
inline OBSSceneItem Get(int idx) { return GetStm()->Get(idx); }
inline QString GetNewGroupName() { return GetStm()->GetNewGroupName(); }
inline void Add(obs_sceneitem_t *item) { model()->Add(item); }
inline OBSSceneItem Get(int idx) { return model()->Get(idx); }
inline QString GetNewGroupName() { return model()->GetNewGroupName(); }

void SelectItem(obs_sceneitem_t *sceneitem, bool select);

Expand All @@ -57,8 +60,8 @@ class SourceTree : public QListView {
void SetIconsVisible(bool visible);

public slots:
inline void ReorderItems() { GetStm()->ReorderItems(); }
inline void RefreshItems() { GetStm()->SceneChanged(); }
inline void ReorderItems() { model()->ReorderItems(); }
inline void RefreshItems() { model()->SceneChanged(); }
void Remove(OBSSceneItem item, OBSScene scene);
void GroupSelectedItems();
void UngroupSelectedGroups();
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/SourceTreeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,9 @@ void SourceTreeItem::ExpandClicked(bool checked)
obs_data_set_bool(data, "collapsed", checked);

if (!checked)
tree->GetStm()->ExpandGroup(sceneitem);
tree->model()->ExpandGroup(sceneitem);
else
tree->GetStm()->CollapseGroup(sceneitem);
tree->model()->CollapseGroup(sceneitem);
}

void SourceTreeItem::Select()
Expand Down
8 changes: 7 additions & 1 deletion frontend/components/VolumeControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,13 @@ void VolumeControl::showVolumeControlMenu(QPoint pos)

void VolumeControl::renameSource()
{
QAction *action = reinterpret_cast<QAction *>(sender());
// FIXME: https://github.com/obsproject/obs-studio/issues/13444
// sender() is a brittle and outdated way to work with signals/slots.
QAction *action = qobject_cast<QAction *>(sender());
Comment thread
Warchamp7 marked this conversation as resolved.
if (!action) {
return;
}

OBSSource source = action->property("source").value<OBSSource>();

std::string uuid = obs_source_get_uuid(source);
Expand Down
2 changes: 1 addition & 1 deletion frontend/dialogs/OBSBasicAdvAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void OBSBasicAdvAudio::SetIconsVisible(bool visible)
showVisible = visible;

QLayoutItem *item = ui->mainLayout->itemAtPosition(0, 0);
QLabel *headerLabel = qobject_cast<QLabel *>(item->widget());
QWidget *headerLabel = item->widget();
visible ? headerLabel->show() : headerLabel->hide();

for (size_t i = 0; i < controls.size(); i++) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/dialogs/OBSBasicFilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ void OBSBasicFilters::FilterNameEdited(QWidget *editor, QListWidget *list)
{
QListWidgetItem *listItem = list->currentItem();
OBSSource filter = listItem->data(Qt::UserRole).value<OBSSource>();
QLineEdit *edit = qobject_cast<QLineEdit *>(editor);
QLineEdit *edit = static_cast<QLineEdit *>(editor);
string name = edit->text().trimmed().toStdString();

const char *prevName = obs_source_get_name(filter);
Expand Down
4 changes: 2 additions & 2 deletions frontend/dialogs/OBSBasicSourceSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ void OBSBasicSourceSelect::rebuildSourceTypeList()
{
ui->sourceTypeList->clear();

OBSBasic *main = qobject_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();

const char *unversioned_type;
const char *type;
Expand Down Expand Up @@ -763,7 +763,7 @@ void OBSBasicSourceSelect::createNew()

OBSSceneItem item = addResult.value();

OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
OBSBasic *main = OBSBasic::Get();
std::string sceneUuid = obs_source_get_uuid(main->GetCurrentSceneSource());
auto undo = [sceneUuid](const std::string &data) {
OBSBasic *main = OBSBasic::Get();
Expand Down
Loading
Loading