Skip to content
Permalink
Browse files
Applied patch #731 from Steven Bell for pixmap fill support in vector…
… rendering.

Many thanks Steve!





git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7040 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Jun 19, 2007
1 parent c316571 commit 7d07c4894d0cc585fb64c2c0f95e95782759bcbc
@@ -96,6 +96,7 @@ QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog(QgsVectorLayer * layer): QDia
QString classbreak=(*it)->lowerValue()+" - "+(*it)->upperValue();
QgsSymbol* sym=new QgsSymbol(mVectorLayer->vectorType(), (*it)->lowerValue(), (*it)->upperValue(), (*it)->label());
sym->setPen((*it)->pen());
sym->setCustomTexture((*it)->customTexture());
sym->setBrush((*it)->brush());
sym->setNamedPointSymbol((*it)->pointSymbolName());
sym->setPointSize((*it)->pointSize());
@@ -185,6 +186,7 @@ void QgsGraduatedSymbolDialog::apply()
if (mVectorLayer->vectorType() != QGis::Line)
{
sy->setFillColor(it->second->brush().color());
sy->setCustomTexture(it->second->customTexture());//necessary?
sy->setFillStyle(it->second->brush().style());
}

@@ -25,6 +25,8 @@

#include <QColorDialog>
#include <QPainter>
#include <QImage>
#include <QFileDialog>


QgsSingleSymbolDialog::QgsSingleSymbolDialog(): QDialog(), mVectorLayer(0)
@@ -100,6 +102,7 @@ QgsSingleSymbolDialog::QgsSingleSymbolDialog(QgsVectorLayer * layer): QDialog(),
dense6->setPixmap(QgsSymbologyUtils::char2PatternPixmap("Dense6Pattern"));
dense7->setPixmap(QgsSymbologyUtils::char2PatternPixmap("Dense7Pattern"));
nopen->setPixmap(QgsSymbologyUtils::char2PatternPixmap("NoBrush"));
texture->setPixmap(QgsSymbologyUtils::char2PatternPixmap("TexturePattern"));


if (mVectorLayer)
@@ -108,9 +111,9 @@ QgsSingleSymbolDialog::QgsSingleSymbolDialog(QgsVectorLayer * layer): QDialog(),

if (renderer)
{
// Set from the existing renderer
set ( renderer->symbol() );
}
// Set from the existing renderer
set ( renderer->symbol() );
}
else
{
// Take values from an example instance
@@ -167,7 +170,8 @@ QgsSingleSymbolDialog::QgsSingleSymbolDialog(QgsVectorLayer * layer): QDialog(),
QObject::connect(dense2, SIGNAL(clicked()), this, SLOT(resendSettingsChanged()));
QObject::connect(dense7, SIGNAL(clicked()), this, SLOT(resendSettingsChanged()));
QObject::connect(nopen, SIGNAL(clicked()), this, SLOT(resendSettingsChanged()));

QObject::connect(texture, SIGNAL(clicked()), this, SLOT(resendSettingsChanged()));
QObject::connect(textureSelect, SIGNAL(clicked()), this, SLOT(selectTextureImage()));
}

QgsSingleSymbolDialog::~QgsSingleSymbolDialog()
@@ -201,6 +205,21 @@ void QgsSingleSymbolDialog::selectFillColor()
setActiveWindow();
}

//should this method have a different name?
void QgsSingleSymbolDialog::selectTextureImage()
{
QString fileName = QFileDialog::getOpenFileName(this, "Open File",
textureFilePath->text(),
"Images (*.png *.xpm *.jpg)"); //should we allow other types of images?

if(fileName.isNull() == false){ //only process the string if the user clicked OK
textureFilePath->setText(fileName);
texture->setOn(true); //set the fill style to custom texture
texture->setPixmap(QPixmap(fileName)); //Change the button to show the selected image
resendSettingsChanged();
}
}

void QgsSingleSymbolDialog::apply( QgsSymbol *sy )
{
//query the values of the widgets and set the symbology of the vector layer
@@ -235,6 +254,10 @@ void QgsSingleSymbolDialog::apply( QgsSymbol *sy )
// Apply the pattern
//

//Store the file path, and set the brush to TexturePattern. If we have a different button selected,
// the below code will override it, but leave the file path alone.
sy->setCustomTexture(textureFilePath->text());

if (solid->isOn())
{
sy->setFillStyle(Qt::SolidPattern);
@@ -295,6 +318,10 @@ void QgsSingleSymbolDialog::apply( QgsSymbol *sy )
{
sy->setFillStyle(Qt::NoBrush);
}
else if (texture->isOn())
{
//we already set the brush to TexturePattern up above, so don't do anything here
}

//apply the label
sy->setLabel(mLabelEdit->text());
@@ -412,10 +439,22 @@ void QgsSingleSymbolDialog::set ( const QgsSymbol *sy )
case Qt::NoBrush :
nopen->setOn(true);
break;
case Qt::TexturePattern :
texture->setOn(true);
break;
default :
solid->setOn(true);
break;
}
textureFilePath->setText(sy->customTexture()); //get and show the file path, even if we aren't using it.
if(sy->customTexture().size() > 0)//if the file path isn't empty, show the image on the button
{
texture->setPixmap(QPixmap(sy->customTexture())); //show the current texture image
}
else
{
texture->setPixmap(QgsSymbologyUtils::char2PatternPixmap("TexturePattern")); //show the default question mark
}
}

void QgsSingleSymbolDialog::setOutlineColor(QColor& c)
@@ -480,6 +519,8 @@ void QgsSingleSymbolDialog::setFillStyle(Qt::BrushStyle fstyle)
(dense6->setOn(true));
else if (fstyle==Qt::Dense7Pattern)
(dense7->setOn(true));
else if (fstyle==Qt::TexturePattern)
(texture->setOn(true));
else if (fstyle==Qt::NoBrush)
(nopen->setOn(true)); //default to no brush
}
@@ -579,6 +620,10 @@ Qt::BrushStyle QgsSingleSymbolDialog::getFillStyle()
{
return Qt::Dense3Pattern;
}
else if (texture->isOn())
{
return Qt::TexturePattern;
}
//fall back to transparent
return Qt::NoBrush;

@@ -62,6 +62,7 @@ public slots:
protected slots:
void selectOutlineColor();
void selectFillColor();
void selectTextureImage();

private:
/** Default constructor is private, do not use this */
@@ -24,7 +24,6 @@
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"


QgsUniqueValueDialog::QgsUniqueValueDialog(QgsVectorLayer* vl): QDialog(), mVectorLayer(vl), sydialog(vl)
{
setupUi(this);
@@ -69,6 +68,7 @@ QgsUniqueValueDialog::QgsUniqueValueDialog(QgsVectorLayer* vl): QDialog(), mVect
QString symbolvalue=symbol->lowerValue();
QgsSymbol* sym=new QgsSymbol(mVectorLayer->vectorType(), symbol->lowerValue(), symbol->upperValue(), symbol->label());
sym->setPen(symbol->pen());
sym->setCustomTexture(symbol->customTexture());
sym->setBrush(symbol->brush());
sym->setNamedPointSymbol(symbol->pointSymbolName());
sym->setPointSize(symbol->pointSize());
@@ -112,6 +112,7 @@ void QgsUniqueValueDialog::apply()
QgsSymbol* symbol=it->second;
QgsSymbol* newsymbol=new QgsSymbol(mVectorLayer->vectorType(), symbol->lowerValue(), symbol->upperValue(), symbol->label());
newsymbol->setPen(symbol->pen());
newsymbol->setCustomTexture(symbol->customTexture());
newsymbol->setBrush(symbol->brush());
newsymbol->setNamedPointSymbol(symbol->pointSymbolName());
newsymbol->setPointSize(symbol->pointSize());
@@ -203,7 +204,7 @@ void QgsUniqueValueDialog::changeCurrentValue()
if(it!=mValues.end())
{
sydialog.set( it->second);
sydialog.setLabel(it->second->label());
sydialog.setLabel(it->second->label());
}
else
{
@@ -227,7 +228,7 @@ void QgsUniqueValueDialog::deleteCurrentClass()
delete (mClassListWidget->takeItem(currentIndex));
qWarning("numRows: ");
qWarning(QString::number(mClassListWidget->count()));
//

if(mClassListWidget->count() < (currentIndex + 1))
{
qWarning("selecting numRows - 1");
@@ -26,6 +26,9 @@
#include <QPainter>
#include <QDomNode>
#include <QDomDocument>
#include <QImage>
//#include <QString>
//do we have to include qstring?

QgsSymbol::QgsSymbol(QGis::VectorType t, QString lvalue, QString uvalue, QString label) :
mLowerValue(lvalue),
@@ -87,6 +90,7 @@ QgsSymbol::QgsSymbol(const QgsSymbol& s)
mType = s.mType;
mPen = s.mPen;
mBrush = s.mBrush;
mTextureFilePath = s.mTextureFilePath;
mPointSymbolName = s.mPointSymbolName;
mPointSize = s.mPointSize;
mPointSymbolImage = s.mPointSymbolImage;
@@ -152,6 +156,20 @@ void QgsSymbol::setFillStyle( Qt::BrushStyle s )
mCacheUpToDate = mCacheUpToDate2 = false;
}

QString QgsSymbol::customTexture() const
{
return mTextureFilePath;
}

void QgsSymbol::setCustomTexture( QString path )
{
mTextureFilePath = path;
mBrush.setTextureImage(QImage (path));
mCacheUpToDate = mCacheUpToDate2 = false;
}

//should we set the path independently of setting the texture?

void QgsSymbol::setNamedPointSymbol(QString name)
{
mPointSymbolName = name;
@@ -322,6 +340,11 @@ bool QgsSymbol::writeXML( QDomNode & item, QDomDocument & document ) const
symbol.appendChild(fillpattern);
fillpattern.appendChild(fillpatterntxt);

QDomElement texturepath=document.createElement("texturepath");
QDomText texturepathtxt=document.createTextNode(mTextureFilePath);
symbol.appendChild(texturepath);
texturepath.appendChild(texturepathtxt);

return returnval;
}

@@ -390,6 +413,11 @@ bool QgsSymbol::readXML( QDomNode & synode )
blue = fillcelement.attribute("blue").toInt();
setFillColor(QColor(red, green, blue));

QDomNode texturepathnode = synode.namedItem("texturepath");
QDomElement texturepathelement = texturepathnode.toElement();
setCustomTexture(texturepathelement.text());

//run this after setting the custom texture path, so we override the brush if it isn't the custom pattern brush.
QDomNode fillpnode = synode.namedItem("fillpattern");
QDomElement fillpelement = fillpnode.toElement();
setFillStyle(QgsSymbologyUtils::qString2BrushStyle(fillpelement.text()));
@@ -65,6 +65,12 @@ class CORE_EXPORT QgsSymbol{
virtual void setLineStyle(Qt::PenStyle s);
/**Set the fill (brush) style*/
virtual void setFillStyle(Qt::BrushStyle s);

/**Gets the path to the customs texture image*/
virtual QString customTexture() const;
/**Sets the path to the custom texture, and sets the brush to use TexturePattern */
virtual void setCustomTexture(QString path);

virtual void setLowerValue(QString value);
virtual QString lowerValue() const;
virtual void setUpperValue(QString value);
@@ -114,6 +120,7 @@ class CORE_EXPORT QgsSymbol{

QPen mPen;
QBrush mBrush;
QString mTextureFilePath;
/* Point symbol name */
QString mPointSymbolName;
/* Point size */
@@ -612,6 +612,32 @@ static const char *nobrush[] = {
".................................................."
};

static const char *texturePatternData[] = {
"50 20 2 1",
"# c #3155c5",
". c #ffffff",
"..................................................",
"..................#########.......................",
"...............##############.....................",
"..............####........#####...................",
"...........................####...................",
"...........................####...................",
"...........................####...................",
"...........................####...................",
"..........................####....................",
"..........................####....................",
"........................####......................",
"......................####........................",
"....................####..........................",
"...................####...........................",
"...................####...........................",
"..................................................",
"...................####...........................",
"...................####...........................",
"...................####...........................",
".................................................."
};

QString QgsSymbologyUtils::penStyle2QString(Qt::PenStyle penstyle)
{
if (penstyle == Qt::NoPen)
@@ -779,6 +805,7 @@ Qt::BrushStyle QgsSymbologyUtils::qString2BrushStyle(QString brushString)
return Qt::TexturePattern;
} else //return a null string
{
qWarning("Brush style \"" + brushString + "\" not found in qString2BrushStyle");
return Qt::NoBrush;
}
}
@@ -861,6 +888,9 @@ QPixmap QgsSymbologyUtils::qString2PatternPixmap(QString patternString)
} else if (patternString == "DiagCrossPattern")
{
return QPixmap(diagCrossData);
} else if (patternString == "TexturePattern")
{
return QPixmap(texturePatternData);
} else if (patternString == "NoBrush")
{
return QPixmap(nobrush);
@@ -1039,7 +1069,10 @@ QPixmap QgsSymbologyUtils::char2PatternPixmap(const char *c)
} else if (strcmp(c, "DiagCrossPattern") == 0)
{
return QPixmap(diagCrossData);
} else if (strcmp(c, "NoBrush") == 0)
} else if (strcmp(c, "TexturePattern") == 0)
{
return QPixmap(texturePatternData);
}else if (strcmp(c, "NoBrush") == 0)
{
return QPixmap(nobrush);
} else
@@ -1127,10 +1160,10 @@ Qt::BrushStyle QgsSymbologyUtils::char2BrushStyle(const char *c)
} else if (strcmp(c, "CustomPattern") == 0)
{
return Qt::TexturePattern;
} else if(strcmp(c, "NoBrush") == 0)
{
return Qt::NoBrush;
}else //return a null string
} else if (strcmp(c, "NoBrush") == 0)
{
return Qt::NoBrush;
}else //return a null string
{
qWarning("Warning, no matching brush style found in QgsSymbologyUtils::char2BrushStyle");
return Qt::NoBrush;
@@ -1211,6 +1244,9 @@ QPixmap QgsSymbologyUtils::brushStyle2Pixmap(Qt::BrushStyle brushstyle)
case (Qt::DiagCrossPattern):
return QPixmap(diagCrossData);
break;
case (Qt::TexturePattern) :
return QPixmap(texturePatternData);
break;
case (Qt::NoBrush):
return QPixmap(nobrush);
default:

0 comments on commit 7d07c48

Please sign in to comment.