diff --git a/Fwk/AppFwk/CMakeLists.txt b/Fwk/AppFwk/CMakeLists.txt index a844191dd5..6e9d39d440 100644 --- a/Fwk/AppFwk/CMakeLists.txt +++ b/Fwk/AppFwk/CMakeLists.txt @@ -45,6 +45,7 @@ add_subdirectory (cafProjectDataModel/cafPdmXml) add_subdirectory(cafProjectDataModel) add_subdirectory(cafCommand) +add_subdirectory(cafCommandFeatures) add_subdirectory(cafUserInterface) #executables diff --git a/Fwk/AppFwk/cafCommand/CMakeLists.txt b/Fwk/AppFwk/cafCommand/CMakeLists.txt index 713a1954b5..f10513ec59 100644 --- a/Fwk/AppFwk/cafCommand/CMakeLists.txt +++ b/Fwk/AppFwk/cafCommand/CMakeLists.txt @@ -28,20 +28,6 @@ set( PROJECT_FILES cafCmdUiCommandSystemImpl.h cafCmdUiCommandSystemImpl.cpp - # Default features - defaultfeatures/cafCmdAddItemExec.cpp - defaultfeatures/cafCmdAddItemExec.h - defaultfeatures/cafCmdAddItemExecData.cpp - defaultfeatures/cafCmdAddItemExecData.h - defaultfeatures/cafCmdAddItemFeature.cpp - defaultfeatures/cafCmdAddItemFeature.h - defaultfeatures/cafCmdDeleteItemExec.cpp - defaultfeatures/cafCmdDeleteItemExec.h - defaultfeatures/cafCmdDeleteItemExecData.cpp - defaultfeatures/cafCmdDeleteItemExecData.h - defaultfeatures/cafCmdDeleteItemFeature.cpp - defaultfeatures/cafCmdDeleteItemFeature.h - cafCmdFieldChangeExec.cpp cafCmdFieldChangeExec.h diff --git a/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.cpp b/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.cpp index 445ac8553f..e906eeb10a 100644 --- a/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.cpp +++ b/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.cpp @@ -41,9 +41,6 @@ #include "cafCmdSelectionHelper.h" #include "cafFactory.h" -#include "defaultfeatures/cafCmdDeleteItemFeature.h" -#include "defaultfeatures/cafCmdAddItemFeature.h" - #include #include @@ -56,9 +53,6 @@ namespace caf //-------------------------------------------------------------------------------------------------- CmdFeatureManager::CmdFeatureManager() { - CmdDeleteItemFeature::idNameStatic(); - CmdAddItemFeature::idNameStatic(); - // Make sure all command features are created. The command feature is registered // in the command factory, and instantiated when required. This will enable possibility // of searching through all command features instead of having to use the string keys to @@ -66,7 +60,7 @@ CmdFeatureManager::CmdFeatureManager() std::vector keys = CommandFeatureFactory::instance()->allKeys(); for (size_t i = 0; i < keys.size(); i++) { - action(QString::fromStdString(keys[i])); + createFeature(keys[i]); } } @@ -337,4 +331,20 @@ std::vector CmdFeatureManager::commandFeaturesMatchingKeyboardShort return matches; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void CmdFeatureManager::setCurrentContextMenuTargetWidget(QWidget * targetWidget) +{ + m_currentContextMenuTargetWidget = targetWidget; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QWidget* CmdFeatureManager::currentContextMenuTargetWidget() +{ + return m_currentContextMenuTargetWidget; +} + } // end namespace caf diff --git a/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.h b/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.h index 76fe9cc931..89ef3a30a8 100644 --- a/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.h +++ b/Fwk/AppFwk/cafCommand/cafCmdFeatureManager.h @@ -43,9 +43,11 @@ #include #include +#include class QAction; class QKeySequence; +class QWidget; namespace caf { @@ -66,14 +68,18 @@ public: QAction* action(const QString& commandId); QAction* action(const QString& commandId, const QString& customActionText); QAction* actionWithUserData(const QString& commandId, const QString& customActionText, const QVariant& userData); - void refreshStates(const QStringList& commandIdList = QStringList()); - void refreshEnabledState(const QStringList& commandIdList = QStringList()); - void refreshCheckedState(const QStringList& commandIdList = QStringList()); - CmdFeature* getCommandFeature(const std::string& commandId); + void refreshStates(const QStringList& commandIdList = QStringList()); + void refreshEnabledState(const QStringList& commandIdList = QStringList()); + void refreshCheckedState(const QStringList& commandIdList = QStringList()); + CmdFeature* getCommandFeature(const std::string& commandId); std::vector commandFeaturesMatchingSubString(const std::string& subString) const; std::vector commandFeaturesMatchingKeyboardShortcut(const QKeySequence& keySequence) const; + + void setCurrentContextMenuTargetWidget(QWidget * targetWidget); + QWidget* currentContextMenuTargetWidget(); + private: CmdFeatureManager(); @@ -87,6 +93,7 @@ private: std::map m_commandIdToFeatureIdxMap; std::map m_actionToFeatureIdxMap; + QPointer m_currentContextMenuTargetWidget; }; diff --git a/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.cpp b/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.cpp index 574c5a8954..a4e6405954 100644 --- a/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.cpp +++ b/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.cpp @@ -168,4 +168,12 @@ bool CmdUiCommandSystemImpl::disableUndoForFieldChange() return m_disableUndoForFieldChange; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void CmdUiCommandSystemImpl::setCurrentContextMenuTargetWidget(QWidget* targetWidget) +{ + caf::CmdFeatureManager::instance()->setCurrentContextMenuTargetWidget(targetWidget); +} + } // end namespace caf diff --git a/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.h b/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.h index 5fe57e6625..ed296235f4 100644 --- a/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.h +++ b/Fwk/AppFwk/cafCommand/cafCmdUiCommandSystemImpl.h @@ -51,6 +51,7 @@ public: CmdUiCommandSystemImpl(); void fieldChangedCommand(const std::vector& fieldsToUpdate, const QVariant& newUiValue) override; + void setCurrentContextMenuTargetWidget(QWidget* targetWidget) override; void populateMenuWithDefaultCommands(const QString& uiConfigName, QMenu* menu) override; bool isUndoEnabled(); diff --git a/Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdAddItemExec.cpp b/Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdAddItemExec.cpp similarity index 100% rename from Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdAddItemExec.cpp rename to Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdAddItemExec.cpp diff --git a/Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdAddItemExec.h b/Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdAddItemExec.h similarity index 100% rename from Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdAddItemExec.h rename to Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdAddItemExec.h diff --git a/Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdAddItemExecData.cpp b/Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdAddItemExecData.cpp similarity index 100% rename from Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdAddItemExecData.cpp rename to Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdAddItemExecData.cpp diff --git a/Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdAddItemExecData.h b/Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdAddItemExecData.h similarity index 100% rename from Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdAddItemExecData.h rename to Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdAddItemExecData.h diff --git a/Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdAddItemFeature.cpp b/Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdAddItemFeature.cpp similarity index 100% rename from Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdAddItemFeature.cpp rename to Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdAddItemFeature.cpp diff --git a/Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdAddItemFeature.h b/Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdAddItemFeature.h similarity index 100% rename from Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdAddItemFeature.h rename to Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdAddItemFeature.h diff --git a/Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdDeleteItemExec.cpp b/Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdDeleteItemExec.cpp similarity index 100% rename from Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdDeleteItemExec.cpp rename to Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdDeleteItemExec.cpp diff --git a/Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdDeleteItemExec.h b/Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdDeleteItemExec.h similarity index 100% rename from Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdDeleteItemExec.h rename to Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdDeleteItemExec.h diff --git a/Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdDeleteItemExecData.cpp b/Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdDeleteItemExecData.cpp similarity index 100% rename from Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdDeleteItemExecData.cpp rename to Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdDeleteItemExecData.cpp diff --git a/Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdDeleteItemExecData.h b/Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdDeleteItemExecData.h similarity index 100% rename from Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdDeleteItemExecData.h rename to Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdDeleteItemExecData.h diff --git a/Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdDeleteItemFeature.cpp b/Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdDeleteItemFeature.cpp similarity index 100% rename from Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdDeleteItemFeature.cpp rename to Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdDeleteItemFeature.cpp diff --git a/Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdDeleteItemFeature.h b/Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdDeleteItemFeature.h similarity index 100% rename from Fwk/AppFwk/cafCommand/defaultfeatures/cafCmdDeleteItemFeature.h rename to Fwk/AppFwk/cafCommandFeatures/AddAndDelete/cafCmdDeleteItemFeature.h diff --git a/Fwk/AppFwk/cafCommandFeatures/CMakeLists.txt b/Fwk/AppFwk/cafCommandFeatures/CMakeLists.txt new file mode 100644 index 0000000000..21d3791811 --- /dev/null +++ b/Fwk/AppFwk/cafCommandFeatures/CMakeLists.txt @@ -0,0 +1,95 @@ +cmake_minimum_required (VERSION 2.8.12) + +project (cafCommandFeatures) + + +# These headers need to go through Qt's MOC compiler +set (MOC_HEADER_FILES + +) + +# Qt +if (CEE_USE_QT5) + find_package(Qt5 COMPONENTS REQUIRED Core Gui Widgets) + set(QT_LIBRARIES Qt5::Core Qt5::Gui Qt5::Widgets) + qt5_wrap_cpp(MOC_SOURCE_FILES ${MOC_HEADER_FILES} ) +else() + find_package(Qt4 COMPONENTS QtCore QtGui QtMain REQUIRED) + include(${QT_USE_FILE}) + qt4_wrap_cpp(MOC_SOURCE_FILES ${MOC_HEADER_FILES} ) +endif(CEE_USE_QT5) + +set( PROJECT_FILES + + # Default features + AddAndDelete/cafCmdAddItemExec.cpp + AddAndDelete/cafCmdAddItemExec.h + AddAndDelete/cafCmdAddItemExecData.cpp + AddAndDelete/cafCmdAddItemExecData.h + AddAndDelete/cafCmdAddItemFeature.cpp + AddAndDelete/cafCmdAddItemFeature.h + AddAndDelete/cafCmdDeleteItemExec.cpp + AddAndDelete/cafCmdDeleteItemExec.h + AddAndDelete/cafCmdDeleteItemExecData.cpp + AddAndDelete/cafCmdDeleteItemExecData.h + AddAndDelete/cafCmdDeleteItemFeature.cpp + AddAndDelete/cafCmdDeleteItemFeature.h + + ToggleCommands/cafToggleItemsFeature.cpp + ToggleCommands/cafToggleItemsFeature.h + ToggleCommands/cafToggleItemsFeatureImpl.cpp + ToggleCommands/cafToggleItemsFeatureImpl.h + ToggleCommands/cafToggleItemsOffFeature.cpp + ToggleCommands/cafToggleItemsOffFeature.h + ToggleCommands/cafToggleItemsOnFeature.cpp + ToggleCommands/cafToggleItemsOnFeature.h + ToggleCommands/cafToggleItemsOnOthersOffFeature.cpp + ToggleCommands/cafToggleItemsOnOthersOffFeature.h +) + +# NOTE! Resources in this subfolder appends to the variable QRC_FILES in parent scope +# CMakeList.txt in the application folder (parent scope) must use the following syntax +# to make sure the QRC_FILES variable contains appended files in subfolders + +# set( QRC_FILES +# ${QRC_FILES} +# +# ) + +set( QRC_FILES + ${QRC_FILES} + ${CMAKE_CURRENT_SOURCE_DIR}/Resources/cafCommandFeatures.qrc + PARENT_SCOPE +) + +# NOTE! Adding the library as a cmake "OBJECT" library +# to make sure the linker is not pruning the seemingly unused features, +# and to make sure that the static initialization based registration of the features into the factory is done properly +# see https://gitlab.kitware.com/cmake/community/wikis/doc/tutorials/Object-Library +# and https://cmake.org/cmake/help/v3.15/command/add_library.html?highlight=add_library#object-libraries +add_library( ${PROJECT_NAME} OBJECT + ${PROJECT_FILES} + ${MOC_SOURCE_FILES} +) + +target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_link_libraries ( ${PROJECT_NAME} + cafCommand + cafUserInterface + ${QT_LIBRARIES} +) + +if (MSVC) + set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/W4 /wd4100 /wd4127") +endif() + +source_group("" FILES ${PROJECT_FILES}) + +# cotire +if (COMMAND caf_apply_cotire) + caf_apply_cotire("${PROJECT_NAME}") +endif() diff --git a/Fwk/AppFwk/cafCommandFeatures/Resources/ToggleOffL16x16.png b/Fwk/AppFwk/cafCommandFeatures/Resources/ToggleOffL16x16.png new file mode 100644 index 0000000000..237744a234 Binary files /dev/null and b/Fwk/AppFwk/cafCommandFeatures/Resources/ToggleOffL16x16.png differ diff --git a/Fwk/AppFwk/cafCommandFeatures/Resources/ToggleOnL16x16.png b/Fwk/AppFwk/cafCommandFeatures/Resources/ToggleOnL16x16.png new file mode 100644 index 0000000000..0591c6f8a2 Binary files /dev/null and b/Fwk/AppFwk/cafCommandFeatures/Resources/ToggleOnL16x16.png differ diff --git a/Fwk/AppFwk/cafCommandFeatures/Resources/ToggleOnOffL16x16.png b/Fwk/AppFwk/cafCommandFeatures/Resources/ToggleOnOffL16x16.png new file mode 100644 index 0000000000..f57d91b14b Binary files /dev/null and b/Fwk/AppFwk/cafCommandFeatures/Resources/ToggleOnOffL16x16.png differ diff --git a/Fwk/AppFwk/cafCommandFeatures/Resources/ToggleOnOthersOffL16x16.png b/Fwk/AppFwk/cafCommandFeatures/Resources/ToggleOnOthersOffL16x16.png new file mode 100644 index 0000000000..1a5c7be056 Binary files /dev/null and b/Fwk/AppFwk/cafCommandFeatures/Resources/ToggleOnOthersOffL16x16.png differ diff --git a/Fwk/AppFwk/cafCommandFeatures/Resources/cafCommandFeatures.qrc b/Fwk/AppFwk/cafCommandFeatures/Resources/cafCommandFeatures.qrc new file mode 100644 index 0000000000..dfdc6ae160 --- /dev/null +++ b/Fwk/AppFwk/cafCommandFeatures/Resources/cafCommandFeatures.qrc @@ -0,0 +1,8 @@ + + + ToggleOnL16x16.png + ToggleOffL16x16.png + ToggleOnOffL16x16.png + ToggleOnOthersOffL16x16.png + + \ No newline at end of file diff --git a/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeature.cpp b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeature.cpp new file mode 100644 index 0000000000..b6cc3b7acc --- /dev/null +++ b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeature.cpp @@ -0,0 +1,79 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2019- Ceetron Solutions AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafToggleItemsFeature.h" + +#include "cafToggleItemsFeatureImpl.h" + +#include "cafSelectionManager.h" + +#include + +namespace caf +{ + +CAF_CMD_SOURCE_INIT(ToggleItemsFeature, "cafToggleItemsFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool ToggleItemsFeature::isCommandEnabled() +{ + return ToggleItemsFeatureImpl::isToggleCommandsAvailable(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void ToggleItemsFeature::onActionTriggered(bool isChecked) +{ + ToggleItemsFeatureImpl::setObjectToggleStateForSelection(ToggleItemsFeatureImpl::TOGGLE_SUBITEMS); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void ToggleItemsFeature::setupActionLook(QAction* actionToSetup) +{ + if (ToggleItemsFeatureImpl::isToggleCommandsForSubItems()) + actionToSetup->setText("Toggle Sub Items"); + else + actionToSetup->setText("Toggle"); + + actionToSetup->setIcon(QIcon(":/cafCommandFeatures/ToggleOnOffL16x16.png")); +} + +} \ No newline at end of file diff --git a/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeature.h b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeature.h new file mode 100644 index 0000000000..d315b9d4ad --- /dev/null +++ b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeature.h @@ -0,0 +1,57 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2019- Ceetron Solutions AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once + +#include "cafCmdFeature.h" + +namespace caf +{ +//================================================================================================== +/// +//================================================================================================== +class ToggleItemsFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; +protected: + + // Overrides + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; +}; + +} \ No newline at end of file diff --git a/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeatureImpl.cpp b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeatureImpl.cpp new file mode 100644 index 0000000000..f9be5c3a3f --- /dev/null +++ b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeatureImpl.cpp @@ -0,0 +1,204 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2019- Ceetron Solutions AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafToggleItemsFeatureImpl.h" + +//#include "RiaFeatureCommandContext.h" +//#include "RiaGuiApplication.h" +//#include "RiuMainWindow.h" +//#include "RiuPlotMainWindow.h" + +#include "cafPdmUiFieldHandle.h" +#include "cafPdmUiItem.h" +#include "cafPdmUiObjectHandle.h" +#include "cafPdmUiTreeOrdering.h" +#include "cafPdmUiTreeView.h" +#include "cafSelectionManager.h" + +#include + +#include +#include "cafCmdFeatureManager.h" + +namespace caf +{ + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool ToggleItemsFeatureImpl::isToggleCommandsAvailable() +{ + std::vector selectedItems; + caf::SelectionManager::instance()->selectedItems(selectedItems); + + if (selectedItems.size() == 1) + { + caf::PdmUiTreeOrdering* treeItem = findTreeItemFromSelectedUiItem(selectedItems[0]); + + if (!treeItem) return false; + + for (int cIdx = 0; cIdx < treeItem->childCount(); ++ cIdx) + { + caf::PdmUiTreeOrdering* child = treeItem->child(cIdx); + if (!child) continue; + if (!child->isRepresentingObject()) continue; + + caf::PdmObjectHandle* childObj = child->object(); + caf::PdmUiObjectHandle* uiObjectHandleChild = uiObj(childObj); + + if (uiObjectHandleChild && + uiObjectHandleChild->objectToggleField() && + !uiObjectHandleChild->objectToggleField()->uiCapability()->isUiReadOnly()) + { + return true; + } + } + } + else + { + for (size_t i = 0; i < selectedItems.size(); ++i) + { + caf::PdmUiObjectHandle* uiObjectHandle = dynamic_cast(selectedItems[i]); + + if (uiObjectHandle && uiObjectHandle->objectToggleField()) + { + return true; + } + } + } + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool ToggleItemsFeatureImpl::isToggleCommandsForSubItems() +{ + std::vector selectedItems; + caf::SelectionManager::instance()->selectedItems(selectedItems); + if (isToggleCommandsAvailable() && selectedItems.size() == 1) + { + return true; + } + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// Set toggle state for list of model indices. +//-------------------------------------------------------------------------------------------------- +void ToggleItemsFeatureImpl::setObjectToggleStateForSelection(SelectionToggleType state) +{ + std::vector selectedItems; + caf::SelectionManager::instance()->selectedItems(selectedItems); + if (state != TOGGLE && selectedItems.size() == 1) + { + // If only one item is selected, loop over its children, and toggle them instead of the + // selected item directly + + // We need to get the children through the tree view, because that is where the actually shown children is + + caf::PdmUiTreeOrdering* treeItem = findTreeItemFromSelectedUiItem(selectedItems[0]); + + if (!treeItem) return; + + for (int cIdx = 0; cIdx < treeItem->childCount(); ++ cIdx) + { + caf::PdmUiTreeOrdering* child = treeItem->child(cIdx); + if (!child) continue; + if (!child->isRepresentingObject()) continue; + + caf::PdmObjectHandle* childObj = child->object(); + caf::PdmUiObjectHandle* uiObjectHandleChild = uiObj(childObj); + + if (uiObjectHandleChild && uiObjectHandleChild->objectToggleField()) + { + caf::PdmField* field = dynamic_cast*>(uiObjectHandleChild->objectToggleField()); + + if (state == TOGGLE_ON) field->setValueWithFieldChanged(true); + if (state == TOGGLE_OFF) field->setValueWithFieldChanged(false); + if (state == TOGGLE_SUBITEMS) field->setValueWithFieldChanged(!(field->v())); + } + } + } + else + { + for (size_t i = 0; i < selectedItems.size(); ++i) + { + caf::PdmUiObjectHandle* uiObjectHandle = dynamic_cast< caf::PdmUiObjectHandle*>(selectedItems[i]); + + if (uiObjectHandle && uiObjectHandle->objectToggleField()) + { + caf::PdmField* field = dynamic_cast* >(uiObjectHandle->objectToggleField()); + + if (state == TOGGLE_ON) field->setValueWithFieldChanged(true); + if (state == TOGGLE_OFF) field->setValueWithFieldChanged(false); + if (state == TOGGLE_SUBITEMS || state == TOGGLE) + { + field->setValueWithFieldChanged(!(field->v())); + } + } + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::PdmUiTreeView* ToggleItemsFeatureImpl::findTreeView(const caf::PdmUiItem* uiItem) +{ + caf::PdmUiTreeView* customActiveTreeView = dynamic_cast(CmdFeatureManager::instance()->currentContextMenuTargetWidget()); + + return customActiveTreeView; +} + +//-------------------------------------------------------------------------------------------------- +/// Finds the tree item in either the 3D main window or plot main window project tree view +//-------------------------------------------------------------------------------------------------- +caf::PdmUiTreeOrdering* ToggleItemsFeatureImpl::findTreeItemFromSelectedUiItem(const caf::PdmUiItem* uiItem) +{ + caf::PdmUiTreeView* pdmUiTreeView = findTreeView(uiItem); + + if (pdmUiTreeView) + { + QModelIndex modIndex = pdmUiTreeView->findModelIndex(uiItem); + return static_cast(modIndex.internalPointer()); + } + + return nullptr; +} + +} \ No newline at end of file diff --git a/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeatureImpl.h b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeatureImpl.h new file mode 100644 index 0000000000..ccb180a257 --- /dev/null +++ b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsFeatureImpl.h @@ -0,0 +1,70 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2019- Ceetron Solutions AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once + +namespace caf +{ + class PdmUiItem; + class PdmUiTreeOrdering; + class PdmUiTreeView; + + +//================================================================================================== +/// +//================================================================================================== +class ToggleItemsFeatureImpl +{ +public: + enum SelectionToggleType + { + TOGGLE_ON, + TOGGLE_OFF, + TOGGLE_SUBITEMS, + TOGGLE, + TOGGLE_UNDEFINED + }; + + static bool isToggleCommandsAvailable(); + static bool isToggleCommandsForSubItems(); + static void setObjectToggleStateForSelection(SelectionToggleType state); + +private: + static caf::PdmUiTreeView* findTreeView(const caf::PdmUiItem* uiItem); + static caf::PdmUiTreeOrdering* findTreeItemFromSelectedUiItem(const caf::PdmUiItem* uiItem); +}; + +}; diff --git a/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOffFeature.cpp b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOffFeature.cpp new file mode 100644 index 0000000000..52b0f765ce --- /dev/null +++ b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOffFeature.cpp @@ -0,0 +1,80 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2019- Ceetron Solutions AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafToggleItemsOffFeature.h" + +#include "cafToggleItemsFeatureImpl.h" + +#include "cafSelectionManager.h" + +#include + +namespace caf +{ + +CAF_CMD_SOURCE_INIT(ToggleItemsOffFeature, "cafToggleItemsOffFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool ToggleItemsOffFeature::isCommandEnabled() +{ + return ToggleItemsFeatureImpl::isToggleCommandsAvailable(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void ToggleItemsOffFeature::onActionTriggered(bool isChecked) +{ + ToggleItemsFeatureImpl::setObjectToggleStateForSelection(ToggleItemsFeatureImpl::TOGGLE_OFF); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void ToggleItemsOffFeature::setupActionLook(QAction* actionToSetup) +{ + if (ToggleItemsFeatureImpl::isToggleCommandsForSubItems()) + actionToSetup->setText("Sub Items Off"); + else + actionToSetup->setText("Off"); + + actionToSetup->setIcon(QIcon(":/cafCommandFeatures/ToggleOffL16x16.png")); + +} + +} \ No newline at end of file diff --git a/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOffFeature.h b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOffFeature.h new file mode 100644 index 0000000000..fac7525e2c --- /dev/null +++ b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOffFeature.h @@ -0,0 +1,57 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2019- Ceetron Solutions AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once + +#include "cafCmdFeature.h" + +namespace caf +{ +//================================================================================================== +/// +//================================================================================================== +class ToggleItemsOffFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; +protected: + + // Overrides + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; +}; + +} \ No newline at end of file diff --git a/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnFeature.cpp b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnFeature.cpp new file mode 100644 index 0000000000..de65c1985f --- /dev/null +++ b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnFeature.cpp @@ -0,0 +1,80 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2019- Ceetron Solutions AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafToggleItemsOnFeature.h" + +#include "cafToggleItemsFeatureImpl.h" + +#include "cafSelectionManager.h" + +#include + +namespace caf +{ + +CAF_CMD_SOURCE_INIT(ToggleItemsOnFeature, "cafToggleItemsOnFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool ToggleItemsOnFeature::isCommandEnabled() +{ + return ToggleItemsFeatureImpl::isToggleCommandsAvailable(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void ToggleItemsOnFeature::onActionTriggered(bool isChecked) +{ + ToggleItemsFeatureImpl::setObjectToggleStateForSelection(ToggleItemsFeatureImpl::TOGGLE_ON); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void ToggleItemsOnFeature::setupActionLook(QAction* actionToSetup) +{ + if (ToggleItemsFeatureImpl::isToggleCommandsForSubItems()) + actionToSetup->setText("Sub Items On"); + else + actionToSetup->setText("On"); + + actionToSetup->setIcon(QIcon(":/cafCommandFeatures/ToggleOnL16x16.png")); + +} + +} \ No newline at end of file diff --git a/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnFeature.h b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnFeature.h new file mode 100644 index 0000000000..2b3b08ce07 --- /dev/null +++ b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnFeature.h @@ -0,0 +1,58 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2019- Ceetron Solutions AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once + +#include "cafCmdFeature.h" + +namespace caf +{ + +//================================================================================================== +/// +//================================================================================================== +class ToggleItemsOnFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; +protected: + + // Overrides + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; +}; + +} \ No newline at end of file diff --git a/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnOthersOffFeature.cpp b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnOthersOffFeature.cpp new file mode 100644 index 0000000000..0a9c06577a --- /dev/null +++ b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnOthersOffFeature.cpp @@ -0,0 +1,165 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2019- Ceetron Solutions AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#include "cafToggleItemsOnOthersOffFeature.h" + +#include "cafToggleItemsFeatureImpl.h" + +#include "cafSelectionManager.h" + +#include +#include "cafPdmObjectHandle.h" +#include "cafPdmObject.h" +#include "cafPdmUiItem.h" + +namespace caf +{ + +CAF_CMD_SOURCE_INIT(ToggleItemsOnOthersOffFeature, "cafToggleItemsOnOthersOffFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool ToggleItemsOnOthersOffFeature::isCommandEnabled() +{ + std::vector selectedObjects; + caf::SelectionManager::instance()->objectsByType(&selectedObjects); + + caf::PdmFieldHandle* commonParent = verifySameParentForSelection(selectedObjects); + std::vector children = childObjects(commonParent); + + return commonParent != nullptr + && children.size() > 0 + && objectToggleField(children.front()) + && children.size() > selectedObjects.size(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void ToggleItemsOnOthersOffFeature::onActionTriggered(bool isChecked) +{ + std::vector selectedObjects; + caf::SelectionManager::instance()->objectsByType(&selectedObjects); + + // First toggle off all siblings + + caf::PdmFieldHandle* commonParent = verifySameParentForSelection(selectedObjects); + + for (caf::PdmObjectHandle* child : childObjects(commonParent)) + { + caf::PdmField* field = objectToggleField(child); + + if (field) + { + field->setValueWithFieldChanged(false); + } + } + + // Then toggle on the selected item(s) + for (caf::PdmObject* selectedObject : selectedObjects) + { + caf::PdmField* field = dynamic_cast*>(selectedObject->objectToggleField()); + + field->setValueWithFieldChanged(true); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void ToggleItemsOnOthersOffFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("On - Others Off"); + + actionToSetup->setIcon(QIcon(":/cafCommandFeatures/ToggleOnOthersOffL16x16.png")); + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::PdmFieldHandle* ToggleItemsOnOthersOffFeature::verifySameParentForSelection(const std::vector& selection) +{ + caf::PdmFieldHandle* sameParent = nullptr; + + for ( caf::PdmObject* obj : selection ) + { + caf::PdmFieldHandle* parent = obj->parentField(); + if ( parent ) + { + if ( !sameParent ) + { + sameParent = parent; + } + else if ( parent != sameParent ) + { + // Different parents detected + + return nullptr; + } + } + } + return sameParent; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector ToggleItemsOnOthersOffFeature::childObjects(caf::PdmFieldHandle* parent) +{ + std::vector children; + if ( parent ) + { + parent->childObjects(&children); + } + return children; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::PdmField* ToggleItemsOnOthersOffFeature::objectToggleField(caf::PdmObjectHandle* objectHandle) +{ + caf::PdmUiObjectHandle* childUiObject = uiObj(objectHandle); + if ( childUiObject && childUiObject->objectToggleField() ) + { + return dynamic_cast*>(childUiObject->objectToggleField()); + } + return nullptr; +} + +} \ No newline at end of file diff --git a/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnOthersOffFeature.h b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnOthersOffFeature.h new file mode 100644 index 0000000000..ab5c4f8179 --- /dev/null +++ b/Fwk/AppFwk/cafCommandFeatures/ToggleCommands/cafToggleItemsOnOthersOffFeature.h @@ -0,0 +1,68 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2019- Ceetron Solutions AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + +#pragma once + +#include "cafCmdFeature.h" +#include "cafPdmField.h" + +namespace caf +{ + class PdmFieldHandle; + class PdmObject; + class PdmObjectHandle; + + +//================================================================================================== +/// +//================================================================================================== +class ToggleItemsOnOthersOffFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; +protected: + + // Overrides + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; + +private: + caf::PdmFieldHandle* verifySameParentForSelection(const std::vector& selectedObjects); + std::vector childObjects(caf::PdmFieldHandle* parent); + caf::PdmField* objectToggleField(caf::PdmObjectHandle* objectHandle); +}; + +} \ No newline at end of file diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafInternalPdmUiCommandSystemInterface.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafInternalPdmUiCommandSystemInterface.h index 89ebc8b453..99553257a9 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafInternalPdmUiCommandSystemInterface.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafInternalPdmUiCommandSystemInterface.h @@ -41,6 +41,7 @@ class QVariant; class QMenu; class QString; +class QWidget; namespace caf { @@ -53,6 +54,8 @@ class PdmUiCommandSystemInterface { public: virtual void fieldChangedCommand( const std::vector& fieldsToUpdate, const QVariant& newUiValue) = 0; + virtual void setCurrentContextMenuTargetWidget(QWidget* targetWidget) = 0; + virtual void populateMenuWithDefaultCommands(const QString& uiConfigName, QMenu* menu) = 0; }; diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiCommandSystemProxy.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiCommandSystemProxy.cpp index a60aa18910..a4e2385f01 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiCommandSystemProxy.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiCommandSystemProxy.cpp @@ -145,6 +145,17 @@ void PdmUiCommandSystemProxy::setUiValueToField(PdmUiFieldHandle* uiFieldHandle, } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiCommandSystemProxy::setCurrentContextMenuTargetWidget(QWidget* targetWidget) +{ + if (m_commandInterface) + { + m_commandInterface->setCurrentContextMenuTargetWidget(targetWidget); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiCommandSystemProxy.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiCommandSystemProxy.h index 8d04ddb63e..d9744d0810 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiCommandSystemProxy.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiCommandSystemProxy.h @@ -39,6 +39,7 @@ class QVariant; class QMenu; class QString; +class QWidget; namespace caf { @@ -57,6 +58,7 @@ public: void setCommandInterface(PdmUiCommandSystemInterface* undoCommandInterface); void setUiValueToField(PdmUiFieldHandle* uiFieldHandle, const QVariant& newUiValue); + void setCurrentContextMenuTargetWidget(QWidget* targetWidget); void populateMenuWithDefaultCommands(const QString& uiConfigName, QMenu* menu); private: diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.cpp index 9f41be8f89..2ff803dc60 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldEditorHandle.cpp @@ -237,12 +237,15 @@ void PdmUiFieldEditorHandle::customMenuRequested(QPoint pos) } QMenu menu; + PdmUiCommandSystemProxy::instance()->setCurrentContextMenuTargetWidget(widget); objectHandle->uiCapability()->defineCustomContextMenu(uiField()->fieldHandle(), &menu, widget); if (!menu.actions().empty()) { menu.exec(globalPos); } + PdmUiCommandSystemProxy::instance()->setCurrentContextMenuTargetWidget(nullptr); + } } diff --git a/Fwk/AppFwk/cafTests/cafTestApplication/CMakeLists.txt b/Fwk/AppFwk/cafTests/cafTestApplication/CMakeLists.txt index cdc1659b78..cfcb04d7b6 100644 --- a/Fwk/AppFwk/cafTests/cafTestApplication/CMakeLists.txt +++ b/Fwk/AppFwk/cafTests/cafTestApplication/CMakeLists.txt @@ -17,6 +17,7 @@ set (MOC_HEADER_FILES # Resource file set( QRC_FILES + ${QRC_FILES} textedit.qrc ) @@ -76,6 +77,7 @@ if (USE_COMMAND_FRAMEWORK) set (TAP_LINK_LIBRARIES ${TAP_LINK_LIBRARIES} cafCommand + cafCommandFeatures ) endif(USE_COMMAND_FRAMEWORK) diff --git a/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp b/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp index 4da3ac2b31..a76fc35c63 100644 --- a/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp +++ b/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp @@ -45,6 +45,7 @@ #include #include #include +#include "cafCmdFeatureMenuBuilder.h" class DemoPdmObjectGroup : public caf::PdmDocument @@ -821,6 +822,14 @@ void MainWindow::createDockPanels() m_pdmUiTreeView = new caf::PdmUiTreeView(dockWidget); dockWidget->setWidget(m_pdmUiTreeView); + m_pdmUiTreeView->treeView()->setContextMenuPolicy(Qt::CustomContextMenu); + + QObject::connect(m_pdmUiTreeView->treeView(), + SIGNAL(customContextMenuRequested(const QPoint&)), + SLOT(slotCustomMenuRequestedForProjectTree(const QPoint&))); + + m_pdmUiTreeView->treeView()->setSelectionMode(QAbstractItemView::ExtendedSelection); + m_pdmUiTreeView->enableSelectionManagerUpdating(true); addDockWidget(Qt::LeftDockWidgetArea, dockWidget); } @@ -1235,3 +1244,31 @@ void MainWindow::slotSaveProject() m_testRoot->writeFile(); } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void MainWindow::slotCustomMenuRequestedForProjectTree(const QPoint&) +{ + QObject* senderObj = this->sender(); + QTreeView* treeView = dynamic_cast(senderObj); + if (treeView) + { + QMenu menu; + caf::CmdFeatureManager::instance()->setCurrentContextMenuTargetWidget(m_pdmUiTreeView); + + caf::CmdFeatureMenuBuilder menuBuilder; + + menuBuilder << "cafToggleItemsOnFeature"; + menuBuilder << "cafToggleItemsOffFeature"; + menuBuilder << "cafToggleItemsFeature"; + menuBuilder << "Separator"; + menuBuilder << "cafToggleItemsOnOthersOffFeature"; + + menuBuilder.appendToMenu(&menu); + + menu.exec(QCursor::pos()); + caf::CmdFeatureManager::instance()->setCurrentContextMenuTargetWidget(nullptr); + } + +} diff --git a/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.h b/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.h index a71d571acc..fd6484dc52 100644 --- a/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.h +++ b/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.h @@ -50,6 +50,8 @@ private slots: void slotLoadProject(); void slotSaveProject(); + void slotCustomMenuRequestedForProjectTree(const QPoint&); + private: static MainWindow* sm_mainWindowInstance; diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiTabbedPropertyViewDialog.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiTabbedPropertyViewDialog.cpp index 6076f4f364..7b9f89c794 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiTabbedPropertyViewDialog.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiTabbedPropertyViewDialog.cpp @@ -21,7 +21,7 @@ PdmUiTabbedPropertyViewDialog::PdmUiTabbedPropertyViewDialog(caf::PdmObject* obj const QStringList& uiConfigNameForTabs, const QString& windowTitle, QWidget* parent) - : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint) + : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint) { this->setWindowTitle(windowTitle); diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.cpp index 1ce4905e01..92158274a2 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeViewEditor.cpp @@ -262,6 +262,8 @@ void PdmUiTreeViewEditor::customMenuRequested(QPoint pos) SelectionManager::instance()->setActiveChildArrayFieldHandle(this->currentChildArrayFieldHandle()); QMenu menu; + PdmUiCommandSystemProxy::instance()->setCurrentContextMenuTargetWidget(m_mainWidget->parentWidget()); + caf::PdmUiCommandSystemProxy::instance()->populateMenuWithDefaultCommands("PdmUiTreeViewEditor", &menu); if (menu.actions().size() > 0) @@ -271,6 +273,8 @@ void PdmUiTreeViewEditor::customMenuRequested(QPoint pos) menu.exec(globalPos); } + + PdmUiCommandSystemProxy::instance()->setCurrentContextMenuTargetWidget(nullptr); }