LimeReport Forum
General Category | Основное => Discussion | Обсуждение => Topic started by: hamlettu on November 19, 2021, 11:44:32 am
-
Hi
I read user manual, in DATA SOURCES session(page 5),
it say "External datasets by implementing QAbstractItemModel".
I want to use external datasets in my app like demo_r1.
I see the picture in user manual,
there are external_customers_data and external_orders_data look like root node.
I try to add "Dataset", but it need to use a exist Datasource and sql.
And the Dataset is a child node of Datasource.
How to add External datasets in LRDesigner?
Thanks
-
Hi!
The simplest way to add an external data source is to realize one slot callback data source.
Just do something like this:
void MainWindow::slotOneSlotDS(LimeReport::CallbackInfo info, QVariant &data)
{
QStringList columns;
columns << "Name" << "Value" << "Image";
switch (info.dataType) {
case LimeReport::CallbackInfo::RowCount:
data = 4;
break;
case LimeReport::CallbackInfo::ColumnCount:
data = columns.size();
break;
case LimeReport::CallbackInfo::ColumnHeaderData: {
data = columns.at(info.index);
break;
}
case LimeReport::CallbackInfo::ColumnData:
qDebug() << info.index <<info.columnName;
if (info.columnName == "Image")
data = QImage(":/report//images/logo32");
else {
data = info.columnName+" "+QString::number(info.index);
}
break;
default: break;
}
}
.....
callbackDatasource = report->dataManager()->createCallbackDatasource("oneSlotDS");
connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)),
this, SLOT(slotOneSlotDS(LimeReport::CallbackInfo,QVariant&)));
-
Alex,
Thanks.
I will try.