Example #1
0
void BasicMibView::Find(bool reevaluate)
{
    if (reevaluate)
    {
        find_string = find_uid.comboFind->currentText();
        if (!find_strings.contains(find_string))
            find_strings.append(find_string);

        if (find_uid.checkWords->isChecked())
            find_word = true;
        else
            find_word = false;
        if (find_uid.checkCase->isChecked())
            find_cs = true;
        else
            find_cs = false;
        if (find_uid.checkBackward->isChecked())
            find_back = true;
        else
            find_back = false;
    }

    QTreeWidgetItem *start = NULL, *begin = NULL, *end = NULL, *cur = NULL;
  
    // Determine begin of tree 
    begin = itemFromIndex(model()->index(0, 0, QModelIndex()));
 
    // Determine end of tree
    if (find_back)
    {
        QTreeWidgetItemIterator it(begin);
        while ( *it ) end = *it++;
    }

    // Determine where we start the find 
    if ((start = itemFromIndex(find_last)) == NULL)
        start = begin;

    // Create iterator
    QTreeWidgetItemIterator it( start );

    goto start_find;

    // Loop thru tree items and break if item is found
    while ( *it && (*it != start))
    {
        cur = *it;

        if ((find_word && !cur->text(0).compare(find_string, 
                           find_cs?Qt::CaseSensitive:Qt::CaseInsensitive)) ||
            (!find_word && cur->text(0).contains(find_string, 
                           find_cs?Qt::CaseSensitive:Qt::CaseInsensitive)))
        {
            // Found item
            setCurrentItem(cur);
            find_last = indexFromItem(cur);
            break;
        }

start_find:
        // Move to next item, handle tree wrap-around
        if (find_back)
        {
            --it;
            if (!*it) it = QTreeWidgetItemIterator(end);
        }
        else
        {
            ++it;
            if (!*it) it = QTreeWidgetItemIterator(begin);
        }
    }
}
Example #2
0
bool BrowseTableModel::setData(const QModelIndex &index, const QVariant &value,
                               int role) {
    Q_UNUSED(role);

    if (!index.isValid()) {
        return false;
    }
    qDebug() << "BrowseTableModel::setData(" << index.data() << ")";
    int row = index.row();
    int col = index.column();
    QString track_location = getTrackLocation(index);
    AudioTagger tagger(track_location);

    // set tagger information
    tagger.setArtist(this->index(row, COLUMN_ARTIST).data().toString());
    tagger.setTitle(this->index(row, COLUMN_TITLE).data().toString());
    tagger.setAlbum(this->index(row, COLUMN_ALBUM).data().toString());
    tagger.setKey(this->index(row, COLUMN_KEY).data().toString());
    tagger.setBpm(this->index(row, COLUMN_BPM).data().toString());
    tagger.setComment(this->index(row, COLUMN_COMMENT).data().toString());
    tagger.setTracknumber(
        this->index(row, COLUMN_TRACK_NUMBER).data().toString());
    tagger.setYear(this->index(row, COLUMN_YEAR).data().toString());
    tagger.setGenre(this->index(row, COLUMN_GENRE).data().toString());
    tagger.setComposer(this->index(row, COLUMN_COMPOSER).data().toString());

    // check if one the item were edited
    if (col == COLUMN_ARTIST) {
        tagger.setArtist(value.toString());
    } else if (col == COLUMN_TITLE) {
        tagger.setTitle(value.toString());
    } else if (col == COLUMN_ALBUM) {
        tagger.setAlbum(value.toString());
    } else if (col == COLUMN_BPM) {
        tagger.setBpm(value.toString());
    } else if (col == COLUMN_KEY) {
        tagger.setKey(value.toString());
    } else if (col == COLUMN_TRACK_NUMBER) {
        tagger.setTracknumber(value.toString());
    } else if (col == COLUMN_COMMENT) {
        tagger.setComment(value.toString());
    } else if (col == COLUMN_GENRE) {
        tagger.setGenre(value.toString());
    } else if (col == COLUMN_COMPOSER) {
        tagger.setComposer(value.toString());
    } else if (col == COLUMN_YEAR) {
        tagger.setYear(value.toString());
    }


    QStandardItem* item = itemFromIndex(index);
    if (tagger.save()) {
        // Modify underlying interalPointer object
        item->setText(value.toString());
        item->setToolTip(item->text());
        return true;
    } else {
        // reset to old value in error
        item->setText(index.data().toString());
        item->setToolTip(item->text());
        QMessageBox::critical(
            0, tr("Mixxx Library"),
            tr("Could not update file metadata.")
            + "\n" +track_location);
        return false;
    }
}
Example #3
0
Config CameraConfigModel::channelConfig(const QModelIndex &index) const
{
	ChannelItem *item = ChannelItem::cast(itemFromIndex(index));
	if(!item) return Config();
	return item->config();
}
Example #4
0
TreeItem* AbstractTreeModel::itemFromIndexAsTreeItem(const QModelIndex & index) const
{
	return (TreeItem*)itemFromIndex(index);
}
Example #5
0
QTreeWidgetItem * ProposalTreeWidget::itemFromRow(int r) const
{
	return itemFromIndex( indexFromRow(r) );
}
Example #6
0
const QString &CameraConfigModel::channelType(const QModelIndex &index) const
{
	ChannelItem *item = ChannelItem::cast(itemFromIndex(index));
	if(!item) return m_blank;
	return item->channelType();
}
Example #7
0
QVariant TreeModel::data(const QModelIndex &idx, int role) const
{
    TreeItem *item = itemFromIndex(idx);
    return item ? item->data(idx.column(), role) : QVariant();
}
Example #8
0
bool QgsLegendModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent )
{
  Q_UNUSED( action );
  Q_UNUSED( column );

  if ( !data->hasFormat( "text/xml" ) )
  {
    return false;
  }

  QStandardItem* dropIntoItem = 0;
  if ( parent.isValid() )
  {
    dropIntoItem = itemFromIndex( parent );
  }
  else
  {
    dropIntoItem = invisibleRootItem();
  }

  //get XML doc
  QByteArray encodedData = data->data( "text/xml" );
  QDomDocument xmlDoc;
  xmlDoc.setContent( encodedData );

  QDomElement dragDataElem = xmlDoc.documentElement();
  if ( dragDataElem.tagName() != "LegendModelDragData" )
  {
    return false;
  }

  QDomNodeList nodeList = dragDataElem.childNodes();
  int nChildNodes = nodeList.size();
  QDomElement currentElem;
  QString currentTagName;
  QgsComposerLegendItem* currentItem = 0;

  for ( int i = 0; i < nChildNodes; ++i )
  {
    currentElem = nodeList.at( i ).toElement();
    if ( currentElem.isNull() )
    {
      continue;
    }
    currentTagName = currentElem.tagName();
    if ( currentTagName == "LayerItem" )
    {
      currentItem = new QgsComposerLayerItem();
    }
    else if ( currentTagName == "GroupItem" )
    {
      currentItem = new QgsComposerGroupItem();
    }
    else
    {
      continue;
    }
    currentItem->readXML( currentElem );
    if ( row < 0 )
    {
      dropIntoItem->insertRow( dropIntoItem->rowCount(), currentItem );
    }
    else
    {
      dropIntoItem->insertRow( row + i, currentItem );
    }
  }
  emit layersChanged();
  return true;
}
void PodcastDiscoveryModel::LazyLoadImage(const QUrl& url,
                                          const QModelIndex& index) {
  QStandardItem* item = itemFromIndex(index);
  item->setData(true, Role_StartedLoadingImage);
  icon_loader_->LoadIcon(url.toString(), QString(), item);
}
Example #10
0
QVariant QgsComposerModel::data( const QModelIndex &index, int role ) const
{
  if ( !index.isValid() )
    return QVariant();

  QgsComposerItem *item = itemFromIndex( index );
  if ( !item )
  {
    return QVariant();
  }

  switch ( role )
  {
    case Qt::DisplayRole:
      if ( index.column() == ItemId )
      {
        return item->displayName();
      }
      else
      {
        return QVariant();
      }

    case Qt::EditRole:
      if ( index.column() == ItemId )
      {
        return item->id();
      }
      else
      {
        return QVariant();
      }

    case Qt::UserRole:
      //store item uuid in userrole so we can later get the QModelIndex for a specific item
      return item->uuid();

    case Qt::TextAlignmentRole:
      return Qt::AlignLeft & Qt::AlignVCenter;

    case Qt::CheckStateRole:
      switch ( index.column() )
      {
        case Visibility:
          //column 0 is visibility of item
          return item->isVisible() ? Qt::Checked : Qt::Unchecked;
        case LockStatus:
          //column 1 is locked state of item
          return item->positionLock() ? Qt::Checked : Qt::Unchecked;
        default:
          return QVariant();
      }

    case Qt::FontRole:
      if ( index.column() == ItemId && item->isSelected() )
      {
        //draw name of selected items in bold
        QFont boldFont;
        boldFont.setBold( true );
        return boldFont;
      }
      else
      {
        return QVariant();
      }
      break;

    default:
      return QVariant();
  }
}
Example #11
0
 QTreeWidgetItem* itemFromIndex_natron(const QModelIndex & index) const
 {
     return itemFromIndex(index);
 }
void QgsDbTableModel::setGeometryTypesForTable( const QString& schema, const QString& table, const QString& attribute, const QString& type )
{
  bool typeIsEmpty = type.isEmpty(); //true means the table has no valid geometry entry and the item for this table should be removed
  QStringList typeList = type.split( "," );

  //find schema item and table item
  QStandardItem* schemaItem;
  QList<QStandardItem*> schemaItems = findItems( schema, Qt::MatchExactly, 0 );

  if ( schemaItems.size() < 1 )
  {
    return;
  }
  schemaItem = schemaItems.at( 0 );
  int numChildren = schemaItem->rowCount();

  QModelIndex currentChildIndex;
  QModelIndex currentTableIndex;
  QModelIndex currentTypeIndex;
  QModelIndex currentGeomColumnIndex;

  for ( int i = 0; i < numChildren; ++i )
  {
    currentChildIndex = indexFromItem( schemaItem->child( i, 0 ) );
    if ( !currentChildIndex.isValid() )
    {
      continue;
    }
    currentTableIndex = currentChildIndex.sibling( i, 1 );
    currentTypeIndex = currentChildIndex.sibling( i, 2 );
    currentGeomColumnIndex = currentChildIndex.sibling( i, 3 );
    QString geomColText = itemFromIndex( currentGeomColumnIndex )->text();

    if ( !currentTypeIndex.isValid() || !currentTableIndex.isValid() || !currentGeomColumnIndex.isValid() )
    {
      continue;
    }

    if ( itemFromIndex( currentTableIndex )->text() == table &&
         ( geomColText == attribute || geomColText.startsWith( attribute + " AS " ) ) )
    {
      if ( typeIsEmpty )
      {
        removeRow( i, indexFromItem( schemaItem ) );
        return;
      }

      QGis::WkbType wkbType = qgisTypeFromDbType( typeList.at( 0 ) );
      QIcon myIcon = iconForType( wkbType );
      itemFromIndex( currentTypeIndex )->setText( typeList.at( 0 ) ); //todo: add other rows
      itemFromIndex( currentTypeIndex )->setIcon( myIcon );
      if ( !geomColText.contains( " AS " ) )
      {
        itemFromIndex( currentGeomColumnIndex )->setText( geomColText + " AS " + typeList.at( 0 ) );
      }

      for ( int j = 1; j < typeList.size(); ++j )
      {
        //todo: add correct type
        addTableEntry( typeList.at( j ), schema, table, geomColText + " AS " + typeList.at( j ), "" );
      }
    }
  }
}
Example #13
0
void
SourceFileModel::moveSourceFilesUpOrDown(QList<SourceFile *> files,
                                         bool up) {
  sortSourceFiles(files, !up);

  // qDebug() << "move up?" << up << "files" << files;

  auto couldNotBeMoved = QHash<SourceFile *, bool>{};
  auto isSelected      = QHash<SourceFile *, bool>{};
  auto const direction = up ? -1 : +1;
  auto const topRows   = rowCount();

  for (auto const &file : files) {
    isSelected[file] = true;

    if (!file->isRegular() && isSelected[file->m_appendedTo])
      continue;

    auto idx = indexFromSourceFile(file);
    Q_ASSERT(idx.isValid());

    auto targetRow = idx.row() + direction;
    if (couldNotBeMoved[fromIndex(idx.sibling(targetRow, 0)).get()]) {
      couldNotBeMoved[file] = true;
      continue;
    }

    if (file->isRegular()) {
      if (!((0 <= targetRow) && (targetRow < topRows))) {
        couldNotBeMoved[file] = true;
        continue;
      }

      // qDebug() << "top level: would like to move" << idx.row() << "to" << targetRow;

      insertRow(targetRow, takeRow(idx.row()));

      continue;
    }

    auto parentItem                   = itemFromIndex(idx.parent());
    auto const appendedAdditionalRows = countAppendedAndAdditionalParts(parentItem);
    auto const additionalPartsRows    = appendedAdditionalRows.first;
    auto const appendedRows           = appendedAdditionalRows.second;
    auto const lowerLimit             = (file->isAdditionalPart() ? 0 : additionalPartsRows);
    auto const upperLimit             = (file->isAdditionalPart() ? 0 : appendedRows) +  additionalPartsRows;

    if ((lowerLimit <= targetRow) && (targetRow < upperLimit)) {
      // qDebug() << "appended level normal: would like to move" << idx.row() << "to" << targetRow;

      parentItem->insertRow(targetRow, parentItem->takeRow(idx.row()));
      continue;
    }

    auto parentIdx = parentItem->index();
    Q_ASSERT(parentIdx.isValid());

    auto newParentRow = parentIdx.row() + direction;
    if ((0 > newParentRow) || (rowCount() <= newParentRow)) {
      // qDebug() << "appended, cannot move further";
      couldNotBeMoved[file] = true;
      continue;
    }

    auto newParent        = fromIndex(index(newParentRow, 0));
    auto newParentItem    = itemFromIndex(index(newParentRow, 0));
    auto rowItems         = parentItem->takeRow(idx.row());
    auto newParentNumbers = countAppendedAndAdditionalParts(newParentItem);
    targetRow             = up  && file->isAdditionalPart() ? newParentNumbers.first
                          : up                              ? newParentNumbers.first + newParentNumbers.second
                          : !up && file->isAdditionalPart() ? 0
                          :                                   newParentNumbers.first;

    Q_ASSERT(!!newParent);

    // qDebug() << "appended level cross: would like to move" << idx.row() << "from" << file->m_appendedTo << "to" << newParent.get() << "as" << targetRow;

    newParentItem->insertRow(targetRow, rowItems);
    file->m_appendedTo = newParent.get();
  }

  updateSourceFileLists();
}
Example #14
0
void QgsPgTableModel::setSql( const QModelIndex &index, const QString &sql )
{
  if ( !index.isValid() || !index.parent().isValid() )
  {
    return;
  }

  //find out schema name and table name
  QModelIndex schemaSibling = index.sibling( index.row(), dbtmSchema );
  QModelIndex tableSibling = index.sibling( index.row(), dbtmTable );
  QModelIndex geomSibling = index.sibling( index.row(), dbtmGeomCol );

  if ( !schemaSibling.isValid() || !tableSibling.isValid() || !geomSibling.isValid() )
  {
    return;
  }

  QString schemaName = itemFromIndex( schemaSibling )->text();
  QString tableName = itemFromIndex( tableSibling )->text();
  QString geomName = itemFromIndex( geomSibling )->text();

  QList<QStandardItem*> schemaItems = findItems( schemaName, Qt::MatchExactly, dbtmSchema );
  if ( schemaItems.size() < 1 )
  {
    return;
  }

  QStandardItem* schemaItem = schemaItems.at( dbtmSchema );

  int n = schemaItem->rowCount();
  for ( int i = 0; i < n; i++ )
  {
    QModelIndex currentChildIndex = indexFromItem( schemaItem->child( i, dbtmSchema ) );
    if ( !currentChildIndex.isValid() )
    {
      continue;
    }

    QModelIndex currentTableIndex = currentChildIndex.sibling( i, dbtmTable );
    if ( !currentTableIndex.isValid() )
    {
      continue;
    }

    QModelIndex currentGeomIndex = currentChildIndex.sibling( i, dbtmGeomCol );
    if ( !currentGeomIndex.isValid() )
    {
      continue;
    }

    if ( itemFromIndex( currentTableIndex )->text() == tableName && itemFromIndex( currentGeomIndex )->text() == geomName )
    {
      QModelIndex sqlIndex = currentChildIndex.sibling( i, dbtmSql );
      if ( sqlIndex.isValid() )
      {
        itemFromIndex( sqlIndex )->setText( sql );
        break;
      }
    }
  }
}
Example #15
0
Qt::ItemFlags TreeModel::flags(const QModelIndex &idx) const
{
    TreeItem *item = itemFromIndex(idx);
    return item ? item->flags(idx.column())
                : (Qt::ItemIsEnabled|Qt::ItemIsSelectable);
}
Example #16
0
bool QgsPgTableModel::setData( const QModelIndex &idx, const QVariant &value, int role )
{
  if ( !QStandardItemModel::setData( idx, value, role ) )
    return false;

  if ( idx.column() == dbtmType || idx.column() == dbtmSrid || idx.column() == dbtmPkCol )
  {
    QgsWkbTypes::Type wkbType = ( QgsWkbTypes::Type ) idx.sibling( idx.row(), dbtmType ).data( Qt::UserRole + 2 ).toInt();

    QString tip;
    if ( wkbType == QgsWkbTypes::Unknown )
    {
      tip = tr( "Specify a geometry type in the '%1' column" ).arg( tr( "Data Type" ) );
    }
    else if ( wkbType != QgsWkbTypes::NoGeometry )
    {
      bool ok;
      int srid = idx.sibling( idx.row(), dbtmSrid ).data().toInt( &ok );

      if ( !ok || srid == INT_MIN )
        tip = tr( "Enter a SRID into the '%1' column" ).arg( tr( "SRID" ) );
    }

    QStringList pkCols = idx.sibling( idx.row(), dbtmPkCol ).data( Qt::UserRole + 1 ).toStringList();
    if ( tip.isEmpty() && !pkCols.isEmpty() )
    {
      QSet<QString> s0( idx.sibling( idx.row(), dbtmPkCol ).data( Qt::UserRole + 2 ).toStringList().toSet() );
      QSet<QString> s1( pkCols.toSet() );
      if ( s0.intersect( s1 ).isEmpty() )
        tip = tr( "Select columns in the '%1' column that uniquely identify features of this layer" ).arg( tr( "Feature id" ) );
    }

    for ( int i = 0; i < dbtmColumns; i++ )
    {
      QStandardItem *item = itemFromIndex( idx.sibling( idx.row(), i ) );
      if ( tip.isEmpty() )
      {
        if ( i == dbtmSchema )
        {
          item->setData( QVariant(), Qt::DecorationRole );
        }

        item->setFlags( item->flags() | Qt::ItemIsSelectable );
        item->setToolTip( "" );
      }
      else
      {
        item->setFlags( item->flags() & ~Qt::ItemIsSelectable );

        if ( i == dbtmSchema )
          item->setData( QgsApplication::getThemeIcon( "/mIconWarning.svg" ), Qt::DecorationRole );

        if ( i == dbtmSchema || i == dbtmTable || i == dbtmGeomCol )
        {
          item->setFlags( item->flags() );
          item->setToolTip( tip );
        }
      }
    }
  }

  return true;
}
Example #17
0
BasketListViewItem* BasketTreeListView::getBasketInTree(const QModelIndex& index) const
{
    QTreeWidgetItem* item = itemFromIndex(index);
    return dynamic_cast<BasketListViewItem*>(item);
}
Example #18
0
void TTreeWidget::rowsInserted( const QModelIndex & parent, int start, int end )
{
    // determine position in parent list

    if( mIsDropAction )
    {
        QModelIndex child = parent.child( start, 0 );
        int parentPosition = parent.row();
        int childPosition = child.row();
        if( mChildID == 0 )
        {
            if( ! parent.model() ) goto END;
            if( ! mpHost ) goto END;
            mChildID = parent.model()->index( start, 0 ).data( Qt::UserRole ).toInt();
        }
        int newParentID = parent.data( Qt::UserRole ).toInt();
        if( mIsTriggerTree )
            mpHost->getTriggerUnit()->reParentTrigger( mChildID, mOldParentID, newParentID, parentPosition, childPosition );
        if( mIsAliasTree )
            mpHost->getAliasUnit()->reParentAlias( mChildID, mOldParentID, newParentID, parentPosition, childPosition );
        if( mIsKeyTree )
            mpHost->getKeyUnit()->reParentKey( mChildID, mOldParentID, newParentID, parentPosition, childPosition );

        if( mIsTimerTree )
        {
            mpHost->getTimerUnit()->reParentTimer( mChildID, mOldParentID, newParentID, parentPosition, childPosition );
            TTimer * pTChild = mpHost->getTimerUnit()->getTimer( mChildID );
            //TTimer * pTnewParent = mpHost->getTimerUnit()->getTimer( newParentID );
            if( pTChild )
            {
                QIcon icon;
                if( pTChild->isOffsetTimer() )
                {
                    if( pTChild->shouldBeActive() )
                    {
                        icon.addPixmap(QPixmap(QString::fromUtf8(":/icons/offsettimer-on.png")), QIcon::Normal, QIcon::Off);
                    }
                    else
                    {
                        icon.addPixmap(QPixmap(QString::fromUtf8(":/icons/offsettimer-off.png")), QIcon::Normal, QIcon::Off);
                    }
                }
                else
                {
                    if( pTChild->shouldBeActive() )
                    {
                        icon.addPixmap(QPixmap(QString::fromUtf8(":/icons/tag_checkbox_checked.png")), QIcon::Normal, QIcon::Off);
                    }
                    else
                    {
                        icon.addPixmap(QPixmap(QString::fromUtf8(":/icons/tag_checkbox.png")), QIcon::Normal, QIcon::Off);
                    }
                }
                QTreeWidgetItem * pParent = itemFromIndex( parent );
                if( ! pParent ) goto END;
                for( int i=0; i<pParent->childCount(); i++ )
                {
                    QTreeWidgetItem * pItem = pParent->child(i);
                    if( ! pItem ) goto END;
                    int id = pItem->data(0, Qt::UserRole).toInt();
                    if( id == mChildID )
                    {
                        pItem->setIcon(0, icon);
                    }
                }
            }
        }
        if( mIsScriptTree )
            mpHost->getScriptUnit()->reParentScript( mChildID, mOldParentID, newParentID, parentPosition, childPosition );
        if( mIsActionTree )
        {
            mpHost->getActionUnit()->reParentAction( mChildID, mOldParentID, newParentID, parentPosition, childPosition );
            mpHost->getActionUnit()->updateToolbar();
        }

        mChildID = 0;
        mOldParentID = 0;
        mIsDropAction = false;
    }
    END: QTreeWidget::rowsInserted( parent, start, end );
}
Example #19
0
void TodoModel::setCategory(const QModelIndex &index, const QColor &color)
{
    QStandardItem *item = itemFromIndex(index);
    item->setData(color, Qt::BackgroundRole);
}