00001 #include "taskdetailswidget.h" 00002 00003 #include "guifactory.h" 00004 #include "widgets/inputwidgets.h" 00005 00006 #include <control/models/taskmodel.h> 00007 #include <control/models/resourcemodel.h> 00008 #include <control/models/userrequirementsmodel.h> 00009 #include <control/models/resourcerequirementsmodel.h> 00010 #include <control/controldata.h> 00011 00012 #include <QDebug> 00013 #include <QVBoxLayout> 00014 00015 using namespace ui; 00016 00017 TaskDetailsWidget::TaskDetailsWidget(const control::data::TaskTypeDetails& type, 00018 QWidget* parent) : QWidget(parent) 00019 { 00020 widgets.setupUi(this); 00021 widgets.startTimeEdit->setDateTime(QDateTime::currentDateTime()); 00022 widgets.deadlineEdit->setDateTime(QDateTime::currentDateTime()); 00023 00024 GuiFactory::initDateTimeEdit(widgets.startTimeEdit); 00025 GuiFactory::initDateTimeEdit(widgets.deadlineEdit); 00026 GuiFactory::initView(widgets.tasksView); 00027 GuiFactory::initView(widgets.userReqView); 00028 GuiFactory::initView(widgets.resourceReqView); 00029 00030 initType(type); 00031 } 00032 00033 void TaskDetailsWidget::initType(const control::data::TaskTypeDetails& type) 00034 { 00035 QVBoxLayout* layout = new QVBoxLayout(widgets.fieldsWidget); 00036 00037 Q_FOREACH (domain::Field field, type.fields) 00038 { 00039 layout->addWidget(new QLabel(field.name)); 00040 InputWidget* w = GuiFactory::createInputWidget(field.nature); 00041 fieldWidgets[field.id] = w; 00042 layout->addWidget(w->widget()); 00043 } 00044 00045 layout->addStretch(); 00046 } 00047 00048 void TaskDetailsWidget::setDetails(const control::data::TaskDetails& details) 00049 { 00050 widgets.startTimeEdit->setDateTime(details.startTime); 00051 widgets.deadlineEdit->setDateTime(details.endTime); 00052 widgets.durationWidget->setDuration(details.duration); 00053 00054 QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::Select | 00055 QItemSelectionModel::Rows; 00056 00057 if (!details.selectedTasks.selection.isEmpty()) 00058 { 00059 QItemSelectionModel* taskSelection = 00060 new QItemSelectionModel(widgets.tasksView->model()); 00061 widgets.tasksView->setSelectionModel(taskSelection); 00062 00063 Q_FOREACH (QModelIndex index, details.selectedTasks.selection) 00064 taskSelection->select(index, flags); 00065 } 00066 00067 Q_FOREACH (QString field, details.fields.keys()) 00068 { 00069 fieldWidgets[field]->setValue(details.fields[field]); 00070 } 00071 } 00072 00073 control::data::TaskDetails TaskDetailsWidget::currentDetails() const 00074 { 00075 control::data::TaskDetails ret; 00076 00077 ret.startTime = widgets.startTimeEdit->dateTime(); 00078 ret.endTime = widgets.deadlineEdit->dateTime(); 00079 ret.duration = domain::Duration(widgets.durationWidget->currentDuration()); 00080 00081 if (widgets.tasksView->selectionModel() != 0) 00082 { 00083 ret.selectedTasks.selection = 00084 widgets.tasksView->selectionModel()->selectedRows(); 00085 } 00086 00087 Q_FOREACH (QString field, fieldWidgets.keys()) 00088 ret.fields[field] = fieldWidgets[field]->value(); 00089 00090 return ret; 00091 } 00092 00093 void TaskDetailsWidget::setTasks(control::TaskModel* tasks) 00094 { 00095 widgets.tasksView->setModel(tasks); 00096 GuiFactory::initViewSize(widgets.tasksView); 00097 } 00098 00099 void TaskDetailsWidget::setUserRequirements(control::UserRequirementsModel* model) 00100 { 00101 widgets.userReqView->setModel(model); 00102 GuiFactory::initViewSize(widgets.userReqView); 00103 } 00104 00105 void TaskDetailsWidget::setResourceRequirements(control::ResourceRequirementsModel* model) 00106 { 00107 widgets.resourceReqView->setModel(model); 00108 GuiFactory::initViewSize(widgets.resourceReqView); 00109 } 00110 00111 void TaskDetailsWidget::setEditMode(bool editMode) 00112 { 00113 widgets.startTimeEdit->setEnabled(editMode); 00114 widgets.deadlineEdit->setEnabled(editMode); 00115 widgets.durationWidget->setEnabled(editMode); 00116 widgets.fieldsWidget->setEnabled(editMode); 00117 } 00118