|
98 | 98 | #include "qgis.h"
|
99 | 99 | #include "qgisplugin.h"
|
100 | 100 | #include "qgsabout.h"
|
| 101 | +#include "qgsapplayertreeviewmenuprovider.h" |
101 | 102 | #include "qgsapplication.h"
|
102 | 103 | #include "qgsattributeaction.h"
|
103 | 104 | #include "qgsattributetabledialog.h"
|
|
135 | 136 | #include "qgsguivectorlayertools.h"
|
136 | 137 | #include "qgslabelinggui.h"
|
137 | 138 | #include "qgslayertreemodel.h"
|
| 139 | +#include "qgslayertreenode.h" |
138 | 140 | #include "qgslayertreeutils.h"
|
139 | 141 | #include "qgslayertreeview.h"
|
| 142 | +#include "qgslayertreeviewdefaultactions.h" |
140 | 143 | #include "qgslegend.h"
|
141 | 144 | #include "qgslegendgroup.h"
|
142 | 145 | #include "qgslayerorder.h"
|
@@ -816,6 +819,7 @@ QgisApp::QgisApp( )
|
816 | 819 | mInternalClipboard = new QgsClipboard;
|
817 | 820 | mMapCanvas = new QgsMapCanvas();
|
818 | 821 | mMapCanvas->freeze();
|
| 822 | + mLayerTreeView = new QgsLayerTreeView( this ); |
819 | 823 | mMapLegend = new QgsLegend( mMapCanvas );
|
820 | 824 | mUndoWidget = new QgsUndoWidget( NULL, mMapCanvas );
|
821 | 825 | mInfoBar = new QgsMessageBar( centralWidget() );
|
@@ -2208,177 +2212,6 @@ QgsMessageBar* QgisApp::messageBar()
|
2208 | 2212 | }
|
2209 | 2213 |
|
2210 | 2214 |
|
2211 |
| - |
2212 |
| - |
2213 |
| -// =========== |
2214 |
| -// TODO: move to a separate file |
2215 |
| -#include "qgslayertreenode.h" |
2216 |
| -#include "qgslayertreeviewdefaultactions.h" |
2217 |
| - |
2218 |
| -class QgsAppLayerTreeViewMenuProvider : public QObject, public QgsLayerTreeViewMenuProvider |
2219 |
| -{ |
2220 |
| -public: |
2221 |
| - QgsAppLayerTreeViewMenuProvider(QgsLayerTreeView* view, QgsMapCanvas* canvas) : mView(view), mCanvas(canvas) {} |
2222 |
| - |
2223 |
| - QMenu* createContextMenu(); |
2224 |
| - |
2225 |
| -protected: |
2226 |
| - QgsLayerTreeView* mView; |
2227 |
| - QgsMapCanvas* mCanvas; |
2228 |
| -}; |
2229 |
| - |
2230 |
| -QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu() |
2231 |
| -{ |
2232 |
| - QMenu* menu = new QMenu; |
2233 |
| - |
2234 |
| - QgsLayerTreeViewDefaultActions* actions = mView->defaultActions(); |
2235 |
| - |
2236 |
| - QModelIndex idx = mView->currentIndex(); |
2237 |
| - if (!idx.isValid()) |
2238 |
| - { |
2239 |
| - // global menu |
2240 |
| - menu->addAction( actions->actionAddGroup(menu) ); |
2241 |
| - |
2242 |
| - // TODO: expand all, collapse all |
2243 |
| - // TODO: update drawing order |
2244 |
| - } |
2245 |
| - else if (QgsLayerTreeNode* node = mView->layerTreeModel()->index2node(idx)) |
2246 |
| - { |
2247 |
| - // layer or group selected |
2248 |
| - if (node->nodeType() == QgsLayerTreeNode::NodeGroup) |
2249 |
| - { |
2250 |
| - menu->addAction( actions->actionZoomToGroup(mCanvas, menu) ); |
2251 |
| - menu->addAction( actions->actionRemoveGroupOrLayer(menu) ); |
2252 |
| - |
2253 |
| - menu->addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ), |
2254 |
| - tr( "&Set Group CRS" ), QgisApp::instance(), SLOT( legendGroupSetCRS() ) ); |
2255 |
| - |
2256 |
| - menu->addAction( actions->actionRenameGroupOrLayer(menu) ); |
2257 |
| - |
2258 |
| - if (mView->selectedNodes(true).count() >= 2) |
2259 |
| - menu->addAction( actions->actionGroupSelected(menu) ); |
2260 |
| - |
2261 |
| - menu->addAction( actions->actionAddGroup(menu) ); |
2262 |
| - } |
2263 |
| - else if (node->nodeType() == QgsLayerTreeNode::NodeLayer) |
2264 |
| - { |
2265 |
| - QgsMapLayer* layer = static_cast<QgsLayerTreeLayer*>(node)->layer(); |
2266 |
| - |
2267 |
| - menu->addAction( actions->actionZoomToLayer(mCanvas, menu) ); |
2268 |
| - menu->addAction( actions->actionShowInOverview(menu) ); |
2269 |
| - |
2270 |
| - if ( layer->type() == QgsMapLayer::RasterLayer ) |
2271 |
| - { |
2272 |
| - menu->addAction( tr( "&Zoom to Best Scale (100%)" ), QgisApp::instance(), SLOT( legendLayerZoomNative() ) ); |
2273 |
| - |
2274 |
| - QgsRasterLayer* rasterLayer = qobject_cast<QgsRasterLayer *>( layer ); |
2275 |
| - if ( rasterLayer && rasterLayer->rasterType() != QgsRasterLayer::Palette ) |
2276 |
| - menu->addAction( tr( "&Stretch Using Current Extent" ), QgisApp::instance(), SLOT( legendLayerStretchUsingCurrentExtent() ) ); |
2277 |
| - } |
2278 |
| - |
2279 |
| - menu->addAction( actions->actionRemoveGroupOrLayer(menu) ); |
2280 |
| - |
2281 |
| - // duplicate layer |
2282 |
| - QAction* duplicateLayersAction = menu->addAction( QgsApplication::getThemeIcon( "/mActionDuplicateLayer.svg" ), tr( "&Duplicate" ), QgisApp::instance(), SLOT( duplicateLayers() ) ); |
2283 |
| - |
2284 |
| - // set layer crs |
2285 |
| - menu->addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ), tr( "&Set Layer CRS" ), QgisApp::instance(), SLOT( setLayerCRS() ) ); |
2286 |
| - |
2287 |
| - // assign layer crs to project |
2288 |
| - menu->addAction( QgsApplication::getThemeIcon( "/mActionSetProjectCRS.png" ), tr( "Set &Project CRS from Layer" ), QgisApp::instance(), SLOT( setProjectCRSFromLayer() ) ); |
2289 |
| - |
2290 |
| - menu->addSeparator(); |
2291 |
| - |
2292 |
| - if ( layer->type() == QgsMapLayer::VectorLayer ) |
2293 |
| - { |
2294 |
| - QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( layer ); |
2295 |
| - |
2296 |
| - QAction *toggleEditingAction = QgisApp::instance()->actionToggleEditing(); |
2297 |
| - QAction *saveLayerEditsAction = QgisApp::instance()->actionSaveActiveLayerEdits(); |
2298 |
| - QAction *allEditsAction = QgisApp::instance()->actionAllEdits(); |
2299 |
| - |
2300 |
| - // attribute table |
2301 |
| - menu->addAction( QgsApplication::getThemeIcon( "/mActionOpenTable.png" ), tr( "&Open Attribute Table" ), |
2302 |
| - QgisApp::instance(), SLOT( attributeTable() ) ); |
2303 |
| - |
2304 |
| - // allow editing |
2305 |
| - int cap = vlayer->dataProvider()->capabilities(); |
2306 |
| - if ( cap & QgsVectorDataProvider::EditingCapabilities ) |
2307 |
| - { |
2308 |
| - if ( toggleEditingAction ) |
2309 |
| - { |
2310 |
| - menu->addAction( toggleEditingAction ); |
2311 |
| - toggleEditingAction->setChecked( vlayer->isEditable() ); |
2312 |
| - } |
2313 |
| - if ( saveLayerEditsAction && vlayer->isModified() ) |
2314 |
| - { |
2315 |
| - menu->addAction( saveLayerEditsAction ); |
2316 |
| - } |
2317 |
| - } |
2318 |
| - |
2319 |
| - if ( allEditsAction->isEnabled() ) |
2320 |
| - menu->addAction( allEditsAction ); |
2321 |
| - |
2322 |
| - // disable duplication of memory layers |
2323 |
| - if ( vlayer->storageType() == "Memory storage" && mView->selectedLayerNodes().count() == 1 ) |
2324 |
| - duplicateLayersAction->setEnabled( false ); |
2325 |
| - |
2326 |
| - // save as vector file |
2327 |
| - menu->addAction( tr( "Save As..." ), QgisApp::instance(), SLOT( saveAsFile() ) ); |
2328 |
| - menu->addAction( tr( "Save As Layer Definition File..." ), QgisApp::instance(), SLOT( saveAsLayerDefinition() ) ); |
2329 |
| - |
2330 |
| - if ( !vlayer->isEditable() && vlayer->dataProvider()->supportsSubsetString() && vlayer->vectorJoins().isEmpty() ) |
2331 |
| - menu->addAction( tr( "&Filter..." ), QgisApp::instance(), SLOT( layerSubsetString() ) ); |
2332 |
| - |
2333 |
| - menu->addAction( actions->actionShowFeatureCount(menu) ); |
2334 |
| - |
2335 |
| - menu->addSeparator(); |
2336 |
| - } |
2337 |
| - else if ( layer->type() == QgsMapLayer::RasterLayer ) |
2338 |
| - { |
2339 |
| - menu->addAction( tr( "Save As..." ), QgisApp::instance(), SLOT( saveAsRasterFile() ) ); |
2340 |
| - menu->addAction( tr( "Save As Layer Definition File..." ), QgisApp::instance(), SLOT( saveAsLayerDefinition() ) ); |
2341 |
| - } |
2342 |
| - else if ( layer->type() == QgsMapLayer::PluginLayer && mView->selectedLayerNodes().count() == 1 ) |
2343 |
| - { |
2344 |
| - // disable duplication of plugin layers |
2345 |
| - duplicateLayersAction->setEnabled( false ); |
2346 |
| - } |
2347 |
| - |
2348 |
| - // TODO: custom actions |
2349 |
| - |
2350 |
| - if (layer && QgsProject::instance()->layerIsEmbedded( layer->id() ).isEmpty() ) |
2351 |
| - menu->addAction( tr( "&Properties" ), QgisApp::instance(), SLOT( layerProperties() ) ); |
2352 |
| - |
2353 |
| - if (node->parent() != mView->layerTreeModel()->rootGroup()) |
2354 |
| - menu->addAction( actions->actionMakeTopLevel(menu) ); |
2355 |
| - |
2356 |
| - menu->addAction( actions->actionRenameGroupOrLayer(menu) ); |
2357 |
| - |
2358 |
| - if (mView->selectedNodes(true).count() >= 2) |
2359 |
| - menu->addAction( actions->actionGroupSelected(menu) ); |
2360 |
| - |
2361 |
| - if ( mView->selectedLayerNodes().count() == 1 ) |
2362 |
| - { |
2363 |
| - QgisApp* app = QgisApp::instance(); |
2364 |
| - menu->addAction( tr( "Copy Style" ), app, SLOT( copyStyle() ) ); |
2365 |
| - if ( app->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) ) |
2366 |
| - { |
2367 |
| - menu->addAction( tr( "Paste Style" ), app, SLOT( pasteStyle() ) ); |
2368 |
| - } |
2369 |
| - } |
2370 |
| - } |
2371 |
| - |
2372 |
| - } |
2373 |
| - else |
2374 |
| - { |
2375 |
| - // symbology item? |
2376 |
| - } |
2377 |
| - |
2378 |
| - return menu; |
2379 |
| -} |
2380 |
| - |
2381 |
| - |
2382 | 2215 | void QgisApp::initLayerTreeView()
|
2383 | 2216 | {
|
2384 | 2217 | mLayerTreeDock = new QDockWidget( tr( "Layers NEW" ), this );
|
|
0 commit comments