fix for crashes when chosing very small scale factors in the single marker dialog

git-svn-id: http://svn.osgeo.org/qgis/trunk@1095 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mhugent 2004-03-26 11:23:48 +00:00
parent 27777b21ce
commit a95aff130d
4 changed files with 14887 additions and 11706 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
/****************************************************************************
** Form interface generated from reading ui file 'pluginguibase.ui'
**
** Created: Die Mär 23 15:00:22 2004
** Created: Fre Mär 26 11:29:32 2004
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
@ -34,7 +34,6 @@ public:
~PluginGuiBase();
QFrame* line1;
QLabel* pixmapLabel1;
QLabel* txtHeading;
QTextEdit* teInstructions;
QLabel* lblInputFile;
@ -49,6 +48,7 @@ public:
QPushButton* pbnOK;
QLineEdit* leInputFile;
QLineEdit* leOutputShapeFile;
QLabel* pixmapLabel1;
public slots:
virtual void pbnOK_clicked();
@ -59,6 +59,8 @@ public slots:
virtual void leOutputShapeFile_textChanged( const QString & theQString );
protected:
QGridLayout* PluginGuiBaseLayout;
QSpacerItem* spacer2;
protected slots:
virtual void languageChange();

View File

@ -57,7 +57,21 @@ QgsSiMaDialog::QgsSiMaDialog(QgsVectorLayer* vectorlayer): QgsSiMaDialogBase(),
QString svgfile=sy->picture();
mImageButton->setName(svgfile);
pic.load(svgfile,"svg");
QPixmap pixmap(pic.boundingRect().width()*scalefactor,pic.boundingRect().height()*scalefactor);
int width=(int)(pic.boundingRect().width()*scalefactor);
int height=(int)(pic.boundingRect().height()*scalefactor);
//prevent 0 width or height, which would cause a crash
if(width==0)
{
width=1;
}
if(height==0)
{
height=1;
}
QPixmap pixmap(width,height);
pixmap.fill();
QPainter p(&pixmap);
p.scale(scalefactor,scalefactor);
@ -139,19 +153,30 @@ void QgsSiMaDialog::apply()
QPixmap *pix = mVectorLayer->legendPixmap();
int width = 20+pic.boundingRect().width()*ms->scaleFactor()+fm.width(name);
int height = (pic.boundingRect().height()*ms->scaleFactor() > fm.height()) ? pic.boundingRect().height()*ms->scaleFactor() +10 : fm.height()+10;
int width = (int)(20+pic.boundingRect().width()*ms->scaleFactor()+fm.width(name));
int height = (int)((pic.boundingRect().height()*ms->scaleFactor() > fm.height()) ? pic.boundingRect().height()*ms->scaleFactor() +10 : fm.height()+10);
//prevent 0 width or height, which would cause a crash
if(width==0)
{
width=1;
}
if(height==0)
{
height=1;
}
pix->resize(width, height);
pix->fill();
QPainter p(pix);
p.scale(ms->scaleFactor(),ms->scaleFactor());
p.drawPicture(10/ms->scaleFactor(),5/ms->scaleFactor(),pic);
p.drawPicture((int)(10/ms->scaleFactor()),(int)(5/ms->scaleFactor()),pic);
p.resetXForm();
p.setPen(Qt::black);
p.setFont(f);
p.drawText(15+pic.boundingRect().width()*ms->scaleFactor(), pix->height() - 10, name);
p.drawText((int)(15+pic.boundingRect().width()*ms->scaleFactor()), (int)(pix->height() - 10), name);
if (mVectorLayer->legendItem())
{
@ -177,7 +202,21 @@ void QgsSiMaDialog::selectMarker()
QPicture pic;
double scalefactor=mScaleEdit->text().toDouble();
pic.load(svgfile,"svg");
QPixmap pixmap(pic.boundingRect().width()*scalefactor,pic.boundingRect().height()*scalefactor);
int width=(int)(pic.boundingRect().width()*scalefactor);
int height=(int)(pic.boundingRect().height()*scalefactor);
//prevent 0 width or height, which would cause a crash
if(width==0)
{
width=1;
}
if(height==0)
{
height=1;
}
QPixmap pixmap(height,width);
pixmap.fill();
QPainter p(&pixmap);
p.scale(scalefactor,scalefactor);
@ -196,7 +235,21 @@ void QgsSiMaDialog::updateMarkerSize()
QPicture pic;
double scalefactor=mScaleEdit->text().toDouble();
pic.load(svgfile,"svg");
QPixmap pixmap(pic.boundingRect().width()*scalefactor,pic.boundingRect().height()*scalefactor);
int width=(int)(pic.boundingRect().width()*scalefactor);
int height=(int)(pic.boundingRect().height()*scalefactor);
//prevent 0 width or height, which would cause a crash
if(width==0)
{
width=1;
}
if(height==0)
{
height=1;
}
QPixmap pixmap(width,height);
pixmap.fill();
QPainter p(&pixmap);
p.scale(scalefactor,scalefactor);

View File

@ -60,17 +60,13 @@ void QgsSiMaRenderer::initializeSymbology(QgsVectorLayer* layer, QgsDlgVectorLay
void QgsSiMaRenderer::renderFeature(QPainter* p, QgsFeature* f, QPicture* pic, double* scalefactor)
{
p->setPen(mItem->getSymbol()->pen());
p->setBrush(mItem->getSymbol()->brush());
p->setPen(Qt::NoPen);
p->setBrush(Qt::NoBrush);
QgsMarkerSymbol* ms=dynamic_cast<QgsMarkerSymbol*>(mItem->getSymbol());
if(ms&&pic)
{
pic->load(ms->picture(),"svg");
//debugging: remove later
//std::cout << pic << std::endl << std::flush;
//p->drawPicture(50,50,(*pic));
//qWarning("scale factor: "+QString::number(ms->scaleFactor()));
(*scalefactor)=ms->scaleFactor();//does not work, but why?
(*scalefactor)=ms->scaleFactor();
}
}