-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDiagramView.h
More file actions
48 lines (38 loc) · 1.66 KB
/
Copy pathDiagramView.h
File metadata and controls
48 lines (38 loc) · 1.66 KB
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
#pragma once
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QString>
#include <QVector>
#include "Schema.h"
// Renders a focus-based diagram: the focused table sits in the center,
// its direct relations (from Schema::relationsFor) are placed around it
// in a cross layout. Clicking any visible table emits tableClicked, which
// MainWindow uses to re-focus the diagram - this is the "spanning tree
// around the active table" behaviour discussed for phase 2.
class DiagramView : public QGraphicsView
{
Q_OBJECT
public:
explicit DiagramView(QWidget* parent = nullptr);
// Redraws the diagram centered on focusTable, using relations from schema.
void setFocusTable(const Schema& schema, const QString& focusTable);
// Empties the diagram - used when no table is focused (e.g. right
// after a new/empty database is opened, or the focused table itself
// was just dropped).
void clear();
// Redraws the diagram centered on focusTable, but with the related
// tables supplied explicitly rather than looked up via Schema::
// relationsFor. Used to drive the diagram from raw, manually-typed
// SQL (FROM/JOIN table names) so typing keeps the visual in sync.
// A solid accent line is drawn when a real foreign key connects the
// pair; a dashed line otherwise (e.g. a JOIN typed without a known
// relation).
void setTablesFromNames(const Schema& schema, const QString& focusTable,
const QVector<QString>& relatedTables);
signals:
void tableClicked(const QString& tableName);
protected:
void mousePressEvent(QMouseEvent* event) override;
private:
QGraphicsScene m_scene;
};