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