Created initial XmlLabelCreator.

This commit is contained in:
Jim Evins
2015-09-05 17:06:56 -04:00
parent 54bfcca5a9
commit 68cb85ce36
13 changed files with 554 additions and 104 deletions
+3 -1
View File
@@ -21,6 +21,7 @@ set (glabels_sources
FieldMenu.cpp FieldMenu.cpp
FieldMenuItem.cpp FieldMenuItem.cpp
File.cpp File.cpp
FileUtil.cpp
Handles.cpp Handles.cpp
Help.cpp Help.cpp
LabelModel.cpp LabelModel.cpp
@@ -43,7 +44,8 @@ set (glabels_sources
TextNode.cpp TextNode.cpp
SimplePreview.cpp SimplePreview.cpp
View.cpp View.cpp
XmlLabel.cpp XmlLabelCreator.cpp
XmlLabelParser.cpp
) )
set (glabels_qobject_headers set (glabels_qobject_headers
+12
View File
@@ -149,6 +149,18 @@ namespace glabels
} }
uint32_t ColorNode::rgba( void ) const
{
uint32_t c =
mColor.red() << 24 |
mColor.green() << 16 |
mColor.blue() << 8 |
mColor.alpha();
return c;
}
#if TODO #if TODO
QColor ColorNode::expand( MergeRecord? record ) QColor ColorNode::expand( MergeRecord? record )
{ {
+3 -1
View File
@@ -75,7 +75,7 @@ namespace glabels
// //
const QColor& color( void ) const; const QColor& color( void ) const;
void setColor( const QColor& color ); void setColor( const QColor& color );
// //
// Key Property // Key Property
@@ -89,6 +89,8 @@ namespace glabels
// Methods // Methods
///////////////////////////////// /////////////////////////////////
public: public:
uint32_t rgba( void ) const;
#if TODO #if TODO
QColor expand( MergeRecord? record ); QColor expand( MergeRecord? record );
#endif #endif
+38 -9
View File
@@ -23,13 +23,17 @@
#include "MainWindow.h" #include "MainWindow.h"
#include "LabelModel.h" #include "LabelModel.h"
#include "NewLabelDialog.h" #include "NewLabelDialog.h"
#include "XmlLabel.h" #include "XmlLabelParser.h"
#include "XmlLabelCreator.h"
#include "FileUtil.h"
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QDebug> #include <QDebug>
namespace glabels namespace glabels
{ {
/// @TODO keep track of cwd between open/save dialogs
/// ///
/// New Label Dialog /// New Label Dialog
@@ -73,7 +77,7 @@ namespace glabels
); );
if ( !fileName.isEmpty() ) if ( !fileName.isEmpty() )
{ {
LabelModel *label = XmlLabel::readFile( fileName ); LabelModel *label = XmlLabelParser::readFile( fileName );
if ( label ) if ( label )
{ {
if ( window->isEmpty() ) if ( window->isEmpty() )
@@ -108,11 +112,14 @@ namespace glabels
{ {
return saveAs( window ); return saveAs( window );
} }
else
if ( !window->model()->isModified() )
{ {
qDebug() << "ACTION: file->Save: " << window->model()->filename();
return true; return true;
} }
XmlLabelCreator::writeFile( window->model(), window->model()->filename() );
return true;
} }
@@ -121,15 +128,37 @@ namespace glabels
/// ///
bool File::saveAs( MainWindow *window ) bool File::saveAs( MainWindow *window )
{ {
QString fileName = QString rawFilename =
QFileDialog::getSaveFileName( window, QFileDialog::getSaveFileName( window,
tr("Save label"), tr("Save Label As"),
".", ".",
tr("glabels files (*.glabels)") tr("glabels files (*.glabels);;All files (*)"),
0,
QFileDialog::DontConfirmOverwrite
); );
if ( !fileName.isEmpty() ) if ( !rawFilename.isEmpty() )
{ {
qDebug() << "ACTION: file->SaveAs: " << fileName; QString filename = FileUtil::addExtension( rawFilename, ".glabels" );
if ( QFileInfo(filename).exists() )
{
QMessageBox msgBox( window );
msgBox.setWindowTitle( tr("Save Label As") );
msgBox.setIcon( QMessageBox::Warning );
msgBox.setText( tr("%1 already exists.").arg(filename) );
msgBox.setInformativeText( tr("Do you want to replace it?") );
msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No );
msgBox.setDefaultButton( QMessageBox::No );
if ( msgBox.exec() == QMessageBox::No )
{
return saveAs( window );
}
}
XmlLabelCreator::writeFile( window->model(), filename );
window->model()->setFilename( filename );
return true; return true;
} }
+44
View File
@@ -0,0 +1,44 @@
/* FileUtil.cpp
*
* Copyright (C) 2015 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt 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 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FileUtil.h"
namespace glabels
{
namespace FileUtil
{
QString addExtension( const QString& rawFilename, const QString& extension )
{
if ( rawFilename.endsWith( extension ) )
{
return rawFilename;
}
return rawFilename + extension;
}
}
}
+38
View File
@@ -0,0 +1,38 @@
/* FileUtil.h
*
* Copyright (C) 2015 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt 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 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef glabels_FileUtil_h
#define glabels_FileUtil_h
#include <QString>
namespace glabels
{
namespace FileUtil
{
QString addExtension( const QString& rawFilename, const QString& extension );
}
}
#endif // glabels_FileUtil_h
+262
View File
@@ -0,0 +1,262 @@
/* XmlLabelCreator.cpp
*
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt 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 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "XmlLabelCreator.h"
#include "LabelModel.h"
#include "LabelModelObject.h"
#include "LabelModelBoxObject.h"
//#include "LabelObjectEllipse.h"
//#include "LabelObjectLine.h"
//#include "LabelObjectImage.h"
//#include "LabelObjectBarcode.h"
#include "libglabels/XmlTemplateCreator.h"
#include "libglabels/XmlUtil.h"
#include <QFile>
#include <QByteArray>
#include <QtDebug>
void
glabels::XmlLabelCreator::writeFile( const LabelModel* label, const QString& fileName )
{
QDomDocument doc;
createDoc( doc, label );
QString buffer = doc.toString( 2 );
QFile file( fileName );
if ( !file.open( QFile::WriteOnly | QFile::Text) )
{
qWarning() << "Error: Cannot write file " << fileName
<< ": " << file.errorString();
}
file.write( buffer.toStdString().c_str(), buffer.size() );
}
void
glabels::XmlLabelCreator::writeBuffer( const LabelModel* label, QString& buffer )
{
QDomDocument doc;
createDoc( doc, label );
buffer = doc.toString( 2 );
}
void
glabels::XmlLabelCreator::createDoc( QDomDocument& doc, const LabelModel* label )
{
QDomNode xmlNode( doc.createProcessingInstruction( "xml", "version=\"1.0\"" ) );
doc.appendChild( xmlNode );
QDomElement root = doc.createElement( "Glabels-document" );
doc.appendChild( root );
libglabels::XmlTemplateCreator().createTemplateNode( root, label->tmplate() );
createObjectsNode( root, label );
// TODO merge node
createDataNode( root, label );
}
void
glabels::XmlLabelCreator::createObjectsNode( QDomElement &parent, const LabelModel* label )
{
QDomDocument doc = parent.ownerDocument();
QDomElement node = doc.createElement( "Objects" );
parent.appendChild( node );
libglabels::XmlUtil::setStringAttr( node, "id", "0" );
libglabels::XmlUtil::setBoolAttr( node, "rotate", label->rotate() );
foreach ( LabelModelObject* object, label->objectList() )
{
if ( LabelModelBoxObject* boxObject = dynamic_cast<LabelModelBoxObject*>(object) )
{
createObjectBoxNode( node, boxObject );
}
// TODO: other object types
else
{
Q_ASSERT_X( false, "XmlLabelCreator::createObjectsNode", "Invalid object type." );
}
}
}
void
glabels::XmlLabelCreator::createObjectBoxNode( QDomElement &parent, const LabelModelBoxObject* object )
{
QDomDocument doc = parent.ownerDocument();
QDomElement node = doc.createElement( "Object-box" );
parent.appendChild( node );
/* position attrs */
libglabels::XmlUtil::setLengthAttr( node, "x", object->x0() );
libglabels::XmlUtil::setLengthAttr( node, "y", object->y0() );
/* size attrs */
libglabels::XmlUtil::setLengthAttr( node, "w", object->w() );
libglabels::XmlUtil::setLengthAttr( node, "h", object->h() );
/* line attrs */
libglabels::XmlUtil::setLengthAttr( node, "line_width", object->lineWidth() );
if ( object->lineColorNode().fieldFlag() )
{
libglabels::XmlUtil::setStringAttr( node, "line_color_field", object->lineColorNode().key() );
}
else
{
libglabels::XmlUtil::setUIntAttr( node, "line_color", object->lineColorNode().rgba() );
}
/* fill attrs */
if ( object->fillColorNode().fieldFlag() )
{
libglabels::XmlUtil::setStringAttr( node, "fill_color_field", object->fillColorNode().key() );
}
else
{
libglabels::XmlUtil::setUIntAttr( node, "fill_color", object->fillColorNode().rgba() );
}
/* affine attrs */
createAffineAttrs( node, object );
/* shadow attrs */
createShadowAttrs( node, object );
}
void
glabels::XmlLabelCreator::createObjectEllipseNode( QDomElement &parent, const LabelModelEllipseObject* object )
{
// TODO
}
void
glabels::XmlLabelCreator::createObjectLineNode( QDomElement &parent, const LabelModelLineObject* object )
{
// TODO
}
void
glabels::XmlLabelCreator::createObjectImageNode( QDomElement &parent, const LabelModelImageObject* object )
{
// TODO
}
void
glabels::XmlLabelCreator::createObjectBarcodeNode( QDomElement &parent, const LabelModelBarcodeObject* object )
{
// TODO
}
void
glabels::XmlLabelCreator::createObjectTextNode( QDomElement &parent, const LabelModelTextObject* object )
{
// TODO
}
void
glabels::XmlLabelCreator::createObjectTopLevelSpanNode( QDomElement &parent, const LabelModelTextObject* object )
{
// TODO
}
void
glabels::XmlLabelCreator::createAffineAttrs( QDomElement &node, const LabelModelObject* object )
{
QTransform a = object->matrix();
libglabels::XmlUtil::setDoubleAttr( node, "a0", a.m11() );
libglabels::XmlUtil::setDoubleAttr( node, "a1", a.m12() );
libglabels::XmlUtil::setDoubleAttr( node, "a2", a.m21() );
libglabels::XmlUtil::setDoubleAttr( node, "a3", a.m22() );
libglabels::XmlUtil::setDoubleAttr( node, "a4", a.dx() );
libglabels::XmlUtil::setDoubleAttr( node, "a5", a.dy() );
}
void
glabels::XmlLabelCreator::createShadowAttrs( QDomElement &node, const LabelModelObject* object )
{
if ( object->shadow() )
{
libglabels::XmlUtil::setBoolAttr( node, "shadow", object->shadow() );
libglabels::XmlUtil::setLengthAttr( node, "shadow_x", object->shadowX() );
libglabels::XmlUtil::setLengthAttr( node, "shadow_y", object->shadowY() );
if ( object->fillColorNode().fieldFlag() )
{
libglabels::XmlUtil::setStringAttr( node, "shadow_color_field", object->shadowColorNode().key() );
}
else
{
libglabels::XmlUtil::setUIntAttr( node, "shadow_color", object->shadowColorNode().rgba() );
}
libglabels::XmlUtil::setDoubleAttr( node, "shadow_opacity", object->shadowOpacity() );
}
}
void
glabels::XmlLabelCreator::createMergeNode( QDomElement &parent, const LabelModel* label )
{
// TODO
}
void
glabels::XmlLabelCreator::createDataNode( QDomElement &parent, const LabelModel* label )
{
// TODO
}
void
glabels::XmlLabelCreator::createPixdataNode( QDomElement &parent, const LabelModel* label, const QString& name )
{
// TODO
}
void
glabels::XmlLabelCreator::createSvgFileNode( QDomElement &parent, const LabelModel* label, const QString& name )
{
// TODO
}
+74
View File
@@ -0,0 +1,74 @@
/* XmlLabelCreator.h
*
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt 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 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef glabels_XmlLabelCreator_h
#define glabels_XmlLabelCreator_h
#include <QObject>
#include <QDomElement>
namespace glabels
{
class LabelModel;
class LabelModelObject;
class LabelModelBoxObject;
class LabelModelEllipseObject;
class LabelModelLineObject;
class LabelModelImageObject;
class LabelModelBarcodeObject;
class LabelModelTextObject;
///
/// XmlLabelCreator
///
class XmlLabelCreator : public QObject
{
Q_OBJECT
public:
static void writeFile( const LabelModel* label, const QString& fileName );
static void writeBuffer( const LabelModel* label, QString& buffer );
private:
static void createDoc( QDomDocument& doc, const LabelModel* label );
static void createRootNode( const LabelModel* label );
static void createObjectsNode( QDomElement &parent, const LabelModel* label );
static void createObjectBoxNode( QDomElement &parent, const LabelModelBoxObject* object );
static void createObjectEllipseNode( QDomElement &parent, const LabelModelEllipseObject* object );
static void createObjectLineNode( QDomElement &parent, const LabelModelLineObject* object );
static void createObjectImageNode( QDomElement &parent, const LabelModelImageObject* object );
static void createObjectBarcodeNode( QDomElement &parent, const LabelModelBarcodeObject* object );
static void createObjectTextNode( QDomElement &parent, const LabelModelTextObject* object );
static void createObjectTopLevelSpanNode( QDomElement &parent, const LabelModelTextObject* object );
static void createAffineAttrs( QDomElement &node, const LabelModelObject* object );
static void createShadowAttrs( QDomElement &node, const LabelModelObject* object );
static void createMergeNode( QDomElement &parent, const LabelModel* label );
static void createDataNode( QDomElement &parent, const LabelModel* label );
static void createPixdataNode( QDomElement &parent, const LabelModel* label, const QString& name );
static void createSvgFileNode( QDomElement &parent, const LabelModel* label, const QString& name );
};
}
#endif // glabels_XmlLabelCreator_h
@@ -1,4 +1,4 @@
/* XmlLabel.cpp /* XmlLabelParser.cpp
* *
* Copyright (C) 2014 Jim Evins <evins@snaught.com> * Copyright (C) 2014 Jim Evins <evins@snaught.com>
* *
@@ -18,7 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "XmlLabel.h" #include "XmlLabelParser.h"
#include "LabelModel.h" #include "LabelModel.h"
#include "LabelModelObject.h" #include "LabelModelObject.h"
@@ -36,7 +36,8 @@
#include <QtDebug> #include <QtDebug>
glabels::LabelModel* glabels::XmlLabel::readFile( const QString& fileName ) glabels::LabelModel*
glabels::XmlLabelParser::readFile( const QString& fileName )
{ {
QFile file( fileName ); QFile file( fileName );
@@ -87,7 +88,8 @@ glabels::LabelModel* glabels::XmlLabel::readFile( const QString& fileName )
} }
glabels::LabelModel* glabels::XmlLabel::readBuffer( const QString& buffer ) glabels::LabelModel*
glabels::XmlLabelParser::readBuffer( const QString& buffer )
{ {
QDomDocument doc; QDomDocument doc;
QString errorString; QString errorString;
@@ -113,40 +115,13 @@ glabels::LabelModel* glabels::XmlLabel::readBuffer( const QString& buffer )
} }
void glabels::XmlLabel::writeFile( const LabelModel* label, const QString& fileName ) void
{ glabels::XmlLabelParser::gunzip( const QByteArray& data, QByteArray& result )
QDomDocument doc;
createDoc( doc, label );
QString buffer = doc.toString( 4 );
QFile file( fileName );
if ( !file.open( QFile::WriteOnly | QFile::Text) )
{
qWarning() << "Error: Cannot read file " << fileName
<< ": " << file.errorString();
}
file.write( buffer.toStdString().c_str(), buffer.size() );
}
void glabels::XmlLabel::writeBuffer( const LabelModel* label, QString& buffer )
{
QDomDocument doc;
createDoc( doc, label );
buffer = doc.toString( 4 );
}
void glabels::XmlLabel::gunzip( const QByteArray& data, QByteArray& result )
{ {
result.clear(); result.clear();
if (data.size() <= 4) { if (data.size() <= 4) {
qWarning("XmlLabel::gunzip: Input data is truncated"); qWarning("XmlLabelParser::gunzip: Input data is truncated");
return; return;
} }
@@ -190,7 +165,8 @@ void glabels::XmlLabel::gunzip( const QByteArray& data, QByteArray& result )
} }
glabels::LabelModel* glabels::XmlLabel::parseRootNode( const QDomElement &node ) glabels::LabelModel*
glabels::XmlLabelParser::parseRootNode( const QDomElement &node )
{ {
using namespace libglabels; using namespace libglabels;
@@ -243,7 +219,8 @@ glabels::LabelModel* glabels::XmlLabel::parseRootNode( const QDomElement &node )
} }
void glabels::XmlLabel::parseObjectsNode( const QDomElement &node, LabelModel* label ) void
glabels::XmlLabelParser::parseObjectsNode( const QDomElement &node, LabelModel* label )
{ {
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() ) for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
{ {
@@ -281,7 +258,8 @@ void glabels::XmlLabel::parseObjectsNode( const QDomElement &node, LabelModel* l
} }
void glabels::XmlLabel::parseObjectBoxNode( const QDomElement &node, LabelModel* label ) void
glabels::XmlLabelParser::parseObjectBoxNode( const QDomElement &node, LabelModel* label )
{ {
using namespace libglabels; using namespace libglabels;
@@ -324,37 +302,44 @@ void glabels::XmlLabel::parseObjectBoxNode( const QDomElement &node, LabelModel*
} }
void glabels::XmlLabel::parseObjectEllipseNode( const QDomElement &node, LabelModel* label ) void
glabels::XmlLabelParser::parseObjectEllipseNode( const QDomElement &node, LabelModel* label )
{ {
} }
void glabels::XmlLabel::parseObjectLineNode( const QDomElement &node, LabelModel* label ) void
glabels::XmlLabelParser::parseObjectLineNode( const QDomElement &node, LabelModel* label )
{ {
} }
void glabels::XmlLabel::parseObjectImageNode( const QDomElement &node, LabelModel* label ) void
glabels::XmlLabelParser::parseObjectImageNode( const QDomElement &node, LabelModel* label )
{ {
} }
void glabels::XmlLabel::parseObjectBarcodeNode( const QDomElement &node, LabelModel* label ) void
glabels::XmlLabelParser::parseObjectBarcodeNode( const QDomElement &node, LabelModel* label )
{ {
} }
void glabels::XmlLabel::parseObjectTextNode( const QDomElement &node, LabelModel* label ) void
glabels::XmlLabelParser::parseObjectTextNode( const QDomElement &node, LabelModel* label )
{ {
} }
void glabels::XmlLabel::parseTopLevelSpanNode( const QDomElement &node, LabelModelTextObject* object ) void
glabels::XmlLabelParser::parseTopLevelSpanNode( const QDomElement &node, LabelModelTextObject* object )
{ {
} }
void glabels::XmlLabel::parseAffineAttrs( const QDomElement &node, LabelModelObject* object ) void
glabels::XmlLabelParser::parseAffineAttrs( const QDomElement &node, LabelModelObject* object )
{ {
using namespace libglabels; using namespace libglabels;
@@ -371,7 +356,8 @@ void glabels::XmlLabel::parseAffineAttrs( const QDomElement &node, LabelModelObj
} }
void glabels::XmlLabel::parseShadowAttrs( const QDomElement &node, LabelModelObject* object ) void
glabels::XmlLabelParser::parseShadowAttrs( const QDomElement &node, LabelModelObject* object )
{ {
using namespace libglabels; using namespace libglabels;
@@ -393,40 +379,27 @@ void glabels::XmlLabel::parseShadowAttrs( const QDomElement &node, LabelModelObj
} }
void glabels::XmlLabel::parseMergeNode( const QDomElement &node, LabelModel* label ) void
glabels::XmlLabelParser::parseMergeNode( const QDomElement &node, LabelModel* label )
{ {
} }
void glabels::XmlLabel::parseDataNode( const QDomElement &node, LabelModel* label ) void
glabels::XmlLabelParser::parseDataNode( const QDomElement &node, LabelModel* label )
{ {
} }
void glabels::XmlLabel::parsePixdataNode( const QDomElement &node, LabelModel* label ) void
glabels::XmlLabelParser::parsePixdataNode( const QDomElement &node, LabelModel* label )
{ {
} }
void glabels::XmlLabel::parseFileNode( const QDomElement &node, LabelModel* label ) void
glabels::XmlLabelParser::parseFileNode( const QDomElement &node, LabelModel* label )
{ {
} }
void glabels::XmlLabel::createDoc( QDomDocument& doc, const LabelModel* label ) {}
void glabels::XmlLabel::createRootNode( const LabelModel* label ) {}
void glabels::XmlLabel::createObjectsNode( QDomElement &parent, const LabelModel* label ) {}
void glabels::XmlLabel::createObjectBoxNode( QDomElement &parent, const LabelModelBoxObject* object ) {}
void glabels::XmlLabel::createObjectEllipseNode( QDomElement &parent, const LabelModelEllipseObject* object ) {}
void glabels::XmlLabel::createObjectLineNode( QDomElement &parent, const LabelModelLineObject* object ) {}
void glabels::XmlLabel::createObjectImageNode( QDomElement &parent, const LabelModelImageObject* object ) {}
void glabels::XmlLabel::createObjectBarcodeNode( QDomElement &parent, const LabelModelBarcodeObject* object ) {}
void glabels::XmlLabel::createObjectTextNode( QDomElement &parent, const LabelModelTextObject* object ) {}
void glabels::XmlLabel::createObjectTopLevelSpanNode( QDomElement &parent, const LabelModelTextObject* object ) {}
void glabels::XmlLabel::createffineAttrs( QDomElement &node, const LabelModelObject* object ) {}
void glabels::XmlLabel::createShadowAttrs( QDomElement &node, const LabelModelObject* object ) {}
void glabels::XmlLabel::createMergeNode( QDomElement &node, LabelModel* label ) {}
void glabels::XmlLabel::createDataNode( QDomElement &node, LabelModel* label ) {}
void glabels::XmlLabel::createPixdataNode( QDomElement &node, LabelModel* label, const QString& name ) {}
void glabels::XmlLabel::createSvgFileNode( QDomElement &node, LabelModel* label, const QString& name ) {}
@@ -1,4 +1,4 @@
/* XmlLabel.h /* XmlLabelParser.h
* *
* Copyright (C) 2014 Jim Evins <evins@snaught.com> * Copyright (C) 2014 Jim Evins <evins@snaught.com>
* *
@@ -18,8 +18,8 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef glabels_XmlLabel_h #ifndef glabels_XmlLabelParser_h
#define glabels_XmlLabel_h #define glabels_XmlLabelParser_h
#include <QObject> #include <QObject>
@@ -39,17 +39,15 @@ namespace glabels
/// ///
/// XmlLabel Actions /// XmlLabelParser
/// ///
class XmlLabel : public QObject class XmlLabelParser : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
static LabelModel* readFile( const QString& fileName ); static LabelModel* readFile( const QString& fileName );
static LabelModel* readBuffer( const QString& buffer ); static LabelModel* readBuffer( const QString& buffer );
static void writeFile( const LabelModel* label, const QString& fileName );
static void writeBuffer( const LabelModel* label, QString& buffer );
private: private:
static void gunzip( const QByteArray& gzippedData, QByteArray& data ); static void gunzip( const QByteArray& gzippedData, QByteArray& data );
@@ -69,25 +67,8 @@ namespace glabels
static void parsePixdataNode( const QDomElement &node, LabelModel* label ); static void parsePixdataNode( const QDomElement &node, LabelModel* label );
static void parseFileNode( const QDomElement &node, LabelModel* label ); static void parseFileNode( const QDomElement &node, LabelModel* label );
static void createDoc( QDomDocument& doc, const LabelModel* label );
static void createRootNode( const LabelModel* label );
static void createObjectsNode( QDomElement &parent, const LabelModel* label );
static void createObjectBoxNode( QDomElement &parent, const LabelModelBoxObject* object );
static void createObjectEllipseNode( QDomElement &parent, const LabelModelEllipseObject* object );
static void createObjectLineNode( QDomElement &parent, const LabelModelLineObject* object );
static void createObjectImageNode( QDomElement &parent, const LabelModelImageObject* object );
static void createObjectBarcodeNode( QDomElement &parent, const LabelModelBarcodeObject* object );
static void createObjectTextNode( QDomElement &parent, const LabelModelTextObject* object );
static void createObjectTopLevelSpanNode( QDomElement &parent, const LabelModelTextObject* object );
static void createffineAttrs( QDomElement &node, const LabelModelObject* object );
static void createShadowAttrs( QDomElement &node, const LabelModelObject* object );
static void createMergeNode( QDomElement &node, LabelModel* label );
static void createDataNode( QDomElement &node, LabelModel* label );
static void createPixdataNode( QDomElement &node, LabelModel* label, const QString& name );
static void createSvgFileNode( QDomElement &node, LabelModel* label, const QString& name );
}; };
} }
#endif // glabels_XmlLabel_h #endif // glabels_XmlLabelParser_h
+4 -1
View File
@@ -94,7 +94,10 @@ namespace libglabels
XmlUtil::setStringAttr( node, "description", tmplate->description() ); XmlUtil::setStringAttr( node, "description", tmplate->description() );
createMetaNode( node, "product_url", tmplate->productUrl() ); if ( !tmplate->productUrl().isEmpty() )
{
createMetaNode( node, "product_url", tmplate->productUrl() );
}
#if TODO #if TODO
foreach ( QString categoryId, tmplate->categoryIds() ) foreach ( QString categoryId, tmplate->categoryIds() )
{ {
+1 -1
View File
@@ -113,7 +113,7 @@ namespace libglabels
QString name = XmlUtil::getStringAttr( node, "name", "" ); QString name = XmlUtil::getStringAttr( node, "name", "" );
if ( name != "" ) if ( name != "" )
{ {
QStringList fields = name.split( " " ); QStringList fields = name.split( " ", QString::SkipEmptyParts );
brand = fields[0]; brand = fields[0];
part = fields[1]; part = fields[1];
} }
+30
View File
@@ -44,12 +44,16 @@ namespace libglabels
Units XmlUtil::defaultUnits() Units XmlUtil::defaultUnits()
{ {
init();
return mDefaultUnits; return mDefaultUnits;
} }
void XmlUtil::setDefaultUnits( const Units& defaultUnits ) void XmlUtil::setDefaultUnits( const Units& defaultUnits )
{ {
init();
mDefaultUnits = defaultUnits; mDefaultUnits = defaultUnits;
} }
@@ -58,6 +62,8 @@ namespace libglabels
const QString& name, const QString& name,
const QString& default_value ) const QString& default_value )
{ {
init();
return node.attribute( name, default_value ); return node.attribute( name, default_value );
} }
@@ -66,6 +72,8 @@ namespace libglabels
const QString& name, const QString& name,
double default_value ) double default_value )
{ {
init();
QString valueString = node.attribute( name, "" ); QString valueString = node.attribute( name, "" );
if ( valueString != "" ) if ( valueString != "" )
{ {
@@ -91,6 +99,8 @@ namespace libglabels
const QString& name, const QString& name,
bool default_value ) bool default_value )
{ {
init();
QString valueString = node.attribute( name, "" ); QString valueString = node.attribute( name, "" );
if ( valueString != "" ) if ( valueString != "" )
{ {
@@ -126,6 +136,8 @@ namespace libglabels
const QString& name, const QString& name,
int default_value ) int default_value )
{ {
init();
QString valueString = node.attribute( name, "" ); QString valueString = node.attribute( name, "" );
if ( valueString != "" ) if ( valueString != "" )
{ {
@@ -151,6 +163,8 @@ namespace libglabels
const QString& name, const QString& name,
uint32_t default_value ) uint32_t default_value )
{ {
init();
QString valueString = node.attribute( name, "" ); QString valueString = node.attribute( name, "" );
if ( valueString != "" ) if ( valueString != "" )
{ {
@@ -177,6 +191,8 @@ namespace libglabels
const QString& name, const QString& name,
const QString& default_value ) const QString& default_value )
{ {
init();
// TODO: are translations done in a compatable way, so that we can use "_name" attributes? // TODO: are translations done in a compatable way, so that we can use "_name" attributes?
QString i18nString = node.attribute( QString("_").append(name), "" ); QString i18nString = node.attribute( QString("_").append(name), "" );
@@ -193,6 +209,8 @@ namespace libglabels
const QString& name, const QString& name,
double default_value ) double default_value )
{ {
init();
QString valueString = node.attribute( name, "" ); QString valueString = node.attribute( name, "" );
if ( valueString != "" ) if ( valueString != "" )
{ {
@@ -223,6 +241,8 @@ namespace libglabels
const QString& name, const QString& name,
const QString& value ) const QString& value )
{ {
init();
node.setAttribute( name, value ); node.setAttribute( name, value );
} }
@@ -231,6 +251,8 @@ namespace libglabels
const QString& name, const QString& name,
double value ) double value )
{ {
init();
node.setAttribute( name, QString::number(value) ); node.setAttribute( name, QString::number(value) );
} }
@@ -239,6 +261,8 @@ namespace libglabels
const QString& name, const QString& name,
bool value ) bool value )
{ {
init();
node.setAttribute( name, value ? "true" : "false" ); node.setAttribute( name, value ? "true" : "false" );
} }
@@ -247,6 +271,8 @@ namespace libglabels
const QString& name, const QString& name,
int value ) int value )
{ {
init();
node.setAttribute( name, QString::number(value) ); node.setAttribute( name, QString::number(value) );
} }
@@ -255,6 +281,8 @@ namespace libglabels
const QString& name, const QString& name,
uint32_t value ) uint32_t value )
{ {
init();
node.setAttribute( name, "0x" + QString::number(value, 16) ); node.setAttribute( name, "0x" + QString::number(value, 16) );
} }
@@ -263,6 +291,8 @@ namespace libglabels
const QString& name, const QString& name,
double value ) double value )
{ {
init();
value *= mDefaultUnits.unitsPerPoint(); value *= mDefaultUnits.unitsPerPoint();
node.setAttribute( name, QString::number(value) + mDefaultUnits.id() ); node.setAttribute( name, QString::number(value) + mDefaultUnits.id() );
} }