Add GetMacroSegmentDescription() and IsValidMacroSegmentIndex()

This commit is contained in:
WarmUpTill
2023-07-22 23:07:44 +02:00
committed by WarmUpTill
parent 78d73af589
commit 7b1c56877e
2 changed files with 58 additions and 0 deletions

View File

@@ -5,6 +5,9 @@
#include "scene-group.hpp"
#include "non-modal-dialog.hpp"
#include "obs-module-helper.hpp"
#include "macro.hpp"
#include "macro-action-edit.hpp"
#include "macro-condition-edit.hpp"
#include <QStandardPaths>
#include <QFile>
@@ -595,6 +598,58 @@ QStringList GetMonitorNames()
return monitorNames;
}
bool IsValidMacroSegmentIndex(Macro *m, const int idx, bool isCondition)
{
if (!m || idx < 0) {
return false;
}
if (isCondition) {
if (idx >= m->Conditions().size()) {
return false;
}
} else {
if (idx >= m->Actions().size()) {
return false;
}
}
return true;
}
QString GetMacroSegmentDescription(Macro *macro, int idx, bool isCondition)
{
if (!macro) {
return "";
}
if (!IsValidMacroSegmentIndex(macro, idx, isCondition)) {
return "";
}
MacroSegment *segment;
if (isCondition) {
segment = macro->Conditions().at(idx).get();
} else {
segment = macro->Actions().at(idx).get();
}
QString description = QString::fromStdString(segment->GetShortDesc());
QString type;
if (isCondition) {
type = obs_module_text(MacroConditionFactory::GetConditionName(
segment->GetId())
.c_str());
} else {
type = obs_module_text(
MacroActionFactory::GetActionName(segment->GetId())
.c_str());
}
QString result = type;
if (!description.isEmpty()) {
result += ": " + description;
}
return result;
}
QStringList GetSourceNames()
{
auto sourceEnum = [](void *param, obs_source_t *source) -> bool /* -- */

View File

@@ -17,6 +17,7 @@ namespace advss {
class SceneSelection;
class RegexConfig;
struct SceneGroup;
class Macro;
/* Source helpers */
@@ -126,6 +127,8 @@ void ReplaceAll(std::string &str, const std::string &from,
QString GetDefaultSettingsSaveLocation();
std::string GetPathInProfileDir(const char *filePath);
QStringList GetMonitorNames();
bool IsValidMacroSegmentIndex(Macro *m, const int idx, bool isCondition);
QString GetMacroSegmentDescription(Macro *, int idx, bool isCondition);
/* Legacy helpers */