2019-05-29 16:32:58 +03:00
|
|
|
#include "lrpreparedpages.h"
|
|
|
|
|
|
|
|
#include "serializators/lrxmlreader.h"
|
|
|
|
#include "serializators/lrxmlwriter.h"
|
|
|
|
|
|
|
|
namespace LimeReport {
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool PreparedPages::loadFromFile(const QString& fileName)
|
2019-05-29 16:32:58 +03:00
|
|
|
{
|
|
|
|
ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName);
|
|
|
|
return readPages(reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PreparedPages::loadFromString(const QString data)
|
|
|
|
{
|
|
|
|
ItemsReaderIntf::Ptr reader = StringXMLreader::create(data);
|
|
|
|
return readPages(reader);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool PreparedPages::loadFromByteArray(QByteArray* data)
|
2019-05-29 16:32:58 +03:00
|
|
|
{
|
|
|
|
ItemsReaderIntf::Ptr reader = ByteArrayXMLReader::create(data);
|
|
|
|
return readPages(reader);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
bool PreparedPages::saveToFile(const QString& fileName)
|
2019-05-29 16:32:58 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!fileName.isEmpty()) {
|
|
|
|
QScopedPointer<ItemsWriterIntf> writer(new XMLWriter());
|
|
|
|
foreach (PageItemDesignIntf::Ptr page, *m_pages) {
|
2019-05-29 16:32:58 +03:00
|
|
|
writer->putItem(page.data());
|
|
|
|
}
|
|
|
|
return writer->saveToFile(fileName);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString PreparedPages::saveToString()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
QScopedPointer<ItemsWriterIntf> writer(new XMLWriter());
|
|
|
|
foreach (PageItemDesignIntf::Ptr page, *m_pages) {
|
2019-05-29 16:32:58 +03:00
|
|
|
writer->putItem(page.data());
|
|
|
|
}
|
|
|
|
return writer->saveToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray PreparedPages::saveToByteArray()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
QScopedPointer<ItemsWriterIntf> writer(new XMLWriter());
|
|
|
|
foreach (PageItemDesignIntf::Ptr page, *m_pages) {
|
2019-05-29 16:32:58 +03:00
|
|
|
writer->putItem(page.data());
|
|
|
|
}
|
|
|
|
return writer->saveToByteArray();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void PreparedPages::clear() { m_pages->clear(); }
|
2019-05-29 16:32:58 +03:00
|
|
|
|
|
|
|
bool PreparedPages::readPages(ItemsReaderIntf::Ptr reader)
|
|
|
|
{
|
2020-06-02 14:54:58 +03:00
|
|
|
clear();
|
2024-09-04 17:31:16 +03:00
|
|
|
if (reader->first()) {
|
2019-05-29 16:32:58 +03:00
|
|
|
PageItemDesignIntf::Ptr page = PageItemDesignIntf::create(0);
|
|
|
|
if (!reader->readItem(page.data()))
|
|
|
|
return false;
|
|
|
|
else {
|
|
|
|
m_pages->append(page);
|
2024-09-04 17:31:16 +03:00
|
|
|
while (reader->next()) {
|
2019-05-29 16:32:58 +03:00
|
|
|
page = PageItemDesignIntf::create(0);
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!reader->readItem(page.data())) {
|
2019-05-29 16:32:58 +03:00
|
|
|
m_pages->clear();
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
m_pages->append(page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
} // namespace LimeReport
|