ComponentPreview¶
- src/ui/component_preview.h
- src/ui/component_preview.ui
Quick Overview¶
The object is constructed
Main window calls
initializeThe user selects a component from the list of components
Main window makes this widget visible (if not already)
initializeNewComponentRemove the previous item from the scene
synchronizeSet the component immovable and unselectable
The user edits the item
The user clicks the Add button
CircuitView::initiateInsertComponentinitializeNewComponent
The user selects an item in the circuit view
Slot
setEditExistingis called
Detailed Explanation¶
This widget has two purposes. One is to edit a new item that has yet
to be placed into the active CircuitView, and the other is to edit an
existing item. In the first case, a small preview window is shown.
The widget that shows the component preview is a plain QGraphicsView.
The user cannot interact with the component in it as they can with components in
the circuit view. For example, the component cannot be selected nor
moved by mouse. Since these are properties of the component and not of the view,
this has to be disabled and enabled each time the component is copied back and
forth between the preview and the circuit view.
When the user selects a component from the component list (see
MainWindow), initializeNewComponent is called. This creates a new
component, with the same properties as the last inserted component. When the
user selects an existing component in the circuit view, setEditExisting is
called with the selected component. The method synchronize is used to
synchronize the text boxes and buttons with the actual properties of the
component.
New components are added into the circuit view when the user clicks on the Add
button. The method CircuitView::initiateInsertComponent is called. A new
component is initialized in the preview immediately. The GraphicComponent instance in the preview is copied using
GraphicComponent::copy.
Note
initialize can be called only after the member circuitView has
been initialized. This is done by the main window.
-
class
Ohmcha::ComponentPreview: public QWidget Public Functions
-
ComponentPreview(QWidget *parent = nullptr)
-
~ComponentPreview()
-
void
initialize() Connect this preview to the active circuit view. Call this when first showing this widget or when the active circuit view changes.
-
void
initializeNewComponent(const QString &type) Create a new GraphicComponent, with the same properties as the previous component.
-
void
synchronize() Synchronize the contents of the text boxes and buttons with the actual properties of component.
-
void
setCircuitView(CircuitView *cv)
-
void
setComponentType(const QString &type)
Public Slots
-
void
setEditExisting(GraphicComponent *component)
Private Functions
-
void
updatePreview() Call this when component is modified.
Private Members
-
Ui::ComponentPreview *
ui
-
GraphicComponent *
component= nullptr component is guaranteed to be non-null whenever this widget is visible.
-
QString
lastComponentType
-
QString
selectedComponentType
-
CircuitView *
circuitView= nullptr The circuit view that is currently active in the window
-
QRadioButton
anchors[3][3] A 3x3 grid of buttons used to choose the text anchor
-
QButtonGroup *
anchorGroup= {}
Private Slots
-
void
on_selectionChanged() Called when the selection in the circuit view changes
-
void
on_itemDeleted(GraphicComponent *component)
-
void
on_textAnchorPicked(int id)
-
void
on_textIndependencePicked(int id)
-
void
on_btnAdd_clicked()
-
void
on_editAngle_textEdited(const QString &s)
-
void
on_editText_textEdited(const QString &s)
-
void
on_editTextAngle_textEdited(const QString &s)
-
void
on_editTextX_textEdited(const QString &s)
-
void
on_editTextY_textEdited(const QString &s)
-
void
on_editValue_textEdited(const QString &s)
-