util Namespace Reference

Utility namespace. More...

Enumerations

enum  CharsetContext { PDF, CON, NAME, UTF8 }

Functions

QString getTypeName (PropertyType typ)
QString getTypeId (PropertyType typ)
QString getTypeName (IProperty *obj)
QString getTypeName (boost::shared_ptr< IProperty > obj)
QString propertyPreview (boost::shared_ptr< IProperty > obj)
QString getTypeId (IProperty *obj)
QString getTypeId (boost::shared_ptr< IProperty > obj)
IndiRef getRef (IProperty *ref)
IndiRef getRef (boost::shared_ptr< IProperty > ref)
bool isRefValid (boost::shared_ptr< CPdf > pdf, IndiRef ref)
bool isSimple (IProperty *prop)
boost::shared_ptr< IPropertydereference (boost::shared_ptr< IProperty > obj)
bool isSimple (boost::shared_ptr< IProperty > prop)
bool saveCopy (boost::shared_ptr< CPdf > obj, const QString &name, QString *error)
template<typename T >
boost::shared_ptr< IProperty_recursiveProperty (boost::shared_ptr< T > obj, const QString &name)
boost::shared_ptr< IPropertyrecursiveProperty (boost::shared_ptr< CDict > obj, const QString &name)
boost::shared_ptr< IPropertyrecursiveProperty (boost::shared_ptr< CArray > obj, const QString &name)
boost::shared_ptr< IPropertygetObjProperty (boost::shared_ptr< CDict > obj, const QString &name)
boost::shared_ptr< IPropertygetObjProperty (boost::shared_ptr< CArray > obj, const QString &name)
QString annotType (CAnnotation::AnnotType at)
QString annotType (boost::shared_ptr< CAnnotation > anot)
QString annotTypeName (boost::shared_ptr< CAnnotation > anot)
boost::shared_ptr< CPdfgetPdfInstance (QWidget *parent, const QString &filename, CPdf::OpenMode mode, bool askPassword)
bool setPdfPassword (boost::shared_ptr< CPdf > pdf, const QString &pass)
QVariant varFromDoubleArray (double *d, int count)
int varToDoubleArray (const QVariant &v, double *out, int out_size)
void fatalError (const QString &message)
QString htmlEnt (const QString &str)
int findSep (int start, const QString &line, char separator)
QStringList explode (char separator, const QString &line, bool escape)
QString loadFromFile (const QString &name)
bool saveToFile (const QString &name, const QString &content)
bool saveRawToFile (const QString &name, const QByteArray &content)
void printList (const QStringList &l)
void consoleLog (const QString &message, const QString &fileName)
void escapeSlash (QString &line)
QString getUntil (char separator, QString &line, bool escape)
void setDebugLevel (const QString &param)
QString countString (int count, QString singular, QString plural)
QColor mixColor (const QColor &oldColor, double weight, const QColor &newColor)
void colorMod (QWidget *widget, QColor fg, double weight_fg, QColor bg, double weight_bg)
QStringList countList (unsigned int count, unsigned int start)
QStringList supportedEncodings ()
void setDefaultCharset (const QString &charsetName)
QString convertToUnicode (const std::string &str, CharsetContext ctx)
std::string convertFromUnicode (const QString &str, CharsetContext ctx)

Variables

QTextCodec * defCodec = NULL

Detailed Description

Utility namespace.

Utility namespace
Contains various static utility functions, used in GUI


Enumeration Type Documentation

Context of unicode to/from 8bit conversion (PDF, console, filename ...)

Enumerator:
PDF 
CON 

PDF

NAME 

Console/terminal

UTF8 

File name


Function Documentation

template<typename T >
boost::shared_ptr<IProperty> util::_recursiveProperty ( boost::shared_ptr< T >  obj,
const QString &  name 
) [inline]

recursive CDict/CArray getProperty(...) Will take the name as slash-separated list of childs to traverse to get to target property. References on the way are automatically dereferenced Can throw exception if some property is not found on the way

Parameters:
obj CDict/CArray to start the search
name Path to property
Returns:
specified property

References debug::DBG_DBG, dereference(), getObjProperty(), guiPrintDbg, Q_OUT, and recursiveProperty().

QString util::annotType ( boost::shared_ptr< CAnnotation >  anot  ) 

Return type identifier of annotation

Parameters:
anot Annotation
QString util::annotType ( CAnnotation::AnnotType  at  ) 

Return type identifier of annotation type

Parameters:
at Annotation type

Referenced by pdfobjects::utils::UniversalAnnotInitializer::getSupportedList(), and gui::QSAnnotation::getType().

QString util::annotTypeName ( boost::shared_ptr< CAnnotation >  anot  ) 

Return human readable, localized type identifier of annotation

Parameters:
anot Annotation

Referenced by gui::QSAnnotation::getTypeName(), and gui::TreeItemAnnotation::reloadSelf().

void util::colorMod ( QWidget *  widget,
QColor  fg,
double  weight_fg,
QColor  bg,
double  weight_bg 
)

Modify widget foreground and background color by blending with new colors using given weight

Parameters:
widget Widget to modify
fg new foreground color
weight_fg weight of new foreground color
bg new background color
weight_bg weight of new background color

Referenced by gui::Property::initLabel(), and gui::Property::modifyColor().

void util::consoleLog ( const QString &  message,
const QString &  fileName 
)

Write line to specified logfile

Parameters:
message Line to write to logfile
fileName Name of log file. If this is null or empty string, nothing is done

Referenced by gui::CommandWindow::addCommand(), gui::CommandWindow::addError(), and gui::CommandWindow::addString().

std::string util::convertFromUnicode ( const QString &  str,
CharsetContext  ctx 
)
QString util::convertToUnicode ( const std::string &  str,
CharsetContext  ctx 
)
QStringList util::countList ( unsigned int  count,
unsigned int  start 
)

Return string list containing 'count' items, numbered from 'start' to 'start+count-1'

Parameters:
count number of items in list
start first item in the list

Referenced by gui::TreeItemOperatorContainer::getQSObject(), gui::TreeItemAnnotationContainer::getQSObject(), and gui::TreeItemPdf::haveChild().

QString util::countString ( int  count,
QString  singular,
QString  plural 
)

Return correctly localized string telling count of some items. Some languages (for example Czech) have more plural forms (2-4 items / 5 or more items), which is handled here

Parameters:
count Count of items
singular English signular form of the noun, without space before the word
plural English plural form of the noun
Returns:
Localized string

Referenced by gui::TreeItemPdf::createChild(), and gui::TreeItemPdfOperator::reloadSelf().

boost::shared_ptr< IProperty > util::dereference ( boost::shared_ptr< IProperty >  obj  ) 

Return referenced IProperty for given reference, or the property itself in case property is not a reference Return NULL (empty shared_ptr) on error

Parameters:
obj Reference to dereference
Returns:
Referenced IProperty

Referenced by _recursiveProperty(), gui::TreeItemRef::getChildType(), and gui::QSIProperty::ref().

void util::escapeSlash ( QString &  line  ) 

Replace two backslashes followed by any character (escaped character) with that character

Parameters:
line String in which to remove extra backslashes (in,out)
QStringList util::explode ( char  separator,
const QString &  line,
bool  escape 
)

splits QString containing elements separated with given character All whitespaces from beginning and end of elements are trimmed

Parameters:
separator Separator of elements
line String containing elements separated with separator
escape If true, "\\" will be converted to "\" and \(separator) will be converted to (separator) and not treated as separator
Returns:
QStringlist with elements

Referenced by gui::QSMenu::addItemDef(), gui::Menu::optimizeItems(), gui::QSMenu::QSMenu(), gui::Settings::restoreSplitter(), gui::Settings::restoreWindow(), and MenuGenerator::setAvail().

void util::fatalError ( const QString &  message  ) 

Prints error message and terminates application

Parameters:
message Error message to show

Referenced by handleParams(), main(), nextParam(), MenuGenerator::setAvail(), and MenuGenerator::translate().

int util::findSep ( int  start,
const QString &  line,
char  separator 
)

Find first occurence of separator in string and return its position, ignoring backslash-escaped separators If separator is not found, -1 is returned

Parameters:
start Start searching from this position in string
separator Separator of string elements
line String to look for separator
Returns:
position of first separator from start position, ignoring backslash-escaped separators
boost::shared_ptr< IProperty > util::getObjProperty ( boost::shared_ptr< CArray >  obj,
const QString &  name 
)

Get property from Array based in QString key

Parameters:
obj Array to get property from
name name of property (must be convertable to number)
Returns:
specified property
boost::shared_ptr< IProperty > util::getObjProperty ( boost::shared_ptr< CDict >  obj,
const QString &  name 
)

Get property from Dict based in QString key

Parameters:
obj Dict to get property from
name name of property
Returns:
specified property

Referenced by _recursiveProperty().

boost::shared_ptr< CPdf > util::getPdfInstance ( QWidget *  parent,
const QString &  filename,
CPdf::OpenMode  mode,
bool  askPassword 
)

Get PDF instance - call CPdf::getInstance with appropriate parameters

Parameters:
parent parent widget of dialog that may spawn
filename Name of file for CPdf::getInstance
mode Open mode for CPdf::getInstance
askPassword If true, password will be asked for if necessary

Referenced by gui::SelectPagesDialog::init(), and gui::MergeDialog::initFileList().

IndiRef util::getRef ( boost::shared_ptr< IProperty >  ref  ) 

Get value (reference target) of CRef

Parameters:
ref CRef reference object

IndiRef util::getRef ( IProperty *  ref  ) 

Get value (reference target) of CRef

Parameters:
ref CRef reference object
QString util::getTypeId ( boost::shared_ptr< IProperty >  obj  ) 

Return string identifier of given type

Parameters:
obj Object to get type from (IProperty)
Returns:
Identifier of type name

QString util::getTypeId ( IProperty *  obj  ) 

Return string identifier of given type

Parameters:
obj Object to get type from (IProperty)
Returns:
Identifier of type name
QString util::getTypeId ( PropertyType  typ  ) 

Return string identifier of given type

Parameters:
typ Type of PDF Object
Returns:
Identifier of type name

Referenced by gui::QSIProperty::getType().

QString util::getTypeName ( boost::shared_ptr< IProperty >  obj  ) 

Return human-readable (and possibly localized) name of given object's type

Parameters:
obj Object to get type from (IProperty)
Returns:
Human readable type name

QString util::getTypeName ( IProperty *  obj  ) 

Return human-readable (and possibly localized) name of given object's type

Parameters:
obj Object to get type from (IProperty)
Returns:
Human readable type name
QString util::getTypeName ( PropertyType  typ  ) 

Return human-readable (and possibly localized) name of given type

Parameters:
typ Type of PDF Object
Returns:
Human readable type name

Referenced by gui::AddItemDialog::AddItemDialog(), gui::RefPropertyDialog::check(), gui::PropertyEditor::commitProperty(), gui::TreeItem::create(), gui::TreeItem::init(), gui::TreeItemRef::reloadSelf(), and gui::TreeItemSimple::setObject().

QString util::getUntil ( char  separator,
QString &  line,
bool  escape 
)

Return string from line up to first separator character and remove that string and the separator from the line. If separator is not found, entire string is returned and the line is set to empty string

Parameters:
separator Separator of string elements
line line to get from and remove first element
escape If true, "\\" will be converted to "\" and \(separator) will be converted to (separator) and not treated as separator
Returns:
first string element (contents of string until separator)
QString util::htmlEnt ( const QString &  str  ) 

Convert < > and & characters to corresponding html entities (> < &)

Parameters:
str String to convert
Returns:
Converted string

Referenced by gui::CommandWindow::addCommand(), gui::CommandWindow::addError(), and gui::CommandWindow::addString().

bool util::isRefValid ( boost::shared_ptr< CPdf >  pdf,
IndiRef  ref 
)

Check for validity of reference - if ref is valid reference (have target) in given CPdf

Parameters:
pdf pdf to check for reference
ref Indirect reference to check
Returns:
true if given reference target exists in given pdf, false otherwise
bool util::isSimple ( boost::shared_ptr< IProperty >  prop  ) 

Return true, if this is simple property (editable as item in property editor and have no children), false otherwise

Parameters:
prop IProperty to check
Returns:
true if simple property, false otherwise
bool util::isSimple ( IProperty *  prop  ) 

Return true, if this is simple property (editable as item in property editor and have no children), false otherwise

Parameters:
prop IProperty to check
Returns:
true if simple property, false otherwise

Referenced by gui::TreeItemDict::getChildNames(), gui::TreeItemCStream::getChildNames(), and gui::TreeItemArray::getChildNames().

QString util::loadFromFile ( const QString &  name  ) 

Load content of file to string. NULL string is returned if file does not exist or is unreadable. It is assumed that the file is in utf8 encoding

Parameters:
name Filename of file to load
Returns:
file contents in string.
QColor util::mixColor ( const QColor &  oldColor,
double  weight,
const QColor &  newColor 
)

Mix colors from oldColor and newColor according to weight Weight should be between 0 and 1, 1 meaning the color will be "new", 0 meaning the color will be "old", everything else mean linear interpolation between new color (with given weight) and old color (with weight of (1-weight))

Parameters:
weight Weight of new color.
oldColor Old color
newColor New color
void util::printList ( const QStringList &  l  ) 

Print stringlist to stdout

Parameters:
l String list to print
QString util::propertyPreview ( boost::shared_ptr< IProperty >  obj  ) 

Return short textual preview of what's in the property

Parameters:
obj property for preview
Returns:
short string (cca. 20 chararters max)

Referenced by gui::RefPropertyDialog::check().

boost::shared_ptr< IProperty > util::recursiveProperty ( boost::shared_ptr< CArray >  obj,
const QString &  name 
)

recursive CDict/CArray getProperty(...) Will take the name as slash-separated list of childs to traverse to get to target property. References on the way are automatically dereferenced Can throw exception if some property is not found on the way

Parameters:
obj CDict/CArray to start the search
name Path to property
Returns:
specified property

boost::shared_ptr< IProperty > util::recursiveProperty ( boost::shared_ptr< CDict >  obj,
const QString &  name 
)

recursive CDict/CArray getProperty(...) Will take the name as slash-separated list of childs to traverse to get to target property. References on the way are automatically dereferenced Can throw exception if some property is not found on the way

Parameters:
obj CDict/CArray to start the search
name Path to property
Returns:
specified property

Referenced by _recursiveProperty(), gui::QSDict::child(), and gui::QSArray::child().

bool util::saveCopy ( boost::shared_ptr< CPdf >  obj,
const QString &  name,
QString *  error 
)

Save currently active revision in document under different filename

Parameters:
obj Pdf document
name New name
error String that will receive error message if saving failed. If null, no message will b e received
Returns:
true if success, false if failure

failed to open file

Referenced by gui::QSPdf::saveAs().

bool util::saveRawToFile ( const QString &  name,
const QByteArray &  content 
)

Save raw bytes into file.

Parameters:
name Filename of file to write to. It will be overwritten.
content Buffer to write.
Returns:
true in case of success, false in case of failure
bool util::saveToFile ( const QString &  name,
const QString &  content 
)

Save string into file with utf8 encoding.

Parameters:
name Filename of file to write to. It will be overwritten.
content String to write.
Returns:
true in case of success, false in case of failure
void util::setDebugLevel ( const QString &  param  ) 

Set debugging verbosity level. Accept debugging level either as number, or as one of symbolic constants:
PANIC, CRITICAL, ERROR, WARNING, INFO, DEBUG, DBG (=DEBUG)
Constants are case insensitive, starting part of constant is sufficient
Only messages with priority equal or higher to specified level are shown

Parameters:
param new debugging level

Referenced by handleDebug().

void util::setDefaultCharset ( const QString &  charsetName  ) 

set default charset used when reading (and writing) property values

Parameters:
charsetName charset name used for all 8bit to/from unicode conversions

Referenced by main().

bool util::setPdfPassword ( boost::shared_ptr< CPdf >  pdf,
const QString &  pass 
)

Try to set PDF password for document.

Parameters:
pdf CPdf instance
pass Password to use
Returns:
true if the password is correct or false if the password is wrong.

Referenced by gui::QSPdf::setPassword().

QStringList util::supportedEncodings (  ) 

Return list of supported text encodings (Based on support from QTextCodec in Qt)

QVariant util::varFromDoubleArray ( double *  d,
int  count 
)

Convert array of double values to variant

Parameters:
d Pointer to array fo doubles
count number of elements in the array

Referenced by gui::Base::transformationMatrixMul().

int util::varToDoubleArray ( const QVariant &  v,
double *  out,
int  out_size 
)

Convert variant to array of doubles. If size of variant array is larger than out_size, only part will be converted. If size is smaller, output array will be zero-padded

Parameters:
v Variant to convert
out pointer to array of doubles
out_size number of elements in output array.
Returns:
number of elements converted (between 0 and out_size)

Variable Documentation

QTextCodec* util::defCodec = NULL

Codec for default charset