Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 7d07c48
Show file tree
Hide file tree
Showing 8 changed files with 455 additions and 286 deletions.
2 changes: 2 additions & 0 deletions src/app/qgsgraduatedsymboldialog.cpp
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
}

Expand Down
53 changes: 49 additions & 4 deletions src/app/qgssinglesymboldialog.cpp
Expand Up @@ -25,6 +25,8 @@

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


QgsSingleSymbolDialog::QgsSingleSymbolDialog(): QDialog(), mVectorLayer(0)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/app/qgssinglesymboldialog.h
Expand Up @@ -62,6 +62,7 @@ public slots:
protected slots:
void selectOutlineColor();
void selectFillColor();
void selectTextureImage();

private:
/** Default constructor is private, do not use this */
Expand Down
7 changes: 4 additions & 3 deletions src/app/qgsuniquevaluedialog.cpp
Expand Up @@ -24,7 +24,6 @@
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"


QgsUniqueValueDialog::QgsUniqueValueDialog(QgsVectorLayer* vl): QDialog(), mVectorLayer(vl), sydialog(vl)
{
setupUi(this);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
{
Expand All @@ -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");
Expand Down
28 changes: 28 additions & 0 deletions src/core/symbology/qgssymbol.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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()));
Expand Down
7 changes: 7 additions & 0 deletions src/core/symbology/qgssymbol.h
Expand Up @@ -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);
Expand Down Expand Up @@ -114,6 +120,7 @@ class CORE_EXPORT QgsSymbol{

QPen mPen;
QBrush mBrush;
QString mTextureFilePath;
/* Point symbol name */
QString mPointSymbolName;
/* Point size */
Expand Down
46 changes: 41 additions & 5 deletions src/core/symbology/qgssymbologyutils.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 7d07c48

Please sign in to comment.