F:/KPlato/koffice/kplato/kptreportview.cc

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 - 2005 Dag Andersen <danders@get2net.dk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation;
00007    version 2 of the License.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kptreportview.h"
00021 
00022 #include "kptview.h"
00023 #include "kptpart.h"
00024 #include "kptcontext.h"
00025 
00026 #include <mreportviewer.h>
00027 #include <mpagecollection.h>
00028 
00029 #include <KoStore.h>
00030 
00031 #include <kdebug.h>
00032 #include <kaction.h>
00033 #include <kstdaction.h>
00034 #include <ktoolbar.h>
00035 #include <kstandarddirs.h>
00036 #include <kurl.h>
00037 #include <kmessagebox.h>
00038 #include <kio/netaccess.h>
00039 #include <klocale.h>
00040 #include <kglobal.h>
00041 #include <kdesktopfile.h>
00042 #include <kfiledialog.h>
00043 
00044 #include <QFile>
00045 #include <qfileinfo.h>
00046 #include <q3header.h>
00047 #include <q3popupmenu.h>
00048 #include <QLayout>
00049 #include <qdom.h>
00050 #include <qstringlist.h>
00051 
00052 namespace KPlato
00053 {
00054 
00055 class ReportTagsPrivate {
00056 public:
00057 
00058     ReportTagsPrivate()
00059     :   m_project(0),
00060         m_task(0),
00061         m_resourcegroup(0),
00062         m_resource(0),
00063         alltasksLevel("-1"),
00064         summarytasksLevel("-1"),
00065         tasksLevel("-1"),
00066         milestonesLevel("-1"),
00067         resourcegroupsLevel("-1"),
00068         resourcesLevel("-1")
00069     {}
00070 
00071     ~ReportTagsPrivate() {}
00072 
00073     QString getData(QString source, QString tag) const {
00074         if (tag.contains("."))
00075             return getData(tag);
00076 
00077         return getData(source + "." + tag);
00078     }
00079 
00080     QString getData(QString tag) const {
00081         //kDebug()<<k_funcinfo<<"tag="<<tag<<endl;
00082         KLocale *l = KGlobal::locale();
00083         if (!tag.contains('.')) {
00084             // global tags
00085             if (tag == "currentdate") {
00086                 return l->formatDate(QDate::currentDate(), true);
00087             }
00088             return QString::null;
00089         }
00090         if (tag.section(".", 0, 0) == "project") {
00091             if (tag.section(".", 1, 1) == "name")
00092                 return (m_project ? m_project->name() : QString::null);
00093             if (tag.section(".", 1, 1) == "leader")
00094                 return (m_project ? m_project->leader() : QString::null);
00095 
00096         } else if (tag.section(".", 0, 0) == "task") {
00097             if (tag.section(".", 1, 1) == "name")
00098                 return (m_task ? m_task->name() : QString::null);
00099             if (tag.section(".", 1, 1) == "responsible")
00100                 return (m_task ? m_task->leader() : QString::null);
00101             else if (tag.section(".", 1, 1) == "wbs")
00102                 return (m_task ? m_task->wbs() : QString::null);
00103             else if (tag.section(".", 1, 1) == "start")
00104                 return (m_task ? l->formatDateTime(m_task->startTime()) : QString::null);
00105             else if (tag.section(".", 1, 1) == "starttime")
00106                 return (m_task ? l->formatTime(m_task->startTime().time()) : QString::null);
00107             else if (tag.section(".", 1, 1) == "startdate")
00108                 return (m_task ? l->formatDate(m_task->startTime().date(), true) : QString::null);
00109             else if (tag.section(".", 1, 1) == "duration") {
00110                     return (m_task ? m_task->duration().toString(Duration::Format_i18nDayTime) : QString::null);
00111             } else if (tag.section(".", 1, 1) == "plannedcost") {
00112                 return (m_task ? l->formatMoney(m_task->plannedCost()) : QString::null);
00113             }
00114         } else if (tag.section(".", 0, 0) == "resourcegroup") {
00115             if (tag.section(".", 1, 1) == "name")
00116                 return (m_resourcegroup ? m_resourcegroup->name() : QString::null);
00117         
00118         } else if (tag.section(".", 0, 0) == "resource") {
00119             if (tag.section(".", 1, 1) == "name")
00120                 return (m_resource ? m_resource->name() : QString::null);
00121             if (tag.section(".", 1, 1) == "type")
00122                 return (m_resource ? m_resource->typeToString() : QString::null);
00123             if (tag.section(".", 1, 1) == "email")
00124                 return (m_resource ? m_resource->email() : QString::null);
00125             if (tag.section(".", 1, 1) == "availablefrom")
00126                 return (m_resource ? l->formatDate(m_resource->availableFrom().date(), true) : QString::null);
00127             if (tag.section(".", 1, 1) == "availableuntil")
00128                 return (m_resource ? l->formatDate(m_resource->availableUntil().date(), true) : QString::null);
00129             if (tag.section(".", 1, 1) == "units")
00130                 return (m_resource ? QString("%1%").arg(m_resource->units()) : QString::null);
00131             if (tag.section(".", 1, 1) == "normalrate")
00132                 return (m_resource ? l->formatMoney(m_resource->normalRate()) : QString::null);
00133             if (tag.section(".", 1, 1) == "overtimerate")
00134                 return (m_resource ? l->formatMoney(m_resource->overtimeRate()) : QString::null);
00135         }
00136         return QString::null;
00137     }
00138 
00139     Project *m_project;
00140     Task *m_task;
00141     ResourceGroup *m_resourcegroup;
00142     Resource *m_resource;
00143 
00144     QString alltasksLevel;
00145     QStringList alltasksProps;
00146     QString summarytasksLevel;
00147     QStringList summarytasksProps;
00148     QString tasksLevel;
00149     QStringList tasksProps;
00150     QString milestonesLevel;
00151     QStringList milestonesProps;
00152     QString resourcegroupsLevel;
00153     QStringList resourcegroupsProps;
00154     QString resourcesLevel;
00155     QStringList resourcesProps;
00156 
00157 };
00158 
00159 class KugarReportViewer : public Kugar::MReportViewer {
00160 public:
00161     KugarReportViewer(QWidget *parent = 0, const char *name = 0)
00162     : MReportViewer(parent, name)
00163     {}
00164     
00165     int currentPage() {
00166         return report ? report->getCurrentIndex() : 0;
00167     }
00168     int pageCount() {
00169         return report ? report->pageCount() : 0;
00170     }
00171 };
00172 
00173 ReportView::ReportView(View *view, QWidget *parent)
00174     : QSplitter(parent),
00175     m_mainview(view),
00176     m_reportTags(0)
00177 {
00178     //kDebug()<<k_funcinfo<<endl;
00179     m_reportList = new K3ListView(this);
00180     m_reportList->setShadeSortColumn(false);
00181     m_reportList->addColumn(i18n("Report Template"));
00182     m_reportList->header()->setStretchEnabled(true, 0);
00183     m_reportList->header()->setSortIndicator(0);
00184     
00185     m_reportview = new KugarReportViewer(this);
00186 
00187     initReportList();
00188     
00189         connect(m_reportList, SIGNAL(clicked(Q3ListViewItem*)), SLOT(slotReportListClicked(Q3ListViewItem*)));
00190         connect(m_reportList, SIGNAL(selectionChanged(Q3ListViewItem*)), SLOT(slotReportListSelectionChanged(Q3ListViewItem*)));
00191 
00192         //setCentralWidget(m_reportview);
00193 
00194         // Create the user interface.
00195         //KStdAction::print(this,SLOT(slotPrint()),actionCollection());
00196         //KStdAction::quit(this,SLOT(slotFileQuit()),actionCollection());
00197 
00198 //      KStdAction::showToolbar(this,SLOT(slotViewToolBar()),actionCollection());
00199 //      KStdAction::showStatusbar(this,SLOT(slotViewStatusBar()),actionCollection());
00200 
00201 //      statusBar();
00202 
00203 //      createGUI();
00204 
00205 }
00206 
00207 
00208 ReportView::~ReportView() {
00209    //safe
00210    delete m_reportTags;
00211 }
00212 
00213 void ReportView::initReportList() {
00214 //FIXME: We need a solution that takes care project specific reports.
00215     //kDebug()<<k_funcinfo<<endl;
00216     QStringList list;
00217     m_reportList->clear();
00218     KStandardDirs std;
00219     QStringList reportDesktopFiles = std.findAllResources("data", "kplato/reports/*.desktop", true, true);
00220     for (QStringList::iterator it = reportDesktopFiles.begin(); it != reportDesktopFiles.end(); ++it) {
00221         KDesktopFile file((*it), true);
00222         QString name = file.readName();
00223         if (!name.isNull()) {
00224             //kDebug()<<" file: "<<*it<<" name="<<name<<endl;
00225             QString url = file.readURL();
00226             if (!url.isNull()) {
00227                 if (url.left(1) != "/" || url.left(6) != "file:/") {
00228                     QString path = (*it).left((*it).findRev('/', -1)+1); // include '/'
00229                     url = path + url;
00230                 }
00231                 m_reportList->insertItem(new ReportItem(m_reportList, name, url));
00232             }
00233         }
00234     }
00235 }
00236 
00237 void ReportView::draw(const QString &report) {
00238     //kDebug()<<k_funcinfo<<endl;
00239     m_reportview->clearReport();
00240     m_reportTags = new ReportTagsPrivate();
00241     getTemplateFile(report);
00242     m_reportview->setReportTemplate(templateDoc.toString());
00243     setReportData();
00244     m_reportview->renderReport();
00245     m_reportview->show();
00246     delete m_reportTags;
00247     m_reportTags=0L;
00248     enableNavigationBtn();
00249 }
00250 
00251 void ReportView::setup(KPrinter &printer) {
00252     //kDebug()<<k_funcinfo<<endl;
00253     m_reportview->setupPrinter(printer);
00254 }
00255 
00256 void ReportView::print(KPrinter &printer) {
00257     //kDebug()<<k_funcinfo<<endl;
00258         m_reportview->printReport(printer);
00259 }
00260 
00261 // Generate report data based on info from the template file
00262 void ReportView::setReportData() {
00263     QString s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
00264     s+="<KugarData>\n";
00265     s += setReportDetail();
00266     s+="</KugarData>\n";
00267     //kDebug()<<s<<endl;
00268     m_reportview->setReportData(s);
00269 }
00270 
00271 QString ReportView::setReportDetail() {
00272     //kDebug()<<k_funcinfo<<endl;
00273     QString s;
00274     if (m_reportTags->alltasksLevel != "-1") {
00275         //kDebug()<<k_funcinfo<<"alltasks level="<<m_reportTags->alltasksLevel<<endl;
00276         if (m_reportTags->summarytasksLevel == "-1") {
00277             m_reportTags->summarytasksLevel = m_reportTags->alltasksLevel;
00278             m_reportTags->summarytasksProps = m_reportTags->alltasksProps;
00279         }
00280         if (m_reportTags->tasksLevel == "-1") {
00281             m_reportTags->tasksLevel = m_reportTags->alltasksLevel;
00282             m_reportTags->tasksProps = m_reportTags->alltasksProps;
00283         }
00284         if (m_reportTags->milestonesLevel == "-1") {
00285             m_reportTags->milestonesLevel = m_reportTags->alltasksLevel;
00286             m_reportTags->milestonesProps = m_reportTags->alltasksProps;
00287         }
00288         s+= setTaskChildren(&(mainView()->getProject()));
00289     
00290     } else if (m_reportTags->summarytasksLevel == "0") {
00291         // make a report that has summarytasks as starting points
00292         Q3PtrListIterator<Node> it(mainView()->getProject().childNodeIterator());
00293         for (; it.current(); ++it) {
00294             if (it.current()->type() == Node::Type_Summarytask) {
00295                 s += setTaskDetail(it.current());
00296                 // Now do subtasks
00297                 s+= setTaskChildren(it.current());
00298             }
00299         }
00300 
00301     } else if (m_reportTags->tasksLevel == "0") {
00302         // make a report that has tasks as starting points
00303         Q3PtrListIterator<Node> it(mainView()->getProject().childNodeIterator());
00304         for (; it.current(); ++it) {
00305             if (it.current()->type() == Node::Type_Task) {
00306                 s += setTaskDetail(it.current());
00307             }
00308             if (it.current()->type() == Node::Type_Summarytask) {
00309                 s+= setTaskChildren(it.current());
00310                 if (m_reportTags->summarytasksLevel != "-1") {
00311                     s += setTaskDetail(it.current());
00312                 }
00313             }
00314         }
00315 
00316     } else if (m_reportTags->milestonesLevel == "0") {
00317 
00318     } else if (m_reportTags->resourcegroupsLevel == "0") {
00319         // make a report that has resourcegroups as starting points
00320         Q3PtrListIterator<ResourceGroup> it(mainView()->getProject().resourceGroups());
00321         for (; it.current(); ++it) {
00322             s += setResourceGroupDetail(it.current());
00323         }
00324 
00325     } else if (m_reportTags->resourcesLevel == "0") {
00326         // make a report that has resources as starting points
00327         Q3PtrListIterator<ResourceGroup> it(mainView()->getProject().resourceGroups());
00328         for (; it.current(); ++it) {
00329             Q3PtrListIterator<Resource> rit(it.current()->resources());
00330             for (; rit.current(); ++rit) {
00331                 s += setResourceDetail(rit.current());
00332             }
00333         }
00334     }
00335     //kDebug()<<k_funcinfo<<s<<endl;
00336     return s;
00337 }
00338 
00339 QString ReportView::setResourceGroupDetail(ResourceGroup *group) {
00340     //kDebug()<<k_funcinfo<<group->name()<<endl;
00341     QString s;
00342     if (m_reportTags->resourcegroupsLevel != "-1") {
00343         m_reportTags->m_resourcegroup = group;
00344         //kDebug()<<k_funcinfo<<group->name()<<": level="<<m_reportTags->resourcegroupsLevel<<endl;
00345         s = setDetail("resourcegroup", m_reportTags->resourcegroupsProps, m_reportTags->resourcegroupsLevel);
00346         Q3PtrListIterator<Resource> rit(group->resources());
00347         for (; rit.current(); ++rit) {
00348             s += setResourceDetail(rit.current());
00349         }
00350     }
00351     return s;
00352 }
00353 
00354 QString ReportView::setResourceDetail(Resource *res) {
00355     //kDebug()<<k_funcinfo<<res->name()<<endl;
00356     QString s;
00357     if (m_reportTags->resourcesLevel != "-1") {
00358         m_reportTags->m_resource = res;
00359         //kDebug()<<k_funcinfo<<res->name()<<": level="<<m_reportTags->resourcesLevel<<endl;
00360         s = setDetail("resource", m_reportTags->resourcesProps, m_reportTags->resourcesLevel);
00361     }
00362     return s;
00363 }
00364 
00365 QString ReportView::setTaskChildren(Node *node) {
00366     //kDebug()<<k_funcinfo<<endl;
00367     QString s;
00368     Q3PtrListIterator<Node> it(node->childNodeIterator());
00369     for (; it.current(); ++it) {
00370         s += setTaskDetail(it.current());
00371         if (it.current()->type() == Node::Type_Summarytask)
00372             s+= setTaskChildren(it.current());
00373     }
00374     return s;
00375 }
00376 
00377 QString ReportView::setTaskDetail(Node *node) {
00378     //kDebug()<<k_funcinfo<<endl;
00379     QString s;
00380     QStringList props;
00381     QString level = "-1";
00382     if (node->type() == Node::Type_Task) {
00383         props = m_reportTags->tasksProps;
00384         level = m_reportTags->tasksLevel;
00385     } else if (node->type() == Node::Type_Summarytask) {
00386         props = m_reportTags->summarytasksProps;
00387         level = m_reportTags->summarytasksLevel;
00388     } else if (node->type() == Node::Type_Milestone) {
00389         props = m_reportTags->milestonesProps;
00390         level = m_reportTags->milestonesLevel;
00391     }
00392     if (level != "-1") {
00393         m_reportTags->m_task = static_cast<Task *>(node);
00394         s = setDetail("task", props, level);
00395     }
00396     return s;
00397 }
00398 
00399 QString ReportView::setDetail(const QString & source, QStringList &properties, QString &level) {
00400     QString s = "<Row";
00401     s += " level=\"" + level + "\"";
00402     for (unsigned int i=0; i < properties.count(); ++i) {
00403         //kDebug()<<k_funcinfo<<"Property: "<<properties[i]<<endl;
00404         s += " " + properties[i].section('=', 0, 0) + "="; // Field
00405         QString data = m_reportTags->getData(source, properties[i].section('=', 1, 1));
00406         if (data.isNull())
00407             data = "";
00408         data = data.replace('<', "&lt;");
00409         data = data.replace('>', "&gt;");
00410         data = data.replace('"', "&quot;");
00411         
00412         s += "\"" + data + "\""; // Property
00413         //kDebug()<<k_funcinfo<<s<<endl;
00414     }
00415     s += "/>\n";
00416     return s;
00417 }
00418 
00419 // Most of this is from KoDocument::loadNativeFormat
00420 void ReportView::openTemplateFile(const QString &file) {
00421     if (!QFileInfo(file).isFile()) {
00422         KMessageBox::sorry( this, i18n("Cannot find report template file!"),
00423                                                         i18n("Generate Report"));
00424         return;
00425     }
00426     QFile in;
00427     in.setName(file);
00428     if (!in.open(QIODevice::ReadOnly)) {
00429         KMessageBox::sorry( this, i18n("Cannot open report template file!"),
00430                                                         i18n("Generate Report"));
00431         return;
00432     }
00433     // Try to find out whether it is a mime multi part file
00434     char buf[5];
00435     if ( in.read( buf, 4 ) < 4 )
00436     {
00437         in.close();
00438         KMessageBox::sorry( this, i18n("Cannot read report template file!"),
00439                                                         i18n("Generate Report"));
00440         return;
00441     }
00442 
00443     if (strncasecmp( buf, "<?xm", 4 ) == 0) { // xml file?
00444         in.at(0);
00445         // fake
00446         //m_reportview->setReportTemplate(&in);
00447         loadTemplate(in);
00448         in.close();
00449         return;
00450     }
00451     in.close();
00452     KoStore* store=KoStore::createStore(file, KoStore::Read);
00453     if (!store)
00454     {
00455         KMessageBox::sorry( this, i18n("Cannot open report template file!"),
00456                                                     i18n("Generate Report"));
00457         return;
00458     }
00459     bool b = store->open("maindoc.xml");
00460     if ( !b )
00461     {
00462         KMessageBox::sorry( this, i18n("Cannot find the proper report template file!"),
00463                                                     i18n("Generate Report"));
00464         delete store;
00465         return;
00466     }
00467     loadTemplate(*(store->device()));
00468     store->close();
00469 }
00470 
00471 void ReportView::loadTemplate(QIODevice &dev) {
00472     QString errorMsg;
00473     int errorLine;
00474     int errorColumn;
00475     if (!templateDoc.setContent( &dev , &errorMsg, &errorLine, &errorColumn)) {
00476         QString msg = "Parsing template file failed with ";
00477         KMessageBox::sorry( this, msg + errorMsg, i18n("Generate Report"));
00478         return;
00479     }
00480     loadTemplate(templateDoc);
00481 }
00482 
00483 void ReportView::loadTemplate(QDomDocument &doc) {
00484     QDomNode tpl;
00485     QDomNode child;
00486     for (tpl = doc.firstChild(); !tpl.isNull(); tpl = tpl.nextSibling())
00487         if (tpl.nodeName() == "KugarTemplate")
00488             break;
00489 
00490     if (tpl.isNull())
00491         return;
00492 
00493     m_reportTags->m_project = &(mainView()->getPart()->getProject());
00494     // Get all the child report elements
00495     QDomNodeList children = tpl.childNodes();
00496     int childCount = children.length();
00497 
00498     for(int j = 0; j < childCount; j++){
00499         child = children.item(j);
00500         if(child.nodeType() == QDomNode::ElementNode) {
00501             QDomElement e = child.toElement();
00502             //kDebug()<<child.nodeName()<<endl;
00503             // Report Header
00504             if(child.nodeName() == "ReportHeader") {
00505                 handleHeader(child);
00506             } else if (child.nodeName() == "PageHeader") {
00507                 handleHeader(child);
00508             } else if(child.nodeName() == "DetailHeader") {
00509                 handleHeader(child);
00510             } else if(child.nodeName() == "Detail") {
00511                 handleDetail(e);
00512             } else if(child.nodeName() == "DetailFooter") {
00513                 handleHeader(child);
00514             } else if(child.nodeName() == "PageFooter") {
00515                 handleHeader(child);
00516             } else if(child.nodeName() == "ReportFooter") {
00517                 handleHeader(child);
00518             } else if(child.nodeName() == "KPlato") {
00519                 handleKPlato(e);
00520             }
00521         }
00522     }
00523 }
00524 
00525 void ReportView::handleHeader(QDomNode &node) {
00526     QDomNode child;
00527     QDomNodeList children = node.childNodes();
00528     int childCount = children.length();
00529     for (int j = 0; j < childCount; j++) {
00530         child = children.item(j);
00531         if (child.nodeName() == "Label") {
00532             QDomNode n = child.attributes().namedItem("Text");
00533             QString s = n.nodeValue();
00534             if (!s.isEmpty()) {
00535                 // Translate labels
00536                 s = i18n(n.nodeValue().latin1()); //NOTE: Not sure if latin1 is ok
00537             }
00538             QString r = s;
00539             int i = 0, j = 0;
00540             do {
00541                 i = j;
00542                 if ( ((i = s.find('[', i)) != -1) && ((j = s.find(']', i+1)) != -1) ) {
00543                     QString tag = s.mid(i, j-i+1);
00544                     QString data = m_reportTags->getData(tag.mid(1, tag.length()-2));
00545                     r = r.replace(tag, data);
00546                 }
00547             } while (i != -1 && j != -1);
00548             n.setNodeValue(r);
00549             //kDebug()<<" new Text="<<n.nodeValue()<<endl;
00550         } else if (child.nodeName() == "Field") {
00551             QDomElement e = child.toElement();
00552             if (!e.isElement()) {
00553                 continue; // !!!!!
00554             }
00555             QString s = e.attribute("Field");
00556             QString data = m_reportTags->getData(s);
00557             e.setAttribute("Text", data);
00558             //kDebug()<<" new Text="<<e.attribute("Text")<<endl;
00559         }
00560     }
00561 }
00562 
00563 QStringList ReportView::getProperties(QDomElement &elem) {
00564     QStringList props;
00565     QDomNodeList list(elem.childNodes());
00566     int childCount = list.length();
00567     for (int j = 0; j < childCount; j++) {
00568         QDomNode child = list.item(j);
00569         if (child.nodeName() == "Field") {
00570             props.append(child.attributes().namedItem("Field").nodeValue()+"="+child.attributes().namedItem("Field").nodeValue());
00571         }
00572     }
00573     return props;
00574 }
00575 
00576 void ReportView::handleKPlato(QDomElement &elem) {
00577     QDomNodeList list(elem.childNodes());
00578     int childCount = list.length();
00579     for (int j = 0; j < childCount; j++) {
00580         QDomNode child = list.item(j);
00581         if (child.nodeName() == "Detail") {
00582             QDomElement e = child.toElement();
00583             if (!e.isElement()) {
00584                 continue; // !!!!!
00585             }
00586             QString source = e.attribute("SelectFrom");
00587             QString level = e.attribute("Level", "-1");
00588             //kDebug()<<k_funcinfo<<"SelectFrom="<<source<<" Level="<<level<<endl;
00589             if (source.isNull() || level == "-1")
00590                 continue;
00591         
00592             QStringList list = QStringList::split(" ", source);
00593             QStringList::iterator it = list.begin();
00594             for (; it != list.end(); ++it) {
00595                 //kDebug()<<k_funcinfo<<(*it)<<endl;
00596                 if ((*it) == "alltasks") {
00597                     m_reportTags->alltasksLevel = level;
00598                 }
00599                 if ((*it) == "summarytasks") {
00600                     m_reportTags->summarytasksLevel = level;
00601                 }
00602                 if ((*it) == "tasks") {
00603                     m_reportTags->tasksLevel = level;
00604                 }
00605                 if ((*it) == "milestones") {
00606                     m_reportTags->milestonesLevel = level;
00607                 }
00608                 if ((*it) == "resourcegroups") {
00609                     m_reportTags->resourcegroupsLevel = level;
00610                 }
00611                 if ((*it) == "resources") {
00612                     m_reportTags->resourcesLevel = level;
00613                 }
00614             }
00615         }
00616     }
00617 }
00618 
00619 void ReportView::handleDetail(QDomElement &elem) {
00620     //kDebug()<<k_funcinfo<<endl;
00621     QString level = elem.attribute("Level", "-1");
00622     if (level == "-1") {
00623         return;
00624     }
00625     
00626     if (level == m_reportTags->alltasksLevel) {
00627         m_reportTags->alltasksProps = getProperties(elem);
00628     }
00629     if (level ==  m_reportTags->summarytasksLevel) {
00630         m_reportTags->summarytasksProps = getProperties(elem);
00631     }
00632     if (level == m_reportTags->tasksLevel) {
00633         m_reportTags->tasksProps = getProperties(elem);
00634     }
00635     if (level == m_reportTags->milestonesLevel) {
00636         m_reportTags->milestonesProps = getProperties(elem);
00637     }
00638     if (level == m_reportTags->resourcegroupsLevel) {
00639         m_reportTags->resourcegroupsProps = getProperties(elem);
00640     }
00641     if (level == m_reportTags->resourcesLevel) {
00642         m_reportTags->resourcesProps = getProperties(elem);
00643     }
00644 }
00645 
00646 void ReportView::replaceTags(QDomNode &node) {
00647     if (node.isNull())
00648         return;
00649 }
00650 
00651 void ReportView::getTemplateFile(const QString &tpl) {
00652 
00653         KUrl url(tpl);
00654         QString localtpl;
00655         bool isTemp = false;
00656 
00657         if (!url.isValid())
00658         {
00659                         KMessageBox::sorry(this,i18n("Malformed template filename: %1", url.prettyUrl()));
00660         }
00661         else
00662         {
00663                 if (KIO::NetAccess::download(url,localtpl,this))
00664                         isTemp = true;
00665                 else
00666                         KMessageBox::sorry(this,i18n("Unable to download template file: %1", url.prettyUrl()));
00667         }
00668 
00669         if (!localtpl.isNull())
00670         {
00671         openTemplateFile(localtpl);
00672                 if (isTemp)
00673                         KIO::NetAccess::removeTempFile(localtpl);
00674         }
00675 }
00676 
00677 void ReportView::enableNavigationBtn() {
00678     //kDebug()<<k_funcinfo<<"curr="<<m_reportview->currentPage()<<" count="<<m_reportview->pageCount()<<endl;
00679     emit setFirstPageActionEnabled(m_reportview->currentPage() > 0);
00680     emit setNextPageActionEnabled(m_reportview->currentPage() < m_reportview->pageCount()-1);
00681     emit setPriorPageActionEnabled(m_reportview->currentPage() > 0);
00682     emit setLastPageActionEnabled(m_reportview->currentPage() < m_reportview->pageCount()-1);
00683 }
00684 void ReportView::slotFirstPage() {
00685     m_reportview->slotFirstPage();
00686     enableNavigationBtn();
00687 }
00688 
00689 void ReportView::slotNextPage() {
00690     m_reportview->slotNextPage();
00691     enableNavigationBtn();
00692 }
00693 
00694 void ReportView::slotPrevPage() {
00695     m_reportview->slotPrevPage();
00696     enableNavigationBtn();
00697 }
00698 
00699 void ReportView::slotLastPage() {
00700     m_reportview->slotLastPage();
00701     enableNavigationBtn();
00702 }
00703 
00704 bool ReportView::setContext(Context::Reportview &context) {
00705     Q_UNUSED(context);
00706     //kDebug()<<k_funcinfo<<endl;
00707     return true;
00708 }
00709 
00710 void ReportView::getContext(Context::Reportview &context) const {
00711     Q_UNUSED(context);
00712     //kDebug()<<k_funcinfo<<endl;
00713 }
00714 
00715 void ReportView::slotReportListClicked(Q3ListViewItem* item) {
00716     if (item == m_reportList->selectedItem())
00717         slotReportListSelectionChanged(item);
00718 }
00719 
00720 void ReportView::slotReportListSelectionChanged(Q3ListViewItem* item) {
00721     ReportItem *ri = dynamic_cast<ReportItem*>(item);
00722     if (ri == 0)
00723         return;
00724     draw(ri->url);
00725 }
00726 
00727 
00728 }  //KPlato namespace
00729 
00730 #include "kptreportview.moc"

Généré le Wed Nov 22 23:40:57 2006 pour KPlato par  doxygen 1.5.1-p1