Moved EnumUtil functionality to XmlUtil.
This commit is contained in:
@@ -42,7 +42,6 @@ set (glabels_sources
|
|||||||
DataCache.cpp
|
DataCache.cpp
|
||||||
Db.cpp
|
Db.cpp
|
||||||
Distance.cpp
|
Distance.cpp
|
||||||
EnumUtil.cpp
|
|
||||||
FieldButton.cpp
|
FieldButton.cpp
|
||||||
File.cpp
|
File.cpp
|
||||||
FileUtil.cpp
|
FileUtil.cpp
|
||||||
|
|||||||
@@ -1,126 +0,0 @@
|
|||||||
/* EnumUtil.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 "EnumUtil.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace glabels
|
|
||||||
{
|
|
||||||
|
|
||||||
namespace EnumUtil
|
|
||||||
{
|
|
||||||
|
|
||||||
QString weightToString( QFont::Weight weight )
|
|
||||||
{
|
|
||||||
switch (weight)
|
|
||||||
{
|
|
||||||
case QFont::Bold:
|
|
||||||
return "bold";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return "normal";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QFont::Weight stringToWeight( const QString& string )
|
|
||||||
{
|
|
||||||
if ( string == "bold" )
|
|
||||||
{
|
|
||||||
return QFont::Bold;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return QFont::Normal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString hAlignToString( Qt::Alignment align )
|
|
||||||
{
|
|
||||||
switch (align)
|
|
||||||
{
|
|
||||||
case Qt::AlignRight:
|
|
||||||
return "right";
|
|
||||||
break;
|
|
||||||
case Qt::AlignHCenter:
|
|
||||||
return "center";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return "left";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Qt::Alignment stringToHAlign( const QString& string )
|
|
||||||
{
|
|
||||||
if ( string == "right" )
|
|
||||||
{
|
|
||||||
return Qt::AlignRight;
|
|
||||||
}
|
|
||||||
else if ( string == "center" )
|
|
||||||
{
|
|
||||||
return Qt::AlignHCenter;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Qt::AlignLeft;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString vAlignToString( Qt::Alignment align )
|
|
||||||
{
|
|
||||||
switch (align)
|
|
||||||
{
|
|
||||||
case Qt::AlignBottom:
|
|
||||||
return "bottom";
|
|
||||||
break;
|
|
||||||
case Qt::AlignVCenter:
|
|
||||||
return "center";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return "top";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Qt::Alignment stringToVAlign( const QString& string )
|
|
||||||
{
|
|
||||||
if ( string == "bottom" )
|
|
||||||
{
|
|
||||||
return Qt::AlignBottom;
|
|
||||||
}
|
|
||||||
else if ( string == "center" )
|
|
||||||
{
|
|
||||||
return Qt::AlignVCenter;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Qt::AlignTop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace glabels
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
/* 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 EnumUtil_h
|
|
||||||
#define EnumUtil_h
|
|
||||||
|
|
||||||
|
|
||||||
#include <QFont>
|
|
||||||
#include <QString>
|
|
||||||
#include <Qt>
|
|
||||||
|
|
||||||
|
|
||||||
namespace glabels
|
|
||||||
{
|
|
||||||
|
|
||||||
namespace EnumUtil
|
|
||||||
{
|
|
||||||
|
|
||||||
QString weightToString( QFont::Weight weight );
|
|
||||||
QFont::Weight stringToWeight( const QString& string );
|
|
||||||
|
|
||||||
QString hAlignToString( Qt::Alignment align );
|
|
||||||
Qt::Alignment stringToHAlign( const QString& string );
|
|
||||||
|
|
||||||
QString vAlignToString( Qt::Alignment align );
|
|
||||||
Qt::Alignment stringToVAlign( const QString& string );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif // EnumUtil_h
|
|
||||||
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include "XmlLabelCreator.h"
|
#include "XmlLabelCreator.h"
|
||||||
|
|
||||||
#include "EnumUtil.h"
|
|
||||||
#include "LabelModel.h"
|
#include "LabelModel.h"
|
||||||
#include "LabelModelObject.h"
|
#include "LabelModelObject.h"
|
||||||
#include "LabelModelBarcodeObject.h"
|
#include "LabelModelBarcodeObject.h"
|
||||||
@@ -332,14 +331,14 @@ namespace glabels
|
|||||||
/* font attrs */
|
/* font attrs */
|
||||||
XmlUtil::setStringAttr( node, "font_family", object->fontFamily() );
|
XmlUtil::setStringAttr( node, "font_family", object->fontFamily() );
|
||||||
XmlUtil::setDoubleAttr( node, "font_size", object->fontSize() );
|
XmlUtil::setDoubleAttr( node, "font_size", object->fontSize() );
|
||||||
XmlUtil::setStringAttr( node, "font_weight", EnumUtil::weightToString( object->fontWeight() ) );
|
XmlUtil::setWeightAttr( node, "font_weight", object->fontWeight() );
|
||||||
XmlUtil::setBoolAttr( node, "font_italic", object->fontItalicFlag() );
|
XmlUtil::setBoolAttr( node, "font_italic", object->fontItalicFlag() );
|
||||||
XmlUtil::setBoolAttr( node, "font_underline", object->fontUnderlineFlag() );
|
XmlUtil::setBoolAttr( node, "font_underline", object->fontUnderlineFlag() );
|
||||||
|
|
||||||
/* text attrs */
|
/* text attrs */
|
||||||
XmlUtil::setDoubleAttr( node, "line_spacing", object->textLineSpacing() );
|
XmlUtil::setDoubleAttr( node, "line_spacing", object->textLineSpacing() );
|
||||||
XmlUtil::setStringAttr( node, "align", EnumUtil::hAlignToString( object->textHAlign() ) );
|
XmlUtil::setAlignmentAttr( node, "align", object->textHAlign() );
|
||||||
XmlUtil::setStringAttr( node, "valign", EnumUtil::vAlignToString( object->textVAlign() ) );
|
XmlUtil::setAlignmentAttr( node, "valign", object->textVAlign() );
|
||||||
|
|
||||||
/* affine attrs */
|
/* affine attrs */
|
||||||
createAffineAttrs( node, object );
|
createAffineAttrs( node, object );
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
#include "XmlLabelParser.h"
|
#include "XmlLabelParser.h"
|
||||||
|
|
||||||
#include "BarcodeBackends.h"
|
#include "BarcodeBackends.h"
|
||||||
#include "EnumUtil.h"
|
|
||||||
#include "LabelModel.h"
|
#include "LabelModel.h"
|
||||||
#include "LabelModelObject.h"
|
#include "LabelModelObject.h"
|
||||||
#include "LabelModelBarcodeObject.h"
|
#include "LabelModelBarcodeObject.h"
|
||||||
@@ -615,14 +614,14 @@ namespace glabels
|
|||||||
/* font attrs */
|
/* font attrs */
|
||||||
QString fontFamily = XmlUtil::getStringAttr( node, "font_family", "Sans" );
|
QString fontFamily = XmlUtil::getStringAttr( node, "font_family", "Sans" );
|
||||||
double fontSize = XmlUtil::getDoubleAttr( node, "font_size", 10 );
|
double fontSize = XmlUtil::getDoubleAttr( node, "font_size", 10 );
|
||||||
QFont::Weight fontWeight = EnumUtil::stringToWeight( XmlUtil::getStringAttr( node, "font_weight", "normal" ) );
|
QFont::Weight fontWeight = XmlUtil::getWeightAttr( node, "font_weight", QFont::Normal );
|
||||||
bool fontItalicFlag = XmlUtil::getBoolAttr( node, "font_italic", false );
|
bool fontItalicFlag = XmlUtil::getBoolAttr( node, "font_italic", false );
|
||||||
bool fontUnderlineFlag = XmlUtil::getBoolAttr( node, "font_underline", false );
|
bool fontUnderlineFlag = XmlUtil::getBoolAttr( node, "font_underline", false );
|
||||||
|
|
||||||
/* text attrs */
|
/* text attrs */
|
||||||
double textLineSpacing = XmlUtil::getDoubleAttr( node, "line_spacing", 1 );
|
double textLineSpacing = XmlUtil::getDoubleAttr( node, "line_spacing", 1 );
|
||||||
Qt::Alignment textHAlign = EnumUtil::stringToHAlign( XmlUtil::getStringAttr( node, "align", "left" ) );
|
Qt::Alignment textHAlign = XmlUtil::getAlignmentAttr( node, "align", Qt::AlignLeft );
|
||||||
Qt::Alignment textVAlign = EnumUtil::stringToVAlign( XmlUtil::getStringAttr( node, "valign", "top" ) );
|
Qt::Alignment textVAlign = XmlUtil::getAlignmentAttr( node, "valign", Qt::AlignTop );
|
||||||
|
|
||||||
/* affine attrs */
|
/* affine attrs */
|
||||||
double a[6];
|
double a[6];
|
||||||
|
|||||||
@@ -234,6 +234,68 @@ namespace glabels
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QFont::Weight XmlUtil::getWeightAttr( const QDomElement& node,
|
||||||
|
const QString& name,
|
||||||
|
QFont::Weight default_value )
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
|
||||||
|
QString valueString = node.attribute( name, "" );
|
||||||
|
if ( valueString != "" )
|
||||||
|
{
|
||||||
|
if ( valueString == "bold" )
|
||||||
|
{
|
||||||
|
return QFont::Bold;
|
||||||
|
}
|
||||||
|
else if ( valueString == "normal" )
|
||||||
|
{
|
||||||
|
return QFont::Normal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Qt::Alignment XmlUtil::getAlignmentAttr( const QDomElement& node,
|
||||||
|
const QString& name,
|
||||||
|
Qt::Alignment default_value )
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
|
||||||
|
QString valueString = node.attribute( name, "" );
|
||||||
|
if ( valueString != "" )
|
||||||
|
{
|
||||||
|
if ( valueString == "right" )
|
||||||
|
{
|
||||||
|
return Qt::AlignRight;
|
||||||
|
}
|
||||||
|
else if ( valueString == "hcenter" )
|
||||||
|
{
|
||||||
|
return Qt::AlignHCenter;
|
||||||
|
}
|
||||||
|
else if ( valueString == "left" )
|
||||||
|
{
|
||||||
|
return Qt::AlignLeft;
|
||||||
|
}
|
||||||
|
else if ( valueString == "bottom" )
|
||||||
|
{
|
||||||
|
return Qt::AlignBottom;
|
||||||
|
}
|
||||||
|
else if ( valueString == "vcenter" )
|
||||||
|
{
|
||||||
|
return Qt::AlignVCenter;
|
||||||
|
}
|
||||||
|
else if ( valueString == "top" )
|
||||||
|
{
|
||||||
|
return Qt::AlignTop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void XmlUtil::setStringAttr( QDomElement& node,
|
void XmlUtil::setStringAttr( QDomElement& node,
|
||||||
const QString& name,
|
const QString& name,
|
||||||
const QString& value )
|
const QString& value )
|
||||||
@@ -294,4 +356,52 @@ namespace glabels
|
|||||||
node.setAttribute( name, QString::number(value.inUnits(units)) + units.toIdString() );
|
node.setAttribute( name, QString::number(value.inUnits(units)) + units.toIdString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void XmlUtil::setWeightAttr( QDomElement& node,
|
||||||
|
const QString& name,
|
||||||
|
QFont::Weight value )
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case QFont::Bold:
|
||||||
|
node.setAttribute( name, "bold" );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
node.setAttribute( name, "normal" );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void XmlUtil::setAlignmentAttr( QDomElement& node,
|
||||||
|
const QString& name,
|
||||||
|
Qt::Alignment value )
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case Qt::AlignRight:
|
||||||
|
node.setAttribute( name, "right" );
|
||||||
|
break;
|
||||||
|
case Qt::AlignHCenter:
|
||||||
|
node.setAttribute( name, "hcenter" );
|
||||||
|
break;
|
||||||
|
case Qt::AlignLeft:
|
||||||
|
node.setAttribute( name, "left" );
|
||||||
|
break;
|
||||||
|
case Qt::AlignBottom:
|
||||||
|
node.setAttribute( name, "bottom" );
|
||||||
|
break;
|
||||||
|
case Qt::AlignVCenter:
|
||||||
|
node.setAttribute( name, "vcenter" );
|
||||||
|
break;
|
||||||
|
case Qt::AlignTop:
|
||||||
|
node.setAttribute( name, "top" );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
node.setAttribute( name, "left" );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace glabels
|
} // namespace glabels
|
||||||
|
|||||||
@@ -25,7 +25,9 @@
|
|||||||
#include "Distance.h"
|
#include "Distance.h"
|
||||||
|
|
||||||
#include <QDomElement>
|
#include <QDomElement>
|
||||||
|
#include <QFont>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <Qt>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
@@ -74,6 +76,15 @@ namespace glabels
|
|||||||
const QString& name,
|
const QString& name,
|
||||||
const Distance& default_value );
|
const Distance& default_value );
|
||||||
|
|
||||||
|
static QFont::Weight getWeightAttr( const QDomElement& node,
|
||||||
|
const QString& name,
|
||||||
|
QFont::Weight default_value );
|
||||||
|
|
||||||
|
static Qt::Alignment getAlignmentAttr( const QDomElement& node,
|
||||||
|
const QString& name,
|
||||||
|
Qt::Alignment default_value );
|
||||||
|
|
||||||
|
|
||||||
static void setStringAttr( QDomElement& node,
|
static void setStringAttr( QDomElement& node,
|
||||||
const QString& name,
|
const QString& name,
|
||||||
const QString& value );
|
const QString& value );
|
||||||
@@ -98,6 +109,15 @@ namespace glabels
|
|||||||
const QString& name,
|
const QString& name,
|
||||||
const Distance& value );
|
const Distance& value );
|
||||||
|
|
||||||
|
static void setWeightAttr( QDomElement& node,
|
||||||
|
const QString& name,
|
||||||
|
QFont::Weight value );
|
||||||
|
|
||||||
|
static void setAlignmentAttr( QDomElement& node,
|
||||||
|
const QString& name,
|
||||||
|
Qt::Alignment value );
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Units mUnits;
|
Units mUnits;
|
||||||
|
|
||||||
|
|||||||
@@ -1128,8 +1128,8 @@
|
|||||||
<context>
|
<context>
|
||||||
<name>glabels::LabelModelTextObject</name>
|
<name>glabels::LabelModelTextObject</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../glabels/LabelModelTextObject.cpp" line="419"/>
|
<location filename="../glabels/LabelModelTextObject.cpp" line="421"/>
|
||||||
<location filename="../glabels/LabelModelTextObject.cpp" line="541"/>
|
<location filename="../glabels/LabelModelTextObject.cpp" line="543"/>
|
||||||
<source>Text</source>
|
<source>Text</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
|||||||
Reference in New Issue
Block a user