// ! [1] protected void dropEvent(QDropEvent event) { if (event.source() == this && event.possibleActions().isSet(Qt.DropAction.MoveAction)) return; // ! [1] // ! [2] if (event.proposedAction().equals(Qt.DropAction.MoveAction)) { event.acceptProposedAction(); // Process the data from the event. // ! [2] dragResult.emit(tr("The data was moved here.")); // ! [3] } else if (event.proposedAction().equals(Qt.DropAction.CopyAction)) { event.acceptProposedAction(); // Process the data from the event. // ! [3] dragResult.emit(tr("The data was copied here.")); // ! [4] } else { // Ignore the drop. return; } // ! [4] // End of quote mimeTypes.emit(event.mimeData().formats()); setData( event.mimeData().formats().get(0), event.mimeData().data(event.mimeData().formats().get(0))); // ! [5] }
// ! [7] protected void mouseMoveEvent(QMouseEvent event) { if (!(event.buttons().isSet(Qt.MouseButton.LeftButton))) return; if ((event.pos().subtract(dragStartPosition)).manhattanLength() < QApplication.startDragDistance()) return; QDrag drag = new QDrag(this); QMimeData mimeData = new QMimeData(); mimeData.setData(mimeType, data); drag.setMimeData(mimeData); Qt.DropAction dropAction = drag.exec(Qt.DropAction.CopyAction, Qt.DropAction.MoveAction); // ! [7] switch (dropAction) { case CopyAction: dragResult.emit(tr("The text was copied.")); break; case MoveAction: dragResult.emit(tr("The text was moved.")); break; default: dragResult.emit(tr("Unknown action.")); break; } // ! [8] }
/** * @param projectIdentifier * @param description * @param projectManager * @param plannedTime * @return Project * @throws WaktuException */ public Project addProject( final String projectIdentifier, final String description, final Usr projectManager, final int plannedTime) throws WaktuException { EntityManager em = PersistenceController.getInstance().getEMF().createEntityManager(); if (!PermissionController.getInstance().checkPermission()) { throw new WaktuException("Permission denied"); } Project newProject = new Project(projectIdentifier, description, projectManager, plannedTime); BusinessRuleController.check(newProject); try { em.getTransaction().begin(); em.persist(newProject); em.getTransaction().commit(); } catch (Exception e) { ExceptionHandling.handleException(e); } finally { em.close(); } add.emit(newProject); logger.info("project " + newProject + " added"); return newProject; }
private void saveProject() { project.setDescription(ui.txtDescription.text()); project.setPlannedTime(ui.txtPlannedTime.value()); project.setProjectManager( (Usr) ui.cmbProjectManager.itemData(ui.cmbProjectManager.currentIndex())); project.setActiveState(!ui.checkBox.isChecked()); try { ProjectController.getInstance().updateProject(project); } catch (WaktuException e) { errorMessage.emit(e.getMessage()); } }
private void addNewProject() { try { project = ProjectController.getInstance() .addProject( ui.txtProjectnumber.text(), ui.txtDescription.text(), (Usr) ui.cmbProjectManager.itemData(ui.cmbProjectManager.currentIndex()), ui.txtPlannedTime.value()); } catch (WaktuException e) { errorMessage.emit(e.getMessage()); } }
/** * @param firstname * @param lastname * @param password * @param pensum * @param role * @param holiday * @return Usr * @throws WaktuException */ public Usr addUser( final String firstname, final String lastname, final String password, final int pensum, final SystemRole role, final double holiday) throws WaktuException { EntityManager em = PersistenceController.getInstance().getEMF().createEntityManager(); Usr newUsr = new Usr( generateUsername(firstname, lastname), firstname, lastname, Md5.hash(password), pensum, role, holiday); if (!PermissionController.getInstance().checkPermission()) { throw new WaktuException("Permission denied"); } BusinessRuleController.check(newUsr); try { em.getTransaction().begin(); em.persist(newUsr); em.getTransaction().commit(); } catch (Exception e) { ExceptionHandling.handleException(e); } finally { em.close(); } add.emit(newUsr); logger.info("user " + newUsr + " added"); return newUsr; }
public static void connect(PythonSignal signal, PyMethod method) { PythonSlot receiver = new PythonSlot(method); if (signal instanceof Signal0) { ((Signal0) signal).signal.connect(receiver, signature(0)); } else if (signal instanceof Signal1) { ((Signal1) signal).signal.connect(receiver, signature(1)); } else if (signal instanceof Signal2) { ((Signal2) signal).signal.connect(receiver, signature(2)); } else if (signal instanceof Signal3) { ((Signal3) signal).signal.connect(receiver, signature(3)); } else if (signal instanceof Signal4) { ((Signal4) signal).signal.connect(receiver, signature(4)); } else if (signal instanceof Signal5) { ((Signal5) signal).signal.connect(receiver, signature(5)); } else if (signal instanceof Signal6) { ((Signal6) signal).signal.connect(receiver, signature(6)); } else if (signal instanceof Signal7) { ((Signal7) signal).signal.connect(receiver, signature(7)); } else if (signal instanceof Signal8) { ((Signal8) signal).signal.connect(receiver, signature(8)); } else if (signal instanceof Signal9) { ((Signal9) signal).signal.connect(receiver, signature(9)); } }
private void setFields() { if (project != null) { if (GuiController.getInstance().canModifyProject()) { ui.btnAdd.setVisible(true); ui.btnAdd.setText(QCoreApplication.translate("ProjectDataView", "Save", null)); ui.txtDescription.setText(project.getDescription()); ui.txtDescription.setEnabled(true); ui.txtProjectnumber.setText(project.getProjectIdentifier()); ui.txtProjectnumber.setEnabled(false); ui.txtPlannedTime.setValue(project.getPlannedTime()); ui.txtPlannedTime.setEnabled(true); ui.txtPlannedTime.setValue(project.getPlannedTime()); ui.txtPlannedTime.setEnabled(true); ui.checkBox.setChecked(!project.isActive()); ui.checkBox.setEnabled(true); try { ComboBoxData.createProjectManagerComboBox( ui.cmbProjectManager, project.getProjectManager()); } catch (WaktuException e) { errorMessage.emit(e.getMessage()); } } else { ui.btnAdd.setVisible(false); ui.txtDescription.setText(project.getDescription()); ui.txtDescription.setEnabled(false); ui.txtProjectnumber.setText(project.getProjectIdentifier()); ui.txtProjectnumber.setEnabled(false); ui.txtPlannedTime.setValue(project.getPlannedTime()); ui.txtPlannedTime.setEnabled(false); ui.txtPlannedTime.setValue(project.getPlannedTime()); ui.txtPlannedTime.setEnabled(false); ui.checkBox.setChecked(!project.isActive()); ui.checkBox.setEnabled(false); try { ComboBoxData.createProjectManagerComboBox( ui.cmbProjectManager, project.getProjectManager()); } catch (WaktuException e) { errorMessage.emit(e.getMessage()); } ui.cmbProjectManager.setEnabled(false); } } else { ui.btnAdd.setVisible(true); ui.txtDescription.setEnabled(true); ui.txtProjectnumber.setEnabled(true); ui.txtPlannedTime.setEnabled(true); ui.txtPlannedTime.setEnabled(true); ui.checkBox.setEnabled(true); ui.cmbProjectManager.setEnabled(true); try { ComboBoxData.createProjectManagerComboBox(ui.cmbProjectManager, null); } catch (WaktuException e) { errorMessage.emit(e.getMessage()); } } }