mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-12 04:11:06 -05:00
Variable related refactors
This commit is contained in:
committed by
WarmUpTill
parent
e265e4828e
commit
eec9244e4c
@@ -12,6 +12,7 @@ static void setVariableTabVisible(QTabWidget *tabWidget, bool visible)
|
||||
obs_module_text("AdvSceneSwitcher.variableTab.title")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
// TODO: Switch to setTabVisible() once QT 5.15 is more wide spread
|
||||
tabWidget->setTabEnabled(idx, visible);
|
||||
@@ -23,9 +24,10 @@ static void setVariableTabVisible(QTabWidget *tabWidget, bool visible)
|
||||
}
|
||||
}
|
||||
|
||||
static QString getSaveActionString(Variable *variable)
|
||||
static QString formatSaveActionText(Variable *variable)
|
||||
{
|
||||
QString saveAction;
|
||||
|
||||
switch (variable->GetSaveAction()) {
|
||||
case Variable::SaveAction::DONT_SAVE:
|
||||
saveAction = obs_module_text(
|
||||
@@ -38,26 +40,27 @@ static QString getSaveActionString(Variable *variable)
|
||||
case Variable::SaveAction::SET_DEFAULT:
|
||||
saveAction =
|
||||
QString(obs_module_text(
|
||||
"AdvSceneSwitcher.variable.save.default")) +
|
||||
" \"" +
|
||||
QString::fromStdString(variable->GetDefaultValue()) +
|
||||
"\"";
|
||||
"AdvSceneSwitcher.variableTab.saveLoadBehavior.text.default"))
|
||||
.arg(QString::fromStdString(
|
||||
variable->GetDefaultValue()));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return saveAction;
|
||||
}
|
||||
|
||||
static QString getLastUsedString(Variable *variable)
|
||||
static QString formatLastUsedText(Variable *variable)
|
||||
{
|
||||
auto lastUsed = variable->SecondsSinceLastUse();
|
||||
auto lastUsed = variable->GetSecondsSinceLastUse();
|
||||
if (!lastUsed) {
|
||||
return obs_module_text(
|
||||
"AdvSceneSwitcher.variableTab.neverNused");
|
||||
"AdvSceneSwitcher.variableTab.lastUsed.text.never");
|
||||
}
|
||||
QString fmt = obs_module_text("AdvSceneSwitcher.variableTab.lastUsed");
|
||||
return fmt.arg(QString::number(*lastUsed));
|
||||
|
||||
QString text = obs_module_text("AdvSceneSwitcher.variableTab.lastUsed.text");
|
||||
return text.arg(QString::number(*lastUsed));
|
||||
}
|
||||
|
||||
static QString formatLastChangedText(Variable *variable)
|
||||
@@ -65,11 +68,11 @@ static QString formatLastChangedText(Variable *variable)
|
||||
auto lastChanged = variable->GetSecondsSinceLastChange();
|
||||
if (!lastChanged) {
|
||||
return obs_module_text(
|
||||
"AdvSceneSwitcher.variableTab.lastChanged.text.never");
|
||||
"AdvSceneSwitcher.variableTab.lastChanged.text.none");
|
||||
}
|
||||
|
||||
QString text =
|
||||
obs_module_text("AdvSceneSwitcher.variableTab.lastChanged");
|
||||
obs_module_text("AdvSceneSwitcher.variableTab.lastChanged.text");
|
||||
return text.arg(QString::number(*lastChanged));
|
||||
}
|
||||
|
||||
@@ -82,7 +85,7 @@ static QString formatLastChangedTooltip(Variable *variable)
|
||||
|
||||
QString tooltip = obs_module_text(
|
||||
"AdvSceneSwitcher.variableTab.lastChanged.tooltip");
|
||||
return tooltip.arg(QString::fromStdString(variable->PreviousValue()));
|
||||
return tooltip.arg(QString::fromStdString(variable->GetPreviousValue()));
|
||||
}
|
||||
|
||||
static void addVariableRow(QTableWidget *table, Variable *variable)
|
||||
@@ -104,9 +107,9 @@ static void addVariableRow(QTableWidget *table, Variable *variable)
|
||||
item = new QTableWidgetItem(varValue);
|
||||
item->setToolTip(varValue);
|
||||
table->setItem(row, ++col, item);
|
||||
item = new QTableWidgetItem(getSaveActionString(variable));
|
||||
item = new QTableWidgetItem(formatSaveActionText(variable));
|
||||
table->setItem(row, ++col, item);
|
||||
item = new QTableWidgetItem(getLastUsedString(variable));
|
||||
item = new QTableWidgetItem(formatLastUsedText(variable));
|
||||
table->setItem(row, ++col, item);
|
||||
item = new QTableWidgetItem(formatLastChangedText(variable));
|
||||
item->setToolTip(formatLastChangedTooltip(variable));
|
||||
@@ -127,26 +130,28 @@ static void removeVariableRow(QTableWidget *table, const QString &name)
|
||||
table->sortByColumn(0, Qt::AscendingOrder);
|
||||
}
|
||||
|
||||
static void updateVaribleStatus(QTableWidget *table)
|
||||
static void updateVariableStatus(QTableWidget *table)
|
||||
{
|
||||
for (int row = 0; row < table->rowCount(); row++) {
|
||||
auto item = table->item(row, 0);
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto weakVariable = GetWeakVariableByQString(item->text());
|
||||
auto variable = weakVariable.lock();
|
||||
if (!variable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
item = table->item(row, 1);
|
||||
auto varValue = QString::fromStdString(variable->Value(false));
|
||||
item->setText(varValue);
|
||||
item->setToolTip(varValue);
|
||||
item = table->item(row, 2);
|
||||
item->setText(getSaveActionString(variable.get()));
|
||||
item->setText(formatSaveActionText(variable.get()));
|
||||
item = table->item(row, 3);
|
||||
item->setText(getLastUsedString(variable.get()));
|
||||
item->setText(formatLastUsedText(variable.get()));
|
||||
item = table->item(row, 4);
|
||||
item->setText(formatLastChangedText(variable.get()));
|
||||
item->setToolTip(formatLastChangedTooltip(variable.get()));
|
||||
@@ -161,6 +166,7 @@ static void renameVariable(QTableWidget *table, const QString &oldName,
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item->text() == oldName) {
|
||||
item->setText(newName);
|
||||
table->sortByColumn(0, Qt::AscendingOrder);
|
||||
@@ -178,13 +184,14 @@ static void openSettingsDialogAtRow(QTableWidget *table, int row)
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto weakVariable = GetWeakVariableByQString(item->text());
|
||||
auto variable = weakVariable.lock();
|
||||
if (!variable) {
|
||||
return;
|
||||
}
|
||||
auto oldName = variable->Name();
|
||||
|
||||
auto oldName = variable->Name();
|
||||
bool accepted =
|
||||
VariableSettingsDialog::AskForSettings(table, *variable.get());
|
||||
if (accepted && oldName != variable->Name()) {
|
||||
@@ -204,14 +211,14 @@ void AdvSceneSwitcher::SetupVariableTab()
|
||||
|
||||
static const QStringList horizontalHeaders =
|
||||
QStringList()
|
||||
<< obs_module_text("AdvSceneSwitcher.variableTab.header.name")
|
||||
<< obs_module_text("AdvSceneSwitcher.variableTab.header.value")
|
||||
<< obs_module_text("AdvSceneSwitcher.variableTab.name.header")
|
||||
<< obs_module_text("AdvSceneSwitcher.variableTab.value.header")
|
||||
<< obs_module_text(
|
||||
"AdvSceneSwitcher.variableTab.header.saveLoadBehavior")
|
||||
"AdvSceneSwitcher.variableTab.saveLoadBehavior.header")
|
||||
<< obs_module_text(
|
||||
"AdvSceneSwitcher.variableTab.header.lastUse")
|
||||
"AdvSceneSwitcher.variableTab.lastUsed.header")
|
||||
<< obs_module_text(
|
||||
"AdvSceneSwitcher.variableTab.header.lastChanged");
|
||||
"AdvSceneSwitcher.variableTab.lastChanged.header");
|
||||
|
||||
auto &variables = GetVariables();
|
||||
|
||||
@@ -258,7 +265,7 @@ void AdvSceneSwitcher::SetupVariableTab()
|
||||
auto timer = new QTimer(this);
|
||||
timer->setInterval(1000);
|
||||
QWidget::connect(timer, &QTimer::timeout,
|
||||
[this]() { updateVaribleStatus(ui->variables); });
|
||||
[this]() { updateVariableStatus(ui->variables); });
|
||||
timer->start();
|
||||
}
|
||||
|
||||
@@ -270,6 +277,7 @@ void AdvSceneSwitcher::on_variableAdd_clicked()
|
||||
if (!accepted) {
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
auto lock = LockContext();
|
||||
auto &variables = GetVariables();
|
||||
|
||||
Reference in New Issue
Block a user