QBrush QTreeWidgetItemProto::foreground(int column) const { QTreeWidgetItem *item = qscriptvalue_cast<QTreeWidgetItem*>(thisObject()); if (item) return item->foreground(column); return QBrush(); }
void ColoringRulesDialog::on_copyToolButton_clicked() { if (!ui->coloringRulesTreeWidget->currentItem()) return; QTreeWidgetItem *ti = ui->coloringRulesTreeWidget->currentItem(); addColoringRule(ti->checkState(0) == Qt::Unchecked, ti->text(name_col_), ti->text(filter_col_), ti->foreground(0).color(), ti->background(0).color(), true); }
GSList *ColoringRulesDialog::createColorFilterList() { GSList *cfl = NULL; QTreeWidgetItemIterator iter(ui->coloringRulesTreeWidget); while (*iter) { QTreeWidgetItem *item = (*iter); color_t fg = ColorUtils::toColorT(item->foreground(0).color()); color_t bg = ColorUtils::toColorT(item->background(0).color()); color_filter_t *colorf = color_filter_new(item->text(name_col_).toUtf8().constData(), item->text(filter_col_).toUtf8().constData(), &bg, &fg, item->checkState(0) == Qt::Unchecked); cfl = g_slist_append(cfl, colorf); ++iter; } return cfl; }
void ColoringRulesDialog::changeColor(bool foreground) { if (!ui->coloringRulesTreeWidget->currentItem()) return; QTreeWidgetItem *ti = ui->coloringRulesTreeWidget->currentItem(); QColorDialog color_dlg; color_dlg.setCurrentColor(foreground ? ti->foreground(0).color() : ti->background(0).color()); if (color_dlg.exec() == QDialog::Accepted) { QColor cc = color_dlg.currentColor(); if (foreground) { for (int i = 0; i < ui->coloringRulesTreeWidget->columnCount(); i++) { ti->setForeground(i, cc); } } else { for (int i = 0; i < ui->coloringRulesTreeWidget->columnCount(); i++) { ti->setBackground(i, cc); } } updateWidgets(); } }
void ColoringRulesDialog::updateWidgets() { QString hint = "<small><i>"; int num_selected = ui->coloringRulesTreeWidget->selectedItems().count(); if (num_selected == 1) { QTreeWidgetItem *ti = ui->coloringRulesTreeWidget->currentItem(); QString color_button_ss = "QPushButton {" " border: 1px solid palette(Dark);" " padding-left: %1px;" " padding-right: %1px;" " color: %2;" " background-color: %3;" "}"; int one_em = fontMetrics().height(); QString fg_color = ti->foreground(0).color().name(); QString bg_color = ti->background(0).color().name(); ui->fGPushButton->setStyleSheet(color_button_ss.arg(one_em).arg(bg_color).arg(fg_color)); ui->bGPushButton->setStyleSheet(color_button_ss.arg(one_em).arg(fg_color).arg(bg_color)); } ui->copyToolButton->setEnabled(num_selected == 1); ui->deleteToolButton->setEnabled(num_selected > 0); ui->fGPushButton->setVisible(num_selected == 1); ui->bGPushButton->setVisible(num_selected == 1); QString error_text; QTreeWidgetItemIterator iter(ui->coloringRulesTreeWidget); bool enable_save = true; while (*iter) { QTreeWidgetItem *item = (*iter); if (item->text(name_col_).contains("@")) { error_text = tr("the \"@\" symbol will be ignored."); } // Check the rule's display filter syntax only if it's checked. QString display_filter = item->text(filter_col_); if (!display_filter.isEmpty() && item->checkState(name_col_) == Qt::Checked) { dfilter_t *dfilter; bool status; gchar *err_msg; status = dfilter_compile(display_filter.toUtf8().constData(), &dfilter, &err_msg); dfilter_free(dfilter); if (!status) { if (!error_text.isEmpty()) error_text += " "; error_text += err_msg; g_free(err_msg); enable_save = false; } } if (!error_text.isEmpty()) { error_text.prepend(QString("%1: ").arg(item->text(name_col_))); break; } ++iter; } if (error_text.isEmpty()) { hint += tr("Double click to edit. Drag to move. Rules are processed in order until a match is found."); } else { hint += error_text; } hint += "</i></small>"; ui->hintLabel->setText(hint); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enable_save); }
/** Generate labels from the values in the color map. * Skip labels which were manually edited (black text). * Text of generated labels is made gray */ void QgsSingleBandPseudoColorRendererWidget::autoLabel() { QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast< QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox->itemData( mColorInterpolationComboBox->currentIndex() ).toInt() ); bool discrete = interpolation == QgsColorRampShader::DISCRETE; QString unit = mUnitLineEdit->text(); QString label; int topLevelItemCount = mColormapTreeWidget->topLevelItemCount(); QTreeWidgetItem* currentItem; for ( int i = 0; i < topLevelItemCount; ++i ) { currentItem = mColormapTreeWidget->topLevelItem( i ); //If the item is null or does not have a pixel values set, skip if ( !currentItem || currentItem->text( ValueColumn ).isEmpty() ) { continue; } if ( discrete ) { if ( i == 0 ) { label = "<= " + currentItem->text( ValueColumn ) + unit; } else if ( currentItem->text( ValueColumn ).toDouble() == std::numeric_limits<double>::infinity() ) { label = "> " + mColormapTreeWidget->topLevelItem( i - 1 )->text( ValueColumn ) + unit; } else { label = mColormapTreeWidget->topLevelItem( i - 1 )->text( ValueColumn ) + " - " + currentItem->text( ValueColumn ) + unit; } } else { label = currentItem->text( ValueColumn ) + unit; } if ( currentItem->text( LabelColumn ).isEmpty() || currentItem->text( LabelColumn ) == label || currentItem->foreground( LabelColumn ).color() == QColor( Qt::gray ) ) { currentItem->setText( LabelColumn, label ); currentItem->setForeground( LabelColumn, QBrush( QColor( Qt::gray ) ) ); } } }