Initial parsing of glabels files.

This commit is contained in:
Jim Evins
2014-09-25 22:56:24 -04:00
parent b318efd68e
commit 3d9875545c
15 changed files with 671 additions and 139 deletions
+1
View File
@@ -33,6 +33,7 @@ set (glabels_sources
NewLabelDialog.cpp
SimplePreview.cpp
View.cpp
XmlLabel.cpp
)
set (glabels_qobject_headers
+13
View File
@@ -42,6 +42,19 @@ namespace glabels
}
///
/// Constructor From Data
///
ColorNode::ColorNode( bool fieldFlag, uint32_t rgba, const QString& key )
: mFieldFlag(fieldFlag), mKey(key)
{
mColor = QColor( (rgba >> 24) & 0xFF,
(rgba >> 16) & 0xFF,
(rgba >> 8) & 0xFF,
(rgba ) & 0xFF );
}
///
/// Constructor From Color
///
+3
View File
@@ -23,6 +23,7 @@
#include <QString>
#include <QColor>
#include <stdint.h>
namespace glabels
@@ -42,6 +43,8 @@ namespace glabels
ColorNode( bool fieldFlag, const QColor& color, const QString& key );
ColorNode( bool fieldFlag, uint32_t rgba, const QString& key );
ColorNode( const QColor& color );
ColorNode( const QString& key );
+24 -2
View File
@@ -1,6 +1,6 @@
/* File.cpp
*
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
@@ -23,6 +23,7 @@
#include "MainWindow.h"
#include "LabelModel.h"
#include "NewLabelDialog.h"
#include "XmlLabel.h"
#include <QFileDialog>
#include <QMessageBox>
@@ -54,7 +55,28 @@ namespace glabels
);
if ( !fileName.isEmpty() )
{
std::cout << "ACTION: file->Open: " << fileName.toStdString() << std::endl;
LabelModel *label = XmlLabel::readFile( fileName );
if ( label )
{
if ( window->isEmpty() )
{
window->setModel( label );
}
else
{
MainWindow *newWindow = new MainWindow();
newWindow->setModel( label );
newWindow->show();
}
}
else
{
QMessageBox msgBox;
msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") );
msgBox.setStandardButtons( QMessageBox::Ok );
msgBox.setDefaultButton( QMessageBox::Ok );
msgBox.exec();
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
/* File.h
*
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
+13 -29
View File
@@ -1,6 +1,6 @@
/* MainWindow.cpp
*
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
@@ -54,42 +54,16 @@ namespace glabels
///
MainWindow::MainWindow()
{
/////////////// TEMPORARY TESTING ///////////////
#if 0
QLabel* tmp = new QLabel( "Coming Soon..." );
setCentralWidget( tmp );
#else
mModel = new LabelModel();
const libglabels::Template* tmplate = libglabels::Db::lookupTemplateFromName( "Avery 5163" );
mModel->setTmplate( tmplate );
LabelModelBoxObject* object = new LabelModelBoxObject();
object->setW( 36 );
object->setH( 36 );
object->setX0( 72 );
object->setY0( 72 );
object->setFillColorNode( ColorNode( QColor( 0, 255, 0 ) ) );
object->setLineColorNode( ColorNode( QColor( 0, 0, 0 ) ) );
object->setLineWidth( 4 );
object->setShadowColorNode( ColorNode( QColor( 0, 0, 0 ) ) );
object->setShadowOpacity( 0.25 );
object->setShadowX( 5 );
object->setShadowY( 5 );
object->setShadow( true );
mModel->addObject( object );
mView = new View();
mView->setModel( mModel );
setCentralWidget( mView );
#endif
/////////////////////////////////////////////////
mModel = 0;
createActions();
createMenus();
createToolBars();
createStatusBar();
setDocVerbsEnabled( true );
setDocVerbsEnabled( false );
setPasteVerbsEnabled( false );
readSettings();
@@ -116,6 +90,16 @@ namespace glabels
}
///
/// Set model accessor
///
void MainWindow::setModel( LabelModel *label )
{
mModel = label;
mView->setModel( mModel );
}
///
/// Is window empty?
///
+2 -1
View File
@@ -1,6 +1,6 @@
/* MainWindow.h
*
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
@@ -59,6 +59,7 @@ namespace glabels
/////////////////////////////////////
public:
LabelModel* model() const;
void setModel( LabelModel* label );
bool isEmpty() const;
static QList<MainWindow *> windowList();
+365
View File
@@ -0,0 +1,365 @@
/* XmlLabel.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 "XmlLabel.h"
#include "LabelModel.h"
#include "LabelModelObject.h"
#include "LabelModelBoxObject.h"
//#include "LabelObjectEllipse.h"
//#include "LabelObjectLine.h"
//#include "LabelObjectImage.h"
//#include "LabelObjectBarcode.h"
#include "libglabels/XmlTemplateParser.h"
#include "libglabels/XmlUtil.h"
#include <QFile>
#include <QtDebug>
glabels::LabelModel* glabels::XmlLabel::readFile( const QString& fileName )
{
QFile file( fileName );
if ( !file.open( QFile::ReadOnly | QFile::Text) )
{
qWarning() << "Error: Cannot read file " << qPrintable(fileName)
<< ": " << file.errorString();
return 0;
}
QDomDocument doc;
QString errorString;
int errorLine;
int errorColumn;
if ( !doc.setContent( &file, false, &errorString, &errorLine, &errorColumn ) )
{
qWarning() << "Error: Parse error at line " << errorLine
<< "column " << errorColumn
<< ": " << errorString;
return 0;
}
QDomElement root = doc.documentElement();
if ( root.tagName() != "Glabels-document" )
{
qWarning() << "Error: Not a Glabels-document file";
return 0;
}
return parseRootNode( root );
}
glabels::LabelModel* glabels::XmlLabel::readBuffer( const QString& buffer )
{
QDomDocument doc;
QString errorString;
int errorLine;
int errorColumn;
if ( !doc.setContent( buffer, false, &errorString, &errorLine, &errorColumn ) )
{
qWarning() << "Error: Parse error at line " << errorLine
<< "column " << errorColumn
<< ": " << errorString;
return 0;
}
QDomElement root = doc.documentElement();
if ( root.tagName() != "Glabels-document" )
{
qWarning() << "Error: Not a Glabels-document file";
return 0;
}
return parseRootNode( root );
}
void glabels::XmlLabel::writeFile( const LabelModel* label, const QString& fileName )
{
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 );
}
glabels::LabelModel* glabels::XmlLabel::parseRootNode( const QDomElement &node )
{
using namespace libglabels;
LabelModel* label = new LabelModel();
/* Pass 1, extract data nodes to pre-load cache. */
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
{
if ( child.toElement().tagName() == "Data" )
{
parseDataNode( child.toElement(), label );
}
}
/* Pass 2, now extract everything else. */
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
{
QString tagName = child.toElement().tagName();
if ( tagName == "Template" )
{
Template* tmplate = XmlTemplateParser().parseTemplateNode( child.toElement() );
if ( tmplate == 0 )
{
qWarning() << "Unable to parse template";
return 0;
}
label->setTmplate( tmplate );
}
else if ( tagName == "Objects" )
{
parseObjectsNode( child.toElement(), label );
}
else if ( tagName == "Merge" )
{
parseMergeNode( child.toElement(), label );
}
else if ( tagName == "Data" )
{
/* Handled in pass 1. */
}
else if ( !child.isComment() )
{
qWarning() << "Unexpected" << node.tagName() << "child:" << tagName;
}
}
return label;
}
void glabels::XmlLabel::parseObjectsNode( const QDomElement &node, LabelModel* label )
{
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
{
QString tagName = child.toElement().tagName();
if ( tagName == "Object-box" )
{
parseObjectBoxNode( child.toElement(), label );
}
else if ( tagName == "Object-ellipse" )
{
parseObjectEllipseNode( child.toElement(), label );
}
else if ( tagName == "Object-line" )
{
parseObjectLineNode( child.toElement(), label );
}
else if ( tagName == "Object-image" )
{
parseObjectImageNode( child.toElement(), label );
}
else if ( tagName == "Object-barcode" )
{
parseObjectBarcodeNode( child.toElement(), label );
}
else if ( tagName == "Object-text" )
{
parseObjectTextNode( child.toElement(), label );
}
else if ( !child.isComment() )
{
qWarning() << "Unexpected" << node.tagName() << "child:" << tagName;
}
}
}
void glabels::XmlLabel::parseObjectBoxNode( const QDomElement &node, LabelModel* label )
{
using namespace libglabels;
LabelModelBoxObject* object = new LabelModelBoxObject();
label->addObject( object );
/* position attrs */
object->setX0( XmlUtil::getLengthAttr( node, "x", 0.0 ) );
object->setY0( XmlUtil::getLengthAttr( node, "y", 0.0 ) );
/* size attrs */
object->setW( XmlUtil::getLengthAttr( node, "w", 0 ) );
object->setH( XmlUtil::getLengthAttr( node, "h", 0 ) );
/* line attrs */
object->setLineWidth( XmlUtil::getLengthAttr( node, "line_width", 1.0 ) );
{
QString key = XmlUtil::getStringAttr( node, "line_color_field", "" );
bool field_flag = !key.isEmpty();
uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0 );
object->setLineColorNode( ColorNode( field_flag, color, key ) );
}
/* fill attrs */
{
QString key = XmlUtil::getStringAttr( node, "line_color_field", "" );
bool field_flag = !key.isEmpty();
uint32_t color = XmlUtil::getUIntAttr( node, "fill_color", 0 );
object->setFillColorNode( ColorNode( field_flag, color, key ) );
}
/* affine attrs */
parseAffineAttrs( node, object );
/* shadow attrs */
parseShadowAttrs( node, object );
}
void glabels::XmlLabel::parseObjectEllipseNode( const QDomElement &node, LabelModel* label )
{
}
void glabels::XmlLabel::parseObjectLineNode( const QDomElement &node, LabelModel* label )
{
}
void glabels::XmlLabel::parseObjectImageNode( const QDomElement &node, LabelModel* label )
{
}
void glabels::XmlLabel::parseObjectBarcodeNode( const QDomElement &node, LabelModel* label )
{
}
void glabels::XmlLabel::parseObjectTextNode( const QDomElement &node, LabelModel* label )
{
}
void glabels::XmlLabel::parseTopLevelSpanNode( const QDomElement &node, LabelModelTextObject* object )
{
}
void glabels::XmlLabel::parseAffineAttrs( const QDomElement &node, LabelModelObject* object )
{
using namespace libglabels;
double a[6];
a[0] = XmlUtil::getDoubleAttr( node, "a0", 0.0 );
a[1] = XmlUtil::getDoubleAttr( node, "a1", 0.0 );
a[2] = XmlUtil::getDoubleAttr( node, "a2", 0.0 );
a[3] = XmlUtil::getDoubleAttr( node, "a3", 0.0 );
a[4] = XmlUtil::getDoubleAttr( node, "a4", 0.0 );
a[5] = XmlUtil::getDoubleAttr( node, "a5", 0.0 );
object->setMatrix( QTransform( a[0], a[1], a[2], a[3], a[4], a[5] ) );
}
void glabels::XmlLabel::parseShadowAttrs( const QDomElement &node, LabelModelObject* object )
{
using namespace libglabels;
object->setShadow( XmlUtil::getBoolAttr( node, "shadow", false ) );
if ( object->shadow() )
{
object->setShadowX( XmlUtil::getLengthAttr( node, "shadow_x", 0.0 ) );
object->setShadowY( XmlUtil::getLengthAttr( node, "shadow_y", 0.0 ) );
QString key = XmlUtil::getStringAttr( node, "shadow_color_field", "" );
bool field_flag = !key.isEmpty();
uint32_t color = XmlUtil::getUIntAttr( node, "shadow_color", 0 );
object->setShadowColorNode( ColorNode( field_flag, color, key ) );
object->setShadowOpacity( XmlUtil::getLengthAttr( node, "shadow_y", 1.0 ) );
}
}
void glabels::XmlLabel::parseMergeNode( const QDomElement &node, LabelModel* label )
{
}
void glabels::XmlLabel::parseDataNode( const QDomElement &node, LabelModel* label )
{
}
void glabels::XmlLabel::parsePixdataNode( const QDomElement &node, LabelModel* label )
{
}
void glabels::XmlLabel::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 ) {}
+92
View File
@@ -0,0 +1,92 @@
/* XmlLabel.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_XmlLabel_h
#define glabels_XmlLabel_h
#include <QObject>
#include <QDomElement>
namespace glabels
{
class LabelModel;
class LabelModelObject;
class LabelModelBoxObject;
class LabelModelEllipseObject;
class LabelModelLineObject;
class LabelModelImageObject;
class LabelModelBarcodeObject;
class LabelModelTextObject;
///
/// XmlLabel Actions
///
class XmlLabel : public QObject
{
Q_OBJECT
public:
static LabelModel* readFile( const QString& fileName );
static LabelModel* readBuffer( const QString& buffer );
static void writeFile( const LabelModel* label, const QString& fileName );
static void writeBuffer( const LabelModel* label, QString& buffer );
private:
static LabelModel* parseRootNode( const QDomElement &node );
static void parseObjectsNode( const QDomElement &node, LabelModel* label );
static void parseObjectBoxNode( const QDomElement &node, LabelModel* label );
static void parseObjectEllipseNode( const QDomElement &node, LabelModel* label );
static void parseObjectLineNode( const QDomElement &node, LabelModel* label );
static void parseObjectImageNode( const QDomElement &node, LabelModel* label );
static void parseObjectBarcodeNode( const QDomElement &node, LabelModel* label );
static void parseObjectTextNode( const QDomElement &node, LabelModel* label );
static void parseTopLevelSpanNode( const QDomElement &node, LabelModelTextObject* object );
static void parseAffineAttrs( const QDomElement &node, LabelModelObject* object );
static void parseShadowAttrs( const QDomElement &node, LabelModelObject* object );
static void parseMergeNode( const QDomElement &node, LabelModel* label );
static void parseDataNode( const QDomElement &node, LabelModel* label );
static void parsePixdataNode( 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
+2 -2
View File
@@ -92,8 +92,8 @@ namespace libglabels
void XmlCategoryParser::parseCategoryNode( const QDomElement &node )
{
QString id = XmlUtil::getAttr( node, "id", "" );
QString name = XmlUtil::getAttrI18n( node, "name", "" );
QString id = XmlUtil::getStringAttr( node, "id", "" );
QString name = XmlUtil::getI18nAttr( node, "name", "" );
Category *category = new Category( id, name );
if ( category != NULL )
+5 -5
View File
@@ -92,13 +92,13 @@ namespace libglabels
void XmlPaperParser::parsePaperSizeNode( const QDomElement &node )
{
QString id = XmlUtil::getAttr( node, "id", "" );
QString name = XmlUtil::getAttrI18n( node, "name", "" );
QString id = XmlUtil::getStringAttr( node, "id", "" );
QString name = XmlUtil::getI18nAttr( node, "name", "" );
double width = XmlUtil::getAttrLength( node, "width", 0 );
double height = XmlUtil::getAttrLength( node, "height", 0 );
double width = XmlUtil::getLengthAttr( node, "width", 0 );
double height = XmlUtil::getLengthAttr( node, "height", 0 );
QString pwgSize = XmlUtil::getAttr( node, "pwg_size", "" );
QString pwgSize = XmlUtil::getStringAttr( node, "pwg_size", "" );
Paper *paper = new Paper( id, name, width, height, pwgSize );
if ( paper != NULL )
+53 -53
View File
@@ -106,13 +106,13 @@ namespace libglabels
Template *XmlTemplateParser::parseTemplateNode( const QDomElement &node )
{
QString brand = XmlUtil::getAttr( node, "brand", "" );
QString part = XmlUtil::getAttr( node, "part", "" );
QString brand = XmlUtil::getStringAttr( node, "brand", "" );
QString part = XmlUtil::getStringAttr( node, "part", "" );
if ( (brand == "") || (part == "") )
{
// Try the deprecated "name" attribute.
QString name = XmlUtil::getAttr( node, "name", "" );
QString name = XmlUtil::getStringAttr( node, "name", "" );
if ( name != "" )
{
QStringList fields = name.split( " " );
@@ -129,7 +129,7 @@ namespace libglabels
Template *tmplate = NULL;
QString equivPart = XmlUtil::getAttr( node, "equiv", "" );
QString equivPart = XmlUtil::getStringAttr( node, "equiv", "" );
if ( equivPart != NULL )
{
tmplate = Template::fromEquiv( brand, part, equivPart );
@@ -150,8 +150,8 @@ namespace libglabels
}
else
{
QString description = XmlUtil::getAttrI18n( node, "description", "" );
QString paperId = XmlUtil::getAttr( node, "size", "" );
QString description = XmlUtil::getI18nAttr( node, "description", "" );
QString paperId = XmlUtil::getStringAttr( node, "size", "" );
if ( !Db::isPaperIdOther( paperId ) )
{
@@ -167,8 +167,8 @@ namespace libglabels
}
else
{
double width = XmlUtil::getAttrLength( node, "width", 0 );
double height = XmlUtil::getAttrLength( node, "height", 0 );
double width = XmlUtil::getLengthAttr( node, "width", 0 );
double height = XmlUtil::getLengthAttr( node, "height", 0 );
tmplate = new Template( brand, part, description, paperId, width, height );
}
@@ -210,13 +210,13 @@ namespace libglabels
void XmlTemplateParser::parseMetaNode( const QDomElement &node, Template *tmplate )
{
QString productUrl = XmlUtil::getAttr( node, "product_url", "" );
QString productUrl = XmlUtil::getStringAttr( node, "product_url", "" );
if ( productUrl != "" )
{
tmplate->setProductUrl( productUrl );
}
QString categoryId = XmlUtil::getAttr( node, "category", "" );
QString categoryId = XmlUtil::getStringAttr( node, "category", "" );
if ( categoryId != "" )
{
tmplate->addCategory( categoryId );
@@ -226,15 +226,15 @@ namespace libglabels
void XmlTemplateParser::parseLabelRectangleNode( const QDomElement &node, Template *tmplate )
{
QString id = XmlUtil::getAttr( node, "id", "0" );
QString id = XmlUtil::getStringAttr( node, "id", "0" );
double w = XmlUtil::getAttrLength( node, "width", 0 );
double h = XmlUtil::getAttrLength( node, "height", 0 );
double r = XmlUtil::getAttrLength( node, "round", 0 );
double w = XmlUtil::getLengthAttr( node, "width", 0 );
double h = XmlUtil::getLengthAttr( node, "height", 0 );
double r = XmlUtil::getLengthAttr( node, "round", 0 );
double xWaste, yWaste;
double waste = XmlUtil::getAttrLength( node, "waste", -1 );
double waste = XmlUtil::getLengthAttr( node, "waste", -1 );
if ( waste >= 0 )
{
xWaste = waste;
@@ -242,8 +242,8 @@ namespace libglabels
}
else
{
xWaste = XmlUtil::getAttrLength( node, "x_waste", 0 );
yWaste = XmlUtil::getAttrLength( node, "y_waste", 0 );
xWaste = XmlUtil::getLengthAttr( node, "x_waste", 0 );
yWaste = XmlUtil::getLengthAttr( node, "y_waste", 0 );
}
Frame *frame = new FrameRect( w, h, r, xWaste, yWaste, id );
@@ -256,11 +256,11 @@ namespace libglabels
void XmlTemplateParser::parseLabelEllipseNode( const QDomElement &node, Template *tmplate )
{
QString id = XmlUtil::getAttr( node, "id", "0" );
QString id = XmlUtil::getStringAttr( node, "id", "0" );
double w = XmlUtil::getAttrLength( node, "width", 0 );
double h = XmlUtil::getAttrLength( node, "height", 0 );
double waste = XmlUtil::getAttrLength( node, "waste", -1 );
double w = XmlUtil::getLengthAttr( node, "width", 0 );
double h = XmlUtil::getLengthAttr( node, "height", 0 );
double waste = XmlUtil::getLengthAttr( node, "waste", -1 );
Frame *frame = new FrameEllipse( w, h, waste, id );
@@ -272,10 +272,10 @@ namespace libglabels
void XmlTemplateParser::parseLabelRoundNode( const QDomElement &node, Template *tmplate )
{
QString id = XmlUtil::getAttr( node, "id", "0" );
QString id = XmlUtil::getStringAttr( node, "id", "0" );
double r = XmlUtil::getAttrLength( node, "radius", 0 );
double waste = XmlUtil::getAttrLength( node, "waste", -1 );
double r = XmlUtil::getLengthAttr( node, "radius", 0 );
double waste = XmlUtil::getLengthAttr( node, "waste", -1 );
Frame *frame = new FrameRound( r, waste, id );
@@ -287,13 +287,13 @@ namespace libglabels
void XmlTemplateParser::parseLabelCdNode( const QDomElement &node, Template *tmplate )
{
QString id = XmlUtil::getAttr( node, "id", "0" );
QString id = XmlUtil::getStringAttr( node, "id", "0" );
double r1 = XmlUtil::getAttrLength( node, "radius", 0 );
double r2 = XmlUtil::getAttrLength( node, "hole", 0 );
double w = XmlUtil::getAttrLength( node, "width", 0 );
double h = XmlUtil::getAttrLength( node, "height", 0 );
double waste = XmlUtil::getAttrLength( node, "waste", -1 );
double r1 = XmlUtil::getLengthAttr( node, "radius", 0 );
double r2 = XmlUtil::getLengthAttr( node, "hole", 0 );
double w = XmlUtil::getLengthAttr( node, "width", 0 );
double h = XmlUtil::getLengthAttr( node, "height", 0 );
double waste = XmlUtil::getLengthAttr( node, "waste", -1 );
Frame *frame = new FrameCd( r1, r2, w, h, waste, id );
@@ -343,14 +343,14 @@ namespace libglabels
void XmlTemplateParser::parseLayoutNode( const QDomElement &node, Frame *frame )
{
int nX = XmlUtil::getAttr( node, "nx", 1 );
int nY = XmlUtil::getAttr( node, "ny", 1 );
int nX = XmlUtil::getIntAttr( node, "nx", 1 );
int nY = XmlUtil::getIntAttr( node, "ny", 1 );
double x0 = XmlUtil::getAttrLength( node, "x0", 0 );
double y0 = XmlUtil::getAttrLength( node, "y0", 0 );
double x0 = XmlUtil::getLengthAttr( node, "x0", 0 );
double y0 = XmlUtil::getLengthAttr( node, "y0", 0 );
double dX = XmlUtil::getAttrLength( node, "dx", 0 );
double dY = XmlUtil::getAttrLength( node, "dy", 0 );
double dX = XmlUtil::getLengthAttr( node, "dx", 0 );
double dY = XmlUtil::getLengthAttr( node, "dy", 0 );
frame->addLayout( new Layout( nX, nY, x0, y0, dX, dY ) );
}
@@ -358,7 +358,7 @@ namespace libglabels
void XmlTemplateParser::parseMarkupMarginNode( const QDomElement &node, Frame *frame )
{
double size = XmlUtil::getAttrLength( node, "size", 0 );
double size = XmlUtil::getLengthAttr( node, "size", 0 );
frame->addMarkup( new MarkupMargin( size ) );
}
@@ -366,10 +366,10 @@ namespace libglabels
void XmlTemplateParser::parseMarkupLineNode( const QDomElement &node, Frame *frame )
{
double x1 = XmlUtil::getAttrLength( node, "x1", 0 );
double y1 = XmlUtil::getAttrLength( node, "y1", 0 );
double x2 = XmlUtil::getAttrLength( node, "x2", 0 );
double y2 = XmlUtil::getAttrLength( node, "y2", 0 );
double x1 = XmlUtil::getLengthAttr( node, "x1", 0 );
double y1 = XmlUtil::getLengthAttr( node, "y1", 0 );
double x2 = XmlUtil::getLengthAttr( node, "x2", 0 );
double y2 = XmlUtil::getLengthAttr( node, "y2", 0 );
frame->addMarkup( new MarkupLine( x1, y1, x2, y2 ) );
}
@@ -377,9 +377,9 @@ namespace libglabels
void XmlTemplateParser::parseMarkupCircleNode( const QDomElement &node, Frame *frame )
{
double x0 = XmlUtil::getAttrLength( node, "x0", 0 );
double y0 = XmlUtil::getAttrLength( node, "y0", 0 );
double r = XmlUtil::getAttrLength( node, "radius", 0 );
double x0 = XmlUtil::getLengthAttr( node, "x0", 0 );
double y0 = XmlUtil::getLengthAttr( node, "y0", 0 );
double r = XmlUtil::getLengthAttr( node, "radius", 0 );
frame->addMarkup( new MarkupCircle( x0, y0, r ) );
}
@@ -387,11 +387,11 @@ namespace libglabels
void XmlTemplateParser::parseMarkupRectNode( const QDomElement &node, Frame *frame )
{
double x1 = XmlUtil::getAttrLength( node, "x1", 0 );
double y1 = XmlUtil::getAttrLength( node, "y1", 0 );
double w = XmlUtil::getAttrLength( node, "w", 0 );
double h = XmlUtil::getAttrLength( node, "h", 0 );
double r = XmlUtil::getAttrLength( node, "r", 0 );
double x1 = XmlUtil::getLengthAttr( node, "x1", 0 );
double y1 = XmlUtil::getLengthAttr( node, "y1", 0 );
double w = XmlUtil::getLengthAttr( node, "w", 0 );
double h = XmlUtil::getLengthAttr( node, "h", 0 );
double r = XmlUtil::getLengthAttr( node, "r", 0 );
frame->addMarkup( new MarkupRect( x1, y1, w, h, r ) );
}
@@ -399,10 +399,10 @@ namespace libglabels
void XmlTemplateParser::parseMarkupEllipseNode( const QDomElement &node, Frame *frame )
{
double x1 = XmlUtil::getAttrLength( node, "x1", 0 );
double y1 = XmlUtil::getAttrLength( node, "y1", 0 );
double w = XmlUtil::getAttrLength( node, "w", 0 );
double h = XmlUtil::getAttrLength( node, "h", 0 );
double x1 = XmlUtil::getLengthAttr( node, "x1", 0 );
double y1 = XmlUtil::getLengthAttr( node, "y1", 0 );
double w = XmlUtil::getLengthAttr( node, "w", 0 );
double h = XmlUtil::getLengthAttr( node, "h", 0 );
frame->addMarkup( new MarkupEllipse( x1, y1, w, h ) );
}
+42 -28
View File
@@ -30,25 +30,23 @@ namespace libglabels
Units *XmlUtil::mDefaultUnits;
QString XmlUtil::getAttr( const QDomElement &node, const QString &name, const char *default_value )
{
return node.attribute( name, QString(default_value) );
}
QString XmlUtil::getAttr( const QDomElement &node, const QString &name, const QString &default_value )
QString XmlUtil::getStringAttr( const QDomElement& node,
const QString& name,
const QString& default_value )
{
return node.attribute( name, default_value );
}
double XmlUtil::getAttr( const QDomElement &node, const QString &name, double default_value )
double XmlUtil::getDoubleAttr( const QDomElement& node,
const QString& name,
double default_value )
{
QString valueString = node.attribute( name, "" );
if ( valueString != "" )
{
bool ok;
double value = valueString.toDouble( &ok );
double value = valueString.toDouble(& ok );
if ( !ok )
{
@@ -66,7 +64,9 @@ namespace libglabels
}
bool XmlUtil::getAttr( const QDomElement &node, const QString &name, bool default_value )
bool XmlUtil::getBoolAttr( const QDomElement& node,
const QString& name,
bool default_value )
{
QString valueString = node.attribute( name, "" );
if ( valueString != "" )
@@ -100,13 +100,15 @@ namespace libglabels
}
int XmlUtil::getAttr( const QDomElement &node, const QString &name, int default_value )
int XmlUtil::getIntAttr( const QDomElement& node,
const QString& name,
int default_value )
{
QString valueString = node.attribute( name, "" );
if ( valueString != "" )
{
bool ok;
int value = valueString.toInt( &ok );
int value = valueString.toInt(& ok );
if ( !ok )
{
@@ -124,14 +126,16 @@ namespace libglabels
}
uint32_t XmlUtil::getAttr( const QDomElement &node, const QString &name, uint32_t default_value )
uint32_t XmlUtil::getUIntAttr( const QDomElement& node,
const QString& name,
uint32_t default_value )
{
QString valueString = node.attribute( name, "" );
if ( valueString != "" )
{
// TODO: Does base-0 do what we want? I.e. use base determined by format e.g. "0xff"
bool ok;
uint32_t value = valueString.toInt( &ok, 0 );
uint32_t value = valueString.toInt(& ok, 0 );
if ( !ok )
{
@@ -149,7 +153,9 @@ namespace libglabels
}
QString XmlUtil::getAttrI18n( const QDomElement &node, const QString &name, const QString &default_value )
QString XmlUtil::getI18nAttr( const QDomElement& node,
const QString& name,
const QString& default_value )
{
// TODO: are translations done in a compatable way, so that we can use "_name" attributes?
QString i18nString = node.attribute( QString("_").append(name), "" );
@@ -163,7 +169,9 @@ namespace libglabels
}
double XmlUtil::getAttrLength( const QDomElement &node, const QString &name, double default_value )
double XmlUtil::getLengthAttr( const QDomElement& node,
const QString& name,
double default_value )
{
QString valueString = node.attribute( name, "" );
if ( valueString != "" )
@@ -192,43 +200,49 @@ namespace libglabels
}
void XmlUtil::setAttr( const QDomElement &node, const QString &name, const char *value )
void XmlUtil::setStringAttr( const QDomElement& node,
const QString& name,
const QString& value )
{
// TODO
}
void XmlUtil::setAttr( const QDomElement &node, const QString &name, const QString &value )
void XmlUtil::setDoubleAttr( const QDomElement& node,
const QString& name,
double value )
{
// TODO
}
void XmlUtil::setAttr( const QDomElement &node, const QString &name, double value )
void XmlUtil::setBoolAttr( const QDomElement& node,
const QString& name,
bool value )
{
// TODO
}
void XmlUtil::setAttr( const QDomElement &node, const QString &name, bool value )
void XmlUtil::setIntAttr( const QDomElement& node,
const QString& name,
int value )
{
// TODO
}
void XmlUtil::setAttr( const QDomElement &node, const QString &name, int value )
void XmlUtil::setUIntAttr( const QDomElement& node,
const QString& name,
uint32_t value )
{
// TODO
}
void XmlUtil::setAttr( const QDomElement &node, const QString &name, uint32_t value )
{
// TODO
}
void XmlUtil::setAttrLength( const QDomElement &node, const QString &name, double value )
void XmlUtil::setLengthAttr( const QDomElement& node,
const QString& name,
double value )
{
// TODO
}
+53 -16
View File
@@ -47,26 +47,63 @@ namespace libglabels
}
static const Units *defaultUnits() { return mDefaultUnits; }
static void setDefaultUnits( Units *defaultUnits ) { mDefaultUnits = defaultUnits; }
static QString getAttr( const QDomElement &node, const QString &name, const char *default_value );
static QString getAttr( const QDomElement &node, const QString &name, const QString &default_value );
static double getAttr( const QDomElement &node, const QString &name, double default_value );
static bool getAttr( const QDomElement &node, const QString &name, bool default_value );
static int getAttr( const QDomElement &node, const QString &name, int default_value );
static uint32_t getAttr( const QDomElement &node, const QString &name, uint32_t default_value );
static void setDefaultUnits( Units *defaultUnits )
{
mDefaultUnits = defaultUnits;
}
static QString getAttrI18n( const QDomElement &node, const QString &name, const QString &default_value );
static double getAttrLength( const QDomElement &node, const QString &name, double default_value );
static QString getStringAttr( const QDomElement& node,
const QString& name,
const QString& default_value );
static void setAttr( const QDomElement &node, const QString &name, const char *value );
static void setAttr( const QDomElement &node, const QString &name, const QString &value );
static void setAttr( const QDomElement &node, const QString &name, double value );
static void setAttr( const QDomElement &node, const QString &name, bool value );
static void setAttr( const QDomElement &node, const QString &name, int value );
static void setAttr( const QDomElement &node, const QString &name, uint32_t value );
static double getDoubleAttr( const QDomElement& node,
const QString& name,
double default_value );
static void setAttrLength( const QDomElement &node, const QString &name, double value );
static bool getBoolAttr( const QDomElement& node,
const QString& name,
bool default_value );
static int getIntAttr( const QDomElement& node,
const QString& name,
int default_value );
static uint32_t getUIntAttr( const QDomElement& node,
const QString& name,
uint32_t default_value );
static QString getI18nAttr( const QDomElement& node,
const QString& name,
const QString& default_value );
static double getLengthAttr( const QDomElement& node,
const QString& name,
double default_value );
static void setStringAttr( const QDomElement& node,
const QString& name,
const QString& value );
static void setDoubleAttr( const QDomElement& node,
const QString& name,
double value );
static void setBoolAttr( const QDomElement& node,
const QString& name,
bool value );
static void setIntAttr( const QDomElement& node,
const QString& name,
int value );
static void setUIntAttr( const QDomElement& node,
const QString& name,
uint32_t value );
static void setLengthAttr( const QDomElement& node,
const QString& name,
double value );
private:
static Units *mDefaultUnits;
+2 -2
View File
@@ -92,8 +92,8 @@ namespace libglabels
void XmlVendorParser::parseVendorNode( const QDomElement &node )
{
QString name = XmlUtil::getAttr( node, "name", "" );
QString url = XmlUtil::getAttr( node, "url", "" );
QString name = XmlUtil::getStringAttr( node, "name", "" );
QString url = XmlUtil::getStringAttr( node, "url", "" );
Vendor *vendor = new Vendor( name, url );
if ( vendor != NULL )