1
/***************************************************************************
2
* Copyright (c) 2024 Florian Foinant-Willig <ffw@2f2v.fr> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
#include <App/Document.h>
26
#include <App/SuppressibleExtension.h>
28
#include "ActionFunction.h"
32
#include "Application.h"
33
#include "TreeItemMode.h"
35
#include "ViewProviderSuppressibleExtension.h"
36
#include "BitmapFactory.h"
37
#include "ViewProviderDocumentObject.h"
43
EXTENSION_PROPERTY_SOURCE(Gui::ViewProviderSuppressibleExtension, Gui::ViewProviderExtension)
45
ViewProviderSuppressibleExtension::ViewProviderSuppressibleExtension()
47
initExtensionType(ViewProviderSuppressibleExtension::getExtensionClassTypeId());
50
ViewProviderSuppressibleExtension::~ViewProviderSuppressibleExtension() = default;
52
void ViewProviderSuppressibleExtension::extensionUpdateData(const App::Property* prop)
54
auto vp = getExtendedViewProvider();
55
auto owner = vp->getObject();
56
if(!owner || !owner->isValid())
59
auto ext = owner->getExtensionByType<App::SuppressibleExtension>();
61
if (ext && prop == &ext->Suppressed) {
62
//update the tree item
63
bool suppressed = ext->Suppressed.getValue();
64
setSuppressedIcon(suppressed);
65
getExtendedViewProvider()->signalChangeHighlight(suppressed, Gui::HighlightMode::StrikeOut);
69
void ViewProviderSuppressibleExtension::setSuppressedIcon(bool onoff) {
70
isSetSuppressedIcon = onoff;
72
getExtendedViewProvider()->signalChangeIcon(); // signal icon change
75
QIcon ViewProviderSuppressibleExtension::extensionMergeColorfullOverlayIcons (const QIcon & orig) const
77
QIcon mergedicon = orig;
79
if(isSetSuppressedIcon) {
80
static QPixmap px(Gui::BitmapFactory().pixmapFromSvg("feature_suppressed", QSize(16, 16)));
82
mergedicon = Gui::BitmapFactoryInst::mergePixmap(mergedicon, px, Gui::BitmapFactoryInst::TopLeft);
84
return Gui::ViewProviderExtension::extensionMergeColorfullOverlayIcons(mergedicon);
88
void ViewProviderSuppressibleExtension::extensionSetupContextMenu(QMenu* menu, QObject*, const char*)
90
auto vp = getExtendedViewProvider();
91
auto obj = vp->getObject()->getExtensionByType<App::SuppressibleExtension>();
92
//Show Suppressed toggle action if the Suppressed property is visible
93
if (obj && ! obj->Suppressed.testStatus(App::Property::Hidden)) {
94
Gui::ActionFunction* func = new Gui::ActionFunction(menu);
95
QAction* act = menu->addAction(QObject::tr("Suppressed"));
96
act->setCheckable(true);
97
act->setChecked(obj->Suppressed.getValue());
98
func->trigger(act, [obj](){
99
obj->Suppressed.setValue(! obj->Suppressed.getValue());
106
EXTENSION_PROPERTY_SOURCE_TEMPLATE(Gui::ViewProviderSuppressibleExtensionPython, Gui::ViewProviderSuppressibleExtension)
108
// explicit template instantiation
109
template class GuiExport ViewProviderExtensionPythonT<ViewProviderSuppressibleExtension>;