⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qgslegendlayerfile.cpp

📁 一个非常好的GIS开源新版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************** *   Copyright (C) 2005 by Tim Sutton   * *   aps02ts@macbuntu   * *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * *   This program is distributed in the hope that it will be useful,       * *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * *   GNU General Public License for more details.                          * *                                                                         * *   You should have received a copy of the GNU General Public License     * *   along with this program; if not, write to the                         * *   Free Software Foundation, Inc.,                                       * *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * ***************************************************************************/#include "qgsapplication.h"#include "qgslegend.h"#include "qgslegendlayer.h"#include "qgslegendlayerfile.h"#include "qgsmaplayer.h"#include "qgsrasterlayer.h"#include "qgsvectorfilewriter.h"#include "qgsvectorlayer.h"#include "qgsvectordataprovider.h"// attribute table#include "qgsattributetable.h"#include "qgsattributetabledisplay.h"#include "qgsencodingfiledialog.h"#include <QApplication>#include <QMenu>#include <QMessageBox>#include <QPainter>#include <QSettings>QgsLegendLayerFile::QgsLegendLayerFile(QTreeWidgetItem * theLegendItem, QString theString, QgsMapLayer* theLayer)  : QgsLegendItem(theLegendItem, theString), mLyr(theLayer), mTableDisplay(NULL){  // Set the initial visibility flag for layers  // This user option allows the user to turn off inital drawing of  // layers when they are added to the map. This is useful when adding  // many layers and the user wants to adjusty symbology, etc prior to  // actually viewing the layer.  QSettings settings;  bool visible = settings.readBoolEntry("/qgis/new_layers_visible", 1);  mLyr.setVisible(visible);  // not in overview by default  mLyr.setInOverview(FALSE);    mType = LEGEND_LAYER_FILE;    setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);  setCheckState(0, Qt::Checked);  setText(0, theString);  // Add check if vector layer when connecting to selectionChanged slot  // Ticket #811 - racicot  QgsMapLayer *currentLayer = mLyr.layer();  QgsVectorLayer *isVectLyr = dynamic_cast < QgsVectorLayer * >(currentLayer);  if (isVectLyr)  {    // get notifications of changed selection - used to update attribute table    connect(mLyr.layer(), SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));    // get notifications of modified layer - used to close table as it's out of sync    connect(mLyr.layer(), SIGNAL(wasModified(bool)), this, SLOT(closeTable(bool)));  }    connect(mLyr.layer(), SIGNAL(layerNameChanged()), this, SLOT(layerNameChanged()));}QgsLegendLayerFile::~QgsLegendLayerFile(){  if (mTableDisplay)  {    mTableDisplay->close();    delete mTableDisplay;  }}QgsLegendItem::DRAG_ACTION QgsLegendLayerFile::accept(LEGEND_ITEM_TYPE type){  return NO_ACTION;}QgsLegendItem::DRAG_ACTION QgsLegendLayerFile::accept(const QgsLegendItem* li) const{  if(li->type() == QgsLegendItem::LEGEND_LAYER_FILE)    {      if(li->parent() == this->parent())	{	  return REORDER;	}    }  return NO_ACTION;}QPixmap QgsLegendLayerFile::getOriginalPixmap() const{  QPixmap myPixmap(QgsApplication::themePath()+"mActionFileSmall.png");  return myPixmap;}void QgsLegendLayerFile::updateLegendItem(){  QPixmap pix = legend()->pixmaps().mOriginalPixmap;    if(mLyr.inOverview())  {    //add overview glasses to the pixmap    QPainter p(&pix);    p.drawPixmap(0,0, legend()->pixmaps().mInOverviewPixmap);  }  if(mLyr.layer()->isEditable())  {    //add editing icon to the pixmap    QPainter p(&pix);    p.drawPixmap(30,0, legend()->pixmaps().mEditablePixmap);  }  /*  // TODO:  if(mLyr.layer()->hasProjectionError())  {    //add overview glasses to the pixmap    QPainter p(&pix);    p.drawPixmap(60,0, legend()->pixmaps().mProjectionErrorPixmap);  }  */    QIcon theIcon(pix);  setIcon(0, theIcon);}void QgsLegendLayerFile::setIconAppearance(bool inOverview,                                           bool editable){  QPixmap newIcon(getOriginalPixmap());  if (inOverview)  {    // Overlay the overview icon on the default icon    QPixmap myPixmap(QgsApplication::themePath()+"mIconOverview.png");    QPainter p(&newIcon);    p.drawPixmap(0,0,myPixmap);    p.end();  }    if (editable)  {    // Overlay the editable icon on the default icon    QPixmap myPixmap(QgsApplication::themePath()+"mIconEditable.png");    QPainter p(&newIcon);    p.drawPixmap(0,0,myPixmap);    p.end();  }  QIcon theIcon(newIcon);  setIcon(0, theIcon);  //also update the icon of the legend layer  ((QgsLegendLayer*)(parent()->parent()))->updateIcon();}QString QgsLegendLayerFile::nameFromLayer(QgsMapLayer* layer){  QString sourcename = layer->source(); //todo: move this duplicated code into a new function  if(sourcename.startsWith("host", false))    {      //this layer is a database layer      //modify source string such that password is not visible      sourcename = layer->name();    }  else    {      //modify source name such that only the file is visible      sourcename = layer->source().section('/',-1,-1);    }  return sourcename;}void QgsLegendLayerFile::setVisible(bool visible){  mLyr.setVisible(visible);}bool QgsLegendLayerFile::isVisible(){  return mLyr.visible();}void QgsLegendLayerFile::setInOverview(bool inOverview){  mLyr.setInOverview(inOverview);}bool QgsLegendLayerFile::isInOverview(){  return mLyr.inOverview();}void QgsLegendLayerFile::showInOverview(){  // toggle current status  setInOverview( ! isInOverview() );    legend()->updateMapCanvasLayerSet();  legend()->updateOverview();}void QgsLegendLayerFile::table(){  QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>(mLyr.layer());  if (!vlayer)  {    QMessageBox::information(0, tr("Not a vector layer"),      tr("To open an attribute table, you must select a vector layer in the legend"));    return;  }  QgsAttributeAction& actions = *vlayer->actions();  if (mTableDisplay)  {    mTableDisplay->raise();    // Give the table the most recent copy of the actions for this layer.    mTableDisplay->table()->setAttributeActions(actions);  }  else  {    // display the attribute table    QApplication::setOverrideCursor(Qt::waitCursor);    // TODO: pointer to QgisApp should be passed instead of NULL    // but we don't have pointer to it. [MD]    // but be can get it using this ugly hack. [jef]    // TODO: do this cleanly    QgisApp *app = NULL;    QList<QWidget *> list = QApplication::topLevelWidgets();    int i;    for(i=0; i<list.size(); i++)      if( list[i]->windowTitle().startsWith("Quantum GIS") )      {        app=reinterpret_cast<QgisApp*>(list[i]);        break;      }      mTableDisplay = new QgsAttributeTableDisplay(vlayer, app);      try      {        mTableDisplay->table()->fillTable(vlayer);      }      catch(std::bad_alloc& ba)      {        UNUSED(ba);        QMessageBox::critical(0, tr("bad_alloc exception"), tr("Filling the attribute table has been stopped because there was no more virtual memory left"));      }      mTableDisplay->table()->setSorting(true);      connect(mTableDisplay, SIGNAL(deleted()), this, SLOT(invalidateTableDisplay()));      mTableDisplay->setTitle(tr("Attribute table - ") + vlayer->name());      mTableDisplay->show();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -