Ejemplo n.º 1
0
void MainWindow::showTaskContextMenu(const QPoint &pos) {
    QPoint globalPos = independentTasksTree->mapToGlobal(pos);
    QMenu* menu = new QMenu(this);
    Task* t;
    QString selectedTask = independentTasksTree->indexAt(pos).data(Qt::DisplayRole).toString();
    try {
        t = &(NonPreemptiveFactory::getInstance().getTask(selectedTask));
        if (t->getTaskType()==COMPOSITE) menu->addAction("add subtasks");
        else {
            menu->addAction("schedule programmation");
        }
        menu->addAction("edit constraints");
        menu->addAction("infos");
        menu->addAction("remove");
    }
    catch (CalendarException e) {return;}
    QAction* selectedItem = menu->exec(globalPos);

    if (selectedItem && selectedItem->text()=="add subtasks") {
        AddTaskToCompositeTaskForm* form = new AddTaskToCompositeTaskForm(dynamic_cast<CompositeTask*>(t),this);
        form->show();
    }
    if (selectedItem && selectedItem->text()=="remove") {
        NonPreemptiveFactory::getInstance().removeTask(t);
        refreshProjectsModel();
        refreshIndependentTasksModel();
    }
    if (selectedItem && selectedItem->text()=="infos") {
        TaskInfo* taskinfo = new TaskInfo(t,this);
        taskinfo->show();
    }
    if (selectedItem && selectedItem->text()=="edit constraints") {
        EditAssociationConstraint* editc = new EditAssociationConstraint(t,this);
        editc->show();
    }
}
Ejemplo n.º 2
0
void MainWindow::showProjectContextMenu(const QPoint &pos) {
    QPoint globalPos = projectsTree->mapToGlobal(pos);
    QMenu* menu = new QMenu(this);
    Project* proj;
    Task* t;
    QString selectedProject = projectsTree->indexAt(pos).data(Qt::DisplayRole).toString();
    if (!(projectsTreeView->isHidden()))
        selectedProject = projectsTreeView->indexAt(pos).data(Qt::DisplayRole).toString();
    try {
        proj = &(ProjectFactory::getInstance().getProject(selectedProject));
        menu->addAction("add tasks");
        menu->addAction("infos");
        menu->addAction("show tree");
        menu->addAction("remove");

        QAction* selectedItem = menu->exec(globalPos);
        if (selectedItem && selectedItem->text()=="add tasks") {
            AddTaskToProjectForm* form = new AddTaskToProjectForm(proj,this);
            form->show();
        }
        if (selectedItem && selectedItem->text()=="remove") {
            ProjectFactory::getInstance().removeProject(proj);
            refreshProjectsModel();
            refreshIndependentTasksModel();
        }
        if (selectedItem && selectedItem->text()=="infos") {
            ProjectInfo* projectinfo = new ProjectInfo(proj,this);
            projectinfo->show();
        }
        if (selectedItem && selectedItem->text()=="show tree") {
            treeScene->clear();
            if (projectsTreeView->isHidden()) {
                itemTypeSelector->setCurrentIndex(2);
                drawProjectTree(projectsTreeView->indexAt(pos));  // called from the projectsTreeView
            }
            else {
                drawProjectTree(projectsTreeView->indexAt(pos));    // called from the projectsTree
            }
            calendarTable->hide();
            treeView->show();
        }
    }
    catch (CalendarException e) {


        QString selectedTask = projectsTree->indexAt(pos).data(Qt::DisplayRole).toString();
        if (!(projectsTreeView->isHidden()))
            selectedTask = projectsTreeView->indexAt(pos).data(Qt::DisplayRole).toString();
    try {
        t = &(NonPreemptiveFactory::getInstance().getTask(selectedTask));
        if (t->getTaskType()==COMPOSITE) menu->addAction("add subtasks");
        else {
            UnitaryTask* ut = &(NonPreemptiveFactory::getInstance().getTypedTask(selectedTask));
            menu->addAction("schedule programmation");
        }
        menu->addAction("edit constraints");
        menu->addAction("infos");
        menu->addAction("remove");

        QAction* selectedItem = menu->exec(globalPos);
        if (selectedItem && selectedItem->text()=="add subtasks") {
            AddTaskToCompositeTaskForm* form = new AddTaskToCompositeTaskForm(dynamic_cast<CompositeTask*>(t),this);
            form->show();
        }
        if (selectedItem && selectedItem->text()=="remove") {
            NonPreemptiveFactory::getInstance().removeTask(t);
            refreshProjectsModel();
            refreshIndependentTasksModel();
        }
        if (selectedItem && selectedItem->text()=="infos") {
            TaskInfo* taskinfo = new TaskInfo(t,this);
            taskinfo->show();
        }
        if (selectedItem && selectedItem->text()=="edit constraints") {
            EditAssociationConstraint* editc = new EditAssociationConstraint(t,this);
            editc->show();
        }
    }
    catch (CalendarException e) {return;}
    }

}