Signals | Public Member Functions | Static Public Attributes | Protected Member Functions | Properties
MapProject Class Reference

Brief description of class still missing. More...

#include <MapProject.h>

Inheritance diagram for MapProject:
QGpCoreTools::XMLClass

List of all members.

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)
DrawScenescene () const
const QString & script () const
void setName (const QString &name)
void setScript (const QString &s)
MapViewview (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

Detailed Description

Brief description of class still missing.

Full description of class still missing


Constructor & Destructor Documentation

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";
}

Description of destructor still missing

References TRACE.

{
  TRACE;
  qDeleteAll(_views);
  delete _scene;
}

Member Function Documentation

void MapProject::addCommand ( const QString &  cmd)

References DrawScene::parse(), and TRACE.

{
  TRACE;
  _script+="\n"+cmd;
  _scene->parse(cmd);
  setModified(true);
}
void MapProject::addConsoleCommand ( const QString &  cmd)

References newCommand(), and TRACE.

{
  TRACE;
  setModified(true);
  emit newCommand(cmd);
}

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;
}

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().

{
  TRACE;
  QPrinter printer(QPrinter::HighResolution);
  if(dpi==0)
    printer.setResolution(300); // TODO Add it in parameters
  else
    printer.setResolution(dpi);
  if(Settings::printSetup(printer) ) {
    QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
    print(printer);
  }
}
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();
}

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().

{
  if(_fileName.isEmpty()) return saveAs();
  XMLHeader hdr(this);
  if(hdr.xml_saveFile(_fileName)==NoError) {
    setModified(false);
    return true;
  }
  return false;
}
bool MapProject::saveAs ( QString  fileName = QString::null)

References QGpCoreTools::XMLClass::NoError, QGpCoreTools::tr(), and QGpCoreTools::XMLHeader::xml_saveFile().

Referenced by save(), and MainWindow::saveDocumentAs().

{
  if(fileName.isEmpty()) {
    fileName=Message::getSaveFileName(tr( "Save current document" ), tr( "FastMap document (*.fmap)" ));
  }
  if(!fileName.isEmpty()) {
    XMLHeader hdr(this);
    if(hdr.xml_saveFile(fileName, 0)==NoError) {
      setFileName(fileName);
      setModified(false);
      return true;
    }
  }
  return false;
}
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)

References name(), and TRACE.

{
  TRACE;
  _name=name;
  setWindowTitle();
}
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:

  • An integer: id number of a property
  • A XMLClass * : a child of this object identified by tag
  • Default constructor: error, unknow child or property

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]

Implements QGpCoreTools::XMLClass.

References xmlMapProjectTag.

{return xmlMapProjectTag;}
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);}

Member Data Documentation

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().


Property Documentation

QString MapProject::script [read, write]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines