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

Method contextMenuEvent

src/frontend/ProjectExplorer.cpp:141–213  ·  view source on GitHub ↗

! shows the context menu in the tree. In addition to the context menu of the currently selected aspect, treeview specific options are added. */

Source from the content-addressed store, hash-verified

139 treeview specific options are added.
140*/
141void ProjectExplorer::contextMenuEvent(QContextMenuEvent* event) {
142 if (!m_treeView->model())
143 return;
144
145 if (!expandTreeAction)
146 createActions();
147
148 const auto& index = m_treeView->indexAt(m_treeView->viewport()->mapFrom(this, event->pos()));
149 if (!index.isValid())
150 m_treeView->clearSelection();
151
152 const auto& items = m_treeView->selectionModel()->selectedIndexes();
153 QMenu* menu = nullptr;
154 if (items.size() / 4 == 1) {
155 auto* aspect = static_cast<AbstractAspect*>(index.internalPointer());
156 menu = aspect->createContextMenu();
157
158 if (aspect == m_project) {
159 auto* firstAction = menu->actions().at(2);
160 menu->insertSeparator(firstAction);
161 menu->insertAction(firstAction, expandTreeAction);
162 menu->insertAction(firstAction, collapseTreeAction);
163 }
164 } else {
165 menu = new QMenu(this);
166
167 if (items.size() / 4 > 1) {
168 // add "expand/collapse" entries if the selected indices have children
169 bool hasChildren = false;
170 for (int i = 0; i < items.size() / 4; ++i) {
171 const auto& index = items.at(i * 4);
172 const auto* aspect = static_cast<AbstractAspect*>(index.internalPointer());
173 if (aspect->childCount<AbstractAspect>()) {
174 hasChildren = true;
175 break;
176 }
177 }
178 if (hasChildren) {
179 menu->addAction(expandSelectedTreeAction);
180 menu->addAction(collapseSelectedTreeAction);
181 menu->addSeparator();
182 }
183
184 menu->addAction(deleteSelectedTreeAction);
185 } else {
186 QMenu* projectMenu = m_project->createContextMenu();
187 projectMenu->setTitle(m_project->name());
188 menu->addMenu(projectMenu);
189
190 menu->addSeparator();
191 menu->addAction(expandTreeAction);
192 menu->addAction(collapseTreeAction);
193 menu->addSeparator();
194 menu->addAction(toggleFilterAction);
195
196 // Menu for showing/hiding the columns in the tree view
197 QMenu* columnsMenu = menu->addMenu(i18n("Columns"));
198 columnsMenu->addAction(showAllColumnsAction);

Callers

nothing calls this directly

Calls 10

clearSelectionMethod · 0.80
selectionModelMethod · 0.80
addSeparatorMethod · 0.80
setTitleMethod · 0.80
execMethod · 0.80
modelMethod · 0.45
isValidMethod · 0.45
sizeMethod · 0.45
createContextMenuMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected