📄 qgscomposerscalebar.cpp
字号:
if (!p) { delete painter; delete pixmap; }//Add the 1/2 the pen width to get the full bounding boxreturn QRectF(barLx - (mPen.widthF()/2), -totalHeight, width + textRightOverhang, totalHeight + (mPen.widthF()/2));}void QgsComposerScalebar::paint(QPainter * painter, const QStyleOptionGraphicsItem * itemStyle, QWidget * pWidget){#ifdef QGISDEBUG std::cout << "draw mPlotStyle = " << plotStyle() << std::endl;#endif mBoundingRect = render(painter); // Show selected / Highlight if (mSelected && plotStyle() == QgsComposition::Preview) { painter->setPen(mComposition->selectionPen()); painter->setBrush(mComposition->selectionBrush()); double s = mComposition->selectionBoxSize(); QRectF r = boundingRect(); painter->drawRect(QRectF(r.x(), r.y(), s, s)); painter->drawRect(QRectF(r.x() + r.width() - s, r.y(), s, s)); painter->drawRect(QRectF(r.x() + r.width() - s, r.y() + r.height() - s, s, s)); painter->drawRect(QRectF(r.x(), r.y() + r.height() - s, s, s)); }}/*void QgsComposerScalebar::drawShape ( QPainter & painter ){ paint ( painter );}*/void QgsComposerScalebar::on_mFontButton_clicked(void){ bool result; mFont = QFontDialog::getFont(&result, mFont, this); if (result) { recalculate(); QAbstractGraphicsShapeItem::update(); QAbstractGraphicsShapeItem::scene()->update(); writeSettings(); }}void QgsComposerScalebar::on_mUnitLabelLineEdit_editingFinished(){ mUnitLabel = mUnitLabelLineEdit->text(); recalculate(); QAbstractGraphicsShapeItem::update(); QAbstractGraphicsShapeItem::scene()->update(); writeSettings();}void QgsComposerScalebar::on_mMapComboBox_activated(int i){ mMap = mMaps[i]; recalculate(); QAbstractGraphicsShapeItem::update(); QAbstractGraphicsShapeItem::scene()->update(); writeSettings();}void QgsComposerScalebar::mapChanged(int id){ if (id != mMap) return; recalculate(); QAbstractGraphicsShapeItem::update(); QAbstractGraphicsShapeItem::scene()->update();}void QgsComposerScalebar::sizeChanged(){ mSegmentLength = mSegmentLengthLineEdit->text().toDouble(); mNumSegments = mNumSegmentsLineEdit->text().toInt(); mPen.setWidthF(mLineWidthSpinBox->value()); mMapUnitsPerUnit = mMapUnitsPerUnitLineEdit->text().toInt(); recalculate(); QAbstractGraphicsShapeItem::update(); QAbstractGraphicsShapeItem::scene()->update(); writeSettings();}void QgsComposerScalebar::on_mLineWidthSpinBox_valueChanged(){ sizeChanged();}void QgsComposerScalebar::on_mMapUnitsPerUnitLineEdit_editingFinished(){ sizeChanged();}void QgsComposerScalebar::on_mNumSegmentsLineEdit_editingFinished(){ sizeChanged();}void QgsComposerScalebar::on_mSegmentLengthLineEdit_editingFinished(){ sizeChanged();}/*void QgsComposerScalebar::moveBy(double x, double y){ std::cout << "QgsComposerScalebar::move" << std::endl; QGraphicsItem::moveBy(x, y); recalculate(); //writeSettings(); // not necessary called by composition}*/void QgsComposerScalebar::recalculate(void){ std::cout << "QgsComposerScalebar::recalculate" << std::endl; // !!! prepareGeometryChange() MUST BE called before the value returned by areaPoints() changes //Is this still true after the port to GraphicsView? QAbstractGraphicsShapeItem::prepareGeometryChange(); mBoundingRect = render(0); QGraphicsItem::update();}QRectF QgsComposerScalebar::boundingRect(void) const{ std::cout << "QgsComposerScalebar::boundingRect" << std::endl; return mBoundingRect;}QPolygonF QgsComposerScalebar::areaPoints(void) const{ std::cout << "QgsComposerScalebar::areaPoints" << std::endl; QRectF r = boundingRect(); QPolygonF pa; pa << QPointF(r.x(), r.y()); pa << QPointF(r.x() + r.width(), r.y()); pa << QPointF(r.x() + r.width(), r.y() + r.height()); pa << QPointF(r.x(), r.y() + r.height()); return pa;}void QgsComposerScalebar::setOptions(void){ mSegmentLengthLineEdit->setText(QString::number(mSegmentLength)); mNumSegmentsLineEdit->setText(QString::number(mNumSegments)); mUnitLabelLineEdit->setText(mUnitLabel); mMapUnitsPerUnitLineEdit->setText(QString::number(mMapUnitsPerUnit)); mLineWidthSpinBox->setValue(mPen.widthF()); // Maps mMapComboBox->clear(); std::vector < QgsComposerMap * >maps = mComposition->maps(); mMaps.clear(); bool found = false; mMapComboBox->insertItem("", 0); mMaps.push_back(0); for (int i = 0; i < (int)maps.size(); i++) { mMapComboBox->insertItem(maps[i]->name(), i + 1); mMaps.push_back(maps[i]->id()); if (maps[i]->id() == mMap) { found = true; mMapComboBox->setCurrentItem(i + 1); } } if (!found) { mMap = 0; mMapComboBox->setCurrentItem(0); }}void QgsComposerScalebar::setSelected(bool s){ mSelected = s; QAbstractGraphicsShapeItem::update(); // show highlight}bool QgsComposerScalebar::selected(void){ return mSelected;}QWidget *QgsComposerScalebar::options(void){ setOptions(); return (dynamic_cast < QWidget * >(this));}bool QgsComposerScalebar::writeSettings(void){ std::cout << "QgsComposerScalebar::writeSettings" << std::endl; QString path; path.sprintf("/composition_%d/scalebar_%d/", mComposition->id(), mId); QgsProject::instance()->writeEntry("Compositions", path + "x", mComposition->toMM((int) QAbstractGraphicsShapeItem::x())); QgsProject::instance()->writeEntry("Compositions", path + "y", mComposition->toMM((int) QAbstractGraphicsShapeItem::y())); QgsProject::instance()->writeEntry("Compositions", path + "map", mMap); QgsProject::instance()->writeEntry("Compositions", path + "unit/label", mUnitLabel); QgsProject::instance()->writeEntry("Compositions", path + "unit/mapunits", mMapUnitsPerUnit); QgsProject::instance()->writeEntry("Compositions", path + "segmentsize", mSegmentLength); QgsProject::instance()->writeEntry("Compositions", path + "numsegments", mNumSegments); QgsProject::instance()->writeEntry("Compositions", path + "font/size", mFont.pointSize()); QgsProject::instance()->writeEntry("Compositions", path + "font/family", mFont.family()); QgsProject::instance()->writeEntry("Compositions", path + "font/weight", mFont.weight()); QgsProject::instance()->writeEntry("Compositions", path + "font/underline", mFont.underline()); QgsProject::instance()->writeEntry("Compositions", path + "font/strikeout", mFont.strikeOut()); QgsProject::instance()->writeEntry("Compositions", path + "pen/width", (double) mPen.widthF()); return true;}bool QgsComposerScalebar::readSettings(void){ bool ok; QString path; path.sprintf("/composition_%d/scalebar_%d/", mComposition->id(), mId); double x = mComposition->fromMM(QgsProject::instance()->readDoubleEntry("Compositions", path + "x", 0, &ok)); double y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry("Compositions", path + "y", 0, &ok)); QAbstractGraphicsShapeItem::setPos(x, y); mMap = QgsProject::instance()->readNumEntry("Compositions", path + "map", 0, &ok); mUnitLabel = QgsProject::instance()->readEntry("Compositions", path + "unit/label", "???", &ok); mMapUnitsPerUnit = QgsProject::instance()->readDoubleEntry("Compositions", path + "unit/mapunits", 1., &ok); mSegmentLength = QgsProject::instance()->readDoubleEntry("Compositions", path + "segmentsize", 1000., &ok); mNumSegments = QgsProject::instance()->readNumEntry("Compositions", path + "numsegments", 5, &ok); mFont.setFamily(QgsProject::instance()->readEntry("Compositions", path + "font/family", "", &ok)); mFont.setPointSize(QgsProject::instance()->readNumEntry("Compositions", path + "font/size", 10, &ok)); mFont.setWeight(QgsProject::instance()->readNumEntry("Compositions", path + "font/weight", (int) QFont::Normal, &ok)); mFont.setUnderline(QgsProject::instance()->readBoolEntry("Compositions", path + "font/underline", false, &ok)); mFont.setStrikeOut(QgsProject::instance()->readBoolEntry("Compositions", path + "font/strikeout", false, &ok)); mPen.setWidthF(QgsProject::instance()->readDoubleEntry("Compositions", path + "pen/width", 1, &ok)); recalculate(); return true;}bool QgsComposerScalebar::removeSettings(void){ std::cerr << "QgsComposerScalebar::deleteSettings" << std::endl; QString path; path.sprintf("/composition_%d/scalebar_%d", mComposition->id(), mId); return QgsProject::instance()->removeEntry("Compositions", path);}bool QgsComposerScalebar::writeXML(QDomNode & node, QDomDocument & document, bool temp){ return true;}bool QgsComposerScalebar::readXML(QDomNode & node){ return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -