本文整理汇总了C++中QTreeWidgetItem::background方法的典型用法代码示例。如果您正苦于以下问题:C++ QTreeWidgetItem::background方法的具体用法?C++ QTreeWidgetItem::background怎么用?C++ QTreeWidgetItem::background使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTreeWidgetItem
的用法示例。
在下文中一共展示了QTreeWidgetItem::background方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: background
QBrush QTreeWidgetItemProto::background(int column) const
{
QTreeWidgetItem *item = qscriptvalue_cast<QTreeWidgetItem*>(thisObject());
if (item)
return item->background(column);
return QBrush();
}
示例2: on_copyToolButton_clicked
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);
}
示例3: on_mSortButton_clicked
void QgsSingleBandPseudoColorRendererWidget::on_mSortButton_clicked()
{
bool inserted = false;
int myCurrentIndex = 0;
int myTopLevelItemCount = mColormapTreeWidget->topLevelItemCount();
QTreeWidgetItem* myCurrentItem;
QList<QgsColorRampShader::ColorRampItem> myColorRampItems;
for ( int i = 0; i < myTopLevelItemCount; ++i )
{
myCurrentItem = mColormapTreeWidget->topLevelItem( i );
//If the item is null or does not have a pixel values set, skip
if ( !myCurrentItem || myCurrentItem->text( 0 ) == "" )
{
continue;
}
//Create a copy of the new Color ramp Item
QgsColorRampShader::ColorRampItem myNewColorRampItem;
myNewColorRampItem.value = myCurrentItem->text( 0 ).toDouble();
myNewColorRampItem.color = myCurrentItem->background( 1 ).color();
myNewColorRampItem.label = myCurrentItem->text( 2 );
//Simple insertion sort - speed is not a huge factor here
inserted = false;
myCurrentIndex = 0;
while ( !inserted )
{
if ( 0 == myColorRampItems.size() || myCurrentIndex == myColorRampItems.size() )
{
myColorRampItems.push_back( myNewColorRampItem );
inserted = true;
}
else if ( myColorRampItems[myCurrentIndex].value > myNewColorRampItem.value )
{
myColorRampItems.insert( myCurrentIndex, myNewColorRampItem );
inserted = true;
}
else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myCurrentIndex == myColorRampItems.size() - 1 )
{
myColorRampItems.push_back( myNewColorRampItem );
inserted = true;
}
else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myColorRampItems[myCurrentIndex+1].value > myNewColorRampItem.value )
{
myColorRampItems.insert( myCurrentIndex + 1, myNewColorRampItem );
inserted = true;
}
myCurrentIndex++;
}
}
populateColormapTreeWidget( myColorRampItems );
}
示例4: mouseMoveEvent
void RDTreeWidget::mouseMoveEvent(QMouseEvent *e)
{
QTreeWidgetItem *item = itemAt(e->pos());
clearHovers(invisibleRootItem(), item);
if(item)
{
QVariant normalIcon = item->data(m_hoverColumn, Qt::DecorationRole);
QVariant hoverIcon = item->data(m_hoverColumn, hoverIconRole);
if(normalIcon.isValid() && hoverIcon.isValid())
{
item->setData(m_hoverColumn, hoverIconRole, QVariant());
item->setData(m_hoverColumn, Qt::DecorationRole, hoverIcon);
item->setData(m_hoverColumn, backupNormalIconRole, normalIcon);
}
if(!item->data(m_hoverColumn, backupBackColourRole).isValid())
{
QVariant backHoverColor = item->data(m_hoverColumn, hoverBackColourRole);
QColor col = item->data(m_hoverColumn, hoverBackColourRole).value<QColor>();
if(!col.isValid())
col = m_defaultHoverColour;
if(col.isValid())
{
item->setData(m_hoverColumn, backupBackColourRole, item->background(m_hoverColumn));
for(int c = 0; c < item->columnCount(); c++)
item->setData(c, Qt::BackgroundRole, QBrush(col));
}
}
QModelIndex idx = indexAt(e->pos());
if(idx.column() == m_hoverColumn && item->data(m_hoverColumn, Qt::DecorationRole).isValid() &&
m_hoverHandCursor)
{
setCursor(QCursor(Qt::PointingHandCursor));
}
else
{
unsetCursor();
}
}
emit mouseMove(e);
QTreeWidget::mouseMoveEvent(e);
}
示例5: renderer
QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
{
QgsRasterShader* rasterShader = new QgsRasterShader();
QgsColorRampShader* colorRampShader = new QgsColorRampShader();
colorRampShader->setClip( mClipCheckBox->isChecked() );
//iterate through mColormapTreeWidget and set colormap info of layer
QList<QgsColorRampShader::ColorRampItem> colorRampItems;
int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
QTreeWidgetItem* currentItem;
for ( int i = 0; i < topLevelItemCount; ++i )
{
currentItem = mColormapTreeWidget->topLevelItem( i );
if ( !currentItem )
{
continue;
}
QgsColorRampShader::ColorRampItem newColorRampItem;
newColorRampItem.value = currentItem->text( 0 ).toDouble();
newColorRampItem.color = currentItem->background( 1 ).color();
newColorRampItem.label = currentItem->text( 2 );
colorRampItems.append( newColorRampItem );
}
// sort the shader items
qSort( colorRampItems );
colorRampShader->setColorRampItemList( colorRampItems );
if ( mColorInterpolationComboBox->currentText() == tr( "Linear" ) )
{
colorRampShader->setColorRampType( QgsColorRampShader::INTERPOLATED );
}
else if ( mColorInterpolationComboBox->currentText() == tr( "Discrete" ) )
{
colorRampShader->setColorRampType( QgsColorRampShader::DISCRETE );
}
else
{
colorRampShader->setColorRampType( QgsColorRampShader::EXACT );
}
rasterShader->setRasterShaderFunction( colorRampShader );
int bandNumber = mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt();
QgsSingleBandPseudoColorRenderer *renderer = new QgsSingleBandPseudoColorRenderer( mRasterLayer->dataProvider(), bandNumber, rasterShader );
renderer->setClassificationMin( lineEditValue( mMinLineEdit ) );
renderer->setClassificationMax( lineEditValue( mMaxLineEdit ) );
renderer->setClassificationMinMaxOrigin( mMinMaxOrigin );
return renderer;
}
示例6: rc
QList< QgsRelief::ReliefColor > QgsRasterTerrainAnalysisDialog::reliefColors() const
{
QList< QgsRelief::ReliefColor > reliefColorList;
for ( int i = 0; i < mReliefClassTreeWidget->topLevelItemCount(); ++i )
{
QTreeWidgetItem* reliefItem = mReliefClassTreeWidget->topLevelItem( i );
if ( reliefItem )
{
QgsRelief::ReliefColor rc( reliefItem->background( 2 ).color(), reliefItem->text( 0 ).toDouble(), reliefItem->text( 1 ).toDouble() );
reliefColorList.push_back( rc );
}
}
return reliefColorList;
}
示例7: iter
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;
}
示例8: changeColor
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();
}
}
示例9: 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);
}
示例10: on_mExportToFileButton_clicked
void QgsSingleBandPseudoColorRendererWidget::on_mExportToFileButton_clicked()
{
QSettings settings;
QString lastDir = settings.value( "lastColorMapDir", QDir::homePath() ).toString();
QString fileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), lastDir, tr( "Textfile (*.txt)" ) );
if ( !fileName.isEmpty() )
{
if ( !fileName.endsWith( ".txt", Qt::CaseInsensitive ) )
{
fileName = fileName + ".txt";
}
QFile outputFile( fileName );
if ( outputFile.open( QFile::WriteOnly ) )
{
QTextStream outputStream( &outputFile );
outputStream << "# " << tr( "QGIS Generated Color Map Export File" ) << '\n';
outputStream << "INTERPOLATION:";
QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast< QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox->itemData( mColorInterpolationComboBox->currentIndex() ).toInt() );
switch ( interpolation )
{
case QgsColorRampShader::INTERPOLATED:
outputStream << "INTERPOLATED\n";
break;
case QgsColorRampShader::DISCRETE:
outputStream << "DISCRETE\n";
break;
case QgsColorRampShader::EXACT:
outputStream << "EXACT\n";
break;
}
int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
QTreeWidgetItem* currentItem;
QColor color;
for ( int i = 0; i < topLevelItemCount; ++i )
{
currentItem = mColormapTreeWidget->topLevelItem( i );
if ( !currentItem )
{
continue;
}
color = currentItem->background( ColorColumn ).color();
outputStream << currentItem->text( ValueColumn ).toDouble() << ',';
outputStream << color.red() << ',' << color.green() << ',' << color.blue() << ',' << color.alpha() << ',';
if ( currentItem->text( LabelColumn ).isEmpty() )
{
outputStream << "Color entry " << i + 1 << '\n';
}
else
{
outputStream << currentItem->text( LabelColumn ) << '\n';
}
}
outputStream.flush();
outputFile.close();
QFileInfo fileInfo( fileName );
settings.setValue( "lastColorMapDir", fileInfo.absoluteDir().absolutePath() );
}
else
{
QMessageBox::warning( this, tr( "Write access denied" ), tr( "Write access denied. Adjust the file permissions and try again.\n\n" ) );
}
}
}
示例11: on_mExportToFileButton_clicked
void QgsSingleBandPseudoColorRendererWidget::on_mExportToFileButton_clicked()
{
QSettings settings;
QString lastDir = settings.value( "lastRasterFileFilterDir", QDir::homePath() ).toString();
QString fileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), lastDir, tr( "Textfile (*.txt)" ) );
if ( !fileName.isEmpty() )
{
if ( !fileName.endsWith( ".txt", Qt::CaseInsensitive ) )
{
fileName = fileName + ".txt";
}
QFile outputFile( fileName );
if ( outputFile.open( QFile::WriteOnly ) )
{
QTextStream outputStream( &outputFile );
outputStream << "# " << tr( "QGIS Generated Color Map Export File" ) << '\n';
outputStream << "INTERPOLATION:";
if ( mColorInterpolationComboBox->currentText() == tr( "Linear" ) )
{
outputStream << "INTERPOLATED\n";
}
else if ( mColorInterpolationComboBox->currentText() == tr( "Discrete" ) )
{
outputStream << "DISCRETE\n";
}
else
{
outputStream << "EXACT\n";
}
int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
QTreeWidgetItem* currentItem;
QColor color;
for ( int i = 0; i < topLevelItemCount; ++i )
{
currentItem = mColormapTreeWidget->topLevelItem( i );
if ( !currentItem )
{
continue;
}
color = currentItem->background( 1 ).color();
outputStream << currentItem->text( 0 ).toDouble() << ',';
outputStream << color.red() << ',' << color.green() << ',' << color.blue() << ',' << color.alpha() << ',';
if ( currentItem->text( 2 ) == "" )
{
outputStream << "Color entry " << i + 1 << '\n';
}
else
{
outputStream << currentItem->text( 2 ) << '\n';
}
}
outputStream.flush();
outputFile.close();
}
else
{
QMessageBox::warning( this, tr( "Write access denied" ), tr( "Write access denied. Adjust the file permissions and try again.\n\n" ) );
}
}
}