Skip to content

Commit e17777b

Browse files
author
wonder
committedMay 12, 2009
Added a bunch of widgets and dialogs for new symbology.
git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@10772 c8812cc2-4d05-0410-92ff-de0c093fc19c

17 files changed

+2533
-2
lines changed
 

‎src/gui/CMakeLists.txt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11

22
SET(QGIS_GUI_SRCS
3+
4+
symbology-ng/qgsbrushstylecombobox.cpp
5+
symbology-ng/qgspenstylecombobox.cpp
6+
symbology-ng/qgssymbollayerv2widget.cpp
7+
symbology-ng/qgssymbolv2propertiesdialog.cpp
8+
symbology-ng/qgsrendererv2propertiesdialog.cpp
9+
symbology-ng/qgsstylev2managerdialog.cpp
10+
symbology-ng/qgssymbolv2selectordialog.cpp
11+
symbology-ng/qgsvectorgradientcolorrampv2dialog.cpp
12+
313
qgisgui.cpp
414
qgisinterface.cpp
515
qgscolorbutton.cpp
@@ -29,6 +39,14 @@ qgsvertexmarker.cpp
2939
)
3040

3141
SET(QGIS_GUI_MOC_HDRS
42+
43+
symbology-ng/qgssymbollayerv2widget.h
44+
symbology-ng/qgssymbolv2propertiesdialog.h
45+
symbology-ng/qgsrendererv2propertiesdialog.h
46+
symbology-ng/qgsstylev2managerdialog.h
47+
symbology-ng/qgssymbolv2selectordialog.h
48+
symbology-ng/qgsvectorgradientcolorrampv2dialog.h
49+
3250
qgscomposerview.h
3351
qgsdetaileditemdelegate.h
3452
qgsdetaileditemwidget.h
@@ -45,8 +63,8 @@ qgsquickprint.h
4563

4664
QT4_WRAP_CPP(QGIS_GUI_MOC_SRCS ${QGIS_GUI_MOC_HDRS})
4765

48-
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ../core
49-
../core/composer ../core/raster ../core/renderer ../core/symbology
66+
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/symbology-ng ../core
67+
../core/composer ../core/raster ../core/renderer ../core/symbology ../core/symbology-ng
5068
${CMAKE_CURRENT_BINARY_DIR}
5169
${CMAKE_CURRENT_BINARY_DIR}/../ui
5270
${GEOS_INCLUDE_DIR}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
#include "qgsbrushstylecombobox.h"
3+
4+
#include <QList>
5+
#include <QPair>
6+
7+
#include <QBrush>
8+
#include <QPainter>
9+
#include <QPen>
10+
11+
QgsBrushStyleComboBox::QgsBrushStyleComboBox(QWidget* parent)
12+
: QComboBox(parent)
13+
{
14+
QList < QPair<Qt::BrushStyle, QString> > styles;
15+
styles << qMakePair(Qt::SolidPattern, QString("Solid"))
16+
<< qMakePair(Qt::HorPattern, QString("Horizontal"))
17+
<< qMakePair(Qt::VerPattern, QString("Vertical"))
18+
<< qMakePair(Qt::CrossPattern, QString("Cross"))
19+
<< qMakePair(Qt::BDiagPattern, QString("BDiagonal"))
20+
<< qMakePair(Qt::FDiagPattern, QString("FDiagonal"))
21+
<< qMakePair(Qt::DiagCrossPattern, QString("Diagonal X"))
22+
<< qMakePair(Qt::Dense1Pattern, QString("Dense 1"))
23+
<< qMakePair(Qt::Dense2Pattern, QString("Dense 2"))
24+
<< qMakePair(Qt::Dense3Pattern, QString("Dense 3"))
25+
<< qMakePair(Qt::Dense4Pattern, QString("Dense 4"))
26+
<< qMakePair(Qt::Dense5Pattern, QString("Dense 5"))
27+
<< qMakePair(Qt::Dense6Pattern, QString("Dense 6"))
28+
<< qMakePair(Qt::Dense7Pattern, QString("Dense 7"))
29+
<< qMakePair(Qt::NoBrush, QString("No Brush"));
30+
31+
setIconSize(QSize(32,16));
32+
33+
for (int i = 0; i < styles.count(); i++)
34+
{
35+
Qt::BrushStyle style = styles.at(i).first;
36+
QString name = styles.at(i).second;
37+
addItem(iconForBrush(style), name, QVariant(style));
38+
}
39+
40+
setCurrentIndex(1);
41+
42+
}
43+
44+
45+
Qt::BrushStyle QgsBrushStyleComboBox::brushStyle() const
46+
{
47+
return (Qt::BrushStyle) itemData(currentIndex()).toInt();
48+
}
49+
50+
void QgsBrushStyleComboBox::setBrushStyle(Qt::BrushStyle style)
51+
{
52+
int idx = findData(QVariant(style));
53+
setCurrentIndex( idx == -1 ? 0 : idx );
54+
}
55+
56+
QIcon QgsBrushStyleComboBox::iconForBrush(Qt::BrushStyle style)
57+
{
58+
QPixmap pix(iconSize());
59+
QPainter p;
60+
pix.fill(Qt::transparent);
61+
62+
p.begin(&pix);
63+
QBrush brush(QColor(100,100,100), style);
64+
p.setBrush(brush);
65+
QPen pen(Qt::NoPen);
66+
p.setPen(pen);
67+
p.drawRect(QRect(QPoint(0,0),iconSize()));
68+
p.end();
69+
70+
return QIcon(pix);
71+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
#ifndef QGSBRUSHSTYLECOMBOBOX_H
3+
#define QGSBRUSHSTYLECOMBOBOX_H
4+
5+
#include <QComboBox>
6+
7+
class QgsBrushStyleComboBox : public QComboBox
8+
{
9+
public:
10+
QgsBrushStyleComboBox(QWidget* parent = NULL);
11+
12+
Qt::BrushStyle brushStyle() const;
13+
14+
void setBrushStyle(Qt::BrushStyle style);
15+
16+
protected:
17+
QIcon iconForBrush(Qt::BrushStyle style);
18+
19+
};
20+
21+
#endif
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
#include "qgspenstylecombobox.h"
3+
4+
#include <QList>
5+
#include <QPair>
6+
7+
#include <QPainter>
8+
#include <QPen>
9+
10+
QgsPenStyleComboBox::QgsPenStyleComboBox(QWidget* parent)
11+
: QComboBox(parent)
12+
{
13+
QList < QPair<Qt::PenStyle, QString> > styles;
14+
styles << qMakePair(Qt::SolidLine, QString("Solid Line"))
15+
<< qMakePair(Qt::DashLine, QString("Dash Line"))
16+
<< qMakePair(Qt::DotLine, QString("Dot Line"))
17+
<< qMakePair(Qt::DashDotLine, QString("Dash Dot Line"))
18+
<< qMakePair(Qt::DashDotDotLine, QString("Dash Dot Dot Line"));
19+
20+
setIconSize(QSize(32,12));
21+
22+
for (int i = 0; i < styles.count(); i++)
23+
{
24+
Qt::PenStyle style = styles.at(i).first;
25+
QString name = styles.at(i).second;
26+
addItem(iconForPen(style), name, QVariant(style));
27+
}
28+
}
29+
30+
Qt::PenStyle QgsPenStyleComboBox::penStyle() const
31+
{
32+
return (Qt::PenStyle) itemData(currentIndex()).toInt();
33+
}
34+
35+
void QgsPenStyleComboBox::setPenStyle(Qt::PenStyle style)
36+
{
37+
int idx = findData(QVariant(style));
38+
setCurrentIndex( idx == -1 ? 0 : idx );
39+
}
40+
41+
QIcon QgsPenStyleComboBox::iconForPen(Qt::PenStyle style)
42+
{
43+
QPixmap pix(iconSize());
44+
QPainter p;
45+
pix.fill(Qt::transparent);
46+
47+
p.begin(&pix);
48+
QPen pen(style);
49+
pen.setWidth(2);
50+
p.setPen(pen);
51+
double mid = iconSize().height() / 2.0;
52+
p.drawLine(0,mid,iconSize().width(),mid);
53+
p.end();
54+
55+
return QIcon(pix);
56+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
#ifndef QGSPENSTYLECOMBOBOX_H
3+
#define QGSPENSTYLECOMBOBOX_H
4+
5+
#include <QComboBox>
6+
7+
class QgsPenStyleComboBox : public QComboBox
8+
{
9+
public:
10+
QgsPenStyleComboBox(QWidget* parent = NULL);
11+
12+
Qt::PenStyle penStyle() const;
13+
14+
void setPenStyle(Qt::PenStyle style);
15+
16+
protected:
17+
QIcon iconForPen(Qt::PenStyle style);
18+
19+
};
20+
21+
#endif

‎src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp

Lines changed: 476 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
#ifndef QGSRENDERERV2PROPERTIESDIALOG_H
3+
#define QGSRENDERERV2PROPERTIESDIALOG_H
4+
5+
#include "ui_qgsrendererv2propsdialogbase.h"
6+
7+
class QgsVectorLayer;
8+
class QgsStyleV2;
9+
class QgsSymbolV2;
10+
class QgsSingleSymbolRendererV2;
11+
class QgsCategorizedSymbolRendererV2;
12+
class QgsGraduatedSymbolRendererV2;
13+
14+
class QgsRendererV2PropertiesDialog : public QDialog, private Ui::QgsRendererV2PropsDialogBase
15+
{
16+
Q_OBJECT
17+
18+
public:
19+
QgsRendererV2PropertiesDialog(QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent = NULL);
20+
~QgsRendererV2PropertiesDialog();
21+
22+
public slots:
23+
void changeSingleSymbol();
24+
void updateRenderer();
25+
26+
void categoryColumnChanged();
27+
void categoriesDoubleClicked(const QModelIndex & idx);
28+
void addCategories();
29+
void deleteCategory();
30+
void deleteAllCategories();
31+
32+
void changeGraduatedSymbol();
33+
void classifyGraduated();
34+
35+
protected:
36+
37+
//! update UI to reflect changes in renderer
38+
void updateUiFromRenderer();
39+
40+
void updateSingleSymbolIcon();
41+
void updateGraduatedSymbolIcon();
42+
43+
//! create default symbol for the layer's geometry type (point/line/polygon)
44+
QgsSymbolV2* createDefaultSymbol();
45+
46+
//! populate categories view
47+
void populateCategories();
48+
49+
//! populate column combos in categorized and graduated page
50+
void populateColumns();
51+
52+
//! populate ranges of graduated symbol renderer
53+
void populateRanges();
54+
55+
void populateColorRamps();
56+
57+
//! return row index for the currently selected category (-1 if on no selection)
58+
int currentCategoryRow();
59+
60+
//! return key for the currently selected category
61+
QVariant currentCategory();
62+
63+
void changeCategorySymbol();
64+
65+
QgsSingleSymbolRendererV2* rendererSingle();
66+
QgsCategorizedSymbolRendererV2* rendererCategorized();
67+
QgsGraduatedSymbolRendererV2* rendererGraduated();
68+
69+
QgsVectorLayer* mLayer;
70+
71+
QgsStyleV2* mStyle;
72+
73+
QgsSymbolV2* mGraduatedSymbol;
74+
};
75+
76+
#endif
Lines changed: 364 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,364 @@
1+
2+
#include "qgsstylev2managerdialog.h"
3+
4+
#include "qgsstylev2.h"
5+
#include "qgssymbolv2.h"
6+
#include "qgssymbollayerv2utils.h"
7+
#include "qgsvectorcolorrampv2.h"
8+
9+
#include "qgssymbolv2propertiesdialog.h"
10+
#include "qgsvectorgradientcolorrampv2dialog.h"
11+
12+
#include <QFile>
13+
#include <QInputDialog>
14+
#include <QStandardItemModel>
15+
16+
#include "qgsapplication.h"
17+
18+
19+
static QString iconPath(QString iconFile)
20+
{
21+
// try active theme
22+
QString path = QgsApplication::activeThemePath();
23+
if ( QFile::exists( path + iconFile ) )
24+
return path + iconFile;
25+
26+
// use default theme
27+
return QgsApplication::defaultThemePath() + iconFile;
28+
}
29+
30+
///////
31+
32+
QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog(QgsStyleV2* style, QWidget* parent)
33+
: QDialog(parent), mStyle(style)
34+
{
35+
36+
setupUi(this);
37+
38+
// setup icons
39+
btnAddItem->setIcon( QIcon( iconPath( "symbologyAdd.png" ) ) );
40+
btnEditItem->setIcon( QIcon( iconPath( "symbologyEdit.png" ) ) );
41+
btnRemoveItem->setIcon( QIcon( iconPath( "symbologyRemove.png" ) ) );
42+
43+
connect(this, SIGNAL(finished(int)), this, SLOT(onFinished()));
44+
45+
connect(listItems, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(editItem()));
46+
47+
connect(btnAddItem, SIGNAL(clicked()), this, SLOT(addItem()));
48+
connect(btnEditItem, SIGNAL(clicked()), this, SLOT(editItem()));
49+
connect(btnRemoveItem, SIGNAL(clicked()), this, SLOT(removeItem()));
50+
51+
QStandardItemModel* model = new QStandardItemModel(listItems);
52+
listItems->setModel(model);
53+
54+
populateTypes();
55+
56+
connect(cboItemType, SIGNAL(currentIndexChanged(int)), this, SLOT(populateList()));
57+
58+
populateList();
59+
60+
}
61+
62+
void QgsStyleV2ManagerDialog::onFinished()
63+
{
64+
// TODO: if modified, save the changes
65+
}
66+
67+
void QgsStyleV2ManagerDialog::populateTypes()
68+
{
69+
// save current selection index in types combo
70+
int current = (cboItemType->count() > 0 ? cboItemType->currentIndex() : 0);
71+
72+
int markerCount = 0, lineCount = 0, fillCount = 0;
73+
74+
QStringList symbolNames = mStyle->symbolNames();
75+
for (int i = 0; i < symbolNames.count(); ++i)
76+
{
77+
switch (mStyle->symbolRef(symbolNames[i])->type())
78+
{
79+
case QgsSymbolV2::Marker: markerCount++; break;
80+
case QgsSymbolV2::Line: lineCount++; break;
81+
case QgsSymbolV2::Fill: fillCount++; break;
82+
default: Q_ASSERT(0 && "unknown symbol type"); break;
83+
}
84+
}
85+
86+
cboItemType->clear();
87+
cboItemType->addItem(QString("Marker symbol (%1)").arg(markerCount), QVariant(QgsSymbolV2::Marker));
88+
cboItemType->addItem(QString("Line symbol (%1)").arg(lineCount), QVariant(QgsSymbolV2::Line));
89+
cboItemType->addItem(QString("Fill symbol (%1)").arg(fillCount), QVariant(QgsSymbolV2::Fill));
90+
91+
cboItemType->addItem(QString("Color ramp (%1)").arg(mStyle->colorRampCount()), QVariant(3));
92+
93+
// update current index to previous selection
94+
cboItemType->setCurrentIndex(current);
95+
96+
}
97+
98+
void QgsStyleV2ManagerDialog::populateList()
99+
{
100+
// get current symbol type
101+
int itemType = currentItemType();
102+
103+
if (itemType < 3)
104+
populateSymbols(itemType);
105+
else
106+
populateColorRamps();
107+
}
108+
109+
void QgsStyleV2ManagerDialog::populateSymbols(int type)
110+
{
111+
QStandardItemModel* model = qobject_cast<QStandardItemModel*>(listItems->model());
112+
model->clear();
113+
114+
QStringList symbolNames = mStyle->symbolNames();
115+
116+
for (int i = 0; i < symbolNames.count(); ++i)
117+
{
118+
QString name = symbolNames[i];
119+
QgsSymbolV2* symbol = mStyle->symbol(name);
120+
if (symbol->type() == type)
121+
{
122+
QStandardItem* item = new QStandardItem(name);
123+
QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon(symbol, listItems->iconSize());
124+
item->setIcon(icon);
125+
// add to model
126+
model->appendRow(item);
127+
}
128+
delete symbol;
129+
}
130+
131+
}
132+
133+
void QgsStyleV2ManagerDialog::populateColorRamps()
134+
{
135+
QStandardItemModel* model = qobject_cast<QStandardItemModel*>(listItems->model());
136+
model->clear();
137+
138+
QStringList colorRamps = mStyle->colorRampNames();
139+
140+
for (int i = 0; i < colorRamps.count(); ++i)
141+
{
142+
QString name = colorRamps[i];
143+
QgsVectorColorRampV2* ramp = mStyle->colorRamp(name);
144+
145+
QStandardItem* item = new QStandardItem(name);
146+
QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon(ramp, listItems->iconSize());
147+
item->setIcon(icon);
148+
model->appendRow(item);
149+
delete ramp;
150+
}
151+
}
152+
153+
int QgsStyleV2ManagerDialog::currentItemType()
154+
{
155+
int idx = cboItemType->currentIndex();
156+
return cboItemType->itemData(idx).toInt();
157+
}
158+
159+
QString QgsStyleV2ManagerDialog::currentItemName()
160+
{
161+
QModelIndex index = listItems->selectionModel()->currentIndex();
162+
if (!index.isValid())
163+
return QString();
164+
return index.model()->data(index, 0).toString();
165+
}
166+
167+
void QgsStyleV2ManagerDialog::addItem()
168+
{
169+
if (currentItemType() < 3)
170+
addSymbol();
171+
else if (currentItemType() == 3)
172+
addColorRamp();
173+
else
174+
Q_ASSERT(0 && "not implemented");
175+
176+
populateList();
177+
populateTypes();
178+
}
179+
180+
bool QgsStyleV2ManagerDialog::addSymbol()
181+
{
182+
// create new symbol with current type
183+
QgsSymbolV2* symbol;
184+
switch (currentItemType())
185+
{
186+
case QgsSymbolV2::Marker: symbol = new QgsMarkerSymbolV2(); break;
187+
case QgsSymbolV2::Line: symbol = new QgsLineSymbolV2(); break;
188+
case QgsSymbolV2::Fill: symbol = new QgsFillSymbolV2(); break;
189+
default: Q_ASSERT(0 && "unknown symbol type"); break;
190+
}
191+
192+
// get symbol design
193+
QgsSymbolV2PropertiesDialog dlg(symbol, this);
194+
if (dlg.exec() == 0)
195+
{
196+
delete symbol;
197+
return false;
198+
}
199+
200+
// get name
201+
bool ok;
202+
QString name = QInputDialog::getText(this, "Symbol name",
203+
"Please enter name for new symbol:", QLineEdit::Normal, "new symbol", &ok);
204+
if (!ok || name.isEmpty())
205+
{
206+
delete symbol;
207+
return false;
208+
}
209+
210+
// add new symbol to style and re-populate the list
211+
mStyle->addSymbol(name, symbol);
212+
return true;
213+
}
214+
215+
bool QgsStyleV2ManagerDialog::addColorRamp()
216+
{
217+
// TODO: random color ramp
218+
/*
219+
QStringList rampTypes;
220+
rampTypes << "Gradient" << "Random";
221+
bool ok;
222+
QString rampType = QInputDialog.getItem(this, "Color ramp type",
223+
"Please select color ramp type:", rampTypes, 0, false, &ok);
224+
if (!ok || rampType.isEmpty())
225+
return false;
226+
*/
227+
QString rampType = "Gradient";
228+
229+
QgsVectorColorRampV2* ramp;
230+
if (rampType == "Gradient")
231+
{
232+
QgsVectorGradientColorRampV2* gradRamp = new QgsVectorGradientColorRampV2();
233+
QgsVectorGradientColorRampV2Dialog dlg(gradRamp, this);
234+
if (!dlg.exec())
235+
{
236+
delete gradRamp;
237+
return false;
238+
}
239+
ramp = gradRamp;
240+
}
241+
else
242+
{
243+
/*
244+
QgsVectorRandomColorRampV2* randRamp = new QgsVectorRandomColorRampV2();
245+
DlgRandomColorRamp dlg(randRamp, this);
246+
if (!dlg.exec())
247+
{
248+
delete randRamp;
249+
return false;
250+
}
251+
ramp = randRamp;
252+
*/
253+
}
254+
255+
// get name
256+
bool ok;
257+
QString name = QInputDialog::getText(this, "Color ramp name",
258+
"Please enter name for new color ramp:", QLineEdit::Normal, "new color ramp", &ok);
259+
if (!ok || name.isEmpty())
260+
{
261+
delete ramp;
262+
return false;
263+
}
264+
265+
// add new symbol to style and re-populate the list
266+
mStyle->addColorRamp(name, ramp);
267+
return true;
268+
}
269+
270+
271+
void QgsStyleV2ManagerDialog::editItem()
272+
{
273+
if (currentItemType() < 3)
274+
editSymbol();
275+
else if (currentItemType() == 3)
276+
editColorRamp();
277+
else
278+
Q_ASSERT(0 && "not implemented");
279+
280+
populateList();
281+
}
282+
283+
bool QgsStyleV2ManagerDialog::editSymbol()
284+
{
285+
QString symbolName = currentItemName();
286+
if (symbolName.isEmpty())
287+
return false;
288+
289+
QgsSymbolV2* symbol = mStyle->symbol(symbolName);
290+
291+
// let the user edit the symbol and update list when done
292+
QgsSymbolV2PropertiesDialog dlg(symbol, this);
293+
if (dlg.exec() == 0)
294+
{
295+
delete symbol;
296+
return false;
297+
}
298+
299+
// by adding symbol to style with the same name the old effectively gets overwritten
300+
mStyle->addSymbol(symbolName, symbol);
301+
return true;
302+
}
303+
304+
bool QgsStyleV2ManagerDialog::editColorRamp()
305+
{
306+
QString name = currentItemName();
307+
if (name.isEmpty())
308+
return false;
309+
310+
QgsVectorColorRampV2* ramp = mStyle->colorRamp(name);
311+
312+
if (ramp->type() == "gradient")
313+
{
314+
QgsVectorGradientColorRampV2* gradRamp = static_cast<QgsVectorGradientColorRampV2*>(ramp);
315+
QgsVectorGradientColorRampV2Dialog dlg(gradRamp, this);
316+
if (!dlg.exec())
317+
{
318+
delete ramp;
319+
return false;
320+
}
321+
}
322+
else
323+
{
324+
// TODO: random color ramp
325+
//dlg = DlgRandomColorRamp(ramp, self)
326+
}
327+
328+
mStyle->addColorRamp(name, ramp);
329+
return true;
330+
}
331+
332+
333+
void QgsStyleV2ManagerDialog::removeItem()
334+
{
335+
if (currentItemType() < 3)
336+
removeSymbol();
337+
else if (currentItemType() == 3)
338+
removeColorRamp();
339+
else
340+
Q_ASSERT(0 && "not implemented");
341+
342+
populateList();
343+
populateTypes();
344+
}
345+
346+
bool QgsStyleV2ManagerDialog::removeSymbol()
347+
{
348+
QString symbolName = currentItemName();
349+
if (symbolName.isEmpty())
350+
return false;
351+
352+
// delete from style and update list
353+
mStyle->removeSymbol(symbolName);
354+
return true;
355+
}
356+
357+
bool QgsStyleV2ManagerDialog::removeColorRamp()
358+
{
359+
QString rampName = currentItemName();
360+
if (rampName.isEmpty())
361+
return false;
362+
363+
mStyle->removeColorRamp(rampName);
364+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
#ifndef QGSSTYLEV2MANAGERDIALOG_H
3+
#define QGSSTYLEV2MANAGERDIALOG_H
4+
5+
#include <QDialog>
6+
7+
#include "ui_qgsstylev2managerdialogbase.h"
8+
9+
class QgsStyleV2;
10+
11+
class QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV2ManagerDialogBase
12+
{
13+
Q_OBJECT
14+
15+
public:
16+
QgsStyleV2ManagerDialog(QgsStyleV2* style, QWidget* parent = NULL);
17+
18+
public slots:
19+
void addItem();
20+
void editItem();
21+
void removeItem();
22+
//! adds symbols of some type to list
23+
void populateList();
24+
25+
//! called when the dialog is going to be closed
26+
void onFinished();
27+
28+
protected:
29+
30+
//! populate combo box with known style items (symbols, color ramps)
31+
void populateTypes();
32+
33+
//! populate list view with symbols of specified type
34+
void populateSymbols(int type);
35+
//! populate list view with color ramps
36+
void populateColorRamps();
37+
38+
int currentItemType();
39+
QString currentItemName();
40+
41+
//! add a new symbol to style
42+
bool addSymbol();
43+
//! add a new color ramp to style
44+
bool addColorRamp();
45+
46+
bool editSymbol();
47+
bool editColorRamp();
48+
49+
bool removeSymbol();
50+
bool removeColorRamp();
51+
52+
QgsStyleV2* mStyle;
53+
54+
};
55+
56+
#endif

‎src/gui/symbology-ng/qgssymbollayerv2widget.cpp

Lines changed: 445 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
2+
#ifndef QGSSYMBOLLAYERV2WIDGET_H
3+
#define QGSSYMBOLLAYERV2WIDGET_H
4+
5+
#include <QWidget>
6+
7+
class QgsSymbolLayerV2;
8+
9+
10+
class QgsSymbolLayerV2Widget : public QWidget
11+
{
12+
Q_OBJECT
13+
14+
public:
15+
QgsSymbolLayerV2Widget(QWidget* parent) : QWidget(parent) {}
16+
17+
virtual void setSymbolLayer(QgsSymbolLayerV2* layer) = 0;
18+
virtual QgsSymbolLayerV2* symbolLayer() = 0;
19+
20+
signals:
21+
void changed();
22+
};
23+
24+
///////////
25+
26+
#include "ui_widget_simpleline.h"
27+
28+
class QgsSimpleLineSymbolLayerV2;
29+
30+
class QgsSimpleLineSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private Ui::WidgetSimpleLine
31+
{
32+
Q_OBJECT
33+
34+
public:
35+
QgsSimpleLineSymbolLayerV2Widget(QWidget* parent = NULL);
36+
37+
static QgsSymbolLayerV2Widget* create() { return new QgsSimpleLineSymbolLayerV2Widget(); }
38+
39+
// from base class
40+
virtual void setSymbolLayer(QgsSymbolLayerV2* layer);
41+
virtual QgsSymbolLayerV2* symbolLayer();
42+
43+
public slots:
44+
void penWidthChanged();
45+
void colorChanged();
46+
void penStyleChanged();
47+
48+
protected:
49+
QgsSimpleLineSymbolLayerV2* mLayer;
50+
};
51+
52+
///////////
53+
54+
#include "ui_widget_simplemarker.h"
55+
56+
class QgsSimpleMarkerSymbolLayerV2;
57+
58+
class QgsSimpleMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private Ui::WidgetSimpleMarker
59+
{
60+
Q_OBJECT
61+
62+
public:
63+
QgsSimpleMarkerSymbolLayerV2Widget(QWidget* parent = NULL);
64+
65+
static QgsSymbolLayerV2Widget* create() { return new QgsSimpleMarkerSymbolLayerV2Widget(); }
66+
67+
// from base class
68+
virtual void setSymbolLayer(QgsSymbolLayerV2* layer);
69+
virtual QgsSymbolLayerV2* symbolLayer();
70+
71+
public slots:
72+
void setName();
73+
void setColorBorder();
74+
void setColorFill();
75+
void setSize();
76+
void setAngle();
77+
78+
protected:
79+
QgsSimpleMarkerSymbolLayerV2* mLayer;
80+
};
81+
82+
///////////
83+
84+
#include "ui_widget_simplefill.h"
85+
86+
class QgsSimpleFillSymbolLayerV2;
87+
88+
class QgsSimpleFillSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private Ui::WidgetSimpleFill
89+
{
90+
Q_OBJECT
91+
92+
public:
93+
QgsSimpleFillSymbolLayerV2Widget(QWidget* parent = NULL);
94+
95+
static QgsSymbolLayerV2Widget* create() { return new QgsSimpleFillSymbolLayerV2Widget(); }
96+
97+
// from base class
98+
virtual void setSymbolLayer(QgsSymbolLayerV2* layer);
99+
virtual QgsSymbolLayerV2* symbolLayer();
100+
101+
public slots:
102+
void setColor();
103+
void setBorderColor();
104+
void setBrushStyle();
105+
106+
protected:
107+
QgsSimpleFillSymbolLayerV2* mLayer;
108+
};
109+
110+
111+
///////////
112+
113+
#include "ui_widget_markerline.h"
114+
115+
class QgsMarkerLineSymbolLayerV2;
116+
117+
class QgsMarkerLineSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private Ui::WidgetMarkerLine
118+
{
119+
Q_OBJECT
120+
121+
public:
122+
QgsMarkerLineSymbolLayerV2Widget(QWidget* parent = NULL);
123+
124+
static QgsSymbolLayerV2Widget* create() { return new QgsMarkerLineSymbolLayerV2Widget(); }
125+
126+
// from base class
127+
virtual void setSymbolLayer(QgsSymbolLayerV2* layer);
128+
virtual QgsSymbolLayerV2* symbolLayer();
129+
130+
public slots:
131+
132+
void setInterval(int val);
133+
void setMarker();
134+
void setRotate();
135+
136+
protected:
137+
138+
void updateMarker();
139+
140+
QgsMarkerLineSymbolLayerV2* mLayer;
141+
};
142+
143+
144+
///////////
145+
146+
#include "ui_widget_svgmarker.h"
147+
148+
class QgsSvgMarkerSymbolLayerV2;
149+
150+
class QgsSvgMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private Ui::WidgetSvgMarker
151+
{
152+
Q_OBJECT
153+
154+
public:
155+
QgsSvgMarkerSymbolLayerV2Widget(QWidget* parent = NULL);
156+
157+
static QgsSymbolLayerV2Widget* create() { return new QgsSvgMarkerSymbolLayerV2Widget(); }
158+
159+
// from base class
160+
virtual void setSymbolLayer(QgsSymbolLayerV2* layer);
161+
virtual QgsSymbolLayerV2* symbolLayer();
162+
163+
public slots:
164+
void setName(const QModelIndex& idx);
165+
void setSize();
166+
void setAngle();
167+
168+
protected:
169+
170+
void populateList();
171+
172+
QgsSvgMarkerSymbolLayerV2* mLayer;
173+
};
174+
175+
176+
///////////
177+
178+
#include "ui_widget_linedecoration.h"
179+
180+
class QgsLineDecorationSymbolLayerV2;
181+
182+
class QgsLineDecorationSymbolLayerV2Widget : public QgsSymbolLayerV2Widget, private Ui::WidgetLineDecoration
183+
{
184+
Q_OBJECT
185+
186+
public:
187+
QgsLineDecorationSymbolLayerV2Widget(QWidget* parent = NULL);
188+
189+
static QgsSymbolLayerV2Widget* create() { return new QgsLineDecorationSymbolLayerV2Widget(); }
190+
191+
// from base class
192+
virtual void setSymbolLayer(QgsSymbolLayerV2* layer);
193+
virtual QgsSymbolLayerV2* symbolLayer();
194+
195+
public slots:
196+
void colorChanged();
197+
198+
protected:
199+
QgsLineDecorationSymbolLayerV2* mLayer;
200+
};
201+
202+
203+
#endif
Lines changed: 363 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,363 @@
1+
2+
#include "qgssymbolv2propertiesdialog.h"
3+
4+
#include <QFile>
5+
#include <QStandardItem>
6+
7+
#include "qgssymbollayerv2.h"
8+
#include "qgssymbolv2.h"
9+
#include "qgssymbollayerv2registry.h"
10+
11+
#include "qgsapplication.h"
12+
13+
#include "qgssymbollayerv2widget.h"
14+
15+
static const int SymbolLayerItemType = QStandardItem::UserType + 1;
16+
17+
class SymbolLayerItem : public QStandardItem
18+
{
19+
public:
20+
SymbolLayerItem(QgsSymbolLayerV2* layer)
21+
{
22+
setLayer(layer);
23+
}
24+
25+
void setLayer(QgsSymbolLayerV2* layer)
26+
{
27+
mLayer = layer;
28+
updatePreview();
29+
}
30+
31+
void updatePreview()
32+
{
33+
QIcon icon = QgsSymbolLayerV2Utils::symbolLayerPreviewIcon(mLayer, QSize(16,16));
34+
setIcon(icon);
35+
}
36+
37+
int type() const { return SymbolLayerItemType; }
38+
39+
QVariant data(int role) const
40+
{
41+
if (role == Qt::DisplayRole)
42+
return QVariant(mLayer->layerType());
43+
if (role == Qt::SizeHintRole)
44+
return QVariant(QSize(32,32));
45+
if (role == Qt::CheckStateRole)
46+
return QVariant(); // could be true/false
47+
return QStandardItem::data(role);
48+
}
49+
50+
protected:
51+
QgsSymbolLayerV2* mLayer;
52+
};
53+
54+
//////////
55+
56+
static QString iconPath(QString iconFile)
57+
{
58+
// try active theme
59+
QString path = QgsApplication::activeThemePath();
60+
if ( QFile::exists( path + iconFile ) )
61+
return path + iconFile;
62+
63+
// use default theme
64+
return QgsApplication::defaultThemePath() + iconFile;
65+
}
66+
67+
//////////
68+
69+
QgsSymbolV2PropertiesDialog::QgsSymbolV2PropertiesDialog(QgsSymbolV2* symbol, QWidget* parent)
70+
: QDialog(parent), mSymbol(symbol)
71+
{
72+
setupUi(this);
73+
74+
// setup icons
75+
btnAddLayer->setIcon( QIcon( iconPath( "symbologyAdd.png" ) ) );
76+
btnRemoveLayer->setIcon( QIcon( iconPath( "symbologyRemove.png" ) ) );
77+
btnLock->setIcon( QIcon( iconPath( "symbologyLock.png" ) ) );
78+
btnUp->setIcon( QIcon( iconPath( "symbologyUp.png" ) ) );
79+
btnDown->setIcon( QIcon( iconPath( "symbologyDown.png" ) ) );
80+
81+
// set widget functions
82+
// (should be probably moved somewhere else)
83+
QgsSymbolLayerV2Registry::instance()->setLayerTypeWidgetFunction("SimpleLine", QgsSimpleLineSymbolLayerV2Widget::create);
84+
QgsSymbolLayerV2Registry::instance()->setLayerTypeWidgetFunction("MarkerLine", QgsMarkerLineSymbolLayerV2Widget::create);
85+
QgsSymbolLayerV2Registry::instance()->setLayerTypeWidgetFunction("LineDecoration", QgsLineDecorationSymbolLayerV2Widget::create);
86+
87+
QgsSymbolLayerV2Registry::instance()->setLayerTypeWidgetFunction("SimpleMarker", QgsSimpleMarkerSymbolLayerV2Widget::create);
88+
QgsSymbolLayerV2Registry::instance()->setLayerTypeWidgetFunction("SvgMarker", QgsSvgMarkerSymbolLayerV2Widget::create);
89+
90+
QgsSymbolLayerV2Registry::instance()->setLayerTypeWidgetFunction("SimpleFill", QgsSimpleFillSymbolLayerV2Widget::create);
91+
92+
loadSymbol();
93+
94+
connect(btnUp, SIGNAL(clicked()), this, SLOT(moveLayerUp()));
95+
connect(btnDown, SIGNAL(clicked()), this, SLOT(moveLayerDown()));
96+
connect(btnAddLayer, SIGNAL(clicked()), this, SLOT(addLayer()));
97+
connect(btnRemoveLayer, SIGNAL(clicked()), this, SLOT(removeLayer()));
98+
connect(btnLock, SIGNAL(clicked()), this, SLOT(lockLayer()));
99+
100+
populateLayerTypes();
101+
connect(cboLayerType, SIGNAL(currentIndexChanged(int)), this, SLOT(layerTypeChanged()));
102+
103+
loadPropertyWidgets();
104+
105+
updateUi();
106+
107+
// set first layer as active
108+
QModelIndex newIndex = listLayers->model()->index(0,0);
109+
listLayers->setCurrentIndex(newIndex);
110+
}
111+
112+
113+
void QgsSymbolV2PropertiesDialog::loadSymbol()
114+
{
115+
QStandardItemModel* model = new QStandardItemModel(this);
116+
listLayers->setModel(model);
117+
118+
QItemSelectionModel* selModel = listLayers->selectionModel();
119+
connect(selModel, SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(layerChanged()));
120+
121+
int count = mSymbol->symbolLayerCount();
122+
for (int i = 0; i < count; i++)
123+
{
124+
model->appendRow(new SymbolLayerItem( mSymbol->symbolLayer(i) ));
125+
}
126+
127+
updatePreview();
128+
}
129+
130+
131+
void QgsSymbolV2PropertiesDialog::populateLayerTypes()
132+
{
133+
QStringList types = QgsSymbolLayerV2Registry::instance()->symbolLayersForType(mSymbol->type());
134+
135+
cboLayerType->clear();
136+
for (int i = 0; i < types.count(); i++)
137+
cboLayerType->addItem(types[i]);
138+
}
139+
140+
141+
void QgsSymbolV2PropertiesDialog::updateUi()
142+
{
143+
int row = currentLayerIndex();
144+
btnUp->setEnabled( row > 0 );
145+
btnDown->setEnabled( row < listLayers->model()->rowCount()-1 && row != -1 );
146+
btnRemoveLayer->setEnabled( row != -1 );
147+
}
148+
149+
void QgsSymbolV2PropertiesDialog::updatePreview()
150+
{
151+
QImage preview = mSymbol->bigSymbolPreviewImage();
152+
lblPreview->setPixmap(QPixmap::fromImage(preview));
153+
}
154+
155+
void QgsSymbolV2PropertiesDialog::updateLayerPreview()
156+
{
157+
// get current layer item and update its icon
158+
SymbolLayerItem* item = currentLayerItem();
159+
if (item)
160+
item->updatePreview();
161+
162+
// update also preview of the whole symbol
163+
updatePreview();
164+
}
165+
166+
void QgsSymbolV2PropertiesDialog::updateSymbolLayerWidget(QgsSymbolLayerV2* layer)
167+
{
168+
QString layerType = layer->layerType();
169+
170+
// stop updating from the original widget
171+
if (stackedWidget->currentWidget() != pageDummy)
172+
disconnect(stackedWidget->currentWidget(), SIGNAL(changed()), this, SLOT(updateLayerPreview()));
173+
174+
// update active properties widget
175+
if (mWidgets.contains(layerType))
176+
{
177+
stackedWidget->setCurrentWidget(mWidgets[layerType]);
178+
mWidgets[layerType]->setSymbolLayer(layer);
179+
180+
// start recieving updates from widget
181+
connect(mWidgets[layerType], SIGNAL(changed()), this, SLOT(updateLayerPreview()));
182+
}
183+
else
184+
{
185+
// use dummy widget instead
186+
stackedWidget->setCurrentWidget(pageDummy);
187+
}
188+
}
189+
190+
void QgsSymbolV2PropertiesDialog::loadPropertyWidgets()
191+
{
192+
QgsSymbolLayerV2Registry* pReg = QgsSymbolLayerV2Registry::instance();
193+
194+
QStringList layerTypes = pReg->symbolLayersForType(mSymbol->type());
195+
196+
for (int i = 0; i < layerTypes.count(); i++)
197+
{
198+
QString layerType = layerTypes[i];
199+
QgsSymbolLayerV2WidgetFunc f = pReg->symbolLayerMetadata(layerType).widgetFunction();
200+
if (f == NULL) // check whether the function is assigned
201+
continue;
202+
203+
QgsSymbolLayerV2Widget* w = f();
204+
if (w == NULL) // check whether the function returns correct widget
205+
continue;
206+
207+
mWidgets[layerType] = w;
208+
stackedWidget->addWidget(w);
209+
}
210+
}
211+
212+
int QgsSymbolV2PropertiesDialog::currentLayerIndex()
213+
{
214+
QModelIndex idx = listLayers->selectionModel()->currentIndex();
215+
if (!idx.isValid())
216+
return -1;
217+
return idx.row();
218+
}
219+
220+
SymbolLayerItem* QgsSymbolV2PropertiesDialog::currentLayerItem()
221+
{
222+
int index = currentLayerIndex();
223+
if (index < 0)
224+
return NULL;
225+
226+
QStandardItemModel* model = qobject_cast<QStandardItemModel*>(listLayers->model());
227+
if (model == NULL)
228+
return NULL;
229+
QStandardItem* item = model->item(index);
230+
if (item->type() != SymbolLayerItemType)
231+
return NULL;
232+
return static_cast<SymbolLayerItem*>(item);
233+
}
234+
235+
QgsSymbolLayerV2* QgsSymbolV2PropertiesDialog::currentLayer()
236+
{
237+
int idx = currentLayerIndex();
238+
if (idx < 0)
239+
return NULL;
240+
241+
return mSymbol->symbolLayer(idx);
242+
}
243+
244+
245+
void QgsSymbolV2PropertiesDialog::layerChanged()
246+
{
247+
updateUi();
248+
249+
// get layer info
250+
QgsSymbolLayerV2* layer = currentLayer();
251+
if (layer == NULL)
252+
return;
253+
254+
// update layer type combo box
255+
int idx = cboLayerType->findText(layer->layerType());
256+
cboLayerType->setCurrentIndex(idx);
257+
258+
updateSymbolLayerWidget(layer);
259+
260+
updateLockButton();
261+
}
262+
263+
264+
void QgsSymbolV2PropertiesDialog::updateLockButton()
265+
{
266+
QgsSymbolLayerV2* layer = currentLayer();
267+
if (layer == NULL) return;
268+
269+
btnLock->setChecked(layer->isLocked());
270+
}
271+
272+
273+
void QgsSymbolV2PropertiesDialog::layerTypeChanged()
274+
{
275+
QgsSymbolLayerV2* layer = currentLayer();
276+
if (layer == NULL) return;
277+
278+
QString newLayerType = cboLayerType->currentText();
279+
if (layer->layerType() == newLayerType)
280+
return;
281+
282+
// get creation function for new layer from registry
283+
QgsSymbolLayerV2Registry* pReg = QgsSymbolLayerV2Registry::instance();
284+
QgsSymbolLayerV2CreateFunc f = pReg->symbolLayerMetadata(newLayerType).createFunction();
285+
if (f == NULL) // check whether the function is assigned
286+
return;
287+
288+
// change layer to a new (with different type)
289+
QgsSymbolLayerV2* newLayer = f(QgsStringMap());
290+
mSymbol->changeSymbolLayer(currentLayerIndex(), newLayer);
291+
292+
updateSymbolLayerWidget(newLayer);
293+
294+
// update symbol layer item
295+
SymbolLayerItem* item = currentLayerItem();
296+
item->setLayer(newLayer);
297+
item->updatePreview();
298+
299+
updatePreview();
300+
}
301+
302+
303+
void QgsSymbolV2PropertiesDialog::addLayer()
304+
{
305+
QgsSymbolLayerV2* newLayer = QgsSymbolLayerV2Registry::instance()->defaultSymbolLayer(mSymbol->type());
306+
307+
mSymbol->appendSymbolLayer(newLayer);
308+
309+
loadSymbol();
310+
311+
QModelIndex newIndex = listLayers->model()->index(0,0);
312+
listLayers->setCurrentIndex(newIndex);
313+
314+
updateUi();
315+
}
316+
317+
318+
void QgsSymbolV2PropertiesDialog::removeLayer()
319+
{
320+
int idx = currentLayerIndex();
321+
if (idx < 0) return;
322+
mSymbol->deleteSymbolLayer(idx);
323+
324+
loadSymbol();
325+
326+
updateUi();
327+
}
328+
329+
330+
void QgsSymbolV2PropertiesDialog::moveLayerDown()
331+
{
332+
moveLayerByOffset(+1);
333+
}
334+
335+
void QgsSymbolV2PropertiesDialog::moveLayerUp()
336+
{
337+
moveLayerByOffset(-1);
338+
}
339+
340+
void QgsSymbolV2PropertiesDialog::moveLayerByOffset(int offset)
341+
{
342+
int idx = currentLayerIndex();
343+
344+
// switch layers
345+
QgsSymbolLayerV2* tmpLayer = mSymbol->takeSymbolLayer(idx);
346+
mSymbol->insertSymbolLayer(idx + offset, tmpLayer);
347+
348+
loadSymbol();
349+
350+
QModelIndex newIndex = listLayers->model()->index(idx + offset,0);
351+
listLayers->setCurrentIndex(newIndex);
352+
353+
updateUi();
354+
}
355+
356+
357+
void QgsSymbolV2PropertiesDialog::lockLayer()
358+
{
359+
QgsSymbolLayerV2* layer = currentLayer();
360+
if (layer == NULL) return;
361+
362+
layer->setLocked( btnLock->isChecked() );
363+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
#ifndef QGSSYMBOLV2PROPERTIESDIALOG_H
3+
#define QGSSYMBOLV2PROPERTIESDIALOG_H
4+
5+
#include "ui_qgssymbolv2propertiesdialogbase.h"
6+
7+
class QgsSymbolV2;
8+
class QgsSymbolLayerV2;
9+
class QgsSymbolLayerV2Widget;
10+
11+
class SymbolLayerItem;
12+
13+
#include <QMap>
14+
15+
16+
class QgsSymbolV2PropertiesDialog : public QDialog, private Ui::DlgSymbolV2Properties
17+
{
18+
Q_OBJECT
19+
20+
public:
21+
QgsSymbolV2PropertiesDialog(QgsSymbolV2* symbol, QWidget* parent = NULL);
22+
23+
24+
public slots:
25+
void moveLayerDown();
26+
void moveLayerUp();
27+
28+
void addLayer();
29+
void removeLayer();
30+
31+
void lockLayer();
32+
33+
void layerTypeChanged();
34+
35+
void layerChanged();
36+
37+
void updateLayerPreview();
38+
void updatePreview();
39+
40+
protected:
41+
42+
void loadSymbol();
43+
44+
void populateLayerTypes();
45+
46+
void updateUi();
47+
48+
void loadPropertyWidgets();
49+
50+
void updateSymbolLayerWidget(QgsSymbolLayerV2* layer);
51+
void updateLockButton();
52+
53+
int currentLayerIndex();
54+
SymbolLayerItem* currentLayerItem();
55+
QgsSymbolLayerV2* currentLayer();
56+
57+
void moveLayerByOffset(int offset);
58+
59+
protected: // data
60+
QgsSymbolV2* mSymbol;
61+
62+
QMap<QString, QgsSymbolLayerV2Widget*> mWidgets;
63+
};
64+
65+
#endif
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
2+
#include "qgssymbolv2selectordialog.h"
3+
4+
#include "qgssymbolv2propertiesdialog.h"
5+
6+
#include "qgssymbolv2.h"
7+
#include "qgssymbollayerv2utils.h"
8+
#include "qgsstylev2.h"
9+
10+
#include <QColorDialog>
11+
#include <QPainter>
12+
#include <QStandardItemModel>
13+
14+
QgsSymbolV2SelectorDialog::QgsSymbolV2SelectorDialog(QgsSymbolV2* symbol, QgsStyleV2* style, QWidget* parent)
15+
: QDialog(parent)
16+
{
17+
mStyle = style;
18+
mSymbol = symbol;
19+
20+
setupUi(this);
21+
22+
connect(btnSymbolProperties, SIGNAL(clicked()), this, SLOT(changeSymbolProperties()));
23+
24+
25+
QStandardItemModel* model = new QStandardItemModel(viewSymbols);
26+
viewSymbols->setModel(model);
27+
connect(viewSymbols, SIGNAL(clicked(const QModelIndex &)), this, SLOT(setSymbolFromStyle(const QModelIndex &)));
28+
29+
populateSymbolView();
30+
updateSymbolPreview();
31+
updateSymbolInfo();
32+
33+
// select correct page in stacked widget
34+
// there's a correspondence between symbol type number and page numbering => exploit it!
35+
stackedWidget->setCurrentIndex(symbol->type());
36+
37+
connect(btnSetColor, SIGNAL(clicked()), this, SLOT(setSymbolColor()));
38+
connect(spinAngle, SIGNAL(valueChanged(double)), this, SLOT(setMarkerAngle(double)));
39+
connect(spinSize, SIGNAL(valueChanged(int)), this, SLOT(setMarkerSize(int)));
40+
connect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(setLineWidth(int)));
41+
42+
}
43+
44+
void QgsSymbolV2SelectorDialog::populateSymbolView()
45+
{
46+
QSize previewSize = viewSymbols->iconSize();
47+
QPixmap p(previewSize);
48+
QPainter painter;
49+
50+
QStandardItemModel* model = qobject_cast<QStandardItemModel*>(viewSymbols->model());
51+
if (!model)
52+
return;
53+
model->clear();
54+
55+
QStringList names = mStyle->symbolNames();
56+
for (int i = 0; i < names.count(); i++)
57+
{
58+
QgsSymbolV2* s = mStyle->symbol(names[i]);
59+
if (s->type() != mSymbol->type())
60+
{
61+
delete s;
62+
continue;
63+
}
64+
QStandardItem* item = new QStandardItem(names[i]);
65+
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
66+
// create preview icon
67+
QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon(s, previewSize);
68+
item->setIcon(icon);
69+
// add to model
70+
model->appendRow(item);
71+
delete s;
72+
}
73+
}
74+
75+
void QgsSymbolV2SelectorDialog::setSymbolFromStyle(const QModelIndex & index)
76+
{
77+
QString symbolName = index.data().toString();
78+
// get new instance of symbol from style
79+
QgsSymbolV2* s = mStyle->symbol(symbolName);
80+
// remove all symbol layers from original symbol
81+
while (mSymbol->symbolLayerCount())
82+
mSymbol->deleteSymbolLayer(0);
83+
// move all symbol layers to our symbol
84+
while (s->symbolLayerCount())
85+
{
86+
QgsSymbolLayerV2* sl = s->takeSymbolLayer(0);
87+
mSymbol->appendSymbolLayer(sl);
88+
}
89+
// delete the temporary symbol
90+
delete s;
91+
92+
updateSymbolPreview();
93+
updateSymbolInfo();
94+
}
95+
96+
void QgsSymbolV2SelectorDialog::updateSymbolPreview()
97+
{
98+
QImage preview = mSymbol->bigSymbolPreviewImage();
99+
lblPreview->setPixmap(QPixmap::fromImage(preview));
100+
}
101+
102+
void QgsSymbolV2SelectorDialog::updateSymbolColor()
103+
{
104+
QPixmap p(20,20);
105+
p.fill(mSymbol->color());
106+
btnSetColor->setIcon(QIcon(p));
107+
}
108+
109+
void QgsSymbolV2SelectorDialog::updateSymbolInfo()
110+
{
111+
updateSymbolColor();
112+
113+
if (mSymbol->type() == QgsSymbolV2::Marker)
114+
{
115+
QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>(mSymbol);
116+
spinSize->setValue(markerSymbol->size());
117+
spinAngle->setValue(markerSymbol->angle());
118+
}
119+
else if (mSymbol->type() == QgsSymbolV2::Line)
120+
{
121+
QgsLineSymbolV2* lineSymbol = static_cast<QgsLineSymbolV2*>(mSymbol);
122+
spinWidth->setValue(lineSymbol->width());
123+
}
124+
}
125+
126+
void QgsSymbolV2SelectorDialog::changeSymbolProperties()
127+
{
128+
QgsSymbolV2PropertiesDialog dlg(mSymbol, this);
129+
if (!dlg.exec())
130+
return;
131+
132+
updateSymbolPreview();
133+
updateSymbolInfo();
134+
}
135+
136+
137+
void QgsSymbolV2SelectorDialog::setSymbolColor()
138+
{
139+
QColor color = QColorDialog::getColor(mSymbol->color(), this);
140+
if (!color.isValid())
141+
return;
142+
143+
mSymbol->setColor(color);
144+
updateSymbolColor();
145+
updateSymbolPreview();
146+
}
147+
148+
void QgsSymbolV2SelectorDialog::setMarkerAngle(double angle)
149+
{
150+
QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>(mSymbol);
151+
if (markerSymbol->angle() == angle)
152+
return;
153+
markerSymbol->setAngle(angle);
154+
updateSymbolPreview();
155+
}
156+
157+
void QgsSymbolV2SelectorDialog::setMarkerSize(int size)
158+
{
159+
QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>(mSymbol);
160+
if (markerSymbol->size() == size)
161+
return;
162+
markerSymbol->setSize(size);
163+
updateSymbolPreview();
164+
}
165+
166+
void QgsSymbolV2SelectorDialog::setLineWidth(int width)
167+
{
168+
QgsLineSymbolV2* lineSymbol = static_cast<QgsLineSymbolV2*>(mSymbol);
169+
if (lineSymbol->width() == width)
170+
return;
171+
lineSymbol->setWidth(width);
172+
updateSymbolPreview();
173+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
#ifndef QGSSYMBOLV2SELECTORDIALOG_H
3+
#define QGSSYMBOLV2SELECTORDIALOG_H
4+
5+
#include <QDialog>
6+
7+
#include "ui_qgssymbolv2selectordialogbase.h"
8+
9+
class QgsStyleV2;
10+
class QgsSymbolV2;
11+
12+
class QgsSymbolV2SelectorDialog : public QDialog, private Ui::QgsSymbolV2SelectorDialogBase
13+
{
14+
Q_OBJECT
15+
16+
public:
17+
QgsSymbolV2SelectorDialog(QgsSymbolV2* symbol, QgsStyleV2* style, QWidget* parent = NULL);
18+
19+
protected:
20+
void populateSymbolView();
21+
void updateSymbolPreview();
22+
void updateSymbolColor();
23+
void updateSymbolInfo();
24+
25+
26+
public slots:
27+
void changeSymbolProperties();
28+
void setSymbolFromStyle(const QModelIndex & index);
29+
void setSymbolColor();
30+
void setMarkerAngle(double angle);
31+
void setMarkerSize(int size);
32+
void setLineWidth(int width);
33+
34+
protected:
35+
QgsStyleV2* mStyle;
36+
QgsSymbolV2* mSymbol;
37+
};
38+
39+
#endif
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
#include "qgsvectorgradientcolorrampv2dialog.h"
3+
4+
#include "qgsvectorcolorrampv2.h"
5+
6+
#include <QColorDialog>
7+
8+
static void updateColorButton(QAbstractButton* button, QColor color)
9+
{
10+
QPixmap p(20,20);
11+
p.fill(color);
12+
button->setIcon(QIcon(p));
13+
}
14+
15+
/////////
16+
17+
18+
QgsVectorGradientColorRampV2Dialog::QgsVectorGradientColorRampV2Dialog(QgsVectorGradientColorRampV2* ramp, QWidget* parent)
19+
: QDialog(parent), mRamp(ramp)
20+
{
21+
22+
setupUi(this);
23+
24+
connect(btnColor1, SIGNAL(clicked()), this, SLOT(setColor1()));
25+
connect(btnColor2, SIGNAL(clicked()), this, SLOT(setColor2()));
26+
27+
updatePreview();
28+
}
29+
30+
void QgsVectorGradientColorRampV2Dialog::updatePreview()
31+
{
32+
QSize size(300,40);
33+
lblPreview->setPixmap(QgsSymbolLayerV2Utils::colorRampPreviewPixmap(mRamp, size));
34+
35+
updateColorButton(btnColor1, mRamp->color1());
36+
updateColorButton(btnColor2, mRamp->color2());
37+
}
38+
39+
void QgsVectorGradientColorRampV2Dialog::setColor1()
40+
{
41+
QColor color = QColorDialog::getColor(mRamp->color1(), this);
42+
if (!color.isValid())
43+
return;
44+
mRamp->setColor1(color);
45+
updatePreview();
46+
}
47+
48+
void QgsVectorGradientColorRampV2Dialog::setColor2()
49+
{
50+
QColor color = QColorDialog::getColor(mRamp->color2(), this);
51+
if (!color.isValid())
52+
return;
53+
mRamp->setColor2(color);
54+
updatePreview();
55+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
#ifndef QGSVECTORGRADIENTCOLORRAMPV2DIALOG_H
3+
#define QGSVECTORGRADIENTCOLORRAMPV2DIALOG_H
4+
5+
#include <QDialog>
6+
7+
#include "ui_qgsvectorgradientcolorrampv2dialogbase.h"
8+
9+
class QgsVectorGradientColorRampV2;
10+
11+
class QgsVectorGradientColorRampV2Dialog : public QDialog, private Ui::QgsVectorGradientColorRampV2DialogBase
12+
{
13+
Q_OBJECT
14+
15+
public:
16+
QgsVectorGradientColorRampV2Dialog(QgsVectorGradientColorRampV2* ramp, QWidget* parent = NULL);
17+
18+
public slots:
19+
void setColor1();
20+
void setColor2();
21+
22+
protected:
23+
24+
void updatePreview();
25+
26+
QgsVectorGradientColorRampV2* mRamp;
27+
};
28+
29+
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.