MCPcopy Create free account
hub / github.com/ModOrganizer2/modorganizer / ModListContextMenu

Method ModListContextMenu

src/modlistcontextmenu.cpp:221–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221ModListContextMenu::ModListContextMenu(const QModelIndex& index, OrganizerCore& core,
222 CategoryFactory* categories, ModListView* view)
223 : QMenu(view), m_core(core), m_categories(categories),
224 m_index(index.model() == view->model() ? view->indexViewToModel(index) : index),
225 m_view(view), m_actions(view->actions())
226{
227 if (view->selectionModel()->hasSelection()) {
228 m_selected = view->indexViewToModel(view->selectionModel()->selectedRows());
229 } else {
230 m_selected = {index};
231 }
232
233 ModInfo::Ptr info = ModInfo::getByIndex(index.data(ModList::IndexRole).toInt());
234
235 QMenu* allMods =
236 new ModListGlobalContextMenu(core, view, m_index, view->topLevelWidget());
237 allMods->setTitle(tr("All Mods"));
238 addMenu(allMods);
239
240 auto viewIndex = view->indexModelToView(m_index);
241 if (view->model()->hasChildren(viewIndex)) {
242 bool expanded = view->isExpanded(viewIndex);
243 addSeparator();
244 addAction(tr("Collapse all"), view, &QTreeView::collapseAll);
245 addAction(tr("Collapse others"), [=]() {
246 m_view->collapseAll();
247 m_view->setExpanded(viewIndex, expanded);
248 });
249 addAction(tr("Expand all"), view, &QTreeView::expandAll);
250 }
251
252 addSeparator();
253
254 // Add type-specific items
255 if (info->isOverwrite()) {
256 addOverwriteActions(info);
257 } else if (info->isBackup()) {
258 addBackupActions(info);
259 } else if (info->isSeparator()) {
260 addSeparatorActions(info);
261 } else if (info->isForeign()) {
262 addForeignActions(info);
263 } else {
264 addRegularActions(info);
265 }
266
267 // add information for all except foreign
268 if (!info->isForeign()) {
269 QAction* infoAction = addAction(tr("Information..."), [=]() {
270 view->actions().displayModInformation(m_index.data(ModList::IndexRole).toInt());
271 });
272 setDefaultAction(infoAction);
273 }
274}
275
276void ModListContextMenu::addMenuAsPushButton(QMenu* menu)
277{

Callers

nothing calls this directly

Calls 12

modelMethod · 0.80
collapseAllMethod · 0.80
setExpandedMethod · 0.80
indexViewToModelMethod · 0.45
dataMethod · 0.45
indexModelToViewMethod · 0.45
hasChildrenMethod · 0.45
isOverwriteMethod · 0.45
isBackupMethod · 0.45
isSeparatorMethod · 0.45
isForeignMethod · 0.45
displayModInformationMethod · 0.45

Tested by

no test coverage detected