Skip to content

Commit

Permalink
Added a 'classify' button to the graduated symbology button. Replaced…
Browse files Browse the repository at this point in the history
… Qt3 compatibility classes with Qt4 ones

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6557 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Feb 10, 2007
1 parent 68f0d84 commit aaf86d7
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 196 deletions.
151 changes: 86 additions & 65 deletions src/app/qgsgraduatedsymboldialog.cpp
Expand Up @@ -63,8 +63,8 @@ QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog(QgsVectorLayer * layer): QDia
return;
}

modeComboBox->insertItem("Empty");
modeComboBox->insertItem("Equal Interval");
modeComboBox->insertItem("Empty");

//restore the correct settings
const QgsGraduatedSymbolRenderer* renderer = dynamic_cast < const QgsGraduatedSymbolRenderer * >(layer->renderer());
Expand Down Expand Up @@ -97,23 +97,22 @@ QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog(QgsVectorLayer * layer): QDia
sym->setNamedPointSymbol((*it)->pointSymbolName());
sym->setPointSize((*it)->pointSize());
mEntries.insert(std::make_pair(classbreak,sym));
mClassBreakBox->insertItem(classbreak);
mClassListWidget->addItem(classbreak);
}

}

//do the necessary signal/slot connections
QObject::connect(numberofclassesspinbox, SIGNAL(valueChanged(int)), this, SLOT(adjustClassification()));
QObject::connect(classificationComboBox, SIGNAL(activated(int)), this, SLOT(adjustClassification()));
QObject::connect(modeComboBox, SIGNAL(activated(int)), this, SLOT(adjustClassification()));
QObject::connect(mClassBreakBox, SIGNAL(selectionChanged()), this, SLOT(changeCurrentValue()));
QObject::connect(mClassifyButton, SIGNAL(clicked()), this, SLOT(adjustClassification()));
QObject::connect(mClassListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(changeCurrentValue()));
QObject::connect(&sydialog, SIGNAL(settingsChanged()), this, SLOT(applySymbologyChanges()));
QObject::connect(mClassBreakBox, SIGNAL(doubleClicked(Q3ListBoxItem*)), this, SLOT(changeClass(Q3ListBoxItem*)));
QObject::connect(mClassListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(modifyClass(QListWidgetItem*)));
QObject::connect(mDeleteClassButton, SIGNAL(clicked()), this, SLOT(deleteCurrentClass()));

mSymbolWidgetStack->addWidget(&sydialog);
mSymbolWidgetStack->raiseWidget(&sydialog);
mSymbolWidgetStack->setCurrentWidget(&sydialog);

mClassBreakBox->setCurrentItem(0);
mClassListWidget->setCurrentRow(0);
}

QgsGraduatedSymbolDialog::QgsGraduatedSymbolDialog(): QDialog(), mVectorLayer(0), sydialog(0)
Expand Down Expand Up @@ -154,78 +153,78 @@ void QgsGraduatedSymbolDialog::apply()

QgsGraduatedSymbolRenderer* renderer = new QgsGraduatedSymbolRenderer(mVectorLayer->vectorType());

for (uint item=0;item<mClassBreakBox->count();++item)
for (int item=0;item<mClassListWidget->count();++item)
{
QString classbreak=mClassBreakBox->text(item);
std::map<QString,QgsSymbol*>::iterator it=mEntries.find(classbreak);
if(it==mEntries.end())
QString classbreak=mClassListWidget->item(item)->text();
std::map<QString,QgsSymbol*>::iterator it=mEntries.find(classbreak);
if(it==mEntries.end())
{
continue;
continue;
}

QString lower_bound=it->second->lowerValue();
QString upper_bound=it->second->upperValue();
QString label=it->second->label();

QgsSymbol* sy = new QgsSymbol(mVectorLayer->vectorType(), lower_bound, upper_bound, label);
sy->setColor(it->second->pen().color());
sy->setLineStyle(it->second->pen().style());
sy->setLineWidth(it->second->pen().width());
if (mVectorLayer->vectorType() == QGis::Point)
QString lower_bound=it->second->lowerValue();
QString upper_bound=it->second->upperValue();
QString label=it->second->label();
QgsSymbol* sy = new QgsSymbol(mVectorLayer->vectorType(), lower_bound, upper_bound, label);

sy->setColor(it->second->pen().color());
sy->setLineStyle(it->second->pen().style());
sy->setLineWidth(it->second->pen().width());

if (mVectorLayer->vectorType() == QGis::Point)
{
sy->setNamedPointSymbol(it->second->pointSymbolName());
sy->setPointSize(it->second->pointSize());

sy->setNamedPointSymbol(it->second->pointSymbolName());
sy->setPointSize(it->second->pointSize());
}
if (mVectorLayer->vectorType() != QGis::Line)

if (mVectorLayer->vectorType() != QGis::Line)
{
sy->setFillColor(it->second->brush().color());
sy->setFillStyle(it->second->brush().style());
sy->setFillColor(it->second->brush().color());
sy->setFillStyle(it->second->brush().style());
}
//test, if lower_bound is numeric or not (making a subclass of QString would be the proper solution)
bool lbcontainsletter = false;
for (int j = 0; j < lower_bound.length(); j++)

//test, if lower_bound is numeric or not (making a subclass of QString would be the proper solution)
bool lbcontainsletter = false;
for (int j = 0; j < lower_bound.length(); j++)
{
if (lower_bound.ref(j).isLetter())
if (lower_bound.ref(j).isLetter())
{
lbcontainsletter = true;
lbcontainsletter = true;
}
}
//test, if upper_bound is numeric or not (making a subclass of QString would be the proper solution)
bool ubcontainsletter = false;
for (int j = 0; j < upper_bound.length(); j++)

//test, if upper_bound is numeric or not (making a subclass of QString would be the proper solution)
bool ubcontainsletter = false;
for (int j = 0; j < upper_bound.length(); j++)
{
if (upper_bound.ref(j).isLetter())
if (upper_bound.ref(j).isLetter())
{
ubcontainsletter = true;
ubcontainsletter = true;
}
}
if (lbcontainsletter == false && ubcontainsletter == false && lower_bound.length() > 0 && upper_bound.length() > 0) //only add the item if the value bounds do not contain letters and are not null strings
if (lbcontainsletter == false && ubcontainsletter == false && lower_bound.length() > 0 && upper_bound.length() > 0) //only add the item if the value bounds do not contain letters and are not null strings
{
renderer->addSymbol(sy);
renderer->addSymbol(sy);
}
else
else
{
delete sy;
delete sy;
}
}

std::map<QString,int>::iterator iter=mFieldMap.find(classificationComboBox->currentText());
if(iter!=mFieldMap.end())
{
renderer->setClassificationField(iter->second);
}
{
renderer->setClassificationField(iter->second);
}
mVectorLayer->setRenderer(renderer);
}

void QgsGraduatedSymbolDialog::adjustClassification()
{
mClassBreakBox->clear();
mClassListWidget->clear();
QGis::VectorType m_type = mVectorLayer->vectorType();
QgsVectorDataProvider *provider = dynamic_cast<QgsVectorDataProvider *>(mVectorLayer->getDataProvider());
double minimum, maximum;
Expand Down Expand Up @@ -275,7 +274,7 @@ void QgsGraduatedSymbolDialog::adjustClassification()
if (modeComboBox->currentText() == "Empty")
{
listboxtext="Empty"+QString::number(i+1);
mClassBreakBox->insertItem(listboxtext);
mClassListWidget->addItem(listboxtext);
}
else if(modeComboBox->currentText() == "Equal Interval")
{
Expand All @@ -292,7 +291,7 @@ void QgsGraduatedSymbolDialog::adjustClassification()
symbol->setLowerValue(QString::number(lower,'f',3));
symbol->setUpperValue(QString::number(upper,'f',3));
listboxtext=QString::number(lower,'f',3)+" - " +QString::number(upper,'f',3);
mClassBreakBox->insertItem(listboxtext);
mClassListWidget->addItem(listboxtext);
}
//set default symbology

Expand Down Expand Up @@ -328,13 +327,13 @@ void QgsGraduatedSymbolDialog::adjustClassification()

mEntries.insert(std::make_pair(listboxtext,symbol));
}
mClassBreakBox->setCurrentItem(0);
mClassListWidget->setCurrentRow(0);
}

void QgsGraduatedSymbolDialog::changeCurrentValue()
{
sydialog.blockSignals(true);//block signals to prevent sydialog from changing the current QgsRenderItem
Q3ListBoxItem* item=mClassBreakBox->selectedItem();
QListWidgetItem* item=mClassListWidget->currentItem();
if(item)
{
QString value=item->text();
Expand All @@ -350,7 +349,7 @@ void QgsGraduatedSymbolDialog::changeCurrentValue()

void QgsGraduatedSymbolDialog::applySymbologyChanges()
{
Q3ListBoxItem* item=mClassBreakBox->selectedItem();
QListWidgetItem* item=mClassListWidget->currentItem();
if(item)
{
QString value=item->text();
Expand All @@ -363,7 +362,7 @@ void QgsGraduatedSymbolDialog::applySymbologyChanges()
}
}

void QgsGraduatedSymbolDialog::changeClass(Q3ListBoxItem* item)
void QgsGraduatedSymbolDialog::modifyClass(QListWidgetItem* item)
{
QString currenttext=item->text();
QgsSymbol* symbol=0;
Expand All @@ -389,12 +388,34 @@ void QgsGraduatedSymbolDialog::changeClass(Q3ListBoxItem* item)
symbol->setUpperValue(dialog.upperValue());
QString newclass=dialog.lowerValue()+"-"+dialog.upperValue();
mEntries.insert(std::make_pair(newclass,symbol));
int index=mClassBreakBox->index(item);
QObject::disconnect(mClassBreakBox, SIGNAL(selectionChanged()), this, SLOT(changeCurrentValue()));
mClassBreakBox->removeItem(index);
mClassBreakBox->insertItem(newclass,index);
mClassBreakBox->setSelected(index,true);
QObject::connect(mClassBreakBox, SIGNAL(selectionChanged()), this, SLOT(changeCurrentValue()));
item->setText(newclass);
}
}
}

void QgsGraduatedSymbolDialog::deleteCurrentClass()
{
QListWidgetItem* currentItem = mClassListWidget->currentItem();
if(!currentItem)
{
return;
}

QString classValue = currentItem->text();
int currentIndex = mClassListWidget->currentRow();
mEntries.erase(classValue);
delete (mClassListWidget->takeItem(currentIndex));
qWarning("numRows: ");
qWarning(QString::number(mClassListWidget->count()));
//
if(mClassListWidget->count() < (currentIndex + 1))
{
qWarning("selecting numRows - 1");
mClassListWidget->setCurrentRow(mClassListWidget->count() - 1);
}
else
{
qWarning("selecting currentIndex");
mClassListWidget->setCurrentRow(currentIndex);
}
}
7 changes: 6 additions & 1 deletion src/app/qgsgraduatedsymboldialog.h
Expand Up @@ -46,7 +46,7 @@ class QgsGraduatedSymbolDialog: public QDialog, private Ui::QgsGraduatedSymbolDi
/**Writes changes in the single symbol dialog to the corresponding QgsRangeRenderItem*/
void applySymbologyChanges();
/**Shows a dialog to modify lower and upper values*/
void changeClass(Q3ListBoxItem* item);
void modifyClass(QListWidgetItem* item);
protected:
/**Pointer to the associated vector layer*/
QgsVectorLayer* mVectorLayer;
Expand All @@ -57,6 +57,11 @@ class QgsGraduatedSymbolDialog: public QDialog, private Ui::QgsGraduatedSymbolDi
/**Dialog which shows the settings of the activated class*/
QgsSingleSymbolDialog sydialog;
int mClassificationField;

protected slots:
/**Removes a class from the classification*/
void deleteCurrentClass();

private:
/**Default constructor is privat to not use is*/
QgsGraduatedSymbolDialog();
Expand Down
38 changes: 19 additions & 19 deletions src/app/qgsuniquevaluedialog.cpp
Expand Up @@ -54,7 +54,7 @@ QgsUniqueValueDialog::QgsUniqueValueDialog(QgsVectorLayer* vl): QDialog(), mVect

if (renderer)
{
mClassBreakBox->clear();
mClassListWidget->clear();

// XXX - mloskot - fix for Ticket #31 (bug)
QgsAttributeList attributes = renderer->classificationAttributes();
Expand All @@ -74,18 +74,18 @@ QgsUniqueValueDialog::QgsUniqueValueDialog(QgsVectorLayer* vl): QDialog(), mVect
sym->setNamedPointSymbol(symbol->pointSymbolName());
sym->setPointSize(symbol->pointSize());
mValues.insert(std::make_pair(symbolvalue,sym));
mClassBreakBox->addItem(symbolvalue);
mClassListWidget->addItem(symbolvalue);
}
}

QObject::connect(mClassifyButton, SIGNAL(clicked()), this, SLOT(changeClassificationAttribute()));
QObject::connect(mDeletePushButton, SIGNAL(clicked()), this, SLOT(deleteCurrentClass()));
QObject::connect(mClassBreakBox, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(changeCurrentValue()));
QObject::connect(mClassListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(changeCurrentValue()));
QObject::connect(&sydialog, SIGNAL(settingsChanged()), this, SLOT(applySymbologyChanges()));
mSymbolWidgetStack->addWidget(&sydialog);
mSymbolWidgetStack->raiseWidget(&sydialog);
mSymbolWidgetStack->setCurrentWidget(&sydialog);

mClassBreakBox->setCurrentItem(0);
mClassListWidget->setCurrentItem(0);
}

QgsUniqueValueDialog::~QgsUniqueValueDialog()
Expand All @@ -100,7 +100,7 @@ QgsUniqueValueDialog::~QgsUniqueValueDialog()
myValueIterator = mValues.begin(); // since iterator invalidated due to
// erase(), reset to new first element
}
mClassBreakBox->setCurrentItem(0);
mClassListWidget->setCurrentItem(0);
}

void QgsUniqueValueDialog::apply()
Expand Down Expand Up @@ -144,8 +144,8 @@ void QgsUniqueValueDialog::changeClassificationAttribute()
provider->reset();
QgsFeature feat;

//go through all the features and insert their value into the map and into mClassBreakBox
mClassBreakBox->clear();
//go through all the features and insert their value into the map and into mClassListWidget
mClassListWidget->clear();
while(provider->getNextFeature(feat, false, attlist))
{
const QgsAttributeMap& vec = feat.attributeMap();
Expand All @@ -168,7 +168,7 @@ void QgsUniqueValueDialog::changeClassificationAttribute()
int green = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0));
int blue = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0));
thecolor.setRgb(red, green, blue);
mClassBreakBox->addItem(it->first);
mClassListWidget->addItem(it->first);
QgsSymbol* sym=it->second;
QPen pen;
QBrush brush;
Expand All @@ -190,13 +190,13 @@ void QgsUniqueValueDialog::changeClassificationAttribute()
sym->setBrush(brush);
}
}
mClassBreakBox->setCurrentItem(0);
mClassListWidget->setCurrentRow(0);
}

void QgsUniqueValueDialog::changeCurrentValue()
{
sydialog.blockSignals(true);//block signal to prevent sydialog from changing the current QgsRenderItem
QListWidgetItem* item=mClassBreakBox->currentItem();
QListWidgetItem* item=mClassListWidget->currentItem();
if(item)
{
QString value=item->text();
Expand All @@ -216,34 +216,34 @@ void QgsUniqueValueDialog::changeCurrentValue()

void QgsUniqueValueDialog::deleteCurrentClass()
{
QListWidgetItem* currentItem = mClassBreakBox->currentItem();
QListWidgetItem* currentItem = mClassListWidget->currentItem();
if(!currentItem)
{
return;
}

QString classValue = currentItem->text();
int currentIndex = mClassBreakBox->currentRow();
int currentIndex = mClassListWidget->currentRow();
mValues.erase(classValue);
delete (mClassBreakBox->takeItem(currentIndex));
delete (mClassListWidget->takeItem(currentIndex));
qWarning("numRows: ");
qWarning(QString::number(mClassBreakBox->count()));
qWarning(QString::number(mClassListWidget->count()));
//
if(mClassBreakBox->count() < (currentIndex + 1))
if(mClassListWidget->count() < (currentIndex + 1))
{
qWarning("selecting numRows - 1");
mClassBreakBox->setCurrentRow(mClassBreakBox->count() - 1);
mClassListWidget->setCurrentRow(mClassListWidget->count() - 1);
}
else
{
qWarning("selecting currentIndex");
mClassBreakBox->setCurrentRow(currentIndex);
mClassListWidget->setCurrentRow(currentIndex);
}
}

void QgsUniqueValueDialog::applySymbologyChanges()
{
QListWidgetItem* item=mClassBreakBox->currentItem();
QListWidgetItem* item=mClassListWidget->currentItem();
if(!item)
{
return;
Expand Down

0 comments on commit aaf86d7

Please sign in to comment.