mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Add last changed column to variable tab
This commit is contained in:
parent
70dad8ebb4
commit
ad6e720912
|
|
@ -78,8 +78,11 @@ AdvSceneSwitcher.variableTab.header.name="Name"
|
|||
AdvSceneSwitcher.variableTab.header.value="Value"
|
||||
AdvSceneSwitcher.variableTab.header.saveLoadBehavior="Save/Load behavior"
|
||||
AdvSceneSwitcher.variableTab.header.lastUse="Last used"
|
||||
AdvSceneSwitcher.variableTab.header.lastChanged="Last changed"
|
||||
AdvSceneSwitcher.variableTab.neverNused="Never"
|
||||
AdvSceneSwitcher.variableTab.lastUsed="%1 seconds ago"
|
||||
AdvSceneSwitcher.variableTab.lastChanged="%1 seconds ago"
|
||||
AdvSceneSwitcher.variableTab.lastChanged.tooltip="Previous value: %1"
|
||||
|
||||
; Macro Tab
|
||||
AdvSceneSwitcher.macroTab.title="Macro"
|
||||
|
|
|
|||
|
|
@ -60,6 +60,31 @@ static QString getLastUsedString(Variable *variable)
|
|||
return fmt.arg(QString::number(*lastUsed));
|
||||
}
|
||||
|
||||
static QString formatLastChangedText(Variable *variable)
|
||||
{
|
||||
auto lastChanged = variable->GetSecondsSinceLastChange();
|
||||
if (!lastChanged) {
|
||||
return obs_module_text(
|
||||
"AdvSceneSwitcher.variableTab.lastChanged.text.never");
|
||||
}
|
||||
|
||||
QString text =
|
||||
obs_module_text("AdvSceneSwitcher.variableTab.lastChanged");
|
||||
return text.arg(QString::number(*lastChanged));
|
||||
}
|
||||
|
||||
static QString formatLastChangedTooltip(Variable *variable)
|
||||
{
|
||||
auto lastChanged = variable->GetSecondsSinceLastChange();
|
||||
if (!lastChanged) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString tooltip = obs_module_text(
|
||||
"AdvSceneSwitcher.variableTab.lastChanged.tooltip");
|
||||
return tooltip.arg(QString::fromStdString(variable->PreviousValue()));
|
||||
}
|
||||
|
||||
static void addVariableRow(QTableWidget *table, Variable *variable)
|
||||
{
|
||||
if (!variable) {
|
||||
|
|
@ -75,16 +100,17 @@ static void addVariableRow(QTableWidget *table, Variable *variable)
|
|||
auto *item =
|
||||
new QTableWidgetItem(QString::fromStdString(variable->Name()));
|
||||
table->setItem(row, col, item);
|
||||
col++;
|
||||
item = new QTableWidgetItem(
|
||||
QString::fromStdString(variable->Value(false)));
|
||||
table->setItem(row, col, item);
|
||||
col++;
|
||||
table->setItem(row, ++col, item);
|
||||
item = new QTableWidgetItem(getSaveActionString(variable));
|
||||
table->setItem(row, col, item);
|
||||
col++;
|
||||
table->setItem(row, ++col, item);
|
||||
item = new QTableWidgetItem(getLastUsedString(variable));
|
||||
table->setItem(row, col, item);
|
||||
table->setItem(row, ++col, item);
|
||||
item = new QTableWidgetItem(formatLastChangedText(variable));
|
||||
item->setToolTip(formatLastChangedTooltip(variable));
|
||||
table->setItem(row, ++col, item);
|
||||
|
||||
table->sortByColumn(0, Qt::AscendingOrder);
|
||||
}
|
||||
|
||||
|
|
@ -118,6 +144,9 @@ static void updateVaribleStatus(QTableWidget *table)
|
|||
item->setText(getSaveActionString(variable.get()));
|
||||
item = table->item(row, 3);
|
||||
item->setText(getLastUsedString(variable.get()));
|
||||
item = table->item(row, 4);
|
||||
item->setText(formatLastChangedText(variable.get()));
|
||||
item->setToolTip(formatLastChangedTooltip(variable.get()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -177,7 +206,9 @@ void AdvSceneSwitcher::SetupVariableTab()
|
|||
<< obs_module_text(
|
||||
"AdvSceneSwitcher.variableTab.header.saveLoadBehavior")
|
||||
<< obs_module_text(
|
||||
"AdvSceneSwitcher.variableTab.header.lastUse");
|
||||
"AdvSceneSwitcher.variableTab.header.lastUse")
|
||||
<< obs_module_text(
|
||||
"AdvSceneSwitcher.variableTab.header.lastChanged");
|
||||
|
||||
auto &variables = GetVariables();
|
||||
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ void Variable::Load(obs_data_t *obj)
|
|||
static_cast<SaveAction>(obs_data_get_int(obj, "saveAction"));
|
||||
_defaultValue = obs_data_get_string(obj, "defaultValue");
|
||||
if (_saveAction == SaveAction::SAVE) {
|
||||
_value = obs_data_get_string(obj, "value");
|
||||
SetValue(obs_data_get_string(obj, "value"));
|
||||
} else if (_saveAction == SaveAction::SET_DEFAULT) {
|
||||
_value = _defaultValue;
|
||||
SetValue(_defaultValue);
|
||||
}
|
||||
lastVariableChange = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
|
@ -70,20 +70,24 @@ std::optional<int> Variable::IntValue() const
|
|||
return GetInt(Value());
|
||||
}
|
||||
|
||||
std::string Variable::PreviousValue() const
|
||||
{
|
||||
return _previousValue;
|
||||
}
|
||||
|
||||
void Variable::SetValue(const std::string &value)
|
||||
{
|
||||
_previousValue = _value;
|
||||
_value = value;
|
||||
|
||||
UpdateLastUsed();
|
||||
UpdateLastChanged();
|
||||
lastVariableChange = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
void Variable::SetValue(double value)
|
||||
{
|
||||
_value = ToString(value);
|
||||
|
||||
UpdateLastUsed();
|
||||
lastVariableChange = std::chrono::high_resolution_clock::now();
|
||||
SetValue(ToString(value));
|
||||
}
|
||||
|
||||
std::optional<uint64_t> Variable::SecondsSinceLastUse() const
|
||||
|
|
@ -96,11 +100,30 @@ std::optional<uint64_t> Variable::SecondsSinceLastUse() const
|
|||
.count();
|
||||
}
|
||||
|
||||
std::optional<uint64_t> Variable::GetSecondsSinceLastChange() const
|
||||
{
|
||||
if (_lastChanged.time_since_epoch().count() == 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto now = std::chrono::high_resolution_clock::now();
|
||||
return std::chrono::duration_cast<std::chrono::seconds>(now -
|
||||
_lastChanged)
|
||||
.count();
|
||||
}
|
||||
|
||||
void Variable::UpdateLastUsed() const
|
||||
{
|
||||
_lastUsed = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
void Variable::UpdateLastChanged() const
|
||||
{
|
||||
if (_previousValue != _value) {
|
||||
_lastChanged = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
}
|
||||
|
||||
std::deque<std::shared_ptr<Item>> &GetVariables()
|
||||
{
|
||||
return variables;
|
||||
|
|
@ -284,7 +307,7 @@ bool VariableSettingsDialog::AskForSettings(QWidget *parent, Variable &settings)
|
|||
}
|
||||
|
||||
settings._name = dialog._name->text().toStdString();
|
||||
settings._value = dialog._value->toPlainText().toStdString();
|
||||
settings.SetValue(dialog._value->toPlainText().toStdString());
|
||||
settings._defaultValue =
|
||||
dialog._defaultValue->toPlainText().toStdString();
|
||||
settings._saveAction =
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ public:
|
|||
EXPORT std::string Value(bool updateLastUsed = true) const;
|
||||
EXPORT std::optional<double> DoubleValue() const;
|
||||
EXPORT std::optional<int> IntValue() const;
|
||||
EXPORT std::string PreviousValue() const;
|
||||
void SetValue(const std::string &value);
|
||||
void SetValue(double value);
|
||||
std::string GetDefaultValue() const { return _defaultValue; }
|
||||
|
|
@ -37,13 +38,17 @@ public:
|
|||
};
|
||||
SaveAction GetSaveAction() const { return _saveAction; }
|
||||
std::optional<uint64_t> SecondsSinceLastUse() const;
|
||||
std::optional<uint64_t> GetSecondsSinceLastChange() const;
|
||||
void UpdateLastUsed() const;
|
||||
void UpdateLastChanged() const;
|
||||
|
||||
private:
|
||||
SaveAction _saveAction = SaveAction::DONT_SAVE;
|
||||
std::string _value = "";
|
||||
std::string _previousValue = "";
|
||||
std::string _defaultValue = "";
|
||||
mutable std::chrono::high_resolution_clock::time_point _lastUsed;
|
||||
mutable std::chrono::high_resolution_clock::time_point _lastChanged;
|
||||
|
||||
friend VariableSelection;
|
||||
friend VariableSettingsDialog;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user