Skip to content
Snippets Groups Projects
Unverified Commit b2843108 authored by Yurov, Dmitry's avatar Yurov, Dmitry Committed by GitHub
Browse files

Merge pull request #444 from waltervh/hotfix

Fix entering of floating point numbers in GUI: issue #2007
parents 1846a3f6 99ef00a9
No related branches found
No related tags found
No related merge requests found
......@@ -39,7 +39,6 @@ QString doubleToString(const SessionItem& item)
auto locale = QLocale::system();
result = locale.toString(item.value().toDouble(), 'f', item.decimals());
}
return result;
}
......@@ -50,8 +49,7 @@ QWidget* createEditorFromIndex(const QModelIndex& index, QWidget* parent) {
}
return nullptr;
}
}
} // unnamed namespace
SessionModelDelegate::SessionModelDelegate(QObject* parent)
: QStyledItemDelegate(parent)
......@@ -64,11 +62,9 @@ void SessionModelDelegate::paint(QPainter* painter, const QStyleOptionViewItem&
if (PropertyEditorFactory::IsCustomVariant(index.data())) {
QString text = PropertyEditorFactory::ToString(index.data());
paintCustomLabel(painter, option, index, text);
} else if (isDoubleProperty(index)) {
auto item = static_cast<SessionItem*>(index.internalPointer());
paintCustomLabel(painter, option, index, doubleToString(*item));
} else {
QStyledItemDelegate::paint(painter, option, index);
}
......@@ -88,11 +84,9 @@ QWidget* SessionModelDelegate::createEditor(QWidget* parent, const QStyleOptionV
// Int and Double will be handled by standard spin boxes
// QStyledItemDelegate already knows how to handle it, no special connections are required
}
} else {
result = QStyledItemDelegate::createEditor(parent, option, index);
}
return result;
}
......
......@@ -60,7 +60,6 @@ void ComponentFlatView::addItem(SessionItem* item)
setItem(item);
return;
}
m_topItems.push_back(item);
updateItemProperties();
}
......@@ -69,34 +68,26 @@ void ComponentFlatView::setModel(SessionModel* model)
{
if (m_model) {
disconnect(m_model, &SessionModel::dataChanged, this, &ComponentFlatView::onDataChanged);
}
m_model = model;
if (m_model) {
connect(m_model, &SessionModel::dataChanged, this, &ComponentFlatView::onDataChanged);
}
}
void ComponentFlatView::clearLayout()
{
Q_ASSERT(m_gridLayout);
LayoutUtils::clearGridLayout(m_gridLayout, false);
for(auto widget: m_widgetItems)
widget->deleteLater();
m_widgetItems.clear();
}
void ComponentFlatView::setShowChildren(bool show)
{
m_show_children = show;
}
void ComponentFlatView::onDataChanged(const QModelIndex& topLeft, const QModelIndex&bottomRight,
......@@ -120,28 +111,22 @@ void ComponentFlatView::clearEditor()
void ComponentFlatView::updateItemProperties()
{
clearLayout();
QList<const SessionItem*> allitems;
for (auto item : m_topItems)
allitems += ComponentUtils::componentItems(*item);
int nrow(0);
for (auto child : allitems) {
auto widget = createWidget(child);
if (!widget)
continue;
widget->addToGrid(m_gridLayout, ++nrow);
m_widgetItems.push_back(widget);
if (!m_show_children)
break;
}
}
void ComponentFlatView::updateItemRoles(SessionItem* item)
......
......@@ -111,21 +111,17 @@ QWidget* PropertyEditorFactory::CreateEditor(const SessionItem& item, QWidget* p
result = createCustomDoubleEditor(item);
}
}
else if(isIntProperty(item.value())) {
result = createCustomIntEditor(item);
}
else if(isBoolProperty(item.value())) {
auto editor = new BoolEditor;
editor->setData(item.value());
result = editor;
}
else if(isStringProperty(item.value())) {
result = createCustomStringEditor(item);
}
else if(isExternalProperty(item.value())) {
auto editor = new ExternalPropertyEditor;
editor->setData(item.value());
......@@ -133,13 +129,11 @@ QWidget* PropertyEditorFactory::CreateEditor(const SessionItem& item, QWidget* p
editor->setExternalDialogType(item.editorType());
result = editor;
}
else if(isComboProperty(item.value())) {
auto editor = new ComboPropertyEditor;
editor->setData(item.value());
result = editor;
}
if (parent && result)
result->setParent(parent);
......
......@@ -98,16 +98,6 @@ void PropertyWidgetItem::connectEditor(QWidget* editor)
if (auto customEditor = dynamic_cast<ComboPropertyEditor*>(editor)) {
connect(customEditor, &ComboPropertyEditor::dataChanged,
[=] { m_delegate->commitData(customEditor); });
} else if (auto customEditor = dynamic_cast<QSpinBox*>(editor)) {
connect(customEditor, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
[=] { m_delegate->commitData(customEditor); });
} else if (auto customEditor = dynamic_cast<QDoubleSpinBox*>(editor)) {
connect(customEditor,
static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
[=] { m_delegate->commitData(customEditor); });
} else if (auto customEditor = dynamic_cast<ScientificDoublePropertyEditor*>(editor)) {
connect(customEditor, &ScientificDoublePropertyEditor::dataChanged,
[=] { m_delegate->commitData(customEditor); });
......
......@@ -122,6 +122,10 @@ void MainWindow::openRecentProject()
void MainWindow::onRunSimulationShortcut()
{
// This clearFocus is needed for the propagation of the current editor value,
// since the runSimulation method will only change focus after finishing the simulation
if (auto widget = QApplication::focusWidget())
widget->clearFocus();
m_simulationView->onRunSimulationShortcut();
}
......@@ -132,11 +136,9 @@ void MainWindow::onSessionModelViewActive(bool isActive)
if (isActive) {
if (m_sessionModelView)
return;
m_sessionModelView = new SessionModelView(this);
m_tabWidget->insertTab(MAXVIEWCOUNT, m_sessionModelView,
QIcon(":/images/main_sessionmodel.svg"), "Models");
} else {
if (!m_sessionModelView)
return;
......@@ -160,7 +162,6 @@ void MainWindow::closeEvent(QCloseEvent* event)
event->ignore();
return;
}
if (m_projectManager->closeCurrentProject()) {
writeSettings();
event->accept();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment