LimeReport
LimeReport copied to clipboard
Signal/slot interface help
So I've read the docs, watched the video, and read issue #21 .
I'm assuming that the version in the docs is out of date since the comments in #2 suggest we only need one signal/slot.
But I seem to be missing a piece of the puzzle... What do I need to put in the form using the front end in order to connect my columns in the slot with the actual form?
Here's what I'm doing:
connect(callbackDatasource, &LimeReport::ICallbackDatasource::getCallbackData, [=] ( const LimeReport::CallbackInfo &inInfo, QVariant &outVariant ) {
qDebug() << " getCallbackData" << outVariant << inInfo.columnName << inInfo.dataType;
const QStringList cColumns{ "Name", "Value" };
const int cColumnCount = cColumns.size();
const int cNumRows = 4;
switch (inInfo.dataType)
{
case LimeReport::CallbackInfo::IsEmpty:
outVariant = false;
break;
case LimeReport::CallbackInfo::HasNext:
outVariant = (inInfo.index != (cNumRows - 1));
break;
case LimeReport::CallbackInfo::ColumnHeaderData:
outVariant = cColumns.at( inInfo.index );
break;
case LimeReport::CallbackInfo::ColumnData:
outVariant = QString( inInfo.columnName + QStringLiteral( " " ) + QString::number( inInfo.index ) );
break;
case LimeReport::CallbackInfo::ColumnCount:
outVariant = cColumnCount;
break;
case LimeReport::CallbackInfo::RowCount:
outVariant = cNumRows;
break;
}
qDebug() << " ...returning" << outVariant;
});
...and it's never asking for data:
Debug: getCallbackData QVariant(Invalid) "" 4
Debug: ...returning QVariant(int, 2)
Debug: getCallbackData QVariant(Invalid) "" 2
Debug: ...returning QVariant(QString, "Name")
Debug: getCallbackData QVariant(Invalid) "" 2
Debug: ...returning QVariant(QString, "Value")
Debug: getCallbackData QVariant(int, 0) "" 5
Debug: ...returning QVariant(int, 4)
Debug: getCallbackData QVariant(Invalid) "" 5
Debug: ...returning QVariant(int, 4)
Debug: getCallbackData QVariant(int, 0) "" 5
Debug: ...returning QVariant(int, 4)
Debug: getCallbackData QVariant(Invalid) "" 5
Debug: ...returning QVariant(int, 4)
Presumably because I need to add fields to the form. I tried adding variables with the column names, but that didn't work.
How do I add the fields to my "DataBand"?
Thanks!
Hi Your Datasource looks right. Perhaps the problem is how You use it. There are several ways to add fields on a band.
- Drag & Drop the field from "DataBrowser" to the band
- Put a TextItem on the band Double click on it Find in the right side of the editor your datasource and select a field by double click on it (it will add something like this $D{yourDatasource.filed}) or simple write $D{yourDatasource.filed}
In my code I set it up like this:
callbackDatasource = report->dataManager()->createCallbackDatasource( "my_report" );
How do I add a datasource for this in the interface? Everything there seems geared towards a db connection (like in the video).
If I go to the Data Browser and select Datasources and click the Add button, I can add a datasource called my_report, but I can't add any fields.
Sorry - I still feel like I'm not connecting some dots here.
callbackDatasource = report->dataManager()->createCallbackDatasource( "my_report" );
After calling this method the "my_report" datasource should appear in Data Browser
You can see how to create and use callback datasource in the demo_r1 This is my demo code:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow), m_progressDialog(0), m_customers(0), m_orders(0)
{
.......
callbackDatasource = report->dataManager()->createCallbackDatasouce("oneSlotDS");
connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)),
this, SLOT(slotOneSlotDS(LimeReport::CallbackInfo,QVariant&)));
......
}
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:
if (info.columnName == "Image")
data = QImage(":/report//images/logo32");
else {
data = info.columnName+" "+QString::number(info.index);
}
break;
default: break;
}
}
Ah. I'm using the Designer to design the form and then using the limereport lib and interface in my application to render the report. So Designer doesn't have access to this info. How do I make it work given this scenario?
Was your intent that the form designer be included in applications?
Yes, at the moment designer is embedded in the application;
report->designReport() run it;
You also can use Designer to do a report but in this case you have to manually write fields and datasources names.
In the future I'm going to decouple the designer from the report generator
Oh - I hadn't actually looked at the code for the designer :-) Is there a plan to be able to keep the renderer and the designer separate?
It would be a lot more convenient to ship just the report renderer built into the app and (optionally) include a form designer as a separate application for those users that want to customize the forms.
I found a workaround (I think) to sort of do what I outlined above - if I declare a new datasource called "my_report" and then manually add variables like $D{my_report.Value} to text fields in the form it seems to work. Not the most convenient though.
Thanks!
Yes, i`m going to separate the render and the designer becouse you not alone in this request. But in my opinion it's very convenient to have ability to preview report in the design time. If you use the designer separately from the application, then this feature disappears for data that is directly transferred from the application.
I found a workaround (I think) to sort of do what I outlined above - if I declare a new datasource called "my_report" and then manually add variables like $D{my_report.Value} to text fields in the form it seems to work. Not the most convenient though.
You needn't to declare "my_report" you can simply write $D{my_report.Value} in the textitem :) and yes it`s not very convenient, but i do not see a way how to do it better. Do you have any suggestions
You needn't to declare "my_report" you can simply write $D{my_report.Value} in the textitem :) and yes it`s not very convenient, but i do not see a way how to do it better. Do you have any suggestions
I left out a step in my description. If I don't create the data source and set it as the datasource on the data band it doesn't work properly.
Some suggestions (keeping in mind I'm talking about the signal/slot method):
-
"preview report in the design time": Right now I'm running my application and the designer at the same time, editing the report, and re-opening the preview in my application. Leaving things mostly as they are, the report preview could add a QFileSystemWatcher to watch the report file it opened and either auto-reload the preview on a change or give the user a dialog "Reload from disk" or whatever. I'd be happy to look at adding this.
-
Currently with the signal/slot method, the data schema is kind of split between the application's slot (# of columns and column names) and the designer. Maybe we could look at a way to add signal/slot specifically as an option in the designer - specify a datasource name and columns for it, etc.. This would make the report more "independent" of the application. On the application slot side, it would remain the same (I think) except not require the column info (# and name).
-
If we do something like (2), then users could run a stand alone designer on a report and know what fields are available to them because it's pulling them from the report rather than the application.
-
If we do something like (2), then maybe we could provide a way to use dummy data for previewing from the stand alone designer? Or just fill things text fields in with Lorem Ipsum?
I'll think about it :)
If I don't create the data source and set it as the datasource on the data band it doesn't work properly.
The data band's datasource property can be specified without selection from dropdown list you can simply type it
I'll think about it :)
Great! :-)
The data band's datasource property can be specified without selection from dropdown list you can simply type it
Ah, ok. One less step I guess.
When I get back to my reports I'll look at implementing the QFileSystemWatcher I mentioned. That will at least make things a little nicer for those using LimeReports the way I am.
If you need any help/feedback/testing implementing a specific solution for signal/slot in the designer, please let me know - I'd be glad to help.
Thanks Arin!