mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-28 12:17:04 -05:00
Fix item selection not updating correctly
* Remove could lead to the "add" dialog being opened * Rename could result in some entries not being renamed (due to FilterComboBox using a QComboBox with setEditable() set to true)
This commit is contained in:
@@ -239,13 +239,11 @@ static bool AskForSettingsWrapper(QWidget *parent, Item &settings)
|
||||
void ActionQueueSelection::SetActionQueue(
|
||||
const std::weak_ptr<ActionQueue> &queue_)
|
||||
{
|
||||
const QSignalBlocker blocker(_selection);
|
||||
auto queue = queue_.lock();
|
||||
if (queue) {
|
||||
_selection->setCurrentText(
|
||||
QString::fromStdString(queue->Name()));
|
||||
SetItem(queue->Name());
|
||||
} else {
|
||||
_selection->setCurrentIndex(-1);
|
||||
SetItem("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,9 +88,12 @@ ItemSelection::ItemSelection(std::deque<std::shared_ptr<Item>> &items,
|
||||
|
||||
void ItemSelection::SetItem(const std::string &item)
|
||||
{
|
||||
const QSignalBlocker blocker(_selection);
|
||||
if (!!GetItemByName(item, _items)) {
|
||||
_selection->setCurrentText(QString::fromStdString(item));
|
||||
if (_selection->lineEdit()) {
|
||||
_selection->lineEdit()->setText(
|
||||
QString::fromStdString(item));
|
||||
}
|
||||
} else {
|
||||
_selection->setCurrentIndex(-1);
|
||||
}
|
||||
@@ -111,7 +114,6 @@ void ItemSelection::ChangeSelection(const QString &sel)
|
||||
return;
|
||||
}
|
||||
_items.emplace_back(item);
|
||||
const QSignalBlocker b(_selection);
|
||||
const QString name = QString::fromStdString(item->_name);
|
||||
AddItem(name);
|
||||
_selection->setCurrentText(name);
|
||||
@@ -195,6 +197,7 @@ void ItemSelection::RenameItem()
|
||||
|
||||
const auto oldName = item->_name;
|
||||
item->_name = name;
|
||||
SetItem(name);
|
||||
emit ItemRenamed(QString::fromStdString(oldName),
|
||||
QString::fromStdString(name));
|
||||
}
|
||||
@@ -205,7 +208,11 @@ void ItemSelection::RenameItem(const QString &oldName, const QString &name)
|
||||
if (idx == -1) {
|
||||
return;
|
||||
}
|
||||
auto currentText = _selection->currentText();
|
||||
_selection->setItemText(idx, name);
|
||||
if (oldName == currentText) {
|
||||
SetItem(name.toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
void ItemSelection::AddItem(const QString &name)
|
||||
@@ -240,9 +247,10 @@ void ItemSelection::RemoveItem()
|
||||
|
||||
void ItemSelection::RemoveItem(const QString &name)
|
||||
{
|
||||
auto currentText = _selection->currentText();
|
||||
const int idx = _selection->findText(name);
|
||||
if (idx == _selection->currentIndex()) {
|
||||
_selection->setCurrentIndex(-1);
|
||||
if (currentText == name) {
|
||||
SetItem("");
|
||||
}
|
||||
_selection->removeItem(idx);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ signals:
|
||||
void ItemRemoved(const QString &);
|
||||
void ItemRenamed(const QString &oldName, const QString &name);
|
||||
|
||||
protected:
|
||||
private:
|
||||
Item *GetCurrentItem();
|
||||
|
||||
FilterComboBox *_selection;
|
||||
|
||||
@@ -285,22 +285,20 @@ VariableSelection::VariableSelection(QWidget *parent)
|
||||
|
||||
void VariableSelection::SetVariable(const std::string &variable)
|
||||
{
|
||||
const QSignalBlocker blocker(_selection);
|
||||
if (!!GetVariableByName(variable)) {
|
||||
_selection->setCurrentText(QString::fromStdString(variable));
|
||||
SetItem(variable);
|
||||
} else {
|
||||
_selection->setCurrentIndex(-1);
|
||||
SetItem("");
|
||||
}
|
||||
}
|
||||
|
||||
void VariableSelection::SetVariable(const std::weak_ptr<Variable> &variable_)
|
||||
{
|
||||
const QSignalBlocker blocker(_selection);
|
||||
auto var = variable_.lock();
|
||||
if (var) {
|
||||
SetVariable(var->Name());
|
||||
SetItem(var->Name());
|
||||
} else {
|
||||
_selection->setCurrentIndex(-1);
|
||||
SetItem("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -298,23 +298,21 @@ ConnectionSelection::ConnectionSelection(QWidget *parent)
|
||||
|
||||
void ConnectionSelection::SetConnection(const std::string &con)
|
||||
{
|
||||
const QSignalBlocker blocker(_selection);
|
||||
if (!!GetConnectionByName(con)) {
|
||||
_selection->setCurrentText(QString::fromStdString(con));
|
||||
SetItem(con);
|
||||
} else {
|
||||
_selection->setCurrentIndex(-1);
|
||||
SetItem("");
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionSelection::SetConnection(
|
||||
const std::weak_ptr<Connection> &connection_)
|
||||
{
|
||||
const QSignalBlocker blocker(_selection);
|
||||
auto connection = connection_.lock();
|
||||
if (connection) {
|
||||
SetConnection(connection->Name());
|
||||
SetItem(connection->Name());
|
||||
} else {
|
||||
_selection->setCurrentIndex(-1);
|
||||
SetItem("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -397,23 +397,21 @@ TwitchConnectionSelection::TwitchConnectionSelection(QWidget *parent)
|
||||
|
||||
void TwitchConnectionSelection::SetToken(const std::string &token)
|
||||
{
|
||||
const QSignalBlocker blocker(_selection);
|
||||
if (!!GetTwitchTokenByName(token)) {
|
||||
_selection->setCurrentText(QString::fromStdString(token));
|
||||
SetItem(token);
|
||||
} else {
|
||||
_selection->setCurrentIndex(-1);
|
||||
SetItem("");
|
||||
}
|
||||
}
|
||||
|
||||
void TwitchConnectionSelection::SetToken(
|
||||
const std::weak_ptr<TwitchToken> &token_)
|
||||
{
|
||||
const QSignalBlocker blocker(_selection);
|
||||
auto token = token_.lock();
|
||||
if (token) {
|
||||
SetToken(token->Name());
|
||||
SetItem(token->Name());
|
||||
} else {
|
||||
_selection->setCurrentIndex(-1);
|
||||
SetItem("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user