void QgsCptCityColorRampDialog::tabBar_currentChanged( int index )
{
  if ( index == 0 )
  {
    setTreeModel( mSelectionsModel );
    mArchiveViewType = QgsCptCityBrowserModel::Selections;
  }
  else if ( index == 1 )
  {
    setTreeModel( mAuthorsModel );
    mArchiveViewType = QgsCptCityBrowserModel::Authors;
  }
  else
  {
    QgsDebugMsg( QStringLiteral( "invalid index %1" ).arg( index ) );
    setTreeModel( mAuthorsModel );
    mArchiveViewType = QgsCptCityBrowserModel::Authors;
  }

  mListWidget->blockSignals( true );
  updateRamp();
  mListWidget->blockSignals( false );
}
QgsCptCityColorRampV2Dialog::QgsCptCityColorRampV2Dialog( QgsCptCityColorRampV2* ramp, QWidget* parent )
    : QDialog( parent )
    , mRamp( 0 )
    , mArchiveViewType( QgsCptCityBrowserModel::Selections )
{
  setupUi( this );

  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );

  QSettings settings;
  restoreGeometry( settings.value( "/Windows/CptCityColorRampV2Dialog/geometry" ).toByteArray() );
  mSplitter->setSizes( QList<int>() << 250 << 550 );
  mSplitter->restoreState( settings.value( "/Windows/CptCityColorRampV2Dialog/splitter" ).toByteArray() );

  mModel = mAuthorsModel = mSelectionsModel = 0; //mListModel = 0;
  mTreeFilter = 0;

  QgsCptCityArchive::initDefaultArchive();
  mArchive = QgsCptCityArchive::defaultArchive();

  // show information on how to install cpt-city files if none are found
  if ( ! mArchive || mArchive->isEmpty() )
  {
    // QgsDialog dlg( this );
    // dlg.setWindowTitle( tr( "cpt-city gradient files not found" ) );
    QTextEdit *edit = new QTextEdit( 0 );
    edit->setReadOnly( true );
    // not sure if we want this long string to be translated
    QString helpText = tr( "Error - cpt-city gradient files not found.\n\n"
                           "You have two means of installing them:\n\n"
                           "1) Install the \"Color Ramp Manager\" python plugin "
                           "(you must enable Experimental plugins in the plugin manager) "
                           "and use it to download latest cpt-city package.\n"
                           "You can install the entire cpt-city archive or a selection for QGIS.\n\n"
                           "2) Download the complete archive (in svg format) "
                           "and unzip it to your QGIS settings directory [%1] .\n\n"
                           "This file can be found at [%2]\nand current file is [%3]"
                         ).arg( QgsApplication::qgisSettingsDirPath()
                              ).arg( "http://soliton.vm.bytemark.co.uk/pub/cpt-city/pkg/"
                                   ).arg( "http://soliton.vm.bytemark.co.uk/pub/cpt-city/pkg/cpt-city-svg-2.07.zip" );
    edit->setText( helpText );
    mStackedWidget->addWidget( edit );
    mStackedWidget->setCurrentIndex( 1 );
    tabBar->setVisible( false );
    // dlg.layout()->addWidget( edit );
    // dlg.resize(500,400);
    // dlg.exec();
    return;
  }

  if ( ! mArchive )
    return;
  QgsDebugMsg( "archive: " + mArchive->archiveName() );

  if ( ramp )
  {
    mRamp = ramp;
  }
  else
  {
    mRamp = new QgsCptCityColorRampV2( "", "", false );
    ramp = mRamp;
  }
  QgsDebugMsg( QString( "ramp name= %1 variant= %2 - %3 variants" ).arg( ramp->schemeName() ).arg( ramp->variantName() ).arg( ramp->variantList().count() ) );

  // model / view
  QgsDebugMsg( "loading model/view objects" );
  if ( mAuthorsModel )
    delete mAuthorsModel;
  mAuthorsModel = new QgsCptCityBrowserModel( this, mArchive, QgsCptCityBrowserModel::Authors );
  if ( mSelectionsModel )
    delete mSelectionsModel;
  mSelectionsModel = new QgsCptCityBrowserModel( this, mArchive, QgsCptCityBrowserModel::Selections );
  setTreeModel( mSelectionsModel );

  mTreeView->setSelectionMode( QAbstractItemView::SingleSelection );
  mTreeView->setColumnHidden( 1, true );
  QgsDebugMsg( "done loading model/view objects" );

  // setup ui
  tabBar->blockSignals( true );
  tabBar->addTab( tr( "Selections by theme" ) );
  tabBar->addTab( tr( "All by author" ) );
  cboVariantName->setIconSize( QSize( 100, 15 ) );
  lblPreview->installEventFilter( this ); // mouse click on preview label shows svg render

  // look for item, if not found in selections archive, look for in authors
  QgsDebugMsg( "looking for ramp " + mRamp->schemeName() );
  if ( mRamp->schemeName() != "" )
  {
    bool found = updateRamp();
    if ( ! found )
    {
      tabBar->setCurrentIndex( 1 );
      setTreeModel( mAuthorsModel );
      found = updateRamp();
      // if not found, go back to selections model
      if ( ! found )
      {
        tabBar->setCurrentIndex( 0 );
        setTreeModel( mSelectionsModel );
      }
    }
    if ( found )
      buttonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
  }
  else
  {
    updateRamp();
  }

  tabBar->blockSignals( false );

  connect( this, SIGNAL( finished( int ) ), this, SLOT( onFinished() ) );

}