void QgsSingleSymbolDialog::apply( QgsSymbol *sy )
{
  //query the values of the widgets and set the symbology of the vector layer
  if ( btnFillColor->isEnabled() )
    sy->setFillColor( btnFillColor->color() );

  if ( outlinewidthspinbox->isEnabled() )
    sy->setLineWidth( outlinewidthspinbox->value() );

  if ( btnOutlineColor->isEnabled() )
    sy->setColor( btnOutlineColor->color() );

  //
  // Apply point symbol
  //
  if ( lstSymbols->isEnabled() && lstSymbols->currentIndex().isValid() )
  {
    QAbstractItemModel *m = lstSymbols->model();
    sy->setNamedPointSymbol( m->data( lstSymbols->currentIndex(), Qt::UserRole ).toString() );
  }

  if ( mPointSizeSpinBox->isEnabled() )
    sy->setPointSize( mPointSizeSpinBox->value() );

  if ( mPointSizeUnitsCheckBox->isEnabled() )
    sy->setPointSizeUnits( mPointSizeUnitsCheckBox->isChecked() );

  std::map<QString, int>::iterator iter;
  if ( mRotationClassificationComboBox->isEnabled() )
  {
    sy->setRotationClassificationField( mRotationClassificationComboBox->itemData( mRotationClassificationComboBox->currentIndex() ).toInt() );
  }

  if ( mScaleClassificationComboBox->isEnabled() )
  {
    sy->setScaleClassificationField( mScaleClassificationComboBox->itemData( mScaleClassificationComboBox->currentIndex() ).toInt() );
  }

  if ( mSymbolComboBox->isEnabled() )
  {
    sy->setSymbolField( mSymbolComboBox->itemData( mSymbolComboBox->currentIndex() ).toInt() );
  }

  //
  // Apply the line style
  //
  if ( cboOutlineStyle->isEnabled() )
  {
    QString myLineStyle =
      cboOutlineStyle->itemData( cboOutlineStyle->currentIndex(), Qt::UserRole ).toString();
    sy->setLineStyle( QgsSymbologyUtils::qString2PenStyle( myLineStyle ) );
  }

  //
  // 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( mTexturePath );

  if ( cboFillStyle->isEnabled() )
  {
    QString myFillStyle =
      cboFillStyle->itemData( cboFillStyle->currentIndex(), Qt::UserRole ).toString();
    sy->setFillStyle( QgsSymbologyUtils::qString2BrushStyle( myFillStyle ) );
  }

  if ( mLabelEdit->isEnabled() )
    sy->setLabel( mLabelEdit->text() );
}
void QgsSingleSymbolDialog::set( const QgsSymbol *sy )
{
  //set label
  mLabelEdit->setText( sy->label() );

  // Set point symbol
  QString mySymbolName = sy->pointSymbolName();

  QAbstractItemModel *m = lstSymbols->model();
  for ( int i = 0; i < m->rowCount(); i++ )
  {
    QModelIndex idx( m->index( i, 0 ) );
    if ( m->data( idx, Qt::UserRole ).toString() == mySymbolName )
    {
      lstSymbols->setCurrentIndex( idx );
      // m->setData( idx, Qt::UserRole+1, Qt::cyan );
      break;
    }
  }
  mPointSizeSpinBox->setValue( sy->pointSize() );
  mPointSizeUnitsCheckBox->setChecked( sy->pointSizeUnits() );

  int index;

  index = mRotationClassificationComboBox->findData( sy->rotationClassificationField() );
  mRotationClassificationComboBox->setCurrentIndex( index < 0 ? 0 : index );

  index = mScaleClassificationComboBox->findData( sy->scaleClassificationField() );
  mScaleClassificationComboBox->setCurrentIndex( index < 0 ? 0 : index );

  index = mSymbolComboBox->findData( sy->symbolField() );
  mSymbolComboBox->setCurrentIndex( index < 0 ? 0 : index );

  outlinewidthspinbox->setValue( sy->pen().widthF() );

  //set line width 1 as minimum to avoid confusion between line width 0 and no pen line style
  // ... but, drawLine is not correct with width > 0 -> until solved set to 0
  outlinewidthspinbox->setMinimum( 0 );

  btnFillColor->setColor( sy->brush().color() );

  btnOutlineColor->setColor( sy->pen().color() );

  //load the icons stored in QgsSymbologyUtils.cpp (to avoid redundancy)

  //
  // Set the line style combo
  //

  QPen myPen = sy->pen();
  QString myLineStyle = QgsSymbologyUtils::penStyle2QString( myPen.style() );
  for ( int i = 0; i < cboOutlineStyle->count(); ++i )
  {
    if ( cboOutlineStyle->itemData( i, Qt::UserRole ).toString() == myLineStyle )
    {
      cboOutlineStyle->setCurrentIndex( i );
      break;
    }
  }

  //
  // Set the brush combo
  //

  QBrush myBrush = sy->brush();
  QString myFillStyle =  QgsSymbologyUtils::brushStyle2QString( myBrush.style() );
  for ( int i = 0; i < cboFillStyle->count(); ++i )
  {
    if ( cboFillStyle->itemData( i, Qt::UserRole ).toString() == myFillStyle )
    {
      cboFillStyle->setCurrentIndex( i );
      break;
    }
  }

  //get and show the file path, even if we aren't using it.
  mTexturePath = sy->customTexture();
  //if the file path isn't empty, show the image on the button
  if ( sy->customTexture().size() > 0 )
  {
    //show the current texture image
    // texture->setPixmap(QPixmap(sy->customTexture()));
  }
  else
  {
    //show the default question mark
    //texture->setPixmap(QgsSymbologyUtils::char2PatternPixmap("TexturePattern"));
  }

  mLabelEdit->setEnabled( true );
  lstSymbols->setEnabled( true );
  mPointSizeSpinBox->setEnabled( true );
  mPointSizeUnitsCheckBox->setEnabled( true );
  mRotationClassificationComboBox->setEnabled( true );
  mScaleClassificationComboBox->setEnabled( true );
  mSymbolComboBox->setEnabled( true );
  outlinewidthspinbox->setEnabled( true );
  btnOutlineColor->setEnabled( true );
  cboOutlineStyle->setEnabled( true );

  if ( mVectorLayer && mVectorLayer->geometryType() != QGis::Line )
  {
    btnFillColor->setEnabled( true );
    cboFillStyle->setEnabled( true );
  }
}
示例#3
0
void RDHeaderView::cacheSections()
{
  if(m_suppressSectionCache)
    return;

  QAbstractItemModel *m = this->model();

  int oldCount = m_sections.count();
  m_sections.resize(m->columnCount());

  // give new sections a default minimum size
  for(int col = oldCount; col < m_sections.count(); col++)
    m_sections[col].size = 10;

  for(int col = 0; col < m_sections.count(); col++)
  {
    if(m_columnGroupRole > 0)
    {
      QVariant v = m->data(m->index(0, col), m_columnGroupRole);
      if(v.isValid())
        m_sections[col].group = v.toInt();
      else
        m_sections[col].group = -m_columnGroupRole - col;

      if(col > 0)
      {
        m_sections[col - 1].groupGap =
            (m_sections[col].group != m_sections[col - 1].group) && m_sections[col].group >= 0;
      }
    }
    else
    {
      m_sections[col].group = col;
      m_sections[col].groupGap = true;
    }
  }

  int accum = 0;

  for(int col = 0; col < m_sections.count(); col++)
  {
    if(col == m_pinnedColumns)
      m_pinnedWidth = accum;

    m_sections[col].offset = accum;
    accum += m_sections[col].size;

    if(hasGroupGap(col))
      accum += groupGapSize();
  }

  if(m_pinnedColumns >= m_sections.count())
    m_pinnedWidth = m_pinnedColumns;

  QStyleOptionHeader opt;
  initStyleOption(&opt);

  QFont f = font();
  f.setBold(true);

  opt.section = 0;
  opt.fontMetrics = QFontMetrics(f);
  opt.text = m->headerData(0, orientation(), Qt::DisplayRole).toString();

  m_sizeHint = style()->sizeFromContents(QStyle::CT_HeaderSection, &opt, QSize(), this);
  m_sizeHint.setWidth(accum);

  viewport()->update(viewport()->rect());
}
void LogDetailWidget::showEditHistory()
{
	QModelIndex index = ui.aaView->currentIndex();
	if(index.row() <0) return;

	QAbstractItemModel* model = ui.aaView->model();

	QString timestamp = model->data(model->index(index.row(), 0), Qt::DisplayRole).toString();
	QString compName = model->data(model->index(index.row(), 2), Qt::DisplayRole).toString();
	QString type = model->data(model->index(index.row(), 4), Qt::DisplayRole).toString();
	QString value = model->data(model->index(index.row(), 5), Qt::DisplayRole).toString();

	QWidget *histWidget = new QWidget;
	histWidget->resize(QSize(800,600));
	QVBoxLayout *boxlayout = new QVBoxLayout;
	QScrollArea* area = new QScrollArea;
	QGridLayout *gridLayout = new QGridLayout;
	QLabel* fileLabel = new QLabel;
	fileLabel->setText("Source Code File: " + compName);
	gridLayout->addWidget(fileLabel, 0, 0, 1, -1);
	histWidget->setLayout(boxlayout);
	boxlayout->addWidget(area);
	area->setLayout(gridLayout);
	
	LogEvent pre_e;
	bool isFirst = true;
	int row = 1;
	for(int i=0; i<logMan.events.size(); i++)
	{
		LogEvent e = logMan.events[i];
		if(!e.isHasAcc) continue;
		
		if(e.acc.parent_name == compName.toStdString() && e.acc.type == type.toStdString())
		{
			if(isFirst)
			{
				QLabel* timeLabel = new QLabel;
				timeLabel->setText(QString::fromStdString(e.timestamp));
				QLabel* edit = new QLabel;
				edit->setText("First Time Open");
				gridLayout->addWidget(timeLabel, row, 0, 1, 1);
				gridLayout->addWidget(edit, row, 1, 1, 1);
				isFirst = false;
			}
			else
			{
				QLabel* timeLabel = new QLabel;
				timeLabel->setText(QString::fromStdString(e.timestamp));
				gridLayout->addWidget(timeLabel, row, 0, 1, 1);

				string s1 = pre_e.acc.value;
				replaceAll(s1, "\\n", "\n");
				replaceAll(s1, "\\t", "\t");

				string s2 = e.acc.value;
				replaceAll(s2, "\\n", "\n");
				replaceAll(s2, "\\t", "\t");

				QString str1 = QString::fromStdString(s1);
				QString str2 = QString::fromStdString(s2);

				diff_match_patch dmp;
				QList<Diff> res =  dmp.diff_main(str1,str2, true);
				dmp.diff_cleanupSemantic(res);
				if(res.size() == 1 && res[0].operation == Operation::EQUAL)
				{
					QLabel* edit = new QLabel;
					edit->setText("No Difference");
					gridLayout->addWidget(edit, row, 1, 1, 1);
				}
				else
				{
					QTextEdit* edit = new QTextEdit;
					edit->setText(dmp.diff_toString(res));
					gridLayout->addWidget(edit, row, 1, 1, 1);
				}			
				
			}

			pre_e = e;
			row++;
		}
	}

	histWidget->show();
}
void KDReports::SpreadsheetReportLayout::paintPageContent(int pageNumber, QPainter &painter)
{
    //qDebug() << "painting with" << m_tableLayout.scaledFont();
    QAbstractItemModel* model = m_tableLayout.m_model;
    const qreal padding = m_tableLayout.scaledCellPadding();
    const QRect cellCoords = m_pageRects[pageNumber];
    //qDebug() << "painting page" << pageNumber << "cellCoords=" << cellCoords;
    qreal y = 0 /*m_topMargin*/; // in pixels
    const qreal rowHeight = m_tableLayout.rowHeight();

    if ( m_tableLayout.m_horizontalHeaderVisible ) {
        qreal x = 0 /*m_leftMargin*/;
        if ( m_tableLayout.m_verticalHeaderVisible ) {
            x += m_tableLayout.vHeaderWidth();
        }
        for ( int col = cellCoords.left(); col <= cellCoords.right(); ++col )
        {
            const QRectF cellRect( x, y, m_tableLayout.m_columnWidths[ col ], m_tableLayout.hHeaderHeight() );
            paintTableHorizontalHeader( cellRect, painter, col );
            x += cellRect.width();
        }
        y += m_tableLayout.hHeaderHeight();
    }

    const int firstRow = cellCoords.top();
    const int firstColumn = cellCoords.left();
    const int numRows = cellCoords.height();
    const int numColumns = cellCoords.width();

    // This won't work across page breaks....
    QVector<QBitArray> coveredCells;
    coveredCells.resize( numRows );
    for ( int row = firstRow; row <= cellCoords.bottom(); ++row )
        coveredCells[row - firstRow].resize( numColumns );

    for ( int row = firstRow; row <= cellCoords.bottom(); ++row )
    {
        qreal x = 0 /*m_leftMargin*/;
        if ( m_tableLayout.m_verticalHeaderVisible ) {
            x = paintTableVerticalHeader( x, y, painter, row );
        }
        painter.setFont( m_tableLayout.scaledFont() );
        for ( int col = cellCoords.left(); col <= cellCoords.right(); ++col )
        {
            if (coveredCells[row - firstRow].testBit(col - firstColumn)) {
                x += m_tableLayout.m_columnWidths[ col ];
                continue;
            }

            const QModelIndex index = model->index( row, col );

            const QSize span = model->span( index );
            if (span.isValid()) {
                for (int r = row; r < row + span.height() && r < numRows; ++r) {
                    for (int c = col; c < col + span.width() && c < numColumns; ++c) {
                        coveredCells[r - firstRow].setBit(c - firstColumn);
                    }
                }
            }

            const QRectF cellRect( x, y, cellWidth( col, span.width() ), qMax(1, span.height()) * rowHeight );
            const QRectF cellContentsRect = cellRect.adjusted( padding, padding, -padding, -padding );
            //qDebug() << "cell" << row << col << "rect=" << cellRect;

            const QString cellText = model->data( index, Qt::DisplayRole ).toString();
            const QColor foreground = qvariant_cast<QColor>( model->data( index, Qt::ForegroundRole ) );
            const QColor background = qvariant_cast<QColor>( model->data( index, Qt::BackgroundRole ) );
            const Qt::Alignment alignment( model->data( index, Qt::TextAlignmentRole ).toInt() );
            const QVariant decorationAlignment( model->data( index, KDReports::AutoTableElement::DecorationAlignmentRole ) );
            const QVariant cellDecoration( model->data( index, Qt::DecorationRole ) );

            if ( background.isValid() ) {
                painter.fillRect( cellRect, QBrush( background ) );
            } else if ( span.isValid() ) {
                painter.fillRect( cellRect, Qt::white );
            }
            drawBorder(cellRect, painter);

            // Per-cell font is not supported, on purpose. All rows use the same font,
            // otherwise the calculations for making things fit into a number of pages
            // become quite complex and slow.
            //const QVariant cellFont = model->data( index, Qt::FontRole );
            //if ( cellFont.isValid() )
            //    painter.setFont( qvariant_cast<QFont>( cellFont ) );
            //else
            //    painter.setFont( scaledFont );

            if ( foreground.isValid() )
                painter.setPen( foreground );

            paintTextAndIcon( painter, cellContentsRect, cellText, cellDecoration, decorationAlignment, alignment );

            if ( foreground.isValid() )
                painter.setPen( Qt::black );

            x += m_tableLayout.m_columnWidths[ col ];
        }
        y += rowHeight;
    }
}
QString displayData(QAbstractItemModel& model, int row, int role)
{
    QModelIndex modelIndex = model.index(row, 0);
    return model.data(modelIndex, role).toString();
}
示例#7
0
QDomElement OOoReportBuilder::processDetail(const QDomElement &rowDetail)
{
    QDomElement lastElement = rowDetail;

    if (rowDetail.isNull() || reportBand(rowDetail) != Detail)
        return QDomElement();

    QString textCell = cellText(rowDetail.firstChild().toElement());
    textCell.remove(QRegExp("\\{|\\}|detail"));
    int modelId = textCell.toInt() - 1;

    if (modelId < m_models.count() - 1) {
        rowDetail.parentNode().removeChild(rowDetail);
        return lastElement.previousSibling().toElement();
    }

    QAbstractItemModel *model = m_models.at(modelId);

    for (int i = 0; i < model->rowCount(); i++) {
        QDomElement tmpRow = rowDetail.cloneNode(true).toElement();

        QDomElement cell = tmpRow.firstChild().toElement();
        cell = cell.nextSibling().toElement();

        while (!cell.isNull()) {
            QString str = cellText(cell);

            if (!str.isEmpty()) {
                str.remove(QRegExp("\\{|\\}"));

                if (!QString::compare(str,"rowno",Qt::CaseInsensitive)) {
                    setText(cell,QString::number(i));
                } else if (str[0] == 'P') {

                    QVariant var = processParams(str.mid(2));
                    if (var.type() == QVariant::Double) {
                        setText(cell,var.toDouble());
                    } else {
                        setText(cell,var.toString());
                    }
                } else {
                    QRegExp rx("col\\d{1,2}");

                    if (rx.indexIn(str) == 0) {
                        int colNo = str.remove(QRegExp("col")).toInt();
                        QVariant var = model->data(model->index(i,colNo));
                        if (colNo <= model->columnCount() - 1) {
                            if (var.type() == QVariant::Double) {
                                setText(cell, var.toDouble());
                            } else
                                setText(cell, var.toString());
                        } else
                            setText(cell,"Err");
                    } else
                        setText(cell,str);
                }
            }

            if (cell.attributes().contains("table:formula")) {
                QString formula = processFormula(cell.attribute("table:formula"), i);
                cell.setAttribute("table:formula",formula);
            }

            cell = cell.nextSibling().toElement();
        }

        lastElement = rowDetail.parentNode().insertBefore(tmpRow,rowDetail).toElement();
    }

    rowDetail.parentNode().removeChild(rowDetail);
    return lastElement;
}
示例#8
0
int ShapeSelector::currentShapeType( ) const
{
	QAbstractItemModel *model = shapeType->model();
	return model->data( model->index(shapeType->currentIndex(),1) ).toInt();
}
示例#9
0
void ShapeSelector::on_shapeType_currentIndexChanged( int index )
{
	QAbstractItemModel *model = shapeType->model();
	shapePreview->setPixmap( model->data( model->index(index,0), Qt::DecorationRole ).value<QIcon>().pixmap( shapePreview->size() ) );
}