Brief description of class still missing. More...
#include <MapProject.h>
Signals | |
void | newCommand (const QString &cmd) |
Public Member Functions | |
void | addCommand (const QString &cmd) |
void | addConsoleCommand (const QString &cmd) |
void | addView (MapView *v) |
QPointF | currentPoint () const |
void | exportImage (QString fileName=QString::null, QString imageFormat=QString::null, int dpi=300) |
QString | fileName () const |
QPixmap | image (int dpi) |
bool | isClosable () |
bool | isModified () const |
MapProject () | |
QString | name () const |
bool | open (QString fileName=QString::null) |
void | print (int dpi=300) |
void | print (QPrinter &printer) |
bool | removeView (MapView *v) |
bool | save () |
bool | saveAs (QString fileName=QString::null) |
DrawScene * | scene () const |
const QString & | script () const |
void | setName (const QString &name) |
void | setScript (const QString &s) |
MapView * | view (int index) |
int | viewCount () const |
virtual const QString & | xml_tagName () const |
~MapProject () | |
Static Public Attributes | |
static const QString | allImageFilter = ";;" + MapProject::pixelImageFilter |
static const QString | pixelImageFilter = "PNG (*.png);;PPM (*.ppm);;XBM (*.xbm);;XPM (*.xpm)" |
static const QString | vectorialImageFilter = "PS (*.ps);;PDF (*.pdf)" |
static const QString | xmlMapProjectTag = "MapProject" |
Protected Member Functions | |
virtual XMLMember | xml_member (XML_MEMBER_ARGS) |
virtual bool | xml_setProperty (XML_SETPROPERTY_ARGS) |
virtual void | xml_writeProperties (XML_WRITEPROPERTIES_ARGS) const |
Properties | |
QString | script |
Brief description of class still missing.
Full description of class still missing
Description of constructor still missing
References TRACE.
{ TRACE; _scene=new DrawScene; _modified=false; _script="/*\n" "Available commands:\n" " Print properties:\n" " unit()\n" " scale()\n" " margin()\n" " Drawing properties:\n" " pen()\n" " brush()\n" " font()\n" " Drawing actions:\n" " move()\n" " line()\n" " rect()\n" " ellipse()\n" " dim()\n" " text()\n" "*/\n"; }
void MapProject::addCommand | ( | const QString & | cmd | ) |
References DrawScene::parse(), and TRACE.
void MapProject::addConsoleCommand | ( | const QString & | cmd | ) |
References newCommand(), and TRACE.
{ TRACE; setModified(true); emit newCommand(cmd); }
void MapProject::addView | ( | MapView * | v | ) |
References MapView::setProject(), and TRACE.
Referenced by MainWindow::createView().
{ TRACE; v->setProject(this); _views.append(v); setWindowTitle(); }
QPointF MapProject::currentPoint | ( | ) | const [inline] |
References DrawScene::currentPoint().
{return _scene->currentPoint();}
void MapProject::exportImage | ( | QString | fileName = QString::null , |
QString | imageFormat = QString::null , |
||
int | dpi = 300 |
||
) |
References allImageFilter, image(), MSG_ID, print(), DinverCore::qHash(), QGpCoreTools::tr(), and TRACE.
Referenced by MainWindow::exportImage().
{ TRACE; if(fileName.isEmpty()) { fileName=Message::getSaveFileName(tr( "Export image as ..." ), allImageFilter); } if(fileName.length() > 0) { if(imageFormat.isEmpty()) { imageFormat=Settings::getFilter( "filter-" + QString::number(qHash( allImageFilter) )). section( ' ', 0, 0); } if(imageFormat =="PS" || imageFormat =="PDF" ) { QPrinter printer(QPrinter::HighResolution); if(dpi==0) printer.setResolution(300); else printer.setResolution(dpi); printer.setOutputFileName(fileName); printer.setOutputFormat(imageFormat =="PDF" ? QPrinter::PdfFormat : QPrinter::PostScriptFormat); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); print(printer); } else { // Pixel based image format QPixmap pixmap=image(dpi); // Save pixmap to disk if(!pixmap.save(fileName, imageFormat.toAscii().data())) { Message::warning(MSG_ID, tr("Exporting as image"), tr("Failed to export image to file %1 with format %2") .arg(fileName).arg(imageFormat.toAscii().data())); } } } }
QString MapProject::fileName | ( | ) | const [inline] |
Referenced by MainWindow::setActiveProject().
{return _fileName;}
QPixmap MapProject::image | ( | int | dpi | ) |
References TRACE.
Referenced by exportImage().
{ TRACE; // TODO take dpi into account, units for draw, output scale (valid for print as well) QPixmap pixmap(5000, 5000); QPainter painter; painter.begin(&pixmap); painter.setRenderHint(QPainter::Antialiasing); painter.fillRect(0, 0, 5000, 5000, Qt::white); _scene->render(&painter); painter.end(); return pixmap; }
bool MapProject::isClosable | ( | ) |
If project is modified ask user for saving. Returns true if the project can be removed.
References isModified(), MSG_ID, name(), save(), QGpCoreTools::tr(), and TRACE.
Referenced by MainEnvironment::quit().
{ TRACE; printf("MapProject::isClosable()\n"); if(isModified()) { switch (Message::warning(MSG_ID, tr( "Closing project" ), tr( "Do you want to save the changes to project %1?" ).arg(name()), Message::yes(), Message::no(), Message::cancel()) ) { case Message::Answer0: save(); if(isModified()) return false; case Message::Answer1: break; default: return false; } } return true; }
bool MapProject::isModified | ( | ) | const [inline] |
Referenced by isClosable(), and setScript().
{return _modified;}
QString MapProject::name | ( | ) | const [inline] |
Referenced by isClosable(), MainWindow::setActiveProject(), and setName().
{return _name;}
void MapProject::newCommand | ( | const QString & | cmd | ) | [signal] |
Referenced by addConsoleCommand().
bool MapProject::open | ( | QString | fileName = QString::null | ) |
References DrawScene::clear(), QGpCoreTools::XMLClass::NoError, DrawScene::parse(), QGpCoreTools::tr(), TRACE, and QGpCoreTools::XMLHeader::xml_restoreFile().
Referenced by MainEnvironment::openDocument().
{ TRACE; if(fileName.isEmpty()) { fileName=Message::getOpenFileName(tr( "Open an existing document" ), tr( "FastMap document (*.fmap)" )); } if(!fileName.isEmpty()) { XMLHeader hdr(this); if(hdr.xml_restoreFile(fileName)==NoError) { setFileName(fileName); _scene->clear(); _scene->parse(_script); setModified(false); return true; } } return false; }
void MapProject::print | ( | int | dpi = 300 | ) |
References TRACE.
Referenced by exportImage(), and MainWindow::printDocument().
void MapProject::print | ( | QPrinter & | printer | ) |
References DrawScene::margin(), TRACE, and DrawScene::unitToDots().
{ TRACE; QPainter p; printer.setFullPage(true); p.begin(&printer); p.setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing | QPainter::SmoothPixmapTransform, true); double s=_scene->unitToDots(printer.resolution()); printf("Resolution %i dot/inch, scale %lg dots/unit\n", printer.resolution(), s); QRectF sourceRect=_scene->itemsBoundingRect(); QRectF targetRect=sourceRect; printf("original rect %lf %lf %lf %lf\n", sourceRect.x(), sourceRect.y(), sourceRect.width(), sourceRect.height()); sourceRect.setLeft(0); // Temporary solution for wrong rectangle at printing, probably errors in bounding rects sourceRect.setTop(0); printf("original rect %lf %lf %lf %lf\n", sourceRect.x(), sourceRect.y(), sourceRect.width(), sourceRect.height()); targetRect.setSize(sourceRect.size()*s); double margin=_scene->margin()*(printer.resolution()/2.54); targetRect.moveLeft(margin); targetRect.moveTop(margin); printf("target rect %lf %lf %lf %lf\n", targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height()); _scene->render(&p, targetRect, sourceRect); p.end(); }
bool MapProject::removeView | ( | MapView * | v | ) |
References TRACE.
Referenced by MapView::~MapView().
{ TRACE; int i=_views.indexOf(v); if(i>=0) { _views.removeAt(i); setWindowTitle(); if(_views.isEmpty()) deleteLater(); } return true; }
bool MapProject::save | ( | ) |
References QGpCoreTools::XMLClass::NoError, saveAs(), and QGpCoreTools::XMLHeader::xml_saveFile().
Referenced by isClosable(), and MainWindow::saveDocument().
bool MapProject::saveAs | ( | QString | fileName = QString::null | ) |
References QGpCoreTools::XMLClass::NoError, QGpCoreTools::tr(), and QGpCoreTools::XMLHeader::xml_saveFile().
Referenced by save(), and MainWindow::saveDocumentAs().
DrawScene* MapProject::scene | ( | ) | const [inline] |
Referenced by DrawConsole::addCommand(), and MapView::setProject().
{return _scene;}
const QString& MapProject::script | ( | ) | const [inline] |
{return _script;}
void MapProject::setName | ( | const QString & | name | ) |
void MapProject::setScript | ( | const QString & | s | ) |
References DrawScene::clear(), isModified(), DrawScene::parse(), and TRACE.
Referenced by MainWindow::refreshScene(), and DrawConsole::setCurrentProject().
{ TRACE; if(!isModified() && _script!=s) setModified(true); _script=s; _scene->clear(); _scene->parse(_script); }
MapView* MapProject::view | ( | int | index | ) | [inline] |
Referenced by MainEnvironment::newDocument(), and MainEnvironment::openDocument().
{return _views.at(index);}
int MapProject::viewCount | ( | ) | const [inline] |
{return _views.count();}
virtual XMLMember MapProject::xml_member | ( | XML_MEMBER_ARGS | ) | [inline, protected, virtual] |
Re-implement this function to offer XML restore (children and properties) support to your class.
From tag and map (with contains the attibute value) return a unique identifier under the format of a XMLMember. XMLMember is initialized with 3 types of contructors:
Map of attributes can be inspected in this way (can be achived also in xml_setProperty()):
static const QString tmp("childrenName"); XMLRestoreAttributeIterator it=map.find(tmp); if(it!=map.end()) { // found attribute "childrenName" }
If the map of attributes is not used:
Q_UNUSED(attributes); if(tag=="x1") return XMLMember(0); else if(tag=="y1") return XMLMember(1); else if(tag=="x2") return XMLMember(2); else if(tag=="y2") return XMLMember(3); else return XMLMember(XMLMember::Unknown);
Arithmetic operations + and - apply to XMLMember to avoid confusion of property id numbers between inherited objects. Offset 3 corresponds to the number of properties defined in this object.
if(tag=="anInteger") return XMLMember(0); else if(tag=="aString") return XMLMember(1); else if(tag=="aDouble") return XMLMember(2); return AbstractLine::xml_member(tag, attributes, context)+3;
For the arguments of this function use Macro XML_MEMBER_ARGS.
Reimplemented from QGpCoreTools::XMLClass.
References QGpCoreTools::XMLClass::qobject_member().
{return qobject_member(this, tag, attributes, context);}
virtual bool MapProject::xml_setProperty | ( | XML_SETPROPERTY_ARGS | ) | [inline, protected, virtual] |
Re-implement this function to offer XML restore properties support to your class.
From memberID set the corresponding property with value content. The map of attributes is given as a supplementary information (not useful in all cases).
For a general case:
Q_UNUSED(attributes); double val=content.toDouble(); switch (memberID) { case 0: _x1=val; return true; case 1: _y1=val; return true; case 2: _x2=val; return true; case 3: _y2=val; return true; default: return false; }
For classes inheriting other classes (see also xml_member())
switch (memberID) { case 0: _anInteger=content.toString(); return true; case 1: _aString=content.toInt(); return true; case 2: _aDouble=content.toDouble(); return true; default: return AbstractLine::xml_setProperty(memberID-3, map, content);
For the arguments of this function use Macro XML_SETPROPERTY_ARGS.
Reimplemented from QGpCoreTools::XMLClass.
References QGpCoreTools::XMLClass::qobject_setProperty().
{return qobject_setProperty(this, memberID, tag, attributes, content, context);}
virtual const QString& MapProject::xml_tagName | ( | ) | const [inline, virtual] |
virtual void MapProject::xml_writeProperties | ( | XML_WRITEPROPERTIES_ARGS | ) | const [inline, protected, virtual] |
Reimplemented from QGpCoreTools::XMLClass.
References QGpCoreTools::XMLClass::qobject_writeProperties().
{qobject_writeProperties(this, this, s, context);}
const QString MapProject::allImageFilter = ";;" + MapProject::pixelImageFilter [static] |
Referenced by exportImage().
const QString MapProject::pixelImageFilter = "PNG (*.png);;PPM (*.ppm);;XBM (*.xbm);;XPM (*.xpm)" [static] |
const QString MapProject::vectorialImageFilter = "PS (*.ps);;PDF (*.pdf)" [static] |
const QString MapProject::xmlMapProjectTag = "MapProject" [static] |
Referenced by xml_tagName().
QString MapProject::script [read, write] |
Referenced by DrawConsole::setCurrentProject().