Browse Source

tycho: add generic drawView function for IProjectView

Alison Watson 1 month ago
parent
commit
8fb49b8929

+ 1
- 1
rust-qt-binding-generator

@@ -1 +1 @@
1
-Subproject commit 8a37b359ca9dba414d84472b1750e952a42710f6
1
+Subproject commit 2a8664e9bfed74150c6a2df28c78f2d6b3f1a674

+ 7
- 0
tycho/bindings.json View File

@@ -59,6 +59,13 @@
59 59
 			"type": "Widget",
60 60
 			"baseClass": "IProjectView",
61 61
 			"functions": {
62
+				"drawView": {
63
+					"return": "void",
64
+					"mut": false,
65
+					"arguments": [
66
+						{"name": "paint", "type": "*mut void"}
67
+					]
68
+				}
62 69
 			},
63 70
 			"properties": {
64 71
 			},

+ 10
- 0
tycho/cc/interface.h View File

@@ -3,6 +3,7 @@
3 3
 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
4 4
 
5 5
 #include <QAbstractItemModel>
6
+#include <QPainter>
6 7
 #include <QWidget>
7 8
 
8 9
 class IProjectModel : public QAbstractItemModel
@@ -40,6 +41,15 @@ public:
40 41
 	using QWidget::QWidget;
41 42
 
42 43
 	virtual ~IProjectView() {}
44
+
45
+	virtual void drawView(void *paint) const = 0;
46
+
47
+protected:
48
+	void paintEvent(QPaintEvent *event) override
49
+	{
50
+		QPainter painter{this};
51
+		drawView(static_cast<void *>(&painter));
52
+	}
43 53
 };
44 54
 
45 55
 // EOF

+ 2
- 7
tycho/cc/mapview.cc View File

@@ -14,16 +14,11 @@ MapView::~MapView()
14 14
 	dbgPrintFunc();
15 15
 }
16 16
 
17
-void MapView::paintEvent(QPaintEvent *)
18
-{
19
-	[[maybe_unused]] QPainter painter{this};
20
-}
21
-
22 17
 // TODO: move to paint.cc
23 18
 extern "C" {
24
-	void paint_point(QPainter *view, int x, int y)
19
+	void paint_point(QPainter *paint, int x, int y)
25 20
 	{
26
-		view->drawPoint(x, y);
21
+		paint->drawPoint(x, y);
27 22
 	}
28 23
 }
29 24
 

+ 0
- 4
tycho/cc/tycho.h View File

@@ -15,7 +15,6 @@
15 15
 #include <QMainWindow>
16 16
 #include <QMdiSubWindow>
17 17
 #include <QMessageBox>
18
-#include <QPainter>
19 18
 
20 19
 #include "../ui/ui_about.h"
21 20
 #include "../ui/ui_license.h"
@@ -55,9 +54,6 @@ public:
55 54
 	explicit MapView(Project *parent);
56 55
 	~MapView();
57 56
 
58
-protected:
59
-	void paintEvent(QPaintEvent *event) override;
60
-
61 57
 private:
62 58
 	MapModel *const m_mapModel;
63 59
 };

+ 21
- 5
tycho/source/cc.rs View File

@@ -1,8 +1,24 @@
1 1
 //! C++ functions.
2 2
 
3
-mod ffi {
3
+use maraiah::ffi;
4
+
5
+mod static_ffi {
6
+	use maraiah::ffi;
7
+
8
+	pub type QPainter = ffi::c_void;
9
+
4 10
 	extern "C" {
5
-		pub fn critical_msg(title: maraiah::ffi::NT, msg: maraiah::ffi::NT);
11
+		pub fn critical_msg(title: ffi::NT, msg: ffi::NT);
12
+		pub fn paint_point(paint: *mut QPainter, x: ffi::c_int, y: ffi::c_int);
13
+	}
14
+}
15
+
16
+pub use static_ffi::QPainter;
17
+
18
+pub fn paint_point(paint: *mut QPainter, x: i32, y: i32)
19
+{
20
+	unsafe {
21
+		static_ffi::paint_point(paint, x.into(), y.into());
6 22
 	}
7 23
 }
8 24
 
@@ -10,11 +26,11 @@ pub fn critical_msg<T, U>(title: T, msg: U)
10 26
 	where T: ToString,
11 27
 	      U: ToString
12 28
 {
13
-	let title = std::ffi::CString::new(title.to_string()).unwrap();
14
-	let msg   = std::ffi::CString::new(msg.to_string()).unwrap();
29
+	let title = ffi::CString::new(title.to_string()).unwrap();
30
+	let msg   = ffi::CString::new(msg.to_string()).unwrap();
15 31
 
16 32
 	unsafe {
17
-		ffi::critical_msg(title.as_ptr(), msg.as_ptr());
33
+		static_ffi::critical_msg(title.as_ptr(), msg.as_ptr());
18 34
 	}
19 35
 }
20 36
 

+ 6
- 0
tycho/source/gui/mapview.rs View File

@@ -1,6 +1,7 @@
1 1
 //! Map view.
2 2
 
3 3
 use super::qobj::*;
4
+use crate::cc;
4 5
 
5 6
 impl IMapViewTrait for IMapView
6 7
 {
@@ -16,6 +17,11 @@ impl IMapViewTrait for IMapView
16 17
 
17 18
 	/// Returns the emitter of `self`.
18 19
 	fn emit(&mut self) -> &mut IMapViewEmitter {&mut self.emit}
20
+
21
+	fn draw_view(&self, paint: *mut cc::QPainter)
22
+	{
23
+		cc::paint_point(paint, 20, 20);
24
+	}
19 25
 }
20 26
 
21 27
 impl Drop for IMapView

Loading…
Cancel
Save