Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- #Created on May 3, 2015
- #@author: Petar Bjeljac
- from PySide2.QtCore import QModelIndex, Qt
- from PySide2.QtWidgets import QTreeView, QMenu, QAction, QAbstractItemView
- from src.model.Node import Node
- from src.gui.MainWindow import *
- class HierarchyTreeView(QTreeView):
- def __init__(self):
- super(HierarchyTreeView, self).__init__()
- # ukljucuje kontekstni meni
- self.setContextMenuPolicy(Qt.CustomContextMenu)
- self.customContextMenuRequested.connect(self.openMenu)
- def openMenu(self, position):
- self.contextMenu = QMenu()
- newMenu = QMenu("New")
- self.contextMenu.addMenu(newMenu)
- actionNewProj = QAction("NewProject", None)
- actionNewProj.triggered.connect(self.addNode)
- actionNewDoc = QAction("NewDocument", None)
- actionNewDoc.triggered.connect(self.addNode) #umesto add node napraviti addDocument
- actionNewElem = QAction("NewElement", None)
- actionNewElem.triggered.connect(self.addNode) #umesto add node napraviti addElement
- actionRename = QAction("Rename", None)
- actionRename.triggered.connect(self.renameNode)
- actionRemProj = QAction("Delete", None)
- actionRemProj.triggered.connect(self.removeNode)
- newMenu.addAction(actionNewProj)
- self.contextMenu.addAction(actionRename)
- self.contextMenu.addAction(actionRemProj)
- newMenu.addAction(actionNewDoc)
- newMenu.addAction(actionNewElem)
- # prikaz kontekstnog menija
- self.contextMenu.exec_(self.viewport().mapToGlobal(position))
- def addNode(self):
- """
- TODO: implementirati dijalog za unos naziva, mogućnost dodavanje tipiziranih čvorova i rukovanje situacijom postojanja elementa sa istim nazivom.
- """
- model = self.model()
- text = self.textInput()
- for cvor in Node.lista:
- while text == cvor:
- self.errorMessage()
- text = self.textInput()
- node = Node(text)
- if not self.currentIndex().isValid():
- model.insertRow(model.rowCount(self.currentIndex()), node)
- else:
- model.insertRow(model.rowCount(self.currentIndex()), node, self.currentIndex())
- self.expand(self.currentIndex())
- def removeNode(self): #ovo je reseno skroz ON POSTOJI ALI MI NE PRIKAZUJE IME
- """
- TODO: implementirati dijalog za potvrdu akcije brisanja.
- """
- flags = QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
- button = QMessageBox.question(self, u"Pitanje", u"Da li ste sigurni?", flags)
- if button == QMessageBox.Yes: #SAMO OVA 2 SAM MENJAO POKRENI PA CES SKONTATI PROMENI IME ALI GA NE ZAPISE NEGO OSTAVI PRAZNO
- QMessageBox.information(self, "Odabrano dugme", "Odabrano je dugme Yes")
- model = self.model()
- model.removeRow(self.currentIndex().internalPointer().getIndex(), self.currentIndex().parent())
- else:
- QMessageBox.information(self, "Odabrano dugme", "Odabrano je dugme No")
- def renameNode(self):
- """
- TODO: implementirati dijalog za unos naziva i rukovanje situacijom postojanja elementa sa istim nazivom.
- """
- text = self.textInput()
- for cvor in Node.lista:
- while text == cvor:
- self.errorMessage()
- text = self.textInput()
- self.currentIndex().internalPointer().setName(text)
- def mousePressEvent(self, event):
- if self.selectionMode() == QAbstractItemView.SingleSelection:
- self.clearSelection()
- self.setCurrentIndex(QModelIndex())
- super(HierarchyTreeView, self).mousePressEvent(event)
- def textInput(self):
- retText, okButton = QInputDialog.getText(self, "Naziv", "Unesite naziv")
- if okButton:
- return retText
- def errorMessage(self):
- QMessageBox.critical(self, u"Greška", u"Dogodila se greška, ista imena! ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement