Esempio n. 1
0
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->data(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;
}
Esempio n. 2
0
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();
}