You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
267 lines
8.3 KiB
267 lines
8.3 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2003 - 2005 Dag Andersen <danders@get2net.dk>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation;
|
||
|
version 2 of the License.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kptrequestresourcespanel.h"
|
||
|
#include "kpttask.h"
|
||
|
#include "kptproject.h"
|
||
|
#include "kptresource.h"
|
||
|
#include "kptcalendar.h"
|
||
|
|
||
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <kptcommand.h>
|
||
|
|
||
14 years ago
|
#include <tqlistbox.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqlineedit.h>
|
||
|
#include <tqstring.h>
|
||
|
#include <tqspinbox.h>
|
||
|
#include <tqvalidator.h>
|
||
|
#include <tqcombobox.h>
|
||
|
#include <tqdatetime.h>
|
||
|
#include <tqdatetimeedit.h>
|
||
15 years ago
|
|
||
|
namespace KPlato
|
||
|
{
|
||
|
|
||
|
ResourceTableItem::ResourceTableItem(Resource *resource, ResourceRequest *request, bool check) {
|
||
|
m_resource = resource;
|
||
|
m_request = request;
|
||
|
m_checked = check;
|
||
|
m_origChecked = check;
|
||
|
m_checkitem = 0;
|
||
|
m_units = 100;
|
||
|
m_origUnits = 100;
|
||
|
//kdDebug()<<k_funcinfo<<"Added: '"<<resource->name()<<"' checked="<<m_checked<<endl;
|
||
|
}
|
||
|
|
||
|
ResourceTableItem::~ResourceTableItem() {
|
||
|
//kdDebug()<<k_funcinfo<<m_resource->name()<<endl;
|
||
|
}
|
||
|
|
||
|
void ResourceTableItem::update() {
|
||
|
if (m_checkitem)
|
||
|
m_checked = m_checkitem->isChecked();
|
||
|
//kdDebug()<<k_funcinfo<<m_resource->name()<<" checked="<<m_checked<<endl;
|
||
|
}
|
||
|
|
||
14 years ago
|
void ResourceTableItem::insert(TQTable *table, int row) {
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<endl;
|
||
14 years ago
|
m_checkitem = new TQCheckTableItem(table, m_resource->name());
|
||
15 years ago
|
m_checkitem->setChecked(m_checked);
|
||
|
table->setItem(row, 0, m_checkitem);
|
||
|
|
||
|
//kdDebug()<<k_funcinfo<<"Added: '"<<m_resource->name()<<"' checked="<<m_checked<<endl;
|
||
|
}
|
||
|
|
||
14 years ago
|
GroupLVItem::GroupLVItem(TQListView *parent, ResourceGroup *group, Task &task)
|
||
13 years ago
|
: TQListViewItem(parent, group->name(), TQString("%1").arg(group->units())),
|
||
15 years ago
|
m_group(group),
|
||
|
m_units(0)
|
||
|
{
|
||
|
|
||
|
m_request = task.resourceGroupRequest(group);
|
||
|
if (m_request) {
|
||
|
m_units = m_request->units();
|
||
|
}
|
||
14 years ago
|
TQPtrListIterator<Resource> it(group->resources());
|
||
15 years ago
|
for (; it.current(); ++it) {
|
||
|
//kdDebug()<<k_funcinfo<<"resource="<<it.current()->name()<<endl;
|
||
|
ResourceRequest *req=0;
|
||
|
if (m_request) {
|
||
14 years ago
|
req = m_request->find(it.current());
|
||
15 years ago
|
}
|
||
|
m_resources.append(new ResourceTableItem(it.current(), req, (bool)req));
|
||
|
}
|
||
|
|
||
|
m_resources.setAutoDelete(true);
|
||
|
}
|
||
|
|
||
|
GroupLVItem::~GroupLVItem() {
|
||
|
//kdDebug()<<k_funcinfo<<m_group->name()<<endl;
|
||
|
}
|
||
|
|
||
|
void GroupLVItem::update() {
|
||
14 years ago
|
TQPtrListIterator<ResourceTableItem> it(m_resources);
|
||
15 years ago
|
for (; it.current(); ++it) {
|
||
|
it.current()->update();
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void GroupLVItem::insert(TQTable *table) {
|
||
15 years ago
|
|
||
|
// clear the table, must be a better way!
|
||
|
for (int i = table->numRows(); i > 0; --i)
|
||
|
table->removeRow(i-1);
|
||
|
|
||
|
if (m_group->numResources() == 0) {
|
||
|
table->setNumRows(1);
|
||
14 years ago
|
table->setItem(0, 0, new TQCheckTableItem(table,i18n("None")));
|
||
|
table->setItem(0, 1, new TQComboTableItem(table,i18n("None")));
|
||
15 years ago
|
} else {
|
||
|
table->setNumRows(m_group->numResources());
|
||
14 years ago
|
TQPtrListIterator<ResourceTableItem> it(m_resources);
|
||
15 years ago
|
for (int i = 0; it.current(); ++it, ++i) {
|
||
|
it.current()->insert(table, i);
|
||
|
}
|
||
|
}
|
||
|
table->adjustColumn(0);
|
||
|
}
|
||
|
|
||
|
int GroupLVItem::numRequests() {
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
int value = m_units;
|
||
14 years ago
|
TQPtrListIterator<ResourceTableItem> it(m_resources);
|
||
15 years ago
|
for (; it.current(); ++it) {
|
||
|
value += it.current()->numRequests();
|
||
|
}
|
||
|
return value;
|
||
|
}
|
||
|
|
||
|
bool GroupLVItem::isNull() const {
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
14 years ago
|
TQPtrListIterator<ResourceTableItem> it(m_resources);
|
||
15 years ago
|
for (; it.current(); ++it) {
|
||
|
if (it.current()->isChecked())
|
||
|
return false;
|
||
|
}
|
||
|
if (m_units > 0)
|
||
|
return false;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
RequestResourcesPanel::RequestResourcesPanel(TQWidget *parent, Task &task, bool baseline)
|
||
|
: TaskResourcesPanelBase(parent),
|
||
15 years ago
|
m_task(task),
|
||
|
m_worktime(0),
|
||
|
selectedGroup(0),
|
||
|
m_blockChanged(false) {
|
||
|
|
||
|
Project *p = dynamic_cast<Project*>(task.projectNode());
|
||
|
if (p) {
|
||
|
m_worktime = p->standardWorktime();
|
||
|
|
||
14 years ago
|
TQPtrListIterator<ResourceGroup> git(p->resourceGroups());
|
||
15 years ago
|
for(int i=0; git.current(); ++git, ++i) {
|
||
|
ResourceGroup *grp = git.current();
|
||
|
GroupLVItem *grpitem = new GroupLVItem(groupList, grp, task);
|
||
|
groupList->insertItem(grpitem);
|
||
|
//kdDebug()<<k_funcinfo<<" Added group: "<<grp->name()<<endl;
|
||
|
}
|
||
|
}
|
||
14 years ago
|
TQListViewItem *item = groupList->firstChild();
|
||
15 years ago
|
if (item) {
|
||
|
groupList->setSelected(item, true);
|
||
|
groupChanged(item);
|
||
|
}
|
||
|
|
||
|
resourceTable->setReadOnly(baseline);
|
||
|
|
||
14 years ago
|
connect(groupList, TQT_SIGNAL(selectionChanged(TQListViewItem*)), TQT_SLOT(groupChanged(TQListViewItem*)));
|
||
|
connect(resourceTable, TQT_SIGNAL(valueChanged(int, int)), TQT_SLOT(resourceChanged(int, int)));
|
||
|
// connect(numUnits, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(unitsChanged(int)));
|
||
15 years ago
|
|
||
|
}
|
||
|
|
||
14 years ago
|
void RequestResourcesPanel::groupChanged(TQListViewItem *item) {
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
GroupLVItem *grp = dynamic_cast<GroupLVItem *>(item);
|
||
|
if (grp == 0)
|
||
|
return;
|
||
|
|
||
|
if (selectedGroup) {
|
||
|
selectedGroup->update();
|
||
|
}
|
||
|
selectedGroup = grp;
|
||
|
|
||
|
/* m_blockChanged = true;
|
||
|
numUnits->setMaxValue(grp->m_group->units());
|
||
|
numUnits->setValue(grp->m_units);
|
||
|
m_blockChanged = false;*/
|
||
|
grp->insert(resourceTable);
|
||
|
}
|
||
|
|
||
|
void RequestResourcesPanel::resourceChanged(int /*r*/, int /*c*/) {
|
||
|
//kdDebug()<<k_funcinfo<<"("<<r<<","<<c<<")"<<endl;
|
||
|
sendChanged();
|
||
|
}
|
||
|
|
||
|
void RequestResourcesPanel::unitsChanged(int units) {
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
if (selectedGroup) {
|
||
|
selectedGroup->m_units = units;
|
||
|
sendChanged();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
KCommand *RequestResourcesPanel::buildCommand(Part *part) {
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
KMacroCommand *cmd = 0;
|
||
|
if (selectedGroup) {
|
||
|
selectedGroup->update();
|
||
|
}
|
||
14 years ago
|
TQListViewItem *item = groupList->firstChild();
|
||
15 years ago
|
for (; item; item = item->nextSibling()) {
|
||
|
GroupLVItem *grp = static_cast<GroupLVItem*>(item);
|
||
14 years ago
|
TQPtrListIterator<ResourceTableItem> it = grp->resources();
|
||
15 years ago
|
for (; it.current(); ++it) {
|
||
|
if (it.current()->isChecked() != it.current()->isOrigChecked()) {
|
||
|
if (!cmd) cmd = new KMacroCommand("");
|
||
|
if (it.current()->isChecked()) {
|
||
|
if (!grp->m_request) {
|
||
|
grp->m_request = new ResourceGroupRequest(grp->m_group, grp->m_units);
|
||
|
cmd->addCommand(new AddResourceGroupRequestCmd(part, m_task, grp->m_request));
|
||
|
}
|
||
|
cmd->addCommand(new AddResourceRequestCmd(part, grp->m_request, new ResourceRequest(it.current()->resource(), it.current()->units())));
|
||
|
|
||
|
continue;
|
||
|
}
|
||
|
if (grp->m_request && it.current()->request()) {
|
||
|
cmd->addCommand(new RemoveResourceRequestCmd(part, grp->m_request, it.current()->request()));
|
||
|
if (grp->isNull()) {
|
||
|
cmd->addCommand(new RemoveResourceGroupRequestCmd(part, m_task, grp->m_request));
|
||
|
}
|
||
|
} else {
|
||
|
kdError()<<k_funcinfo<<"Remove failed"<<endl;
|
||
|
}
|
||
|
continue;
|
||
|
}
|
||
|
if (!it.current()->isChecked()) {
|
||
|
continue;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return cmd;
|
||
|
}
|
||
|
|
||
|
bool RequestResourcesPanel::ok() {
|
||
|
if (selectedGroup)
|
||
|
selectedGroup->update();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void RequestResourcesPanel::sendChanged() {
|
||
|
if (!m_blockChanged) emit changed();
|
||
|
}
|
||
|
|
||
|
} //KPlato namespace
|
||
|
|
||
|
#include "kptrequestresourcespanel.moc"
|