Files
qelectrotech-source-mirror/sources/container/qetzreader.cpp
T
ispyisail 93157a579d Move reading and writing a .qetz out of QETProject
QETZ-DB-FIRST stage 3a. QETProject::openFile() unzipped and joined a .qetz
itself and kept what it held beside the document in three members of its
own (the entries, each folio's part, the pictures), and writeContainer()
split and zipped it. Both now live in their own classes under
sources/container: QetzReader reads a .qet or a .qetz and keeps what a
.qetz holds for as long as the project is open; QetzWriter writes the
document as a .qetz.

No behaviour change: the same calls in the same order. This is the seam
stage 3b needs, where opening fills the working database straight from
project.sqlite instead of rebuilding it from the joined XML.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 18:31:37 +13:00

51 lines
1.6 KiB
C++

/*
Copyright 2006-2026 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qetzreader.h"
#include "qetzip.h"
/**
@brief QetzReader::read
Read @p content, the bytes of a .qet or a .qetz, into @p document.
For a .qetz, its entries, folio parts, pictures and format are kept.
@return false, with @p error set, if it cannot be read
*/
bool QetzReader::read(const QByteArray &content, QDomDocument *document, QString *error)
{
m_files.clear();
m_folio_parts.clear();
m_format = 0;
bool read = false;
if (QetContainer::isZip(content)) {
QList<QetZip::Entry> entries;
read = QetZip::fromBytes(content, &entries, error)
&& QetContainer::join(entries, document, error, &m_folio_parts,
&m_pictures, &m_format);
if (read)
for (const QetZip::Entry &entry : std::as_const(entries))
m_files.insert(entry.name, entry.data);
} else {
read = QetContainer::readDocument(content, document, error);
}
if (!read) {
m_pictures.clear();
m_folio_parts.clear();
}
return read;
}