aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2018-04-15 13:01:40 +0200
committerKarel Kočí <cynerd@email.cz>2018-04-15 13:01:40 +0200
commit3ce0bbb92731f67aa09b20cd21208505daea5e6b (patch)
tree88097451a413ef39fffdbbee397cb7d4d1530676 /qtmips_gui
parentd7ca8071777cc1b11572dbb0d79dcf8a677a0bcd (diff)
downloadqtmips-3ce0bbb92731f67aa09b20cd21208505daea5e6b.tar.gz
qtmips-3ce0bbb92731f67aa09b20cd21208505daea5e6b.tar.bz2
qtmips-3ce0bbb92731f67aa09b20cd21208505daea5e6b.zip
Rename CoreView to GraphicsView
This generalizes CoreView to be used with other parts of the project too.
Diffstat (limited to 'qtmips_gui')
-rw-r--r--qtmips_gui/coreview.cpp43
-rw-r--r--qtmips_gui/coreview.h20
-rw-r--r--qtmips_gui/graphicsview.cpp36
-rw-r--r--qtmips_gui/graphicsview.h20
-rw-r--r--qtmips_gui/mainwindow.cpp2
-rw-r--r--qtmips_gui/mainwindow.h2
-rw-r--r--qtmips_gui/qtmips_gui.pro2
7 files changed, 69 insertions, 56 deletions
diff --git a/qtmips_gui/coreview.cpp b/qtmips_gui/coreview.cpp
index 66ad933..d32f4aa 100644
--- a/qtmips_gui/coreview.cpp
+++ b/qtmips_gui/coreview.cpp
@@ -7,41 +7,6 @@
#define SC_HEIGHT 540
//////////////////////////////////////////////////////////////////////////////
-CoreView::CoreView(QWidget *parent) : QGraphicsView(parent) {
- setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
-}
-
-void CoreView::setScene(QGraphicsScene *scene) {
- QGraphicsView::setScene(scene);
- update_scale();
-}
-
-void CoreView::resizeEvent(QResizeEvent *event) {
- QGraphicsView::resizeEvent(event);
- update_scale();
-}
-
-void CoreView::update_scale() {
- if (scene() == nullptr)
- return; // Skip if we have no scene
-
- // Note: there is somehow three pixels error when viewing so we have to always compensate
- const int w = scene()->width() + 3;
- const int h = scene()->height() + 3;
-
- qreal scale = 1;
- if (height() > h && width() > w) {
- if (height() > width()) {
- scale = (qreal)width() / w;
- } else {
- scale = (qreal)height() / h;
- }
- }
- QTransform t;
- t.scale(scale, scale);
- setTransform(t, false);
-}
-
#define NEW_B(TYPE, VAR, ...) do { \
VAR = new coreview::TYPE(__VA_ARGS__);\
addItem(VAR);\
@@ -55,7 +20,7 @@ void CoreView::update_scale() {
connect(machine->core(), SIGNAL(SIG), VAR, SLOT(instruction_update(const machine::Instruction&))); \
} while(false)
-CoreViewScene::CoreViewScene(CoreView *view, machine::QtMipsMachine *machine) : QGraphicsScene(view) {
+CoreViewScene::CoreViewScene(GraphicsView *view, machine::QtMipsMachine *machine) : QGraphicsScene(view) {
setSceneRect(0, 0, SC_WIDTH, SC_HEIGHT);
// Elements //
@@ -133,6 +98,8 @@ CoreViewScene::CoreViewScene(CoreView *view, machine::QtMipsMachine *machine) :
connect(mem_data, SIGNAL(open_mem()), this, SIGNAL(request_data_memory()));
connect(ft.pc, SIGNAL(open_program()), this, SIGNAL(request_program_memory()));
connect(ft.pc, SIGNAL(jump_to_pc(std::uint32_t)), this, SIGNAL(request_jump_to_program_counter(std::uint32_t)));
+ connect(mem_program, SIGNAL(open_cache()), this, SIGNAL(request_cache_program()));
+ connect(mem_data, SIGNAL(open_cache()), this, SIGNAL(request_cache_data()));
}
CoreViewScene::~CoreViewScene() {
@@ -160,7 +127,7 @@ coreview::Signal *CoreViewScene::new_signal(const coreview::Connector *a, const
return c;
}
-CoreViewSceneSimple::CoreViewSceneSimple(CoreView *view, machine::QtMipsMachine *machine) : CoreViewScene(view, machine) {
+CoreViewSceneSimple::CoreViewSceneSimple(GraphicsView *view, machine::QtMipsMachine *machine) : CoreViewScene(view, machine) {
NEW_I(instr_prim, 230, 60, instruction_fetched(const machine::Instruction&));
if (machine->config().delay_slot()) {
NEW(Latch, delay_slot_latch, 55, 470, machine, 25);
@@ -226,7 +193,7 @@ CoreViewSceneSimple::CoreViewSceneSimple(CoreView *view, machine::QtMipsMachine
con->setAxes({CON_AXIS_Y(430), CON_AXIS_X(500), CON_AXIS_Y(210)});
}
-CoreViewScenePipelined::CoreViewScenePipelined(CoreView *view, machine::QtMipsMachine *machine) : CoreViewScene(view, machine) {
+CoreViewScenePipelined::CoreViewScenePipelined(GraphicsView *view, machine::QtMipsMachine *machine) : CoreViewScene(view, machine) {
NEW(Latch, latch_if_id, 158, 70, machine, 400);
latch_if_id->setTitle("IF/ID");
NEW(Latch, latch_id_ex, 392, 70, machine, 400);
diff --git a/qtmips_gui/coreview.h b/qtmips_gui/coreview.h
index 9fdf0a3..8935d41 100644
--- a/qtmips_gui/coreview.h
+++ b/qtmips_gui/coreview.h
@@ -4,6 +4,7 @@
#include <QGraphicsView>
#include <QGraphicsScene>
#include "qtmipsmachine.h"
+#include "graphicsview.h"
#include "coreview/connection.h"
#include "coreview/programcounter.h"
#include "coreview/multiplexer.h"
@@ -18,22 +19,10 @@
#include "coreview/logicblock.h"
#include "coreview/and.h"
-class CoreView : public QGraphicsView {
-public:
- CoreView(QWidget *parent);
-
- void setScene(QGraphicsScene *scene);
-
-protected:
- void resizeEvent(QResizeEvent *event);
-private:
- void update_scale();
-};
-
class CoreViewScene : public QGraphicsScene {
Q_OBJECT
public:
- CoreViewScene(CoreView *view, machine::QtMipsMachine *machine);
+ CoreViewScene(GraphicsView *view, machine::QtMipsMachine *machine);
~CoreViewScene();
signals:
@@ -86,7 +75,7 @@ protected:
class CoreViewSceneSimple : public CoreViewScene {
public:
- CoreViewSceneSimple(CoreView *view, machine::QtMipsMachine *machine);
+ CoreViewSceneSimple(GraphicsView *view, machine::QtMipsMachine *machine);
private:
coreview::InstructionView *instr_prim, *instr_delay;
@@ -95,7 +84,7 @@ private:
class CoreViewScenePipelined : public CoreViewScene {
public:
- CoreViewScenePipelined(CoreView *view, machine::QtMipsMachine *machine);
+ CoreViewScenePipelined(GraphicsView *view, machine::QtMipsMachine *machine);
private:
coreview::Latch *latch_if_id, *latch_id_ex, *latch_ex_mem, *latch_mem_wb;
@@ -105,7 +94,6 @@ private:
#else
-class CoreView;
class CoreViewScene;
class CoreViewSceneSimple;
class CoreViewScenePipelined;
diff --git a/qtmips_gui/graphicsview.cpp b/qtmips_gui/graphicsview.cpp
new file mode 100644
index 0000000..6ef118d
--- /dev/null
+++ b/qtmips_gui/graphicsview.cpp
@@ -0,0 +1,36 @@
+#include "graphicsview.h"
+
+GraphicsView::GraphicsView(QWidget *parent) : QGraphicsView(parent) {
+ setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
+}
+
+void GraphicsView::setScene(QGraphicsScene *scene) {
+ QGraphicsView::setScene(scene);
+ update_scale();
+}
+
+void GraphicsView::resizeEvent(QResizeEvent *event) {
+ QGraphicsView::resizeEvent(event);
+ update_scale();
+}
+
+void GraphicsView::update_scale() {
+ if (scene() == nullptr)
+ return; // Skip if we have no scene
+
+ // Note: there is somehow three pixels error when viewing so we have to always compensate
+ const int w = scene()->width() + 3;
+ const int h = scene()->height() + 3;
+
+ qreal scale = 1;
+ if (height() > h && width() > w) {
+ if (height() > width()) {
+ scale = (qreal)width() / w;
+ } else {
+ scale = (qreal)height() / h;
+ }
+ }
+ QTransform t;
+ t.scale(scale, scale);
+ setTransform(t, false);
+}
diff --git a/qtmips_gui/graphicsview.h b/qtmips_gui/graphicsview.h
new file mode 100644
index 0000000..6b16d40
--- /dev/null
+++ b/qtmips_gui/graphicsview.h
@@ -0,0 +1,20 @@
+#ifndef GRAPHICSVIEW_H
+#define GRAPHICSVIEW_H
+
+#include <QGraphicsView>
+#include <QGraphicsScene>
+
+class GraphicsView : public QGraphicsView {
+public:
+ GraphicsView(QWidget *parent);
+
+ void setScene(QGraphicsScene *scene);
+
+protected:
+ void resizeEvent(QResizeEvent *event);
+
+private:
+ void update_scale();
+};
+
+#endif // GRAPHICSVIEW_H
diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp
index ce6f52c..b61c0e5 100644
--- a/qtmips_gui/mainwindow.cpp
+++ b/qtmips_gui/mainwindow.cpp
@@ -10,7 +10,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
setWindowTitle("QtMips");
// Prepare empty core view
- coreview = new CoreView(this);
+ coreview = new GraphicsView(this);
this->setCentralWidget(coreview);
// Create/prepare other widgets
ndialog = new NewDialog(this, settings);
diff --git a/qtmips_gui/mainwindow.h b/qtmips_gui/mainwindow.h
index 3c1cf9f..acfeb05 100644
--- a/qtmips_gui/mainwindow.h
+++ b/qtmips_gui/mainwindow.h
@@ -50,7 +50,7 @@ private:
NewDialog *ndialog;
- CoreView *coreview;
+ GraphicsView *coreview;
CoreViewScene *corescene;
RegistersDock *registers;
diff --git a/qtmips_gui/qtmips_gui.pro b/qtmips_gui/qtmips_gui.pro
index 2d8ba78..e12eaef 100644
--- a/qtmips_gui/qtmips_gui.pro
+++ b/qtmips_gui/qtmips_gui.pro
@@ -37,6 +37,7 @@ SOURCES += \
coreview/and.cpp \
statictable.cpp \
cachedock.cpp \
+ graphicsview.cpp
HEADERS += \
mainwindow.h \
@@ -61,6 +62,7 @@ HEADERS += \
coreview/and.h \
statictable.h \
cachedock.h \
+ graphicsview.h
FORMS += \
NewDialog.ui \