Index: src/app/qgssinglesymboldialog.h =================================================================== --- src/app/qgssinglesymboldialog.h (revision 6947) +++ src/app/qgssinglesymboldialog.h (working copy) @@ -62,6 +62,7 @@ protected slots: void selectOutlineColor(); void selectFillColor(); + void selectTextureImage(); private: /** Default constructor is private, do not use this */ Index: src/app/qgsgraduatedsymboldialog.cpp =================================================================== --- src/app/qgsgraduatedsymboldialog.cpp (revision 6947) +++ src/app/qgsgraduatedsymboldialog.cpp (working copy) @@ -96,6 +96,7 @@ 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 @@ if (mVectorLayer->vectorType() != QGis::Line) { sy->setFillColor(it->second->brush().color()); + sy->setCustomTexture(it->second->customTexture());//necessary? sy->setFillStyle(it->second->brush().style()); } Index: src/app/qgsuniquevaluedialog.cpp =================================================================== --- src/app/qgsuniquevaluedialog.cpp (revision 6947) +++ src/app/qgsuniquevaluedialog.cpp (working copy) @@ -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 @@ 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 @@ 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 @@ if(it!=mValues.end()) { sydialog.set( it->second); - sydialog.setLabel(it->second->label()); + sydialog.setLabel(it->second->label()); } else { @@ -227,7 +228,7 @@ delete (mClassListWidget->takeItem(currentIndex)); qWarning("numRows: "); qWarning(QString::number(mClassListWidget->count())); - // + if(mClassListWidget->count() < (currentIndex + 1)) { qWarning("selecting numRows - 1"); Index: src/app/qgssinglesymboldialog.cpp =================================================================== --- src/app/qgssinglesymboldialog.cpp (revision 6947) +++ src/app/qgssinglesymboldialog.cpp (working copy) @@ -25,6 +25,8 @@ #include #include +#include +#include QgsSingleSymbolDialog::QgsSingleSymbolDialog(): QDialog(), mVectorLayer(0) @@ -100,6 +102,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ // 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 @@ { 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 @@ 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 @@ (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 @@ { return Qt::Dense3Pattern; } + else if (texture->isOn()) + { + return Qt::TexturePattern; + } //fall back to transparent return Qt::NoBrush; Index: src/core/symbology/qgssymbol.cpp =================================================================== --- src/core/symbology/qgssymbol.cpp (revision 6947) +++ src/core/symbology/qgssymbol.cpp (working copy) @@ -26,6 +26,9 @@ #include #include #include +#include +//#include +//do we have to include qstring? QgsSymbol::QgsSymbol(QGis::VectorType t, QString lvalue, QString uvalue, QString label) : mLowerValue(lvalue), @@ -87,6 +90,7 @@ 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 @@ 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 @@ 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 @@ 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())); Index: src/core/symbology/qgssymbologyutils.cpp =================================================================== --- src/core/symbology/qgssymbologyutils.cpp (revision 6947) +++ src/core/symbology/qgssymbologyutils.cpp (working copy) @@ -612,6 +612,32 @@ ".................................................." }; +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 @@ return Qt::TexturePattern; } else //return a null string { + qWarning("Brush style \"" + brushString + "\" not found in qString2BrushStyle"); return Qt::NoBrush; } } @@ -861,6 +888,9 @@ } else if (patternString == "DiagCrossPattern") { return QPixmap(diagCrossData); + } else if (patternString == "TexturePattern") + { + return QPixmap(texturePatternData); } else if (patternString == "NoBrush") { return QPixmap(nobrush); @@ -1039,8 +1069,11 @@ } 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,11 +1160,11 @@ } 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 @@ case (Qt::DiagCrossPattern): return QPixmap(diagCrossData); break; + case (Qt::TexturePattern) : + return QPixmap(texturePatternData); + break; case (Qt::NoBrush): return QPixmap(nobrush); default: Index: src/core/symbology/qgssymbol.h =================================================================== --- src/core/symbology/qgssymbol.h (revision 6947) +++ src/core/symbology/qgssymbol.h (working copy) @@ -65,6 +65,12 @@ 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 @@ QPen mPen; QBrush mBrush; + QString mTextureFilePath; /* Point symbol name */ QString mPointSymbolName; /* Point size */ Index: src/ui/qgssinglesymboldialogbase.ui =================================================================== --- src/ui/qgssinglesymboldialogbase.ui (revision 6947) +++ src/ui/qgssinglesymboldialogbase.ui (working copy) @@ -6,7 +6,7 @@ 0 0 413 - 486 + 497 @@ -27,24 +27,76 @@ 6 - - + + + + 0 + + + 6 + + + + + + 0 + 22 + + + + Label: + + + mLabelEdit + + + + + + + + 0 + 22 + + + + + + + + - Fill Patterns: + Point - 4 + 9 - 4 + 6 - - + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 78 + 35 + + + + + + - 1 - 1 + 7 + 7 0 0 @@ -57,6 +109,75 @@ + 32767 + 40 + + + + + + + + Size + + + mPointSizeSpinBox + + + + + + + 1000 + + + 3 + + + 1 + + + 3 + + + + + + + + 5 + 1 + 0 + 0 + + + + Symbol + + + mPointSymbolComboBox + + + + + + + + + + Fill Patterns: + + + + 4 + + + 4 + + + + + 60 30 @@ -78,22 +199,8 @@ - - - - - 5 - 5 - 0 - 0 - - - - - 0 - 0 - - + + 60 @@ -117,8 +224,8 @@ - - + + 60 @@ -142,31 +249,14 @@ - - - - - 5 - 5 - 0 - 0 - - - - - 0 - 0 - - + + 60 30 - - No Fill - @@ -184,8 +274,8 @@ - - + + 60 @@ -234,16 +324,22 @@ - - + + - 5 - 5 + 1 + 1 0 0 + + + 0 + 0 + + 60 @@ -267,8 +363,16 @@ - - + + + + + 5 + 5 + 0 + 0 + + 60 @@ -292,8 +396,8 @@ - - + + 60 @@ -317,16 +421,8 @@ - - - - - 5 - 5 - 0 - 0 - - + + 60 @@ -350,8 +446,22 @@ - - + + + + + 5 + 5 + 0 + 0 + + + + + 0 + 0 + + 60 @@ -375,8 +485,16 @@ - - + + + + + 5 + 5 + 0 + 0 + + 60 @@ -400,8 +518,8 @@ - - + + 5 @@ -410,12 +528,21 @@ 0 + + + 0 + 0 + + 60 30 + + No Fill + @@ -433,8 +560,16 @@ - - + + + + + 5 + 5 + 0 + 0 + + 60 @@ -491,146 +626,55 @@ - - - - - - - - - - - 8 - - - 6 - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - + + + + + + - 201 - 16 + 60 + 30 - + + Browse: + + - - + + - 4 - 0 + 5 + 5 0 0 - 100 - 32767 + 60 + 30 - - 0 - - - - - - Outline Width: - - - outlinewidthspinbox - - - - - - - - 100 - 0 - - - - - - - - + - 100 - 0 + 50 + 20 - - + + true - - - - - - Qt::Horizontal + + true - - QSizePolicy::Expanding - - - - 138 - 16 - - - - - - - - Fill Color: - - - btnFillColor - - - - - Outline color: - - - btnOutlineColor - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 116 - 16 - - - - @@ -799,19 +843,19 @@ - - + + - Point + - 9 + 8 6 - + Qt::Horizontal @@ -821,119 +865,124 @@ - 78 - 35 + 201 + 16 - - + + - 7 - 7 + 4 + 0 0 0 - - - 0 - 0 - - - 32767 - 40 + 100 + 32767 + + 0 + - - + + - Size + Outline Width: - mPointSizeSpinBox + outlinewidthspinbox - - - - 1000 + + + + + 100 + 0 + - - 3 + + - - 1 + + + + + + + 100 + 0 + - - 3 + + - - - - - 5 - 1 - 0 - 0 - + + + + Qt::Horizontal + + QSizePolicy::Expanding + + + + 138 + 16 + + + + + + - Symbol + Fill Color: - mPointSymbolComboBox + btnFillColor + + + + Outline color: + + + btnOutlineColor + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 116 + 16 + + + + - - - - 0 - - - 6 - - - - - - 0 - 22 - - - - Label: - - - mLabelEdit - - - - - - - - 0 - 22 - - - - - -