CircuitView

src/ui/circuitview.h

This is where the schematic is drawn.

Note

Zooming does not behave as intended. What is intended is that when you scroll your mouse wheel, the scene should scale around the point where your cursor is. Instead, the current implementation scales with the center of the view as the pivot. We are working on a fix for this. We might even ditch the QGraphicsView and use a lower-level framework.

class Ohmcha::CircuitView : public QGraphicsView

Public Types

enum Mode

Values:

enumerator Idle
enumerator InsertDragDrop
enumerator InsertPoints

Public Functions

CircuitView(QWidget *parent = nullptr)
CircuitView(QWidget *parent, Schematic *schematic)
~CircuitView()
void initialize()
void initiateInsertComponent(GraphicComponent *component, Mode insertMode)
void solve()
void showValues(bool show = true)
void load(Schematic *schematic)
void zoomIn(float scale = 1.2)
void resetZoom()
CircuitViewScene *scene()
void setGridVisibility(bool visibility)

Show/hide the grid.

void setSnap(bool state)

Enable/disable snap to grid.

void setComponentPreview(ComponentPreview *componentPreview)
void setZoomLevel(float zoom)
QPointF getCursorPosition()

Return the cursor position with any snap-to-grid applied.

ComponentPreview *getComponentPreview()
Schematic *getSchematic()

Return the Schematic representation of this circuit. The result is guaranteed to be non-null.

float getZoomLevel() const

Signals

void componentSelected(GraphicComponent*)

Emitted when a component is selected individually.

void itemDeleted(GraphicComponent*)

Private Functions

void wheelEvent(QWheelEvent *event) override
void mousePressEvent(QMouseEvent *event) override
void mouseReleaseEvent(QMouseEvent *event) override
void mouseMoveEvent(QMouseEvent *event) override
void keyPressEvent(QKeyEvent *event) override
void resizeEvent(QResizeEvent *event) override
void updateCursorGuides()

Update cursor guides’ position based on the current cursor position.

void snapToGrid()

Change the internally tracked cursor position to make it snap to grid.

Private Members

float zoomLevel = 1
QGraphicsLineItem *hGuide = {}
QGraphicsLineItem *vGuide = {}
GraphicComponent *pendingInsert = {}
ComponentPreview *componentPreview = {}
Schematic *schematic = {}
QList<QGraphicsItem*> results
Mode mode = Idle
QPointF rawCursorPos
QPointF cursorPos
float gridSpacingX = 20
float gridSpacingY = 20
bool snapOn = false
bool showGrid = true
bool _selectionModeDetermined = false
QPointF _dragPos
bool _dragging = false

Friends

friend class CircuitViewScene