BandDataModel *ReportItemBand::model() { if(!m_model) { QVariant dta = modelData(); if(!dta.isValid() || dta.userType() == QVariant::String) { QString data_key = dta.toString(); ReportItemBand *pr = parentBand(); if(pr) { BandDataModel *dm = pr->model(); ReportItemDetail *det = pr->detail(); if(dm && det) { dta = dm->table(det->currentIndex(), data_key); } } else { /// take data from report processor ReportProcessor *proc = processor(!qf::core::Exception::Throw); if(proc) { dta = QVariant::fromValue(proc->data(data_key)); } } } m_model = BandDataModel::createFromData(dta, this); } return m_model; }
QVariant ReportItemDetail::data(int row_no, const QString &field_name, int role) { qfLogFuncFrame() << "row_no:" << row_no << "field_name:" << field_name; QVariant ret; if(row_no >= 0) { ReportItemBand *band = parentBand(); if(band) { BandDataModel *m = band->model(); if(m) { ret = m->dataByName(row_no, field_name, (BandDataModel::DataRole)role); } else { qfWarning() << "Parent Band has not valid data model."; } } else { qfWarning() << "Detail without parent Band."; } } else { // this is not necessary error // when data is not loaded and QML is instantiated then currentIndex == -1 and code goes this way // return QString to avoid warning: Unable to assign [undefined] to QString // when data is assigned to QML property of type string ret = QString(); //qfWarning() << "row_no:" << row_no; //ret = QStringLiteral("BAD_ROW"); } qfDebug() << "\t RETURN:" << ret; return ret; }
int ReportItemDetail::rowCount() { int ret = 0; ReportItemBand *band = parentBand(); if(band && band->isModelLoaded()) { BandDataModel *m = band->model(); if(m) { ret = m->rowCount(); } } return ret; }
QVariant ReportItemBand::data(const QString &field_name, int role) { qfLogFuncFrame() << "field_name:" << field_name; QVariant ret; BandDataModel *m = model(); if(m) { ret = m->tableData(field_name, (BandDataModel::DataRole)role); } else { qfWarning() << "Band has not valid data model."; } return ret; }
ReportItem::PrintResult ReportItemDetail::printMetaPaint(ReportItemMetaPaint *out, const ReportItem::Rect &bounding_rect) { qfLogFuncFrame(); QF_TIME_SCOPE("ReportItemDetail::printMetaPaint"); ReportItemBand *band = qobject_cast<ReportItemBand*>(parent()); BandDataModel *model = nullptr; if(band) { model = band->model(); if(model) { if(currentIndex() < 0) { //qfWarning() << "emit rowCountChanged()"; //emit rowCountChanged(); setCurrentIndex(0); } } } /*-- PrintResult res; bool design_mode = processor()->isDesignMode(); /// true znamena, zobraz prvni radek, i kdyz tam nejsou data. //qfInfo() << "design mode:" << design_mode; if(!design_mode && (data_table.isNull() || dataRow().isNull())) { /// prazdnej detail vubec netiskni res.value = PrintOk; return res; } --*/ PrintResult res = Super::printMetaPaint(out, bounding_rect); if(res.isPrintFinished()) { if(model) { /// take next data row int ix = currentIndex() + 1; qfDebug() << currentIndex() << "/" << model->rowCount(); //qfDebug() << model->dump(); if(ix < model->rowCount()) { QF_TIME_SCOPE("ReportItemDetail::printMetaPaint 3"); setCurrentIndex(ix); resetIndexToPrintRecursively(ReportItem::IncludingParaTexts); res.setNextDetailRowExists(true); } else { resetCurrentIndex(); } } } return res; }
void ReportItemBand::createChildItemsFromData() { BandDataModel *mod = model(); qfLogFuncFrame() << "model:" << mod; if(mod) { style::Brush *brush_lightgray = new style::Brush(this); { style::Color *c = new style::Color(brush_lightgray); c->setDefinition(QColor(Qt::lightGray)); brush_lightgray->setColor(c); } ReportItemFrame *it_header_frm = new ReportItemFrame(this); { it_header_frm->setWidth("%"); it_header_frm->setLayout(ReportItemFrame::LayoutHorizontal); it_header_frm->setFill(brush_lightgray); //it_header_frm->setHinset(3); //it_header_frm->setVinset(3); } addItem(it_header_frm); style::Pen *pen_black1 = new style::Pen(this); { pen_black1->setWidth(1); style::Color *c = new style::Color(pen_black1); c->setDefinition(QColor(Qt::black)); pen_black1->setColor(c); } int col_cnt = mod->columnCount(); for(int i=0; i<col_cnt; i++) { ReportItemPara *it_para = new ReportItemPara(it_header_frm); it_para->setBorder(pen_black1); it_para->setWidth(mod->headerData(i, Qt::SizeHintRole)); it_para->setText(mod->headerData(i).toString()); it_para->setHinset(1); it_header_frm->addItem(it_para); } ReportItemDetail *it_det = new ReportItemDetail(this); { it_det->setWidth("%"); it_det->setLayout(ReportItemFrame::LayoutHorizontal); it_det->setExpandChildrenFrames(true); } addItem(it_det); for(int i=0; i<col_cnt; i++) { ReportItemPara *it_para = new ReportItemPara(it_det); it_para->setBorder(pen_black1); it_para->setWidth(mod->headerData(i, Qt::SizeHintRole)); it_para->setHinset(1); auto fn = [mod, it_det, i]()->QString { QString ret = mod->data(it_det->currentIndex(), i).toString(); return ret; }; it_para->setGetTextCppFunction(fn); it_det->addItem(it_para); } } //dumpObjectTree(); }
//=================================================================== // ReportItemDetail //=================================================================== ReportItem::PrintResult ReportItemDetail::printHtml(HTMLElement & out) { qfLogFuncFrame(); ReportItemBand *band = qobject_cast<ReportItemBand*>(parent()); BandDataModel *model = nullptr; if(band) { model = band->model(); if(model) { if(currentIndex() < 0) { /// kdyz neni f_dataRow, vezmi prvni radek dat setCurrentIndex(0); } } } PrintResult res; /*-- bool design_mode = processor->isDesignMode(); if(!design_mode && (data_table.isNull() || dataRow().isNull())) { /// prazdnej detail vubec netiskni res.value = PrintOk; return res; } --*/ res = Super::printHtml(out); if(res.value == PrintOk) { if(model) { /// take next data row setCurrentIndex(currentIndex() + 1); if(currentIndex() < model->rowCount()) { resetIndexToPrintRecursively(ReportItem::IncludingParaTexts); res.flags |= FlagPrintAgain; } } } return res; }