tycho: add generic drawView function for IProjectView
parent
01a5cdc683
commit
8fb49b8929
|
@ -1 +1 @@
|
|||
Subproject commit 8a37b359ca9dba414d84472b1750e952a42710f6
|
||||
Subproject commit 2a8664e9bfed74150c6a2df28c78f2d6b3f1a674
|
|
@ -59,6 +59,13 @@
|
|||
"type": "Widget",
|
||||
"baseClass": "IProjectView",
|
||||
"functions": {
|
||||
"drawView": {
|
||||
"return": "void",
|
||||
"mut": false,
|
||||
"arguments": [
|
||||
{"name": "paint", "type": "*mut void"}
|
||||
]
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
},
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QPainter>
|
||||
#include <QWidget>
|
||||
|
||||
class IProjectModel : public QAbstractItemModel
|
||||
|
@ -40,6 +41,15 @@ public:
|
|||
using QWidget::QWidget;
|
||||
|
||||
virtual ~IProjectView() {}
|
||||
|
||||
virtual void drawView(void *paint) const = 0;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override
|
||||
{
|
||||
QPainter painter{this};
|
||||
drawView(static_cast<void *>(&painter));
|
||||
}
|
||||
};
|
||||
|
||||
// EOF
|
||||
|
|
|
@ -14,16 +14,11 @@ MapView::~MapView()
|
|||
dbgPrintFunc();
|
||||
}
|
||||
|
||||
void MapView::paintEvent(QPaintEvent *)
|
||||
{
|
||||
[[maybe_unused]] QPainter painter{this};
|
||||
}
|
||||
|
||||
// TODO: move to paint.cc
|
||||
extern "C" {
|
||||
void paint_point(QPainter *view, int x, int y)
|
||||
void paint_point(QPainter *paint, int x, int y)
|
||||
{
|
||||
view->drawPoint(x, y);
|
||||
paint->drawPoint(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include <QMainWindow>
|
||||
#include <QMdiSubWindow>
|
||||
#include <QMessageBox>
|
||||
#include <QPainter>
|
||||
|
||||
#include "../ui/ui_about.h"
|
||||
#include "../ui/ui_license.h"
|
||||
|
@ -55,9 +54,6 @@ public:
|
|||
explicit MapView(Project *parent);
|
||||
~MapView();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
private:
|
||||
MapModel *const m_mapModel;
|
||||
};
|
||||
|
|
|
@ -1,8 +1,24 @@
|
|||
//! C++ functions.
|
||||
|
||||
mod ffi {
|
||||
use maraiah::ffi;
|
||||
|
||||
mod static_ffi {
|
||||
use maraiah::ffi;
|
||||
|
||||
pub type QPainter = ffi::c_void;
|
||||
|
||||
extern "C" {
|
||||
pub fn critical_msg(title: maraiah::ffi::NT, msg: maraiah::ffi::NT);
|
||||
pub fn critical_msg(title: ffi::NT, msg: ffi::NT);
|
||||
pub fn paint_point(paint: *mut QPainter, x: ffi::c_int, y: ffi::c_int);
|
||||
}
|
||||
}
|
||||
|
||||
pub use static_ffi::QPainter;
|
||||
|
||||
pub fn paint_point(paint: *mut QPainter, x: i32, y: i32)
|
||||
{
|
||||
unsafe {
|
||||
static_ffi::paint_point(paint, x.into(), y.into());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,11 +26,11 @@ pub fn critical_msg<T, U>(title: T, msg: U)
|
|||
where T: ToString,
|
||||
U: ToString
|
||||
{
|
||||
let title = std::ffi::CString::new(title.to_string()).unwrap();
|
||||
let msg = std::ffi::CString::new(msg.to_string()).unwrap();
|
||||
let title = ffi::CString::new(title.to_string()).unwrap();
|
||||
let msg = ffi::CString::new(msg.to_string()).unwrap();
|
||||
|
||||
unsafe {
|
||||
ffi::critical_msg(title.as_ptr(), msg.as_ptr());
|
||||
static_ffi::critical_msg(title.as_ptr(), msg.as_ptr());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! Map view.
|
||||
|
||||
use super::qobj::*;
|
||||
use crate::cc;
|
||||
|
||||
impl IMapViewTrait for IMapView
|
||||
{
|
||||
|
@ -16,6 +17,11 @@ impl IMapViewTrait for IMapView
|
|||
|
||||
/// Returns the emitter of `self`.
|
||||
fn emit(&mut self) -> &mut IMapViewEmitter {&mut self.emit}
|
||||
|
||||
fn draw_view(&self, paint: *mut cc::QPainter)
|
||||
{
|
||||
cc::paint_point(paint, 20, 20);
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for IMapView
|
||||
|
|
Loading…
Reference in New Issue