diff --git a/res/ui/communityConfigurationDialog.ui b/res/ui/communityConfigurationDialog.ui index 01a077de706081ed1698a3156dd30931ebc35073..2d0233754558ed1b1c11ad4232d2f86037338a4f 100644 --- a/res/ui/communityConfigurationDialog.ui +++ b/res/ui/communityConfigurationDialog.ui @@ -24,7 +24,11 @@ </property> <layout class="QVBoxLayout" name="verticalLayout_3"> <item> - <widget class="QTreeView" name="communityView"/> + <widget class="QTreeView" name="communityView"> + <property name="contextMenuPolicy"> + <enum>Qt::CustomContextMenu</enum> + </property> + </widget> </item> <item> <layout class="QHBoxLayout" name="horizontalLayout_3"> @@ -125,8 +129,25 @@ </hint> </hints> </connection> + <connection> + <sender>communityView</sender> + <signal>customContextMenuRequested(QPoint)</signal> + <receiver>CommunityConfigurationDialog</receiver> + <slot>showContextMenu(QPoint)</slot> + <hints> + <hint type="sourcelabel"> + <x>199</x> + <y>128</y> + </hint> + <hint type="destinationlabel"> + <x>199</x> + <y>149</y> + </hint> + </hints> + </connection> </connections> <slots> <slot>addNode()</slot> + <slot>showContextMenu(QPoint)</slot> </slots> </ui> diff --git a/src/cutecoin/gui/configureCommunityDialog.py b/src/cutecoin/gui/configureCommunityDialog.py index 1ca0b7a8dc805bfaf0f630929707c48e02b6e9d0..bd1f6cf1c12b36790f798a162ada5c31308feebf 100644 --- a/src/cutecoin/gui/configureCommunityDialog.py +++ b/src/cutecoin/gui/configureCommunityDialog.py @@ -4,7 +4,7 @@ Created on 8 mars 2014 @author: inso ''' from cutecoin.gen_resources.communityConfigurationDialog_uic import Ui_CommunityConfigurationDialog -from PyQt5.QtWidgets import QDialog, QErrorMessage +from PyQt5.QtWidgets import QDialog, QErrorMessage, QMenu from cutecoin.models.community.treeModel import CommunityTreeModel from cutecoin.models.node import TrustedNode from cutecoin.core.exceptions import NotMemberOfCommunityError @@ -52,6 +52,20 @@ class ConfigureCommunityDialog(QDialog, Ui_CommunityConfigurationDialog): self.community.addTrustedNode( TrustedNode(server, port )) self.communityView.setModel( CommunityTreeModel(self.community )) + def showContextMenu(self, point): + menu = QMenu() + action = menu.addAction("Delete", self.removeNode) + if self.community is not None: + if len(self.community.trustedNodes) == 1: + action.setEnabled(False) + menu.exec_(self.communityView.mapToGlobal(point)) + + def removeNode(self): + for index in self.communityView.selectedIndexes(): + self.community.trustedNodes.pop(index.row()) + + self.communityView.setModel( CommunityTreeModel(self.community )) + def accept(self): self.close()