void SelectionModelInspector::currentChanged(const QModelIndex &current)
{
  QObject *selectionModelObject = current.data(ObjectModel::ObjectRole).value<QObject*>();
  QItemSelectionModel *selectionModel = qobject_cast<QItemSelectionModel*>(selectionModelObject);
  if (selectionModel && selectionModel->model()) {
    m_current->setSourceModel(const_cast<QAbstractItemModel*>(selectionModel->model()));
  } else {
    m_current->setSourceModel(0);
  }
}
QList<QgsSymbolV2*> QgsCategorizedSymbolRendererV2Widget::selectedSymbols()
{
  QList<QgsSymbolV2*> selectedSymbols;

  QItemSelectionModel* m = viewCategories->selectionModel();
  QModelIndexList selectedIndexes = m->selectedRows( 1 );

  if ( m && selectedIndexes.size() > 0 )
  {
    const QgsCategoryList& categories = mRenderer->categories();
    QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
    for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
    {
      QStandardItem* currentItem = qobject_cast<const QStandardItemModel*>( m->model() )->itemFromIndex( *indexIt );
      if ( currentItem )
      {
        QgsSymbolV2* s = categories[mRenderer->categoryIndexForValue( currentItem->data() )].symbol();
        if ( s )
        {
          selectedSymbols.append( s );
        }
      }
    }
  }
  return selectedSymbols;
}
Example #3
0
QList<QgsSymbolV2*> QgsGraduatedSymbolRendererV2Widget::selectedSymbols()
{
  QList<QgsSymbolV2*> selectedSymbols;

  QItemSelectionModel* m = viewGraduated->selectionModel();
  QModelIndexList selectedIndexes = m->selectedRows( 1 );
  if ( m && selectedIndexes.size() > 0 )
  {
    const QgsRangeList& ranges = mRenderer->ranges();
    QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
    for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
    {
      QStandardItem* currentItem = qobject_cast<const QStandardItemModel*>( m->model() )->itemFromIndex( *indexIt );
      if ( currentItem )
      {
        QStringList list = currentItem->data( 0 ).toString().split( " " );
        if ( list.size() < 3 )
        {
          continue;
        }

        double lowerBound = list.at( 0 ).toDouble();
        double upperBound = list.at( 2 ).toDouble();
        QgsSymbolV2* s = findSymbolForRange( lowerBound, upperBound, ranges );
        if ( s )
        {
          selectedSymbols.append( s );
        }
      }
    }
  }
  return selectedSymbols;
}
Example #4
0
void LocalView::slot_show_properties()
{
    //qDebug() <<__FUNCTION__<<": "<<__LINE__<<":"<< __FILE__;
    QItemSelectionModel *ism = this->curr_item_view->selectionModel();
    QModelIndex cidx, idx;
    
    if (ism == 0) {
        qDebug()<<"Why???? no QItemSelectionModel??";
        return;
    }
    
    // QModelIndexList mil = ism->selectedIndexes();
    if (!ism->hasSelection()) {
        qDebug()<<"Why???? no QItemSelectionModel??";
        return;
    }

    cidx = ism->currentIndex();
    idx = ism->model()->index(cidx.row(), 0, cidx.parent());

    QString local_file = this->curr_item_view==this->uiw->treeView
        ? this->dir_file_model->filePath(idx) : this->model->filePath(idx);
    //  文件类型,大小,几个时间,文件权限
    //TODO 从模型中取到这些数据并显示在属性对话框中。
    LocalFileProperties *fp = new LocalFileProperties(this);
    fp->set_file_info_model_list(local_file);
    fp->exec();
    delete fp;
}
Example #5
0
void MList::selectItem(const QModelIndex &index)
{
    QItemSelectionModel *sModel = selectionModel();

    if (index.isValid() && sModel->model() != index.model()) {
        qWarning("MList::selectItem() failed: "
                 "Trying to select an item that is for"
                 " a different model than the view ");
        return;
    }

    if (sModel != NULL) {
        if (selectionMode() == MList::MultiSelection) {
            if (sModel->isSelected(index)) {
                sModel->select(index, QItemSelectionModel::Deselect);
            } else {
                sModel->select(index, QItemSelectionModel::Select);
            }
        } else if (selectionMode() == MList::SingleSelection) {
            sModel->select(index, QItemSelectionModel::ClearAndSelect);
        }
    }

    emit itemClicked(index);
}
QList<QgsSymbol *> QgsGraduatedSymbolRendererWidget::selectedSymbols()
{
  QList<QgsSymbol *> selectedSymbols;

  QItemSelectionModel *m = viewGraduated->selectionModel();
  QModelIndexList selectedIndexes = m->selectedRows( 1 );
  if ( m && !selectedIndexes.isEmpty() )
  {
    const QgsRangeList &ranges = mRenderer->ranges();
    QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
    for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
    {
      QStringList list = m->model()->data( *indexIt ).toString().split( ' ' );
      if ( list.size() < 3 )
      {
        continue;
      }
      // Not strictly necessary because the range should have been sanitized already
      // after user input, but being permissive never hurts
      bool ok = false;
      double lowerBound = qgsPermissiveToDouble( list.at( 0 ), ok );
      if ( ! ok )
        lowerBound = 0.0;
      double upperBound = qgsPermissiveToDouble( list.at( 2 ), ok );
      if ( ! ok )
        upperBound = 0.0;
      QgsSymbol *s = findSymbolForRange( lowerBound, upperBound, ranges );
      if ( s )
      {
        selectedSymbols.append( s );
      }
    }
  }
  return selectedSymbols;
}
Example #7
0
// can not support recursive selected now.
void LocalView::slot_local_new_upload_requested()
{
    //qDebug() <<__FUNCTION__<<": "<<__LINE__<<":"<< __FILE__;
    TaskPackage pkg(PROTO_FILE);
    QString local_file_name;
    QByteArray ba;

    QItemSelectionModel *ism = this->curr_item_view->selectionModel();
    QModelIndex cidx, idx, pidx;

    cidx = ism->currentIndex();
    pidx = cidx.parent();

    for (int i = ism->model()->rowCount(pidx) - 1 ; i >= 0 ; --i) {
        if (ism->isRowSelected(i, pidx)) {
            QModelIndex midx = idx = ism->model()->index(i, 0, pidx);
            if (this->curr_item_view == this->uiw->treeView) {
                midx = this->dir_file_model->mapToSource(midx);
            }
            qDebug()<<this->model->fileName(midx);
            qDebug()<<this->model->filePath(midx);
            local_file_name = this->model->filePath(midx);
            pkg.files<<local_file_name;
        }
    }
    
    // QModelIndexList mil = ism->selectedIndexes(); // TODO should fix win x64

    // for (int i = 0 ; i < mil.count() ; i += this->curr_item_view->model()->columnCount(QModelIndex())) {
    //     QModelIndex midx = mil.at(i);
    //     if (this->curr_item_view==this->uiw->treeView) {
    //         midx = this->dir_file_model->mapToSource(midx);
    //     }
    //     qDebug()<<this->model->fileName(midx);
    //     qDebug()<<this->model->filePath(midx);
    //     local_file_name = this->model->filePath(midx);
    //     pkg.files<<local_file_name;
    // }
    emit new_upload_requested(pkg);
}
Example #8
0
void LocalView::slot_rename()
{
    qDebug() <<__FUNCTION__<<": "<<__LINE__<<":"<< __FILE__;
    QItemSelectionModel *ism = this->curr_item_view->selectionModel();
    // QModelIndexList mil;
    QModelIndex cidx, idx;

    if (ism == 0 || !ism->hasSelection()) {
        QMessageBox::critical(this, tr("Warning..."),
                              tr("No item selected").leftJustified(60, ' '));
        return;
    }
    // mil = ism->selectedIndexes();
    cidx = ism->currentIndex();
    idx = ism->model()->index(cidx.row(), 0, cidx.parent());

    QString local_file = this->curr_item_view==this->uiw->treeView
        ? this->dir_file_model->filePath(idx) : this->model->filePath(idx);
    QString file_name = this->curr_item_view==this->uiw->treeView
        ? this->dir_file_model->fileName(idx) : this->model->fileName(idx);

    QString rename_to;
    rename_to = QInputDialog::getText(this, tr("Rename to:"), 
                                      tr("Input new name for: \"%1\"").arg(file_name).leftJustified(100, ' '),
                                      QLineEdit::Normal, file_name );
     
    if (rename_to  == QString::null) {
        //qDebug()<<" selectedIndexes count :"<< mil.count() << " why no item selected????";
        //QMessageBox::critical(this,tr("Warning..."),tr("No new name supplyed "));
        return;
    }
    if (rename_to.length() == 0) {
        QMessageBox::critical(this, tr("Warning..."), tr("No new name supplyed "));
        return;
    }
    q_debug()<<rename_to<<local_file<<this->curr_item_view<<file_name;
    // QTextCodec *codec = GlobalOption::instance()->locale_codec;
    QString file_path = local_file.left(local_file.length()-file_name.length());
    rename_to = file_path + rename_to;

    if (!QFile::rename(local_file, rename_to)) {
        q_debug()<<"file rename faild";
    }
    // 为什么用这个函数,直接用qt的函数不好吗
    // ::rename(codec->fromUnicode(local_file).data(), codec->fromUnicode(rename_to).data());
    
    this->slot_refresh_directory_tree();
}
Example #9
0
void LocalView::slot_mkdir()
{
    QString dir_name;
    QItemSelectionModel *ism = this->curr_item_view->selectionModel();
    QModelIndex cidx, idx;

    // QModelIndexList mil;
    if (ism == 0 || !ism->hasSelection()) {
        // qDebug()<<" selectedIndexes count :"<< mil.count() << " why no item selected????";
        qDebug()<<" selectedIndexes count :"<< ism->hasSelection() << " why no item selected????";
        QMessageBox::critical(this, tr("Warning..."), tr("No item selected"));
        return;
    }

    // mil = ism->selectedIndexes() ;
    cidx = ism->currentIndex();
    idx = ism->model()->index(cidx.row(), 0, cidx.parent());

    // QModelIndex midx = mil.at(0);
    QModelIndex midx = idx;
    QModelIndex aim_midx = (this->curr_item_view == this->uiw->treeView)
        ? this->dir_file_model->mapToSource(midx): midx;

    //检查所选择的项是不是目录
    if (!this->model->isDir(aim_midx)) {
        QMessageBox::critical(this, tr("Warning..."), tr("The selected item is not a directory."));
        return;
    }
    
    dir_name = QInputDialog::getText(this, tr("Create directory:"),
                                     tr("Input directory name:").leftJustified(80, ' '),
                                     QLineEdit::Normal, tr("new_direcotry"));
    if (dir_name == QString::null) {
        return;
    } 
    if (dir_name.length () == 0) {
        // qDebug()<<" selectedIndexes count :"<< mil.count() << " why no item selected????";
        qDebug()<<" selectedIndexes count :"<< ism->hasSelection() << " why no item selected????";
        QMessageBox::critical(this, tr("Warning..."), tr("No directory name supplyed."));
        return;
    }

    if (!QDir().mkdir(this->model->filePath(aim_midx) + "/" + dir_name)) {
        QMessageBox::critical(this, tr("Warning..."), tr("Create directory faild."));
    } else {
        this->slot_refresh_directory_tree();
    }
}
Example #10
0
QString LocalView::get_selected_directory()
{
    qDebug() <<__FUNCTION__<<": "<<__LINE__<<":"<< __FILE__;
    
    QString local_path;
    QItemSelectionModel *ism = this->uiw->treeView->selectionModel();
    QModelIndex cidx, idx;

    if (ism == 0) {        
        return QString();
    }

    if (!ism->hasSelection()) {
        qDebug()<<"why no tree selection???";
        return QString();
    }

    // QModelIndexList mil = ism->selectedIndexes();
    // if (mil.count() == 0) {
    //     return QString();
    // }
    
    //qDebug() << mil ;
    //qDebug() << model->fileName ( mil.at ( 0 ) );
    //qDebug() << model->filePath ( mil.at ( 0 ) );

    cidx = ism->currentIndex();
    if (!ism->isSelected(cidx)) {
        // so currentIndex is not always a selected index !!!!!!
        qDebug()<<"Why current index is not a selected index???";
    }
    idx = ism->model()->index(cidx.row(), 0, cidx.parent());

    // QString local_file = this->dir_file_model->filePath(mil.at(0));
    // local_path = this->dir_file_model->filePath(mil.at(0));

    QString local_file = this->dir_file_model->filePath(idx);
    local_path = this->dir_file_model->filePath(idx);

    return local_path;
}
void QgsGeometryCheckerFixSummaryDialog::onTableSelectionChanged( const QItemSelection &newSel, const QItemSelection & /*oldSel*/ )
{
  QItemSelectionModel *selModel = qobject_cast<QItemSelectionModel *>( QObject::sender() );
  const QAbstractItemModel *model = selModel->model();

  for ( QTableWidget *table : {ui.tableWidgetFixedErrors, ui.tableWidgetNewErrors, ui.tableWidgetNotFixed, ui.tableWidgetObsoleteErrors} )
  {
    if ( table->selectionModel() != selModel )
    {
      table->selectionModel()->blockSignals( true );
      table->clearSelection();
      table->selectionModel()->blockSignals( false );
    }
  }

  if ( !newSel.isEmpty() && !newSel.first().indexes().isEmpty() )
  {
    QModelIndex idx = newSel.first().indexes().first();
    QgsGeometryCheckError *error = reinterpret_cast<QgsGeometryCheckError *>( model->data( model->index( idx.row(), 0 ), Qt::UserRole ).value<void *>() );
    emit errorSelected( error );
  }
}
Example #12
0
void LocalView::slot_copy_path_url()
{
    QItemSelectionModel *ism = this->curr_item_view->selectionModel();
    QModelIndex cidx, idx;

    if (ism == 0) {
        qDebug()<<"Why???? no QItemSelectionModel??";        
        return;
    }
    
    // QModelIndexList mil = ism->selectedIndexes();
    if (!ism->hasSelection()) {
        qDebug()<<" why???? no QItemSelectionModel??";
        return;
    }

    cidx = ism->currentIndex();
    idx = ism->model()->index(cidx.row(), 0, cidx.parent());

    QString local_file = this->curr_item_view==this->uiw->treeView
        ? this->dir_file_model->filePath(idx) : this->model->filePath(idx);
    
    QApplication::clipboard()->setText(local_file);
}
Example #13
0
void LocalView::slot_refresh_directory_tree()
{
    //qDebug() <<__FUNCTION__<<": "<<__LINE__<<":"<< __FILE__;

    QItemSelectionModel *ism = this->uiw->treeView->selectionModel();
    QModelIndex cidx, idx;

    if (ism != 0) {
        if (ism->hasSelection()) {
            cidx = ism->currentIndex();
            idx = ism->model()->index(cidx.row(), 0, cidx.parent());
            // QModelIndex origIndex = this->dir_file_model->mapToSource(mil.at(0));
            QModelIndex origIndex = this->dir_file_model->mapToSource(idx);
        }
        // QModelIndexList mil = ism->selectedIndexes();
        // if (mil.count() > 0) {
        //     // model->refresh(mil.at(0));
        //     QModelIndex origIndex = this->dir_file_model->mapToSource(mil.at(0));
        //     q_debug()<<mil.at(0)<<origIndex;
        //     // model->refresh(origIndex);
        // }
    }
    this->dir_file_model->refresh(this->uiw->tableView->rootIndex());
}
Example #14
0
// makes current and selects the specified row and emits a change signal regardless of the element that was selected before; makes current the default invalid index (-1,-1) if the table is empty;
void FilesModel::selectRow(int nRow, const vector<int>& vnSel /* = std::vector<int>()*/)
{
    QItemSelectionModel* pSelModel (m_pCommonData->m_pFilesG->selectionModel());
//m_pCommonData->printFilesCrt();

    {
        NonblockingGuard g (m_pCommonData->m_bChangeGuard);
        if (!g) { return; }
        pSelModel->clear(); // 2008.07.08: this doesn't work quite as expected: it does trigger SelectionChanged, but it changes the current item after emitting the signal, so whoever catches it, doesn't know what the current item is (it's probably in the second param of CurrentChanged, but that doesn't help SelectionChanged, which has QItemSelection params, which don't seem to offer any way to get at the "current" index)
    }

//m_pCommonData->printFilesCrt();

    emit layoutChanged();

    m_nPrevCurrentRow = -2; // to make sure that onFilesGSelChanged() updates the notes and streams regardless of whether there are any files in m_pFilesG or not
    if (!m_pCommonData->getViewHandlers().empty())
    {
        //pSelModel->select(index(0, 0), QItemSelectionModel::Current);
        //pSelModel->select(index(0, 0), QItemSelectionModel::Select);

        //m_pCommonData->printFilesCrt();
        m_pCommonData->m_pFilesG->setCurrentIndex(index(nRow, 0)); // this sometimes calls onFilesGSelChanged(), but not always;
        //m_pCommonData->printFilesCrt();
    }

    if (-2 == m_nPrevCurrentRow)
    {
        onFilesGSelChanged();
    }

    for (int i = 0, n = cSize(vnSel); i < n; ++i)
    {
        pSelModel->select(pSelModel->model()->index(vnSel[i], 0), QItemSelectionModel::Select);
    }
}
Example #15
0
void LocalView::slot_remove()
{
    QItemSelectionModel *ism = this->curr_item_view->selectionModel();
    // QModelIndexList mil;
    QModelIndex cidx, idx;

    if (ism == 0 || !ism->hasSelection()) {
        QMessageBox::critical(this, tr("Warning..."), tr("No item selected").leftJustified(50, ' '));
        return;
    }
    // mil = ism->selectedIndexes();
    cidx = ism->currentIndex();
    idx = ism->model()->index(cidx.row(), 0, cidx.parent());

    QString local_file = this->curr_item_view==this->uiw->treeView
        ? this->dir_file_model->filePath(idx) : this->model->filePath(idx);

    QStringList local_files;
    for (int i = ism->model()->rowCount(cidx.parent())-1; i >= 0; --i) {
        idx = ism->model()->index(i, 0, cidx.parent());
        if (ism->isRowSelected(i, cidx.parent())) {
            local_file = this->curr_item_view==this->uiw->treeView
                ? this->dir_file_model->filePath(idx) : this->model->filePath(idx);
            local_files.prepend(local_file);
        }
    }

    if (QMessageBox::question(this, tr("Question..."), 
                             QString("%1\n    %2").arg(QString(tr("Are you sure remove it?")))
                              .arg(local_files.join("\n    ")),
                             QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) {

        bool bok;
        for (int i = ism->model()->rowCount(cidx.parent())-1; i >= 0; --i) {
            idx = ism->model()->index(i, 0, cidx.parent());
            if (ism->isRowSelected(i, cidx.parent())) {
                idx = ism->model()->index(i, 0, cidx.parent());
                if (ism->model() == this->model ?
                    this->model->isDir(idx) : this->model->isDir(idx)) {
                    bok = ism->model() == this->model ?
                        this->model->rmdir(idx) : this->model->rmdir(idx);
                } else {
                    bok = ism->model() == this->model ?
                        this->model->remove(idx) : this->model->remove(idx);
                }

                if (bok) {
                    // this->slot_refresh_directory_tree();
                } else {
                    local_file = this->curr_item_view==this->uiw->treeView
                        ? this->dir_file_model->filePath(idx) : this->model->filePath(idx);
                    q_debug()<<"can not remove file/direcotry:"<<i<<local_file;
                }
            }
        }

        // if (QFile::remove(local_file)) {
        //     this->slot_refresh_directory_tree();    
        // } else {
        //     q_debug()<<"can not remove file:"<<local_file;
        // }
    }
}
Example #16
0
void LocalView::slot_rmdir()
{
    QString dir_name;
    
    QItemSelectionModel *ism = this->curr_item_view->selectionModel();
    // QModelIndexList mil;
    QModelIndex cidx, idx;

    if (ism == 0 || !ism->hasSelection()) {
        qDebug()<<"SelectedIndexes count :"<< ism->hasSelection() << " why no item selected????";
        QMessageBox::critical(this, tr("Warning..."), tr("No item selected"));
        return;
    }    
    
    // mil = ism->selectedIndexes();
    cidx = ism->currentIndex();
    idx = ism->model()->index(cidx.row(), 0, cidx.parent());
    
    QModelIndex midx = idx;
    QModelIndex aim_midx = (this->curr_item_view == this->uiw->treeView) 
        ? this->dir_file_model->mapToSource(midx): midx;

    //检查所选择的项是不是目录
    if (!this->model->isDir(aim_midx)) {
        QMessageBox::critical(this, tr("Warning..."), tr("The selected item is not a directory."));
        return ;
    }
    // qDebug()<<QDir(this->model->filePath(aim_midx)).count();
    if (QDir(this->model->filePath(aim_midx)).count() > 2) {
        QMessageBox::critical(this, tr("Warning..."), tr("Selected director not empty."));
        return;
    }

    QModelIndex tree_midx = this->dir_file_model->mapFromSource(aim_midx);
    QModelIndex pidx = aim_midx.parent();
    int it_row = tree_midx.row();
    QModelIndex nidx = tree_midx.parent();
    QString next_select_path;
    
    if (this->dir_file_model->rowCount(nidx) == 1) {
        // goto parent 
        next_select_path = this->dir_file_model->filePath(nidx);
    } else if (it_row == this->dir_file_model->rowCount(nidx)-1) {
        // goto privious
        next_select_path = this->dir_file_model->filePath(this->dir_file_model->index(it_row-1, 0, nidx));
    } else if (it_row > this->dir_file_model->rowCount(nidx)-1) {
        // not possible
    } else if (it_row < this->dir_file_model->rowCount(nidx)-1) {
        // goto next
        next_select_path = this->dir_file_model->filePath(this->dir_file_model->index(it_row+1, 0, nidx));
    } else {
        // not possible
    }

    Q_ASSERT(!next_select_path.isEmpty());
    
    if (this->model->rmdir(aim_midx)) {
        if (this->curr_item_view == this->uiw->treeView) {
            // this->slot_dir_tree_item_clicked(tree_midx.parent());
            // A: if has next sible, will select next sible
            // B: if has priv sible, will select privious sible
            // C: if no next and no priv, will select parent 

            // ism = this->curr_item_view->selectionModel();
            idx = ism->currentIndex();
            qDebug()<<idx<<this->dir_file_model->filePath(idx);

            // set selection and go on
            ism->clearSelection();
            QItemSelection *selection = new QItemSelection();
                                                           
            // ism->select(this->dir_file_model->index(next_select_path), QItemSelectionModel::Select | QItemSelectionModel::Current  | QItemSelectionModel::Rows);
            ism->setCurrentIndex(this->dir_file_model->index(next_select_path), QItemSelectionModel::Select | QItemSelectionModel::Current  | QItemSelectionModel::Rows);

            idx = ism->currentIndex();
            qDebug()<<idx<<this->dir_file_model->filePath(idx);

            this->slot_dir_tree_item_clicked(this->dir_file_model->index(next_select_path));
        }
    } else {
        QMessageBox::critical(this, tr("Warning..."),
                              tr("Delete directory faild. Maybe the directory is not empty."));
    }

    // if (!QDir().rmdir(this->model->filePath(aim_midx))) {
    //     QMessageBox::critical(this, tr("Warning..."), tr("Delete directory faild. Mayby the directory is not empty."));
    // } else {
    //     this->slot_refresh_directory_tree();
    // }
}