int ReportSectionDetail::findSection(const QString & name) { // find the item by its name ReportSectionDetailGroup * rsd = 0; for(int i = 0; i < groupList.count(); i++) { rsd = groupList.at(i); if(name == rsd->getTitle()) return i; } return -1; }
void SectionEditor::btnEdit_clicked() { if (m_reportSectionDetail) { const int idx = m_ui.lbGroups->currentRow(); if (idx < 0) { return; } ReportSectionDetailGroup * rsdg = m_reportSectionDetail->groupSection(idx); if (editDetailGroup(rsdg)) { // update name in list m_ui.lbGroups->item(idx)->setText(columnName(rsdg->column())); } } }
void SectionEditor::brnMoveDown_clicked() { if (m_reportSectionDetail) { int idx = lbGroups->currentRow(); if (idx == (int)(lbGroups->count() - 1)) return; QString s = lbGroups->currentItem()->text(); lbGroups->takeItem(idx); lbGroups->insertItem (idx + 1, s); ReportSectionDetailGroup * rsdg = m_reportSectionDetail->groupSection(idx); bool showgh = rsdg->groupHeaderVisible(); bool showgf = rsdg->groupFooterVisible(); m_reportSectionDetail->removeSection(idx); m_reportSectionDetail->insertSection(idx + 1, rsdg); rsdg->setGroupHeaderVisible(showgh); rsdg->setGroupFooterVisible(showgf); } }
void SectionEditor::btnMoveUp_clicked() { if (m_reportSectionDetail) { int idx = m_ui.lbGroups->currentRow(); if (idx <= 0) return; QString s = m_ui.lbGroups->currentItem()->text(); m_ui.lbGroups->takeItem(idx); m_ui.lbGroups->insertItem(idx - 1, s); m_ui.lbGroups->setCurrentRow(idx - 1, QItemSelectionModel::ClearAndSelect); ReportSectionDetailGroup * rsdg = m_reportSectionDetail->groupSection(idx); bool showgh = rsdg->groupHeaderVisible(); bool showgf = rsdg->groupFooterVisible(); m_reportSectionDetail->removeGroupSection(idx); m_reportSectionDetail->insertGroupSection(idx - 1, rsdg); rsdg->setGroupHeaderVisible(showgh); rsdg->setGroupFooterVisible(showgf); } }
void SectionEditor::btnAdd_clicked() { if (m_reportSectionDetail) { // lets add a new section // search for unused column QString column; const QStringList keys = m_reportDesigner->fieldKeys(); const QSet<QString> columns = groupingColumns(); foreach(const QString &key, keys) { // skip any editor helper fields if (isEditorHelperField(key)) { continue; } if (! columns.contains(key)) { column = key; break; } } // should not happen, but we do not really know if m_reportDesigner is in sync if (column.isEmpty()) { return; } // create new group, have it edited and add it, if not cancelled ReportSectionDetailGroup * rsdg = new ReportSectionDetailGroup(column, m_reportSectionDetail, m_reportSectionDetail); if (editDetailGroup(rsdg)) { // append to group sections m_reportSectionDetail->insertGroupSection(m_reportSectionDetail->groupSectionCount(), rsdg); // add to combobox const QString column = rsdg->column(); QListWidgetItem *item = new QListWidgetItem(columnName(column)); item->setData(KeyRole, column); m_ui.lbGroups->addItem(item); m_ui.lbGroups->setCurrentRow(m_ui.lbGroups->count() - 1); updateAddButton(); } else { delete rsdg; } } }
void ReportSectionDetail::buildXML(QDomDocument & doc, QDomElement & section) { // name/title QDomElement name = doc.createElement("name"); name.appendChild(doc.createTextNode(getTitle())); section.appendChild(name); for(unsigned int i = 0; i < groupList.count(); i++) { ReportSectionDetailGroup * rsdg = groupList.at(i); QDomNode grp = doc.createElement("group"); QDomNode gname = doc.createElement("name"); gname.appendChild(doc.createTextNode(rsdg->getTitle())); grp.appendChild(gname); QDomNode gcol = doc.createElement("column"); gcol.appendChild(doc.createTextNode(rsdg->column())); grp.appendChild(gcol); //group head if(rsdg->isGroupHeadShowing()) { QDomElement ghead = doc.createElement("head"); rsdg->getGroupHead()->buildXML(doc,ghead); grp.appendChild(ghead); } // group foot if(rsdg->isGroupFootShowing()) { QDomElement gfoot = doc.createElement("foot"); rsdg->getGroupFoot()->buildXML(doc,gfoot); grp.appendChild(gfoot); } section.appendChild(grp); } // detail section QDomElement gdetail = doc.createElement("detail"); QDomElement key = doc.createElement("key"); QDomElement kquery = doc.createElement("query"); kquery.appendChild(doc.createTextNode(query())); key.appendChild(kquery); gdetail.appendChild(key); _detail->buildXML(doc,gdetail); section.appendChild(gdetail); }
void ReportSectionDetail::initFromXML(QDomNode & section) { QDomNodeList nl = section.childNodes(); QDomNode node; QString n; // some code to handle old style defs QString o_name = "unnamed"; QString o_column = QString::null; bool old_head = FALSE; QDomNode o_head; bool old_foot = FALSE; QDomNode o_foot; for(int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if(n == "name") { o_name = node.firstChild().nodeValue(); setTitle(o_name); } else if(n == "pagebreak") { QDomElement eThis = node.toElement(); if(eThis.attribute("when") == "at end") setPageBreak(BreakAtEnd); } else if(n == "group") { ReportSectionDetailGroup * rsdg = new ReportSectionDetailGroup("unnamed", this, this); QDomNodeList gnl = node.childNodes(); QDomNode gnode; bool show_head = FALSE; bool show_foot = FALSE; for(int gi = 0; gi < gnl.count(); gi++) { gnode = gnl.item(gi); if(gnode.nodeName() == "name") { rsdg->setTitle(gnode.firstChild().nodeValue()); } else if(gnode.nodeName() == "column") { rsdg->setColumn(gnode.firstChild().nodeValue()); } else if(gnode.nodeName() == "pagebreak") { QDomElement elemThis = gnode.toElement(); QString n = elemThis.attribute("when"); if("after foot" == n) rsdg->setPageBreak(ReportSectionDetailGroup::BreakAfterGroupFooter); } else if(gnode.nodeName() == "head") { rsdg->getGroupHead()->initFromXML(gnode); rsdg->showGroupHead(TRUE); show_head = TRUE; } else if(gnode.nodeName() == "foot") { rsdg->getGroupFoot()->initFromXML(gnode); rsdg->showGroupFoot(TRUE); show_foot = TRUE; } else { qDebug("encountered unknown element while parsing group element: %s", gnode.nodeName().latin1()); } } insertSection(groupSectionCount(), rsdg); rsdg->showGroupHead(show_head); rsdg->showGroupFoot(show_foot); } else if(n == "grouphead") { o_head = node; old_head = TRUE; } else if(n == "groupfoot") { o_foot = node; old_foot = TRUE; } else if(n == "detail") { // need to pull out the query key values QDomNode key = node.namedItem("key"); if(key.isNull()) { qDebug("Did not find a key element while parsing detail section"); } else { QDomNodeList knl = key.childNodes(); QDomNode knode; for(int ki = 0; ki < knl.count(); ki++) { knode = knl.item(ki); if(knode.nodeName() == "query") { setQuery(knode.firstChild().nodeValue()); } else if(knode.nodeName() == "column") { o_column = knode.firstChild().nodeValue(); } else { qDebug("encountered unknown element while parsing key element: %s", knode.nodeName().latin1()); } } } _detail->initFromXML(node); } else { // unknown element qDebug("while parsing section encountered and unknown element: %s", n.latin1()); } } if(old_head || old_foot) { ReportSectionDetailGroup * rsdg = new ReportSectionDetailGroup(o_name, this, this); rsdg->setColumn(o_column); if(old_head) rsdg->getGroupHead()->initFromXML(o_head); if(old_foot) rsdg->getGroupFoot()->initFromXML(o_foot); // if we encountered this situation then we shouldn't have // any other sections but to be sure we will just tack this one // onto the end insertSection(groupSectionCount(), rsdg); rsdg->showGroupHead(old_head); rsdg->showGroupFoot(old_foot); } }
void ReportSectionDetail::buildXML(QDomDocument & doc, QDomElement & section) { // name/title QDomElement name = doc.createElement("name"); name.appendChild(doc.createTextNode(getTitle())); section.appendChild(name); if(pageBreak() != ReportSectionDetail::BreakNone) { QDomElement spagebreak = doc.createElement("pagebreak"); if(pageBreak() == ReportSectionDetail::BreakAtEnd) spagebreak.setAttribute("when", "at end"); section.appendChild(spagebreak); } for(int i = 0; i < groupList.count(); i++) { ReportSectionDetailGroup * rsdg = groupList.at(i); QDomNode grp = doc.createElement("group"); QDomNode gname = doc.createElement("name"); gname.appendChild(doc.createTextNode(rsdg->getTitle())); grp.appendChild(gname); QDomNode gcol = doc.createElement("column"); gcol.appendChild(doc.createTextNode(rsdg->column())); grp.appendChild(gcol); if(rsdg->pageBreak() != ReportSectionDetailGroup::BreakNone) { QDomElement pagebreak = doc.createElement("pagebreak"); if(rsdg->pageBreak() == ReportSectionDetailGroup::BreakAfterGroupFooter) pagebreak.setAttribute("when", "after foot"); grp.appendChild(pagebreak); } //group head if(rsdg->isGroupHeadShowing()) { QDomElement ghead = doc.createElement("head"); rsdg->getGroupHead()->buildXML(doc,ghead); grp.appendChild(ghead); } // group foot if(rsdg->isGroupFootShowing()) { QDomElement gfoot = doc.createElement("foot"); rsdg->getGroupFoot()->buildXML(doc,gfoot); grp.appendChild(gfoot); } section.appendChild(grp); } // detail section QDomElement gdetail = doc.createElement("detail"); QDomElement key = doc.createElement("key"); QDomElement kquery = doc.createElement("query"); kquery.appendChild(doc.createTextNode(query())); key.appendChild(kquery); gdetail.appendChild(key); _detail->buildXML(doc,gdetail); section.appendChild(gdetail); }
void SectionEditor::btnEdit_clicked() { if (m_reportSectionDetail) { int idx = lbGroups->currentRow(); if (idx < 0) return; ReportSectionDetailGroup * rsdg = m_reportSectionDetail->groupSection(idx); DetailGroupSectionDialog * dgsd = new DetailGroupSectionDialog(this); dgsd->cbColumn->clear(); QStringList keys = m_reportDesigner->fieldKeys(); QStringList names = m_reportDesigner->fieldNames(); for (int i = 0; i < keys.count(); ++i) { dgsd->cbColumn->insertItem( i, names.value(i), keys.at(i)); } dgsd->cbColumn->setCurrentIndex(keys.indexOf(rsdg->column())); dgsd->cbSort->clear(); dgsd->cbSort->addItem(i18n("Ascending"), "ascending"); dgsd->cbSort->addItem(i18n("Descending"), "descending"); if (rsdg->sort() == Qt::AscendingOrder) { dgsd->cbSort->setCurrentIndex(dgsd->cbSort->findData("ascending")); } else { dgsd->cbSort->setCurrentIndex(dgsd->cbSort->findData("descending")); } dgsd->breakAfterFooter->setChecked(rsdg->pageBreak() == ReportSectionDetailGroup::BreakAfterGroupFooter); dgsd->cbHead->setChecked(rsdg->groupHeaderVisible()); dgsd->cbFoot->setChecked(rsdg->groupFooterVisible()); bool exitLoop = false; while (!exitLoop) { if (dgsd->exec() == QDialog::Accepted) { QString column = dgsd->cbColumn->itemData(dgsd->cbColumn->currentIndex()).toString(); bool showgh = dgsd->cbHead->isChecked(); bool showgf = dgsd->cbFoot->isChecked(); bool breakafterfoot = dgsd->breakAfterFooter->isChecked(); if (column != rsdg->column() && m_reportSectionDetail->indexOfSection(column) != -1) { QMessageBox::warning(this, i18n("Error Encountered"), i18n("Unable to add a new group because its name would not be unique")); } else { lbGroups->item(idx)->setText(dgsd->cbColumn->currentText()); rsdg->setColumn(column); rsdg->setGroupHeaderVisible(showgh); rsdg->setGroupFooterVisible(showgf); if (breakafterfoot) rsdg->setPageBreak(ReportSectionDetailGroup::BreakAfterGroupFooter); else rsdg->setPageBreak(ReportSectionDetailGroup::BreakNone); if (dgsd->cbSort->itemData(dgsd->cbSort->currentIndex()).toString() == "ascending") { rsdg->setSort(Qt::AscendingOrder); } else { rsdg->setSort(Qt::DescendingOrder); } exitLoop = true; } } else { exitLoop = true; } } if (dgsd) delete dgsd; } }