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; }
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; }
//=================================================================== // 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; }