mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
save settings in project
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@2849 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
2d230f4a98
commit
0df72b902e
@ -449,11 +449,33 @@ void QgsComposer::projectRead(void)
|
||||
std::cout << "QgsComposer::projectRead" << std::endl;
|
||||
|
||||
if ( mComposition ) delete mComposition;
|
||||
|
||||
mComposition = new QgsComposition( this, 1 );
|
||||
mComposition->setActive ( true );
|
||||
mComposition->readSettings ( );
|
||||
|
||||
// Read composition if it is defined in project
|
||||
QStringList l = QgsProject::instance()->subkeyList ( "Compositions", "" );
|
||||
|
||||
bool found = false;
|
||||
for ( QStringList::iterator it = l.begin(); it != l.end(); ++it ) {
|
||||
std::cout << "key: " << (*it).ascii() << std::endl;
|
||||
if ( (*it).compare ( "composition_1" ) == 0 ) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( found ) {
|
||||
mComposition->readSettings ( );
|
||||
mFirstTime = false;
|
||||
} else {
|
||||
if ( isVisible() ) {
|
||||
mComposition->createDefault();
|
||||
mFirstTime = false;
|
||||
} else {
|
||||
mFirstTime = true;
|
||||
}
|
||||
}
|
||||
|
||||
mComposition->setActive ( true );
|
||||
}
|
||||
|
||||
void QgsComposer::newProject(void)
|
||||
|
@ -35,6 +35,19 @@ class QResizeEvent;
|
||||
class QgisApp;
|
||||
class QgsComposerItem;
|
||||
|
||||
/* The constructor creates empty composer, without compositions and mFirstTime set to true.
|
||||
* - if signal projectRead() is recieved all old compositions are deleted and
|
||||
* - if the composition exists in project it is created from project settings (mFirstTime set to false)
|
||||
* - if the composition does not exist in project
|
||||
* - if the composer is visible new default composition is created (mFirstTime set to false)
|
||||
* - if the composer is not visible the composer is left empty (mFirstTime set to true)
|
||||
* - if signal newProject() is recieved all old compositions are deleted and
|
||||
* - if the composer is visible a new default composition is created (mFirstTime set to false)
|
||||
* - if the composer is not visible the composer is left empty (mFirstTime set to true)
|
||||
*
|
||||
* If open() is called and mFirstTime == true, a new default composition is created.
|
||||
*
|
||||
*/
|
||||
class QgsComposer: public QgsComposerBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -77,8 +77,38 @@ QgsComposerLabel::QgsComposerLabel ( QgsComposition *composition, int id,
|
||||
writeSettings();
|
||||
}
|
||||
|
||||
QgsComposerLabel::QgsComposerLabel ( QgsComposition *composition, int id )
|
||||
: QCanvasPolygonalItem(0)
|
||||
{
|
||||
std::cout << "QgsComposerLabel::QgsComposerLabel()" << std::endl;
|
||||
|
||||
mComposition = composition;
|
||||
mId = id;
|
||||
mSelected = false;
|
||||
|
||||
readSettings();
|
||||
|
||||
setOptions();
|
||||
|
||||
// Add to canvas
|
||||
setCanvas(mComposition->canvas());
|
||||
QCanvasPolygonalItem::setZ(100);
|
||||
setActive(true);
|
||||
QCanvasPolygonalItem::show();
|
||||
QCanvasPolygonalItem::update(); // ?
|
||||
|
||||
}
|
||||
|
||||
QgsComposerLabel::~QgsComposerLabel()
|
||||
{
|
||||
std::cout << "QgsComposerLabel::~QgsComposerLabel" << std::endl;
|
||||
QCanvasItem::hide();
|
||||
}
|
||||
|
||||
void QgsComposerLabel::drawShape ( QPainter & painter )
|
||||
{
|
||||
std::cout << "QgsComposerLabel::drawShape" << std::endl;
|
||||
draw ( painter );
|
||||
}
|
||||
|
||||
void QgsComposerLabel::draw ( QPainter & painter )
|
||||
@ -163,11 +193,6 @@ QRect QgsComposerLabel::boundingRect ( void ) const
|
||||
return r;
|
||||
}
|
||||
|
||||
void QgsComposerLabel::drawShape(QPainter&)
|
||||
{
|
||||
std::cout << "QgsComposerLabel::drawShape" << std::endl;
|
||||
}
|
||||
|
||||
QPointArray QgsComposerLabel::areaPoints() const
|
||||
{
|
||||
std::cout << "QgsComposerLabel::areaPoints" << std::endl;
|
||||
@ -192,6 +217,7 @@ void QgsComposerLabel::textChanged ( void )
|
||||
{
|
||||
mText = mTextLineEdit->text();
|
||||
QCanvasPolygonalItem::update();
|
||||
QCanvasPolygonalItem::canvas()->update();
|
||||
writeSettings();
|
||||
}
|
||||
|
||||
@ -219,29 +245,44 @@ bool QgsComposerLabel::writeSettings ( void )
|
||||
{
|
||||
QString path;
|
||||
path.sprintf("/composition_%d/label_%d/", mComposition->id(), mId );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"x", (int)QCanvasPolygonalItem::x() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"y", (int)QCanvasPolygonalItem::y() );
|
||||
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"text", mText );
|
||||
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)QCanvasPolygonalItem::x()) );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)QCanvasPolygonalItem::y()) );
|
||||
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"font/size", mFont.pointSize() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"font/family", mFont.family() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"font/weight", mFont.weight() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"font/underline", mFont.underline() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"font/strikeout", mFont.strikeOut() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QgsComposerLabel::readSettings ( void )
|
||||
{
|
||||
std::cout << "QgsComposerLabel::readSettings mId = " << mId << std::endl;
|
||||
bool ok;
|
||||
|
||||
QString path;
|
||||
path.sprintf("/composition_%d/label_%d/", mComposition->id(), mId );
|
||||
|
||||
QCanvasPolygonalItem::setX( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok)) );
|
||||
QCanvasPolygonalItem::setY( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok)) );
|
||||
mText = QgsProject::instance()->readEntry("Compositions", path+"text", "???", &ok);
|
||||
|
||||
int x = mComposition->fromMM( QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok) );
|
||||
QCanvasPolygonalItem::setX( x );
|
||||
int y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok) );
|
||||
QCanvasPolygonalItem::setY( y );
|
||||
|
||||
mFont.setFamily ( QgsProject::instance()->readEntry("Compositions", path+"font/family", "", &ok) );
|
||||
mFont.setPointSize ( QgsProject::instance()->readNumEntry("Compositions", path+"font/size", 10, &ok) );
|
||||
mFont.setWeight( QgsProject::instance()->readNumEntry("Compositions", path+"font/weight", (int)QFont::Normal, &ok) );
|
||||
mFont.setUnderline( QgsProject::instance()->readBoolEntry("Compositions", path+"font/underline", false, &ok) );
|
||||
mFont.setStrikeOut( QgsProject::instance()->readBoolEntry("Compositions", path+"font/strikeout", false, &ok) );
|
||||
|
||||
QCanvasPolygonalItem::update();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -61,10 +61,17 @@ class QgsComposerLabel : public QgsComposerLabelBase, public QCanvasPolygonalIte
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/** \brief Preview style
|
||||
/** \brief Constructor. Settings are written to project.
|
||||
* \param id object id
|
||||
* \param fontSize font size in typographic points!
|
||||
*/
|
||||
QgsComposerLabel( QgsComposition *composition, int id, int x, int y, QString text, int fontSize = 0 );
|
||||
|
||||
/** \brief Constructor. Settings are read from project.
|
||||
* \param id object id
|
||||
*/
|
||||
QgsComposerLabel( QgsComposition *composition, int id );
|
||||
|
||||
~QgsComposerLabel();
|
||||
|
||||
// Reimplement QgsComposerItem:
|
||||
|
@ -46,18 +46,43 @@ QgsComposerMap::QgsComposerMap ( QgsComposition *composition, int id, int x, int
|
||||
mComposition = composition;
|
||||
mId = id;
|
||||
mMapCanvas = mComposition->mapCanvas();
|
||||
mNumCachedLayers;
|
||||
mName.sprintf ( tr("Map %d"), mId );
|
||||
|
||||
mSelected = false;
|
||||
|
||||
init();
|
||||
recalculate();
|
||||
|
||||
// Add to canvas
|
||||
setCanvas(mComposition->canvas());
|
||||
QCanvasRectangle::setZ(20);
|
||||
setActive(true);
|
||||
QCanvasRectangle::show();
|
||||
QCanvasRectangle::update(); // ?
|
||||
|
||||
|
||||
writeSettings();
|
||||
}
|
||||
|
||||
QgsComposerMap::QgsComposerMap ( QgsComposition *composition, int id )
|
||||
: QCanvasRectangle(0,0,10,10,0)
|
||||
{
|
||||
mComposition = composition;
|
||||
mId = id;
|
||||
mMapCanvas = mComposition->mapCanvas();
|
||||
mName.sprintf ( tr("Map %d"), mId );
|
||||
|
||||
init();
|
||||
readSettings();
|
||||
recalculate();
|
||||
|
||||
// Add to canvas
|
||||
setCanvas(mComposition->canvas());
|
||||
QCanvasRectangle::show();
|
||||
QCanvasRectangle::update(); // ?
|
||||
}
|
||||
|
||||
void QgsComposerMap::init ()
|
||||
{
|
||||
mNumCachedLayers = 0;
|
||||
mSelected = false;
|
||||
mUserExtent = mMapCanvas->extent();
|
||||
|
||||
// Cache
|
||||
mCachePixmap = new QPixmap();
|
||||
|
||||
@ -77,11 +102,13 @@ QgsComposerMap::QgsComposerMap ( QgsComposition *composition, int id, int x, int
|
||||
mSymbolScale = 1.0;
|
||||
mFontScale = 1.0;
|
||||
|
||||
writeSettings();
|
||||
QCanvasRectangle::setZ(20);
|
||||
setActive(true);
|
||||
}
|
||||
|
||||
QgsComposerMap::~QgsComposerMap()
|
||||
{
|
||||
std::cerr << "QgsComposerMap::~QgsComposerMap" << std::endl;
|
||||
}
|
||||
|
||||
void QgsComposerMap::draw ( QPainter *painter, QgsRect *extent, QgsMapToPixel *transform, QPaintDevice *device )
|
||||
@ -136,6 +163,8 @@ void QgsComposerMap::cache ( void )
|
||||
|
||||
int w = QCanvasRectangle::width() < 1000 ? QCanvasRectangle::width() : 1000;
|
||||
int h = (int) ( mExtent.height() * w / mExtent.width() );
|
||||
// It can happen that extent is not initialised well -> check
|
||||
if ( h < 1 || h > 10000 ) h = w;
|
||||
|
||||
std::cout << "extent = " << mExtent.width() << " x " << mExtent.height() << std::endl;
|
||||
std::cout << "cache = " << w << " x " << h << std::endl;
|
||||
@ -375,15 +404,21 @@ bool QgsComposerMap::writeSettings ( void )
|
||||
{
|
||||
QString path;
|
||||
path.sprintf("/composition_%d/map_%d/", mComposition->id(), mId );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"x", (int)QCanvasRectangle::x() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"y", QCanvasRectangle::y() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"width", (double)QCanvasRectangle::width() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"height", (double)QCanvasRectangle::height() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)QCanvasRectangle::x()) );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)QCanvasRectangle::y()) );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"width", mComposition->toMM(QCanvasRectangle::width()) );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"height", mComposition->toMM(QCanvasRectangle::height()) );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"north", mUserExtent.yMax() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"south", mUserExtent.yMin() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"east", mUserExtent.xMax() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"west", mUserExtent.xMin() );
|
||||
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"widthscale", mWidthScale );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"symbolscale", mSymbolScale );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"fontscale", mFontScale );
|
||||
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"previewmode", mPreviewMode );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -404,6 +439,12 @@ bool QgsComposerMap::readSettings ( void )
|
||||
mUserExtent.setYmin ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"south", 0, &ok) );
|
||||
mUserExtent.setXmax ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"east", 100, &ok) );
|
||||
mUserExtent.setXmin ( QgsProject::instance()->readDoubleEntry( "Compositions", path+"west", 0, &ok) );
|
||||
|
||||
mWidthScale = QgsProject::instance()->readDoubleEntry("Compositions", path+"widthscale", 1., &ok);
|
||||
mSymbolScale = QgsProject::instance()->readDoubleEntry("Compositions", path+"symbolscale", 1., &ok);
|
||||
mFontScale = QgsProject::instance()->readDoubleEntry("Compositions", path+"fontscale", 1., &ok);
|
||||
|
||||
mPreviewMode = (PreviewMode) QgsProject::instance()->readNumEntry("Compositions", path+"previewmode", Cache, &ok);
|
||||
|
||||
recalculate();
|
||||
|
||||
|
@ -53,12 +53,14 @@ class QgsComposition;
|
||||
*/
|
||||
// NOTE: QgsComposerMapBase must be first, otherwise does not compile
|
||||
class QgsComposerMap : public QgsComposerMapBase, public QCanvasRectangle, public QgsComposerItem
|
||||
//class QgsComposerMap : public QCanvasSprite, public QgsComposerItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/** Constructor. */
|
||||
QgsComposerMap( QgsComposition *composition, int id, int x, int y, int width, int height );
|
||||
/** Constructor. Settings are read from project. */
|
||||
QgsComposerMap( QgsComposition *composition, int id );
|
||||
~QgsComposerMap();
|
||||
|
||||
/** \brief Preview style */
|
||||
@ -68,6 +70,9 @@ public:
|
||||
Rectangle // Display only rectangle
|
||||
};
|
||||
|
||||
/** \brief Initialise GUI and other settings, shared by constructors */
|
||||
void init ( void );
|
||||
|
||||
// Reimplement QgsComposerItem:
|
||||
void setSelected( bool s );
|
||||
bool selected( void );
|
||||
|
@ -70,17 +70,72 @@ QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition,
|
||||
mComposition = composition;
|
||||
mId = id;
|
||||
mMapCanvas = mComposition->mapCanvas();
|
||||
mNumCachedLayers = 0;
|
||||
|
||||
mTitle = "Legend";
|
||||
init();
|
||||
|
||||
// Font and pen
|
||||
mFont.setPointSize ( fontSize );
|
||||
|
||||
// Set map to the first available if any
|
||||
std::vector<QgsComposerMap*> maps = mComposition->maps();
|
||||
if ( maps.size() > 0 ) {
|
||||
mMap = maps[0]->id();
|
||||
}
|
||||
|
||||
// Calc size and cache
|
||||
recalculate();
|
||||
cache();
|
||||
|
||||
// Add to canvas
|
||||
setCanvas(mComposition->canvas());
|
||||
|
||||
QCanvasRectangle::show();
|
||||
QCanvasRectangle::update();
|
||||
|
||||
|
||||
writeSettings();
|
||||
}
|
||||
|
||||
QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition, int id )
|
||||
: QCanvasRectangle(0,0,10,10,0)
|
||||
{
|
||||
std::cout << "QgsComposerVectorLegend::QgsComposerVectorLegend()" << std::endl;
|
||||
|
||||
mComposition = composition;
|
||||
mId = id;
|
||||
mMapCanvas = mComposition->mapCanvas();
|
||||
|
||||
init();
|
||||
|
||||
readSettings();
|
||||
|
||||
// Calc size and cache
|
||||
recalculate();
|
||||
cache();
|
||||
|
||||
// Add to canvas
|
||||
setCanvas(mComposition->canvas());
|
||||
|
||||
QCanvasRectangle::show();
|
||||
QCanvasRectangle::update();
|
||||
}
|
||||
|
||||
void QgsComposerVectorLegend::init ( void )
|
||||
{
|
||||
mSelected = false;
|
||||
mNumCachedLayers = 0;
|
||||
mTitle = "Legend";
|
||||
mMap = 0;
|
||||
|
||||
// Cache
|
||||
mCachePixmap = new QPixmap();
|
||||
|
||||
// Rectangle
|
||||
QCanvasRectangle::setZ(50);
|
||||
setActive(true);
|
||||
|
||||
// Plot style
|
||||
setPlotStyle ( QgsComposition::Preview );
|
||||
|
||||
mSelected = false;
|
||||
|
||||
// Preview style
|
||||
mPreviewMode = Render;
|
||||
@ -89,42 +144,17 @@ QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition,
|
||||
mPreviewModeComboBox->insertItem ( "Rectangle", Rectangle );
|
||||
mPreviewModeComboBox->setCurrentItem ( mPreviewMode );
|
||||
|
||||
// Cache
|
||||
mCachePixmap = new QPixmap();
|
||||
|
||||
// Calc size and cache
|
||||
recalculate();
|
||||
cache();
|
||||
|
||||
// Add to canvas
|
||||
setCanvas(mComposition->canvas());
|
||||
QCanvasRectangle::setZ(50);
|
||||
setActive(true);
|
||||
QCanvasRectangle::show();
|
||||
QCanvasRectangle::update(); // ?
|
||||
|
||||
// Set map to the first available if any
|
||||
std::vector<QgsComposerMap*> maps = mComposition->maps();
|
||||
|
||||
if ( maps.size() > 0 ) {
|
||||
mMap = maps[0]->id();
|
||||
} else {
|
||||
mMap = 0;
|
||||
}
|
||||
|
||||
connect ( mComposition, SIGNAL(mapChanged(int)), this, SLOT(mapChanged(int)) );
|
||||
|
||||
setOptions();
|
||||
writeSettings();
|
||||
}
|
||||
|
||||
QgsComposerVectorLegend::~QgsComposerVectorLegend()
|
||||
{
|
||||
std::cerr << "QgsComposerVectorLegend::~QgsComposerVectorLegend()" << std::endl;
|
||||
}
|
||||
|
||||
QRect QgsComposerVectorLegend::render ( QPainter *p )
|
||||
{
|
||||
std::cout << "QgsComposerVectorLegend::render" << std::endl;
|
||||
std::cout << "QgsComposerVectorLegend::render p = " << p << std::endl;
|
||||
|
||||
// Painter can be 0, create dummy to avoid many if below
|
||||
QPainter *painter;
|
||||
@ -136,11 +166,14 @@ QRect QgsComposerVectorLegend::render ( QPainter *p )
|
||||
painter = new QPainter( pixmap );
|
||||
}
|
||||
|
||||
std::cout << "mComposition->scale() = " << mComposition->scale() << std::endl;
|
||||
// Font size in canvas units
|
||||
int titleSize = (int) ( 25.4 * mComposition->scale() * mTitleFont.pointSize() / 72);
|
||||
int sectionSize = (int) ( 25.4 * mComposition->scale() * mSectionFont.pointSize() / 72);
|
||||
int size = (int) ( 25.4 * mComposition->scale() * mFont.pointSize() / 72);
|
||||
|
||||
std::cout << "font sizes = " << titleSize << " " << sectionSize << " " << size << std::endl;
|
||||
|
||||
// Metrics
|
||||
QFont titleFont ( mTitleFont );
|
||||
QFont sectionFont ( mSectionFont );
|
||||
@ -153,7 +186,7 @@ QRect QgsComposerVectorLegend::render ( QPainter *p )
|
||||
QFontMetrics titleMetrics ( titleFont );
|
||||
QFontMetrics sectionMetrics ( sectionFont );
|
||||
QFontMetrics metrics ( font );
|
||||
|
||||
|
||||
// Fonts for rendering
|
||||
|
||||
// It seems that font pointSize is used in points in Postscript, that means it depends
|
||||
@ -461,7 +494,7 @@ void QgsComposerVectorLegend::recalculate ( void )
|
||||
|
||||
QCanvasRectangle::setSize ( r.width(), r.height() );
|
||||
|
||||
setOptions();
|
||||
//setOptions();
|
||||
cache();
|
||||
}
|
||||
|
||||
@ -514,11 +547,21 @@ bool QgsComposerVectorLegend::writeSettings ( void )
|
||||
{
|
||||
QString path;
|
||||
path.sprintf("/composition_%d/vectorlegend_%d/", mComposition->id(), mId );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"x", (int)QCanvasRectangle::x() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"y", (int)QCanvasRectangle::y() );
|
||||
|
||||
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)QCanvasRectangle::x()) );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)QCanvasRectangle::y()) );
|
||||
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"map", mMap );
|
||||
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"title", mTitle );
|
||||
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"font/size", mFont.pointSize() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"font/family", mFont.family() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"font/weight", mFont.weight() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"font/underline", mFont.underline() );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"font/strikeout", mFont.strikeOut() );
|
||||
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"previewmode", mPreviewMode );
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -531,9 +574,17 @@ bool QgsComposerVectorLegend::readSettings ( void )
|
||||
|
||||
QCanvasRectangle::setX( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok)) );
|
||||
QCanvasRectangle::setY( mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok)) );
|
||||
|
||||
mMap = QgsProject::instance()->readNumEntry("Compositions", path+"map", 0, &ok);
|
||||
mTitle = QgsProject::instance()->readEntry("Compositions", path+"title", "???", &ok);
|
||||
|
||||
mFont.setFamily ( QgsProject::instance()->readEntry("Compositions", path+"font/family", "", &ok) );
|
||||
mFont.setPointSize ( QgsProject::instance()->readNumEntry("Compositions", path+"font/size", 10, &ok) );
|
||||
mFont.setWeight( QgsProject::instance()->readNumEntry("Compositions", path+"font/weight", (int)QFont::Normal, &ok) );
|
||||
mFont.setUnderline( QgsProject::instance()->readBoolEntry("Compositions", path+"font/underline", false, &ok) );
|
||||
mFont.setStrikeOut( QgsProject::instance()->readBoolEntry("Compositions", path+"font/strikeout", false, &ok) );
|
||||
|
||||
mPreviewMode = (PreviewMode) QgsProject::instance()->readNumEntry("Compositions", path+"previewmode", Render, &ok);
|
||||
|
||||
recalculate();
|
||||
|
||||
|
@ -85,10 +85,16 @@ class QgsComposerVectorLegend : public QgsComposerVectorLegendBase, public QCanv
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/** \brief Preview style
|
||||
/** \brief Constructor
|
||||
* \param id object id
|
||||
* \param fontSize font size in typographic points!
|
||||
*/
|
||||
QgsComposerVectorLegend( QgsComposition *composition, int id, int x, int y, int fontSize = 0 );
|
||||
|
||||
/** \brief Constructor. Settings are read from project.
|
||||
* \param id object id
|
||||
*/
|
||||
QgsComposerVectorLegend( QgsComposition *composition, int id );
|
||||
~QgsComposerVectorLegend();
|
||||
|
||||
/** \brief Preview style */
|
||||
@ -98,6 +104,9 @@ public:
|
||||
Rectangle // Display only rectangle
|
||||
};
|
||||
|
||||
/** \brief Initialise GUI etc., share by constructors. */
|
||||
void init(void);
|
||||
|
||||
// Reimplement QgsComposerItem:
|
||||
void setSelected( bool s );
|
||||
bool selected( void );
|
||||
|
@ -86,12 +86,14 @@ QgsComposition::QgsComposition( QgsComposer *c, int id )
|
||||
mPapers.push_back ( QgsCompositionPaper( tr("Letter (8.5x11 inches)"), 216, 279 ) );
|
||||
mPapers.push_back ( QgsCompositionPaper( tr("Legal (8.5x14 inches)"), 216, 356 ) );
|
||||
|
||||
mDefaultPaper = mCustomPaper = 0;
|
||||
for( int i = 0; i < mPapers.size(); i++ ) {
|
||||
mPaperSizeComboBox->insertItem( mPapers[i].mName );
|
||||
// Map - A4 land for now, if future read from template
|
||||
if ( mPapers[i].mWidth == 210 && mPapers[i].mHeight == 297 ){
|
||||
mDefaultPaper = i;
|
||||
}
|
||||
if ( mPapers[i].mCustom ) mCustomPaper = i;
|
||||
}
|
||||
|
||||
// Orientation
|
||||
@ -100,11 +102,6 @@ QgsComposition::QgsComposition( QgsComposer *c, int id )
|
||||
|
||||
mPaperUnitsComboBox->insertItem( "mm" );
|
||||
|
||||
// Some defaults, not important because true defaults are set by createDefault()
|
||||
mPaperSizeComboBox->setCurrentItem(mDefaultPaper);
|
||||
mPaperOrientationComboBox->setCurrentItem(Landscape);
|
||||
mResolution = 72;
|
||||
|
||||
// Create canvas
|
||||
mPaperWidth = 1;
|
||||
mPaperHeight = 1;
|
||||
@ -122,23 +119,18 @@ void QgsComposition::createDefault(void)
|
||||
mPaperSizeComboBox->setCurrentItem(mDefaultPaper);
|
||||
mPaperOrientationComboBox->setCurrentItem(Landscape);
|
||||
|
||||
mPaperWidth = mPapers[mDefaultPaper].mWidth;
|
||||
mPaperHeight = mPapers[mDefaultPaper].mHeight;
|
||||
mUserPaperWidth = mPapers[mDefaultPaper].mWidth;
|
||||
mUserPaperHeight = mPapers[mDefaultPaper].mHeight;
|
||||
|
||||
// TODO: The resolution should be at least 300, but point layer is rescaled
|
||||
// in Postscript if != 72
|
||||
//mResolution = 300;
|
||||
mResolution = 72;
|
||||
recalculate();
|
||||
|
||||
mResolution = 300;
|
||||
|
||||
paperSizeChanged();
|
||||
setOptions();
|
||||
|
||||
resizeCanvas();
|
||||
|
||||
// Add the map to coposition
|
||||
QgsComposerMap *m = new QgsComposerMap ( this, mNextItemId++,
|
||||
mScale*15, mScale*15, mScale*180, mScale*180 );
|
||||
m->setUserExtent( mMapCanvas->extent());
|
||||
mItems.push_back(m);
|
||||
|
||||
// Add vector legend
|
||||
@ -182,13 +174,37 @@ void QgsComposition::createCanvas(void)
|
||||
void QgsComposition::resizeCanvas(void)
|
||||
{
|
||||
mCanvas->resize ( (int) mPaperWidth * mScale, (int) mPaperHeight * mScale );
|
||||
|
||||
std::cout << "mCanvas width = " << mCanvas->width() << " height = " << mCanvas->height() << std::endl;
|
||||
mPaperItem->setSize ( (int) mPaperWidth * mScale, (int) mPaperHeight * mScale );
|
||||
}
|
||||
|
||||
QgsComposition::~QgsComposition()
|
||||
{
|
||||
// TODO: Delete all objects!!!!
|
||||
std::cerr << "QgsComposition::~QgsComposition" << std::endl;
|
||||
mView->setCanvas ( 0 );
|
||||
|
||||
if ( mPaperItem ) delete mPaperItem;
|
||||
|
||||
/* TODO: For some strange reason, it crashes if QgsComposerItem (QgsComposerLabel,QgsComposerMap)
|
||||
* is deleted. It crashes before the destructor is called. QgsComposerVectorLegend works.
|
||||
* -> deleting canvas items
|
||||
*/
|
||||
for (std::list < QgsComposerItem * >::iterator it = mItems.begin();
|
||||
it != mItems.end(); ++it)
|
||||
{
|
||||
//delete *it; // crashes on QgsComposerLabel and QgsComposerMap
|
||||
QCanvasItem *ci = dynamic_cast<QCanvasItem*>(*it);
|
||||
delete ci;
|
||||
}
|
||||
|
||||
/*
|
||||
QCanvasItemList l = mCanvas->allItems();
|
||||
for ( QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
*/
|
||||
|
||||
if ( mCanvas ) delete mCanvas;
|
||||
}
|
||||
|
||||
QgsMapCanvas *QgsComposition::mapCanvas(void) { return mMapCanvas; }
|
||||
@ -220,13 +236,10 @@ void QgsComposition::contentsMousePressEvent(QMouseEvent* e)
|
||||
|
||||
QCanvasItem * newItem = 0;
|
||||
|
||||
std::cerr << "-->" << std::endl;
|
||||
for ( QCanvasItemList::Iterator it=l.fromLast(); it!=l.end(); --it) {
|
||||
std::cerr << "it = " << (*it) << std::endl;
|
||||
if (! (*it)->isActive() ) continue;
|
||||
newItem = *it;
|
||||
}
|
||||
std::cerr << "-->" << std::endl;
|
||||
|
||||
if ( newItem ) { // found
|
||||
if ( newItem != mSelectedItem ) { // Show options
|
||||
@ -275,7 +288,6 @@ void QgsComposition::contentsMousePressEvent(QMouseEvent* e)
|
||||
mNewCanvasItem->setY( p.y() );
|
||||
QgsComposerVectorLegend *vl = dynamic_cast <QgsComposerVectorLegend*> (mNewCanvasItem);
|
||||
mItems.push_back(vl);
|
||||
vl->writeSettings();
|
||||
mNewCanvasItem = 0;
|
||||
mComposer->selectItem(); // usually just one legend
|
||||
|
||||
@ -294,7 +306,6 @@ void QgsComposition::contentsMousePressEvent(QMouseEvent* e)
|
||||
mNewCanvasItem->setY( p.y() );
|
||||
QgsComposerLabel *lab = dynamic_cast <QgsComposerLabel*> (mNewCanvasItem);
|
||||
mItems.push_back(lab);
|
||||
lab->writeSettings();
|
||||
mNewCanvasItem = 0;
|
||||
mComposer->selectItem(); // usually just one ???
|
||||
|
||||
@ -321,7 +332,6 @@ void QgsComposition::contentsMouseMoveEvent(QMouseEvent* e)
|
||||
if ( mSelectedItem ) {
|
||||
double x,y;
|
||||
mView->inverseWorldMatrix().map( e->pos().x(), e->pos().y(), &x, &y );
|
||||
std::cout << "move: " << x << ", " << y << std::endl;
|
||||
|
||||
mSelectedItem->setX( mSelectedItem->x() + x - mLastX );
|
||||
mSelectedItem->setY( mSelectedItem->y() + y - mLastY );
|
||||
@ -417,7 +427,6 @@ void QgsComposition::keyPressEvent ( QKeyEvent * e )
|
||||
if ( e->key() == Qt::Key_Delete && mSelectedItem ) { // delete
|
||||
|
||||
QgsComposerItem *coi = dynamic_cast <QgsComposerItem *> (mSelectedItem);
|
||||
//coi->setItemSelected ( false );
|
||||
coi->setSelected ( false );
|
||||
for (std::list < QgsComposerItem * >::iterator it = mItems.begin();
|
||||
it != mItems.end(); ++it)
|
||||
@ -438,9 +447,11 @@ void QgsComposition::paperSizeChanged ( void )
|
||||
{
|
||||
std::cout << "QgsComposition::paperSizeChanged" << std::endl;
|
||||
|
||||
std::cout << "custom = " << mPapers[mPaperSizeComboBox->currentItem()].mCustom << std::endl;
|
||||
std::cout << "orientation = " << mPaperOrientationComboBox->currentItem() << std::endl;
|
||||
if ( mPapers[mPaperSizeComboBox->currentItem()].mCustom ) {
|
||||
mPaper = mPaperSizeComboBox->currentItem();
|
||||
mPaperOrientation = mPaperOrientationComboBox->currentItem();
|
||||
std::cout << "custom = " << mPapers[mPaper].mCustom << std::endl;
|
||||
std::cout << "orientation = " << mPaperOrientation << std::endl;
|
||||
if ( mPapers[mPaper].mCustom ) {
|
||||
mUserPaperWidth = mPaperWidthLineEdit->text().toDouble();
|
||||
mUserPaperHeight = mPaperHeightLineEdit->text().toDouble();
|
||||
mPaperWidthLineEdit->setEnabled( TRUE );
|
||||
@ -452,9 +463,17 @@ void QgsComposition::paperSizeChanged ( void )
|
||||
mPaperHeightLineEdit->setEnabled( FALSE );
|
||||
setOptions();
|
||||
}
|
||||
|
||||
recalculate();
|
||||
|
||||
if ( (mPaperOrientationComboBox->currentItem() == Portrait && mUserPaperWidth < mUserPaperHeight) ||
|
||||
(mPaperOrientationComboBox->currentItem() == Landscape && mUserPaperWidth > mUserPaperHeight) )
|
||||
mView->repaintContents();
|
||||
writeSettings();
|
||||
}
|
||||
|
||||
void QgsComposition::recalculate ( void )
|
||||
{
|
||||
if ( (mPaperOrientation == Portrait && mUserPaperWidth < mUserPaperHeight) ||
|
||||
(mPaperOrientation == Landscape && mUserPaperWidth > mUserPaperHeight) )
|
||||
{
|
||||
mPaperWidth = mUserPaperWidth;
|
||||
mPaperHeight = mUserPaperHeight;
|
||||
@ -462,18 +481,9 @@ void QgsComposition::paperSizeChanged ( void )
|
||||
mPaperWidth = mUserPaperHeight;
|
||||
mPaperHeight = mUserPaperWidth;
|
||||
}
|
||||
|
||||
std::cout << "mPaperWidth = " << mPaperWidth << " mPaperHeight = " << mPaperHeight << std::endl;
|
||||
|
||||
mCanvas->resize( (int) (mPaperWidth * mScale), (int) (mPaperHeight * mScale) );
|
||||
|
||||
std::cout << "mCanvas width = " << mCanvas->width() << " height = " << mCanvas->height() << std::endl;
|
||||
|
||||
mPaperItem->setSize((int) (mPaperWidth * mScale), (int) (mPaperHeight * mScale) );
|
||||
|
||||
resizeCanvas();
|
||||
mComposer->zoomFull();
|
||||
mView->repaintContents();
|
||||
writeSettings();
|
||||
}
|
||||
|
||||
void QgsComposition::resolutionChanged ( void )
|
||||
@ -484,6 +494,8 @@ void QgsComposition::resolutionChanged ( void )
|
||||
|
||||
void QgsComposition::setOptions ( void )
|
||||
{
|
||||
mPaperSizeComboBox->setCurrentItem(mPaper);
|
||||
mPaperOrientationComboBox->setCurrentItem(mPaperOrientation);
|
||||
mPaperWidthLineEdit->setText ( QString("%1").arg(mUserPaperWidth,0,'g') );
|
||||
mPaperHeightLineEdit->setText ( QString("%1").arg(mUserPaperHeight,0,'g') );
|
||||
mResolutionLineEdit->setText ( QString("%1").arg(mResolution) );
|
||||
@ -517,7 +529,10 @@ double QgsComposition::paperHeight ( void ) { return mPaperHeight; }
|
||||
|
||||
int QgsComposition::resolution ( void ) { return mResolution; }
|
||||
|
||||
int QgsComposition::scale( void ) { return mScale; }
|
||||
int QgsComposition::scale( void ) {
|
||||
std::cout << "QgsComposition::scale = " << mScale << std::endl;
|
||||
return mScale;
|
||||
}
|
||||
|
||||
double QgsComposition::toMM ( int v ) { return v/mScale ; }
|
||||
|
||||
@ -624,14 +639,19 @@ void QgsComposition::emitMapChanged ( int id )
|
||||
|
||||
bool QgsComposition::writeSettings ( void )
|
||||
{
|
||||
QString path;
|
||||
path.sprintf("/composition_%d/width", mId );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path, mPaperWidth );
|
||||
path.sprintf("/composition_%d/height", mId );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path, mPaperHeight );
|
||||
QString path, val;
|
||||
path.sprintf("/composition_%d/", mId );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"width", mUserPaperWidth );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"height", mUserPaperHeight );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"resolution", mResolution );
|
||||
|
||||
path.sprintf("/composition_%d/resolution", mId );
|
||||
QgsProject::instance()->writeEntry( "Compositions", path, mResolution );
|
||||
if ( mPaperOrientation == Landscape ) {
|
||||
val = "landscape";
|
||||
} else {
|
||||
val = "portrait";
|
||||
}
|
||||
QgsProject::instance()->writeEntry( "Compositions", path+"orientation", val );
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -642,31 +662,55 @@ bool QgsComposition::readSettings ( void )
|
||||
|
||||
bool ok;
|
||||
|
||||
QString path;
|
||||
path.sprintf("/composition_%d/width", mId );
|
||||
mPaperWidth = QgsProject::instance()->readDoubleEntry( "Compositions", path, 297, &ok);
|
||||
path.sprintf("/composition_%d/height", mId );
|
||||
mPaperHeight = QgsProject::instance()->readDoubleEntry( "Compositions", path, 210, &ok);
|
||||
mPaper = mCustomPaper;
|
||||
|
||||
path.sprintf("/composition_%d/resolution", mId );
|
||||
mResolution = QgsProject::instance()->readNumEntry( "Compositions", path, 300, &ok);
|
||||
QString path, val;
|
||||
path.sprintf("/composition_%d/", mId );
|
||||
mUserPaperWidth = QgsProject::instance()->readDoubleEntry( "Compositions", path+"width", 297, &ok);
|
||||
mUserPaperHeight = QgsProject::instance()->readDoubleEntry( "Compositions", path+"height", 210, &ok);
|
||||
mResolution = QgsProject::instance()->readNumEntry( "Compositions", path+"resolution", 300, &ok);
|
||||
|
||||
resizeCanvas();
|
||||
val = QgsProject::instance()->readEntry( "Compositions", path+"orientation", "landscape", &ok);
|
||||
if ( val.compare("landscape") == 0 ) {
|
||||
mPaperOrientation = Landscape;
|
||||
} else {
|
||||
mPaperOrientation = Portrait;
|
||||
}
|
||||
|
||||
recalculate();
|
||||
setOptions();
|
||||
|
||||
// TODO: read all objects
|
||||
// BUG in readListEntry
|
||||
/*
|
||||
// Create objects
|
||||
path.sprintf("/composition_%d", mId );
|
||||
QStringList el = QgsProject::instance()->readListEntry ( "Compositions", path, &ok );
|
||||
QStringList el = QgsProject::instance()->subkeyList ( "Compositions", path );
|
||||
|
||||
for ( QStringList::iterator it = el.begin(); it != el.end(); ++it ) {
|
||||
std::cout << "entry: " << (*it).ascii() << std::endl;
|
||||
std::cout << "key: " << (*it).ascii() << std::endl;
|
||||
|
||||
QStringList l = QStringList::split( '_', (*it) );
|
||||
if ( l.size() == 2 ) {
|
||||
QString name = l.first();
|
||||
QString ids = l.last();
|
||||
int id = ids.toInt();
|
||||
|
||||
if ( name.compare("map") == 0 ) {
|
||||
QgsComposerMap *map = new QgsComposerMap ( this, id );
|
||||
mItems.push_back(map);
|
||||
} else if ( name.compare("vectorlegend") == 0 ) {
|
||||
QgsComposerVectorLegend *vl = new QgsComposerVectorLegend ( this, id );
|
||||
mItems.push_back(vl);
|
||||
} else if ( name.compare("label") == 0 ) {
|
||||
QgsComposerLabel *lab = new QgsComposerLabel ( this, id );
|
||||
mItems.push_back(lab);
|
||||
}
|
||||
|
||||
if ( id >= mNextItemId ) mNextItemId = id + 1;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
setOptions();
|
||||
|
||||
|
||||
mCanvas->update();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -110,6 +110,13 @@ public:
|
||||
/** \brief Create default composition */
|
||||
void createDefault ( void );
|
||||
|
||||
/** \brief Remove all items */
|
||||
void clear ( void );
|
||||
|
||||
/** \brief Recalculate page size according to mUserPaperWidth/Height and mPaperOrientation,
|
||||
* resize canvas and zoomFull */
|
||||
void recalculate(void);
|
||||
|
||||
/** \brief pointer to map canvas */
|
||||
QgsMapCanvas *mapCanvas(void);
|
||||
|
||||
@ -210,18 +217,27 @@ private:
|
||||
/** \brief paper height in mm in GUI */
|
||||
double mUserPaperHeight;
|
||||
|
||||
/** \brief paper width in mm */
|
||||
/** \brief paper width in mm (orientaion applied) */
|
||||
double mPaperWidth;
|
||||
|
||||
/** \brief paper height in mm */
|
||||
/** \brief paper height in mm (orientaion applied) */
|
||||
double mPaperHeight;
|
||||
|
||||
/** \brief Papers */
|
||||
std::vector<QgsCompositionPaper> mPapers;
|
||||
|
||||
/** \brief Current paper */
|
||||
int mPaper;
|
||||
|
||||
/** \brief Default paper index */
|
||||
int mDefaultPaper;
|
||||
|
||||
/** \brief Custom paper index */
|
||||
int mCustomPaper;
|
||||
|
||||
/** \brief Orientation */
|
||||
int mPaperOrientation;
|
||||
|
||||
/** \brief pointer to map canvas */
|
||||
QgsMapCanvas *mMapCanvas;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user