00001 #include "resourcemodel.h"
00002
00003 #include <domain/taskmanagerdata.h>
00004 #include <domain/resource.h>
00005
00006 using namespace control;
00007
00008 ResourceModel::ResourceModel(domain::TaskManagerData* d,
00009 QList<domain::Resource*> r) : DomainModel(d),
00010 resourcesList(r)
00011 {
00012 if (resourcesList.isEmpty())
00013 connect(d, SIGNAL(resourcesChanged()), this, SLOT(emitDataChange()));
00014 else
00015 {
00016 Q_FOREACH (domain::Resource* resource, resourcesList)
00017 {
00018 connect(resource, SIGNAL(dataChanged()),
00019 this, SLOT(emitDataChange()));
00020 }
00021 }
00022 }
00023
00024 int ResourceModel::columnCount(const QModelIndex& parent) const
00025 {
00026 if (!parent.isValid())
00027 return LastColumn;
00028
00029 return 0;
00030 }
00031
00032 int ResourceModel::rowCount(const QModelIndex& parent) const
00033 {
00034 if (!parent.isValid())
00035 return resources().size();
00036
00037 return 0;
00038 }
00039
00040 QVariant ResourceModel::headerData(int section, Qt::Orientation orientation,
00041 int role) const
00042 {
00043 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
00044 {
00045 switch (section)
00046 {
00047 case Description: return "Description";
00048 case Type: return "Type";
00049
00050 default: return QVariant();
00051 }
00052 }
00053
00054 return QVariant();
00055 }
00056
00057 QVariant ResourceModel::data(const QModelIndex& index, int role) const
00058 {
00059 const domain::Resource* resource = resourceForIndex(index);
00060
00061 if (role == Qt::DisplayRole)
00062 {
00063 switch (index.column())
00064 {
00065 case Description: return resource->description();
00066 case Type: return resource->resourceTypeName();
00067
00068 default: return QVariant();
00069 }
00070 }
00071 else if (role == Qt::ToolTipRole)
00072 {
00073 QString toolTip = resource->description() + "\n";
00074 toolTip += "Is used in " + QString::number(resource->dependentData().size())
00075 + " tasks\n";
00076 return toolTip;
00077 }
00078 else
00079 return QVariant();
00080 }
00081
00082 domain::Resource* ResourceModel::resourceForIndex(const QModelIndex& index) const
00083 {
00084 return resources()[index.row()];
00085 }
00086
00087 QModelIndex ResourceModel::indexForResource(domain::Resource* resource) const
00088 {
00089 if (!resources().contains(resource))
00090 return QModelIndex();
00091
00092 return index(resources().indexOf(resource), 0);
00093 }
00094
00095 QList<domain::Resource*> ResourceModel::resources() const
00096 {
00097 return resourcesList.isEmpty() ? domainData->resources() : resourcesList;
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123