예제 #1
0
void QgsBrowserModel::addRootItems()
{
  updateProjectHome();

  // give the home directory a prominent third place
  QgsDirectoryItem *item = new QgsDirectoryItem( nullptr, tr( "Home" ), QDir::homePath(), QStringLiteral( HOME_PREFIX ) + QDir::homePath() );
  item->setSortKey( QStringLiteral( " 2" ) );
  QStyle *style = QApplication::style();
  QIcon homeIcon( style->standardPixmap( QStyle::SP_DirHomeIcon ) );
  item->setIcon( homeIcon );
  connectItem( item );
  mRootItems << item;

  // add favorite directories
  mFavorites = new QgsFavoritesItem( nullptr, tr( "Favorites" ) );
  if ( mFavorites )
  {
    connectItem( mFavorites );
    mRootItems << mFavorites;
  }

  // add drives
  Q_FOREACH ( const QFileInfo &drive, QDir::drives() )
  {
    QString path = drive.absolutePath();

    if ( QgsDirectoryItem::hiddenPath( path ) )
      continue;

    QgsDirectoryItem *item = new QgsDirectoryItem( nullptr, path, path );
    item->setSortKey( QStringLiteral( " 3 %1" ).arg( path ) );

    connectItem( item );
    mRootItems << item;
  }
예제 #2
0
void QgsBrowserModel::addRootItems()
{
  updateProjectHome();

  // give the home directory a prominent third place
  QgsDirectoryItem *item = new QgsDirectoryItem( nullptr, tr( "Home" ), QDir::homePath(), QStringLiteral( HOME_PREFIX ) + QDir::homePath() );
  item->setSortKey( QStringLiteral( " 2" ) );
  setupItemConnections( item );
  mRootItems << item;

  // add favorite directories
  mFavorites = new QgsFavoritesItem( nullptr, tr( "Favorites" ) );
  if ( mFavorites )
  {
    setupItemConnections( mFavorites );
    mRootItems << mFavorites;
  }

  // add drives
  Q_FOREACH ( const QFileInfo &drive, QDir::drives() )
  {
    const QString path = drive.absolutePath();

    if ( QgsDirectoryItem::hiddenPath( path ) )
      continue;

    QgsDirectoryItem *item = new QgsDirectoryItem( nullptr, path, path );
    item->setSortKey( QStringLiteral( " 3 %1" ).arg( path ) );
    mDriveItems.insert( path, item );

    setupItemConnections( item );
    mRootItems << item;
  }

#ifdef Q_OS_MAC
  QString path = QString( "/Volumes" );
  QgsDirectoryItem *vols = new QgsDirectoryItem( nullptr, path, path );
  mRootItems << vols;
#endif

  // container for displaying providers as sorted groups (by QgsDataProvider::DataCapability enum)
  QMap<int, QgsDataItem *> providerMap;

  Q_FOREACH ( QgsDataItemProvider *pr, QgsApplication::dataItemProviderRegistry()->providers() )
  {
    int capabilities = pr->capabilities();
    if ( capabilities == QgsDataProvider::NoDataCapabilities )
    {
      QgsDebugMsgLevel( pr->name() + " does not have any dataCapabilities", 4 );
      continue;
    }

    QgsDataItem *item = pr->createDataItem( QString(), nullptr );  // empty path -> top level
    if ( item )
    {
      // Forward the signal from the root items to the model (and then to the app)
      connect( item, &QgsDataItem::connectionsChanged, this, &QgsBrowserModel::connectionsChanged );
      QgsDebugMsgLevel( "Add new top level item : " + item->name(), 4 );
      setupItemConnections( item );
      providerMap.insertMulti( capabilities, item );
    }
  }