* Minor style changes
* Move function definitions
* Split utility.hpp
* Enable include of export-symbol-helper.hpp in tests
This commit is contained in:
Przemek Pawlas 2024-02-22 23:38:49 +01:00 committed by WarmUpTill
parent dcba7c535d
commit 01cf000cbe
22 changed files with 125 additions and 81 deletions

View File

@ -177,6 +177,8 @@ target_sources(
lib/utils/obs-dock.hpp
lib/utils/obs-module-helper.cpp
lib/utils/obs-module-helper.hpp
lib/utils/path-helpers.cpp
lib/utils/path-helpers.hpp
lib/utils/plugin-state-helpers.cpp
lib/utils/plugin-state-helpers.hpp
lib/utils/priority-helper.cpp

View File

@ -3,6 +3,7 @@
#include "log-helper.hpp"
#include "macro-helpers.hpp"
#include "obs-module-helper.hpp"
#include "path-helpers.hpp"
#include "platform-funcs.hpp"
#include "scene-switch-helpers.hpp"
#include "source-helpers.hpp"

View File

@ -3,6 +3,7 @@
#include "filter-combo-box.hpp"
#include "layout-helpers.hpp"
#include "macro.hpp"
#include "path-helpers.hpp"
#include "selection-helpers.hpp"
#include "source-helpers.hpp"
#include "splitter-helpers.hpp"

View File

@ -68,6 +68,7 @@ static void modifyNumValue(Variable &var, double val, const bool increment)
if (!current.has_value()) {
return;
}
if (increment) {
var.SetValue(*current + val);
} else {

View File

@ -2,6 +2,7 @@
#include "advanced-scene-switcher.hpp"
#include "macro-properties.hpp"
#include "macro.hpp"
#include "path-helpers.hpp"
#include "section.hpp"
#include "ui-helpers.hpp"
#include "utility.hpp"

View File

@ -5,7 +5,9 @@
#include "macro-properties.hpp"
#include "macro-tree.hpp"
#include "macro.hpp"
#include "math-helpers.hpp"
#include "name-dialog.hpp"
#include "path-helpers.hpp"
#include "switcher-data.hpp"
#include "ui-helpers.hpp"
#include "utility.hpp"

View File

@ -1,5 +1,6 @@
#include "macro-tree.hpp"
#include "macro.hpp"
#include "path-helpers.hpp"
#include "sync-helpers.hpp"
#include "ui-helpers.hpp"
#include "utility.hpp"
@ -21,7 +22,9 @@ namespace advss {
MacroTreeItem::MacroTreeItem(MacroTree *tree, std::shared_ptr<Macro> macroItem,
bool highlight)
: _tree(tree), _highlight(highlight), _macro(macroItem)
: _tree(tree),
_highlight(highlight),
_macro(macroItem)
{
setAttribute(Qt::WA_TranslucentBackground);
// This is necessary for some theses to display active selections properly
@ -72,7 +75,9 @@ MacroTreeItem::MacroTreeItem(MacroTree *tree, std::shared_ptr<Macro> macroItem,
Update(true);
setLayout(_boxLayout);
auto setRunning = [this](bool val) { _macro->SetPaused(!val); };
auto setRunning = [this](bool val) {
_macro->SetPaused(!val);
};
connect(_running, &QAbstractButton::clicked, setRunning);
connect(_tree->window(), SIGNAL(HighlightMacrosChanged(bool)), this,
SLOT(EnableHighlight(bool)));
@ -523,7 +528,9 @@ MacroTreeModel::GetCurrentMacros(const QModelIndexList &selection) const
MacroTreeModel::MacroTreeModel(MacroTree *st_,
std::deque<std::shared_ptr<Macro>> &macros)
: QAbstractListModel(st_), _mt(st_), _macros(macros)
: QAbstractListModel(st_),
_mt(st_),
_macros(macros)
{
UpdateGroupState(false);
}

View File

@ -1,5 +1,12 @@
#pragma once
#ifdef UNIT_TEST
#define EXPORT
#define ADVSS_EXPORT
#else
#ifdef _MSC_VER
#define EXPORT __declspec(dllexport)
#else
@ -12,3 +19,5 @@
#else
#define ADVSS_EXPORT Q_DECL_IMPORT
#endif
#endif // UNIT_TEST

View File

@ -14,7 +14,9 @@ std::variant<double, std::string> EvalMathExpression(const std::string &expr)
static std::random_device rd;
static std::mt19937 gen(rd());
static std::uniform_real_distribution<double> dis(0.0, 1.0);
static auto randomFunc = []() { return dis(gen); };
static auto randomFunc = []() {
return dis(gen);
};
if (!setupDone) {
symbolTable.add_function("random", randomFunc);
@ -42,10 +44,12 @@ std::optional<double> GetDouble(const std::string &str)
{
char *end = nullptr;
double value = std::strtod(str.c_str(), &end);
if (end != str.c_str() && *end == '\0' && value != HUGE_VAL &&
value != -HUGE_VAL) {
return value;
}
return {};
}
@ -53,11 +57,18 @@ std::optional<int> GetInt(const std::string &str)
{
char *end = nullptr;
int value = std::strtol(str.c_str(), &end, 10);
if (end != str.c_str() && *end == '\0' && value != INT_MAX &&
value != INT_MIN) {
return value;
}
return {};
}
bool DoubleEquals(double left, double right, double epsilon)
{
return (fabs(left - right) < epsilon);
}
} // namespace advss

View File

@ -9,8 +9,9 @@ namespace advss {
std::variant<double, std::string>
EvalMathExpression(const std::string &expression);
bool IsValidNumber(const std::string &);
EXPORT std::optional<double> GetDouble(const std::string &);
EXPORT std::optional<int> GetInt(const std::string &);
bool IsValidNumber(const std::string &str);
EXPORT std::optional<double> GetDouble(const std::string &str);
EXPORT std::optional<int> GetInt(const std::string &str);
EXPORT bool DoubleEquals(double left, double right, double epsilon);
} // namespace advss

View File

@ -0,0 +1,50 @@
#include "path-helpers.hpp"
#include "obs-module-helper.hpp"
#include "obs.hpp"
#include <obs-frontend-api.h>
#include <QDateTime>
#include <QFile>
#include <QStandardPaths>
namespace advss {
std::string GetDataFilePath(const std::string &file)
{
std::string root_path = obs_get_module_data_path(obs_current_module());
if (!root_path.empty()) {
return root_path + "/" + file;
}
return "";
}
QString GetDefaultSettingsSaveLocation()
{
QString desktopPath = QStandardPaths::writableLocation(
QStandardPaths::DesktopLocation);
auto scName = obs_frontend_get_current_scene_collection();
QString sceneCollectionName(scName);
bfree(scName);
auto timestamp = QDateTime::currentDateTime();
auto path = desktopPath + "/adv-ss-" + sceneCollectionName + "-" +
timestamp.toString("yyyy.MM.dd.hh.mm.ss");
// Check if scene collection name contains invalid path characters
QFile file(path);
if (file.exists()) {
return path;
}
bool validPath = file.open(QIODevice::WriteOnly);
if (validPath) {
file.remove();
return path;
}
return desktopPath + "/adv-ss-" +
timestamp.toString("yyyy.MM.dd.hh.mm.ss");
}
} // namespace advss

View File

@ -0,0 +1,12 @@
#pragma once
#include "export-symbol-helper.hpp"
#include <QString>
#include <string>
namespace advss {
EXPORT std::string GetDataFilePath(const std::string &file);
QString GetDefaultSettingsSaveLocation();
} // namespace advss

View File

@ -1,7 +1,7 @@
#include "regex-config.hpp"
#include "obs-module-helper.hpp"
#include "path-helpers.hpp"
#include "ui-helpers.hpp"
#include "utility.hpp"
#include <QLayout>

View File

@ -1,5 +1,6 @@
#include "status-control.hpp"
#include "obs-module-helper.hpp"
#include "path-helpers.hpp"
#include "plugin-state-helpers.hpp"
#include "ui-helpers.hpp"
#include "utility.hpp"

View File

@ -1,12 +1,6 @@
#include "utility.hpp"
#include "obs-module-helper.hpp"
#include "obs.hpp"
#include <nlohmann/json.hpp>
#include <obs-frontend-api.h>
#include <QDateTime>
#include <QFile>
#include <QStandardPaths>
#include <sstream>
namespace advss {
@ -17,11 +11,6 @@ std::pair<int, int> GetCursorPos()
return {cursorPos.x(), cursorPos.y()};
}
bool DoubleEquals(double left, double right, double epsilon)
{
return (fabs(left - right) < epsilon);
}
bool ReplaceAll(std::string &str, const std::string &from,
const std::string &to)
{
@ -85,51 +74,11 @@ std::string ToString(double value)
return stream.str();
}
std::string GetDataFilePath(const std::string &file)
{
std::string root_path = obs_get_module_data_path(obs_current_module());
if (!root_path.empty()) {
return root_path + "/" + file;
}
return "";
}
QString GetDefaultSettingsSaveLocation()
{
QString desktopPath = QStandardPaths::writableLocation(
QStandardPaths::DesktopLocation);
auto scName = obs_frontend_get_current_scene_collection();
QString sceneCollectionName(scName);
bfree(scName);
auto timestamp = QDateTime::currentDateTime();
auto path = desktopPath + "/adv-ss-" + sceneCollectionName + "-" +
timestamp.toString("yyyy.MM.dd.hh.mm.ss");
// Check if scene collection name contains invalid path characters
QFile file(path);
if (file.exists()) {
return path;
}
bool validPath = file.open(QIODevice::WriteOnly);
if (validPath) {
file.remove();
return path;
}
return desktopPath + "/adv-ss-" +
timestamp.toString("yyyy.MM.dd.hh.mm.ss");
}
void listAddClicked(QListWidget *list, QWidget *newWidget,
QPushButton *addButton,
QMetaObject::Connection *addHighlight)
{
if (!list || !newWidget) {
blog(LOG_WARNING,
"listAddClicked called without valid list or widget");
return;
}

View File

@ -6,7 +6,6 @@
#include <QMetaObject>
#include <QPushButton>
#include <QString>
#include <QTextStream>
#include <QWidget>
#include <string>
@ -14,8 +13,6 @@ namespace advss {
EXPORT std::pair<int, int> GetCursorPos();
EXPORT bool DoubleEquals(double left, double right, double epsilon);
bool ReplaceAll(std::string &str, const std::string &from,
const std::string &to);
EXPORT std::optional<std::string> GetJsonField(const std::string &json,
@ -23,9 +20,6 @@ EXPORT std::optional<std::string> GetJsonField(const std::string &json,
EXPORT bool CompareIgnoringLineEnding(QString &s1, QString &s2);
std::string ToString(double value);
EXPORT std::string GetDataFilePath(const std::string &file);
QString GetDefaultSettingsSaveLocation();
/* Legacy helpers */
void listAddClicked(QListWidget *list, QWidget *newWidget,

View File

@ -70,17 +70,19 @@ std::optional<int> Variable::IntValue() const
return GetInt(Value());
}
void Variable::SetValue(const std::string &val)
void Variable::SetValue(const std::string &value)
{
_value = val;
_lastUsed = std::chrono::high_resolution_clock::now();
_value = value;
UpdateLastUsed();
lastVariableChange = std::chrono::high_resolution_clock::now();
}
void Variable::SetValue(double value)
{
_value = ToString(value);
_lastUsed = std::chrono::high_resolution_clock::now();
UpdateLastUsed();
lastVariableChange = std::chrono::high_resolution_clock::now();
}

View File

@ -6,7 +6,7 @@
#include <string>
#include <optional>
#include <QStringList>
#include <obs.hpp>
#include <obs-data.h>
namespace advss {
@ -22,8 +22,8 @@ public:
EXPORT std::string Value(bool updateLastUsed = true) const;
EXPORT std::optional<double> DoubleValue() const;
EXPORT std::optional<int> IntValue() const;
void SetValue(const std::string &val);
void SetValue(double);
void SetValue(const std::string &value);
void SetValue(double value);
std::string GetDefaultValue() const { return _defaultValue; }
static std::shared_ptr<Item> Create()
{

View File

@ -1,8 +1,9 @@
#include "macro-condition-obs-stats.hpp"
#include "layout-helpers.hpp"
#include "utility.hpp"
#include "math-helpers.hpp"
#include <obs-frontend-api.h>
#include <QListView>
namespace advss {

View File

@ -3,6 +3,7 @@
#include <layout-helpers.hpp>
#include <log-helper.hpp>
#include <obs-module-helper.hpp>
#include <path-helpers.hpp>
#include <plugin-state-helpers.hpp>
#include <selection-helpers.hpp>
#include <sync-helpers.hpp>
@ -564,7 +565,8 @@ static inline QStringList getOutputDeviceNames()
}
MidiDeviceSelection::MidiDeviceSelection(QWidget *parent, MidiDeviceType t)
: QComboBox(parent), _type(t)
: QComboBox(parent),
_type(t)
{
AddSelectionEntry(this, obs_module_text("AdvSceneSwitcher.selectItem"));

View File

@ -5,6 +5,7 @@
#include <name-dialog.hpp>
#include <obs-module-helper.hpp>
#include <obs.hpp>
#include <path-helpers.hpp>
#include <QVBoxLayout>
#include <ui-helpers.hpp>
#include <utility.hpp>
@ -189,8 +190,9 @@ void CategoryGrabber::Search(const std::string &)
int startCount = _categoryMap.size();
std::string cursor;
httplib::Params params = {
{"first", "100"}, {"after", cursor}, {"query", _searchString}};
httplib::Params params = {{"first", "100"},
{"after", cursor},
{"query", _searchString}};
auto response = SendGetRequest(*_token, uri, path, params);
while (response.status == 200 && !_stop) {

View File

@ -9,11 +9,6 @@ std::pair<int, int> GetCursorPos()
return {0, 0};
}
bool DoubleEquals(double left, double right, double epsilon)
{
return (fabs(left - right) < epsilon);
}
bool ReplaceAll(std::string &str, const std::string &from,
const std::string &to)
{