1
Discussion | Обсуждение / Re: Верните память!!!)
« on: October 11, 2017, 10:05:58 am »
неа, не стоит
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
namespace report {
typedef QMap<QString, QString> Variables;
typedef QMapIterator<QString, QString> VarsIter;
class reports_printer : public Singleton<reports_printer>
{
private:
reports_printer() : m_report(nullptr) { ; }
//
reports_printer(const reports_printer &) = delete;
reports_printer& operator = (const reports_printer &) = delete;
//
virtual ~reports_printer() { reset_report(); }
public:
void create_report(QAbstractItemModel* data, QString report_templte, Variables vars = Variables())
{
m_report = new LimeReport::ReportEngine;
if(data && !report_templte.isEmpty())
{
if(vars.isEmpty()) qDebug() << "No variables";
else
{
VarsIter iter(vars);// vars.begin();
while(iter.hasNext())
{
iter.next();
m_report->dataManager()->setReportVariable(iter.key(), QVariant(iter.value()));
}
}
const QString REPORT_MODEL_NAME = "table_model";
m_report->dataManager()->addModel(REPORT_MODEL_NAME, data, false);
if(!m_report->loadFromFile(report_templte))
{
qDebug() << "Wrong report template";
reset_report();
return;
}
if (ref_data::get()->debug_prn())
{
m_report->designReport();
}
else
{
m_report->setPreviewWindowTitle(QObject::tr("Preview"));
//m_report->createPreviewWidget()->show();
m_report->setResultEditable(false);
m_report->setShowProgressDialog(true);
m_report->previewReport();
}
}
else
{
if(!data) qDebug() << "Wrong data: nullptr";
if(report_templte.isEmpty()) qDebug() << "Wrong report template: path is empty";
}
reset_report();
}
private:
void reset_report()
{
QGuiApplication::restoreOverrideCursor();
if(m_report) delete m_report;
m_report = nullptr;
}
friend class Singleton<reports_printer>;
private:
LimeReport::ReportEngine* m_report;
};
} // namespace report
m_report->dataManager()->addModel(REPORT_MODEL_NAME, data, false);
каким образом осуществыляется передача владения - копирование модели?
по теме колбэка потом еще гляну.
По последней... не понял, в чем пробема? Цепляешь к проекту qrc, запускаешь из проекта дизайнер
LimeReport::ReportEngine *m_report=new LimeReport::ReportEngine(this);
m_report->designReport();
и спокойно юзаешь твой qrc