Qt/IOWindow: Apply expressions immediately so we can query the current value of the expression.
This commit is contained in:
parent
cae741584b
commit
ddfb8fa404
|
@ -93,9 +93,8 @@ QTextCharFormat GetCommentCharFormat()
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ControlExpressionSyntaxHighlighter::ControlExpressionSyntaxHighlighter(QTextDocument* parent,
|
ControlExpressionSyntaxHighlighter::ControlExpressionSyntaxHighlighter(QTextDocument* parent)
|
||||||
QLineEdit* result)
|
: QSyntaxHighlighter(parent)
|
||||||
: QSyntaxHighlighter(parent), m_result_text(result)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,18 +167,11 @@ void ControlExpressionSyntaxHighlighter::highlightBlock(const QString&)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This doesn't need to be run for every "block", but it works.
|
// This doesn't need to be run for every "block", but it works.
|
||||||
if (ciface::ExpressionParser::ParseStatus::Successful != tokenize_status)
|
if (ciface::ExpressionParser::ParseStatus::Successful == tokenize_status)
|
||||||
{
|
|
||||||
m_result_text->setText(tr("Invalid Token."));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
ciface::ExpressionParser::RemoveInertTokens(&tokens);
|
ciface::ExpressionParser::RemoveInertTokens(&tokens);
|
||||||
const auto parse_status = ciface::ExpressionParser::ParseTokens(tokens);
|
const auto parse_status = ciface::ExpressionParser::ParseTokens(tokens);
|
||||||
|
|
||||||
m_result_text->setText(
|
|
||||||
QString::fromStdString(parse_status.description.value_or(_trans("Success."))));
|
|
||||||
|
|
||||||
if (ciface::ExpressionParser::ParseStatus::Successful != parse_status.status)
|
if (ciface::ExpressionParser::ParseStatus::Successful != parse_status.status)
|
||||||
{
|
{
|
||||||
const auto token = *parse_status.token;
|
const auto token = *parse_status.token;
|
||||||
|
@ -203,7 +195,8 @@ private:
|
||||||
|
|
||||||
IOWindow::IOWindow(MappingWidget* parent, ControllerEmu::EmulatedController* controller,
|
IOWindow::IOWindow(MappingWidget* parent, ControllerEmu::EmulatedController* controller,
|
||||||
ControlReference* ref, IOWindow::Type type)
|
ControlReference* ref, IOWindow::Type type)
|
||||||
: QDialog(parent), m_reference(ref), m_controller(controller), m_type(type)
|
: QDialog(parent), m_reference(ref), m_original_expression(ref->GetExpression()),
|
||||||
|
m_controller(controller), m_type(type)
|
||||||
{
|
{
|
||||||
CreateMainLayout();
|
CreateMainLayout();
|
||||||
|
|
||||||
|
@ -242,7 +235,7 @@ void IOWindow::CreateMainLayout()
|
||||||
|
|
||||||
m_expression_text = new QPlainTextEdit();
|
m_expression_text = new QPlainTextEdit();
|
||||||
m_expression_text->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
|
m_expression_text->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
|
||||||
new ControlExpressionSyntaxHighlighter(m_expression_text->document(), m_parse_text);
|
new ControlExpressionSyntaxHighlighter(m_expression_text->document());
|
||||||
|
|
||||||
m_operators_combo = new QComboBox();
|
m_operators_combo = new QComboBox();
|
||||||
m_operators_combo->addItem(tr("Operators"));
|
m_operators_combo->addItem(tr("Operators"));
|
||||||
|
@ -404,6 +397,7 @@ void IOWindow::ConnectWidgets()
|
||||||
connect(m_expression_text, &QPlainTextEdit::textChanged, [this] {
|
connect(m_expression_text, &QPlainTextEdit::textChanged, [this] {
|
||||||
m_apply_button->setText(m_apply_button->text().remove(QStringLiteral("*")));
|
m_apply_button->setText(m_apply_button->text().remove(QStringLiteral("*")));
|
||||||
m_apply_button->setText(m_apply_button->text() + QStringLiteral("*"));
|
m_apply_button->setText(m_apply_button->text() + QStringLiteral("*"));
|
||||||
|
UpdateExpression(m_expression_text->toPlainText().toStdString());
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_operators_combo, qOverload<int>(&QComboBox::activated), [this](int index) {
|
connect(m_operators_combo, qOverload<int>(&QComboBox::activated), [this](int index) {
|
||||||
|
@ -423,6 +417,9 @@ void IOWindow::ConnectWidgets()
|
||||||
|
|
||||||
m_functions_combo->setCurrentIndex(0);
|
m_functions_combo->setCurrentIndex(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// revert the expression when the window closes without using the OK button
|
||||||
|
connect(this, &IOWindow::finished, [this] { UpdateExpression(m_original_expression); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void IOWindow::AppendSelectedOption()
|
void IOWindow::AppendSelectedOption()
|
||||||
|
@ -448,8 +445,10 @@ void IOWindow::OnDialogButtonPressed(QAbstractButton* button)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_reference->SetExpression(m_expression_text->toPlainText().toStdString());
|
const auto lock = m_controller->GetStateLock();
|
||||||
m_controller->UpdateSingleControlReference(g_controller_interface, m_reference);
|
|
||||||
|
UpdateExpression(m_expression_text->toPlainText().toStdString());
|
||||||
|
m_original_expression = m_reference->GetExpression();
|
||||||
|
|
||||||
m_apply_button->setText(m_apply_button->text().remove(QStringLiteral("*")));
|
m_apply_button->setText(m_apply_button->text().remove(QStringLiteral("*")));
|
||||||
|
|
||||||
|
@ -532,6 +531,26 @@ void IOWindow::UpdateDeviceList()
|
||||||
QString::fromStdString(m_controller->GetDefaultDevice().ToString()));
|
QString::fromStdString(m_controller->GetDefaultDevice().ToString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IOWindow::UpdateExpression(std::string new_expression)
|
||||||
|
{
|
||||||
|
const auto lock = m_controller->GetStateLock();
|
||||||
|
if (new_expression == m_reference->GetExpression())
|
||||||
|
return;
|
||||||
|
|
||||||
|
const auto error = m_reference->SetExpression(std::move(new_expression));
|
||||||
|
const auto status = m_reference->GetParseStatus();
|
||||||
|
m_controller->UpdateSingleControlReference(g_controller_interface, m_reference);
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
m_parse_text->setText(QString::fromStdString(*error));
|
||||||
|
else if (status == ciface::ExpressionParser::ParseStatus::EmptyExpression)
|
||||||
|
m_parse_text->setText(QString());
|
||||||
|
else if (status != ciface::ExpressionParser::ParseStatus::Successful)
|
||||||
|
m_parse_text->setText(tr("Invalid Expression."));
|
||||||
|
else
|
||||||
|
m_parse_text->setText(tr("Success."));
|
||||||
|
}
|
||||||
|
|
||||||
InputStateDelegate::InputStateDelegate(IOWindow* parent) : QItemDelegate(parent), m_parent(parent)
|
InputStateDelegate::InputStateDelegate(IOWindow* parent) : QItemDelegate(parent), m_parent(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QSyntaxHighlighter>
|
#include <QSyntaxHighlighter>
|
||||||
|
@ -34,13 +37,10 @@ class ControlExpressionSyntaxHighlighter final : public QSyntaxHighlighter
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ControlExpressionSyntaxHighlighter(QTextDocument* parent, QLineEdit* result);
|
explicit ControlExpressionSyntaxHighlighter(QTextDocument* parent);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void highlightBlock(const QString& text) final override;
|
void highlightBlock(const QString& text) final override;
|
||||||
|
|
||||||
private:
|
|
||||||
QLineEdit* const m_result_text;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class IOWindow final : public QDialog
|
class IOWindow final : public QDialog
|
||||||
|
@ -74,6 +74,8 @@ private:
|
||||||
void UpdateOptionList();
|
void UpdateOptionList();
|
||||||
void UpdateDeviceList();
|
void UpdateDeviceList();
|
||||||
|
|
||||||
|
void UpdateExpression(std::string new_expression);
|
||||||
|
|
||||||
// Main Layout
|
// Main Layout
|
||||||
QVBoxLayout* m_main_layout;
|
QVBoxLayout* m_main_layout;
|
||||||
|
|
||||||
|
@ -108,6 +110,7 @@ private:
|
||||||
QPushButton* m_apply_button;
|
QPushButton* m_apply_button;
|
||||||
|
|
||||||
ControlReference* m_reference;
|
ControlReference* m_reference;
|
||||||
|
std::string m_original_expression;
|
||||||
ControllerEmu::EmulatedController* m_controller;
|
ControllerEmu::EmulatedController* m_controller;
|
||||||
|
|
||||||
ciface::Core::DeviceQualifier m_devq;
|
ciface::Core::DeviceQualifier m_devq;
|
||||||
|
|
Loading…
Reference in New Issue