summaryrefslogtreecommitdiff
blob: ec970b64ad815ad8b7a14b5d145c9d516c071fc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
From 730a5492e4780504a80db1a27dc307d8f61b4696 Mon Sep 17 00:00:00 2001
From: Zoltan Padrah <zoltan_padrah@users.sf.net>
Date: Fri, 18 Dec 2020 20:47:55 +0200
Subject: [PATCH] property editor: fix crash when changing a property and
 clicking circuit

apparently Ubuntu 18.04 is affected (Qt 5.9.5)
and Ubuntu 20.04 is not (Qt 5.12.8).

to reproduce:

1. place and select a resistor
2. in the property editor click on any of its properties,
   in order to start editing it
3. click on the circuit, to stop editing of the properties
3.1. Expected: property value is kept, program continues
3.2. Actually: crash with the same stack trace from above

Should fix issue on GitHub:
https://github.com/ktechlab/ktechlab/issues/60
---
 src/gui/itemeditor/propertyeditor.cpp | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/gui/itemeditor/propertyeditor.cpp b/src/gui/itemeditor/propertyeditor.cpp
index 88b86842..60821177 100644
--- a/src/gui/itemeditor/propertyeditor.cpp
+++ b/src/gui/itemeditor/propertyeditor.cpp
@@ -476,8 +476,19 @@ void PropertyEditor::showDefaultsButton(bool show)
 
 void PropertyEditor::updateDefaultsButton()
 {
-	if (!m_editItem)
+    QTableWidgetItem *currItem = currentItem();
+    if (!currItem) {
+        m_editItem = nullptr;
 		return;
+    }
+    m_editItem = dynamic_cast<PropertyEditorItem*>(currItem);
+    if (!m_editItem) {
+        qWarning() << "failed to cast current item to PropertyEditorItem, " << currItem;
+        return;
+    }
+    qDebug() << "currentItem=" << currentItem();
+    qDebug() << "m_editItem=" << m_editItem;
+    qDebug() << "m_editItem->property=" << m_editItem->property();
 	showDefaultsButton( m_editItem->property()->changed() );
 	repaint(); // m_editItem->repaint();
 }
-- 
GitLab