MCPcopy Create free account
hub / github.com/KDE/labplot / WorksheetView

Method WorksheetView

src/frontend/worksheet/WorksheetView.cpp:75–129  ·  view source on GitHub ↗

! Constructor of the class. Creates a view for the Worksheet \c worksheet and initializes the internal model. */

Source from the content-addressed store, hash-verified

73 Creates a view for the Worksheet \c worksheet and initializes the internal model.
74*/
75WorksheetView::WorksheetView(Worksheet* worksheet)
76 : QGraphicsView()
77 , m_worksheet(worksheet) {
78 setScene(m_worksheet->scene());
79
80 setRenderHint(QPainter::Antialiasing);
81 setRubberBandSelectionMode(Qt::ContainsItemBoundingRect);
82 setTransformationAnchor(QGraphicsView::AnchorViewCenter);
83 setResizeAnchor(QGraphicsView::AnchorViewCenter);
84 setMinimumSize(16, 16);
85 setFocusPolicy(Qt::StrongFocus);
86
87 updateScrollBarPolicy();
88
89 viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
90 viewport()->setAttribute(Qt::WA_NoSystemBackground);
91 setAcceptDrops(true);
92 setCacheMode(QGraphicsView::CacheBackground);
93
94 m_gridSettings.style = GridStyle::NoGrid;
95
96 // signal/slot connections
97 connect(m_worksheet, &Worksheet::requestProjectContextMenu, this, &WorksheetView::createContextMenu);
98 connect(m_worksheet, &Worksheet::itemSelected, this, &WorksheetView::selectItem);
99 connect(m_worksheet, &Worksheet::itemDeselected, this, &WorksheetView::deselectItem);
100 connect(m_worksheet, &Worksheet::requestUpdate, this, &WorksheetView::updateBackground);
101 connect(m_worksheet, &Worksheet::childAspectAboutToBeRemoved, this, &WorksheetView::aspectAboutToBeRemoved);
102 connect(m_worksheet, &Worksheet::useViewSizeChanged, this, &WorksheetView::useViewSizeChanged);
103 connect(m_worksheet, &Worksheet::layoutChanged, this, &WorksheetView::layoutChanged);
104 connect(m_worksheet, &Worksheet::changed, this, [=] {
105 if (m_magnificationWindow && m_magnificationWindow->isVisible())
106 updateMagnificationWindow(mapToScene(mapFromGlobal(QCursor::pos())));
107 });
108 connect(scene(), &QGraphicsScene::selectionChanged, this, &WorksheetView::selectionChanged);
109
110 // resize the view to make the complete scene visible.
111 // no need to resize the view when the project is being opened,
112 // all views will be resized to the stored values at the end
113 if (!m_worksheet->isLoading()) {
114 float w = Worksheet::convertFromSceneUnits(sceneRect().width(), Worksheet::Unit::Inch);
115 float h = Worksheet::convertFromSceneUnits(sceneRect().height(), Worksheet::Unit::Inch);
116 auto dpi = GuiTools::dpi(this);
117 w *= dpi.first;
118 h *= dpi.second;
119 resize(w * 1.1, h * 1.1);
120 }
121
122 // rescale to the original size
123 static const qreal hscale = GuiTools::dpi(this).first / (Worksheet::convertToSceneUnits(1, Worksheet::Unit::Inch));
124 static const qreal vscale = GuiTools::dpi(this).second / (Worksheet::convertToSceneUnits(1, Worksheet::Unit::Inch));
125 setTransform(QTransform::fromScale(hscale, vscale));
126
127 initBasicActions();
128 installEventFilter(this);
129}
130
131/*!
132 * initializes couple of actions that have shortcuts assigned in the constructor as opposed

Callers

nothing calls this directly

Calls 5

isLoadingMethod · 0.80
heightMethod · 0.80
sceneMethod · 0.45
isVisibleMethod · 0.45
widthMethod · 0.45

Tested by

no test coverage detected