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

Method init

src/frontend/spreadsheet/SpreadsheetView.cpp:142–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142void SpreadsheetView::init() {
143 // create a new SpreadsheetModel if not available yet.
144 // the creation of the model is done here since it's only required
145 // for the view but its lifecycle is managed in Spreadsheet,
146 // i.e. the deletion of the model is done in the destructor of Spreadsheet
147 m_model = m_spreadsheet->model();
148 if (!m_model)
149 m_model = new SpreadsheetModel(m_spreadsheet);
150
151 m_tableView->setModel(m_model);
152 auto* delegate = new SpreadsheetItemDelegate(this);
153 connect(delegate, &SpreadsheetItemDelegate::returnPressed, this, &SpreadsheetView::advanceCell);
154 connect(delegate, &SpreadsheetItemDelegate::editorEntered, this, [=]() {
155 m_editorEntered = true;
156 });
157 connect(delegate, &SpreadsheetItemDelegate::closeEditor, this, [=]() {
158 m_editorEntered = false;
159 });
160
161 m_tableView->setItemDelegate(delegate);
162 m_tableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
163
164 // horizontal header
165 m_horizontalHeader = new SpreadsheetHeaderView(this);
166
167 m_horizontalHeader->setSectionsClickable(true);
168 m_horizontalHeader->setHighlightSections(true);
169 m_tableView->setHorizontalHeader(m_horizontalHeader);
170 m_horizontalHeader->setSectionsMovable(true);
171 m_horizontalHeader->installEventFilter(this);
172 m_tableView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
173 // m_tableView->installEventFilter(this);
174
175 resizeHeader();
176
177 connect(m_horizontalHeader, &SpreadsheetHeaderView::sectionMoved, this, &SpreadsheetView::handleHorizontalSectionMoved);
178 connect(m_horizontalHeader, &SpreadsheetHeaderView::sectionDoubleClicked, this, &SpreadsheetView::handleHorizontalHeaderDoubleClicked);
179 connect(m_horizontalHeader, &SpreadsheetHeaderView::sectionResized, this, &SpreadsheetView::handleHorizontalSectionResized);
180 connect(m_horizontalHeader, &SpreadsheetHeaderView::sectionClicked, this, &SpreadsheetView::columnClicked);
181
182 // vertical header
183 auto* v_header = m_tableView->verticalHeader();
184 v_header->setSectionResizeMode(QHeaderView::Fixed);
185 v_header->setSectionsMovable(false);
186 v_header->installEventFilter(this);
187 m_tableView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
188
189 setFocusPolicy(Qt::StrongFocus);
190 setFocus();
191 installEventFilter(this);
192
193 connect(m_model, &SpreadsheetModel::headerDataChanged, this, &SpreadsheetView::updateHeaderGeometry);
194 connect(m_model, &SpreadsheetModel::headerDataChanged, this, &SpreadsheetView::handleHeaderDataChanged);
195 connect(m_spreadsheet, &Spreadsheet::aspectsInserted, this, &SpreadsheetView::handleAspectsAdded);
196 connect(m_spreadsheet, &Spreadsheet::aspectsAboutToBeRemoved, this, &SpreadsheetView::handleAspectAboutToBeRemoved);
197 connect(m_spreadsheet, &Spreadsheet::requestProjectContextMenu, this, &SpreadsheetView::createContextMenu);
198 connect(m_spreadsheet, &Spreadsheet::manyAspectsAboutToBeInserted, [this] {
199 m_suppressResize = true;

Callers

nothing calls this directly

Calls 8

refreshMethod · 0.80
selectionModelMethod · 0.80
modelMethod · 0.45
setModelMethod · 0.45
columnCountMethod · 0.45
columnMethod · 0.45
showSparklinesMethod · 0.45
showCommentsMethod · 0.45

Tested by

no test coverage detected