Exemple #1
0
 bool TreeModel::removeColumns(int position, int columns, const QModelIndex &parent)
 {
     bool success;

     beginRemoveColumns(parent, position, position + columns - 1);
     success = rootItem->removeColumns(position, columns);
     endRemoveColumns();

     if (rootItem->columnCount() == 0)
         removeRows(0, rowCount());

     return success;
 }
Exemple #2
0
bool FilterTable::removeColumns(int column, int count, const QModelIndex &parent) {
    beginRemoveColumns(parent, column, column+count-1);

    for(int pos = column; pos < column+count; ++pos)
        table.removeAt(pos);

    if((column + count) < table.size())
        for(int pos=column+count; pos < table.size(); ++pos)
            table.move(pos, pos-count);

    endRemoveColumns();
    return true;
}
bool PersonsTableModel::removeColumns(int column, int count, const QModelIndex &parent)
{
    if(column == 0)
        return false;
    Q_D(PersonsTableModel);
    beginRemoveColumns(parent, column, column+count);
    QList<QDate> dateToRemove = d->columns.mid(column-1, count);
    for(QList<Person>::Iterator personIter = d->persons.begin();
        personIter != d->persons.end();
        ++personIter) {
        foreach(const QDate& date, dateToRemove) {
            personIter->removeDate(date);
        }
    }
void QgsAttributeTableModel::loadAttributes()
{
  if ( !layer() )
  {
    return;
  }

  bool ins = false, rm = false;

  QgsAttributeList attributes;
  const QgsFields& fields = layer()->pendingFields();

  mWidgetFactories.clear();
  mAttributeWidgetCaches.clear();
  mWidgetConfigs.clear();

  for ( int idx = 0; idx < fields.count(); ++idx )
  {
    QgsEditorWidgetFactory* widgetFactory = QgsEditorWidgetRegistry::instance()->factory( layer()->editorWidgetV2( idx ) );

    mWidgetFactories.append( widgetFactory );
    mWidgetConfigs.append( layer()->editorWidgetV2Config( idx ) );
    mAttributeWidgetCaches.append( widgetFactory->createCache( layer(), idx, mWidgetConfigs.last() ) );

    attributes << idx;
  }

  if ( mFieldCount < attributes.size() )
  {
    ins = true;
    beginInsertColumns( QModelIndex(), mFieldCount, attributes.size() - 1 );
  }
  else if ( attributes.size() < mFieldCount )
  {
    rm = true;
    beginRemoveColumns( QModelIndex(), attributes.size(), mFieldCount - 1 );
  }

  mFieldCount = attributes.size();
  mAttributes = attributes;

  if ( ins )
  {
    endInsertColumns();
  }
  else if ( rm )
  {
    endRemoveColumns();
  }
}
Exemple #5
0
bool TableModel::removeColumns(int position, int columns, const QModelIndex &parent)
{
    int rows = rowCount();
    beginRemoveColumns(parent, position, position + columns - 1);

    for (int row = 0; row < rows; ++row) {
        for (int column = 0; column < columns; ++column) {
            rowList[row].removeAt(position);
        }
    }

    endRemoveColumns();
    return true;
}
void DataFrameModel::beginChanges(int nr, int nc) {
    if (_dataframe != R_NilValue) {
        int oldnr = rowCount(QModelIndex());
        int oldnc = columnCount(QModelIndex());
        if (oldnr > nr)
            beginRemoveRows(QModelIndex(), nr, oldnr - 1L);
        else if (oldnr < nr)
            beginInsertRows(QModelIndex(), oldnr, nr - 1L);
        if (oldnc > nc)
            beginRemoveColumns(QModelIndex(), nc, oldnc - 1L);
        else if (oldnc < nc)
            beginInsertColumns(QModelIndex(), oldnc, nc - 1L);
    }
}
Exemple #7
0
void WGTransposeProxy::setSourceModel(QAbstractItemModel* sourceModel)
{
	beginResetModel();
	connections_.reset();
	QAbstractProxyModel::setSourceModel(sourceModel);
	if (sourceModel != nullptr)
	{
		connections_ +=
		QObject::connect(sourceModel, &QAbstractItemModel::modelAboutToBeReset, [this]() { beginResetModel(); });
		connections_ += QObject::connect(sourceModel, &QAbstractItemModel::modelReset, [this]() { endResetModel(); });
		connections_ += QObject::connect(
		sourceModel, &QAbstractItemModel::dataChanged,
		[this](const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles) {
			auto proxyTopLeft = topLeft.isValid() ? index(topLeft.column(), topLeft.row()) : QModelIndex();
			auto proxyBottomRight =
			bottomRight.isValid() ? index(bottomRight.column(), bottomRight.row()) : QModelIndex();
			dataChanged(proxyTopLeft, proxyBottomRight, roles);
		});
		connections_ += QObject::connect(sourceModel, &QAbstractItemModel::rowsAboutToBeInserted,
		                                 [this](const QModelIndex& parent, int first, int last) {
			                                 TF_ASSERT(!parent.isValid());
			                                 beginInsertColumns(QModelIndex(), first, last);
			                             });
		connections_ +=
		QObject::connect(sourceModel, &QAbstractItemModel::rowsInserted, [this]() { endInsertColumns(); });
		connections_ += QObject::connect(sourceModel, &QAbstractItemModel::rowsAboutToBeRemoved,
		                                 [this](const QModelIndex& parent, int first, int last) {
			                                 TF_ASSERT(!parent.isValid());
			                                 beginRemoveColumns(QModelIndex(), first, last);
			                             });
		connections_ +=
		QObject::connect(sourceModel, &QAbstractItemModel::rowsRemoved, [this]() { endRemoveColumns(); });
		connections_ += QObject::connect(sourceModel, &QAbstractItemModel::columnsAboutToBeInserted,
		                                 [this](const QModelIndex& parent, int first, int last) {
			                                 TF_ASSERT(!parent.isValid());
			                                 beginInsertRows(QModelIndex(), first, last);
			                             });
		connections_ +=
		QObject::connect(sourceModel, &QAbstractItemModel::columnsInserted, [this]() { endInsertRows(); });
		connections_ += QObject::connect(sourceModel, &QAbstractItemModel::columnsAboutToBeRemoved,
		                                 [this](const QModelIndex& parent, int first, int last) {
			                                 TF_ASSERT(!parent.isValid());
			                                 beginRemoveRows(QModelIndex(), first, last);
			                             });
		connections_ +=
		QObject::connect(sourceModel, &QAbstractItemModel::columnsRemoved, [this]() { endRemoveRows(); });
	}
	endResetModel();
}
Exemple #8
0
    bool Gui::EntityTreeModel::removeColumns( int position, int columns, const QModelIndex& parent )
    {
        bool success;

        beginRemoveColumns( parent, position, position + columns - 1 );
        success = m_rootItem->removeColumns( position, columns );
        endRemoveColumns();

        if ( m_rootItem->getColumnCount() == 0 )
        {
            removeRows( 0, rowCount() );
        }

        return success;
    }
void QxtScheduleViewHeaderModel::setDataSource(QxtScheduleView *dataSource)
{
    if (this->m_dataSource)
    {
        disconnect(m_dataSource, SIGNAL(newZoomDepth(const int)), this, SLOT(newZoomDepth(const int)));
        disconnect(m_dataSource, SIGNAL(viewModeChanged(const int)), this, SLOT(viewModeChanged(const int)));

        emit beginRemoveRows(QModelIndex(), 0, m_rowCountBuffer);
        m_rowCountBuffer = 0;
        emit endRemoveRows();

        emit beginRemoveColumns(QModelIndex(), 0, m_colCountBuffer);
        m_colCountBuffer = 0;
        emit endRemoveColumns();
    }
Exemple #10
0
void AdjMatrixModel::decrementN()
{
    //do we need matrices of 1x1?
    if (n < 2)
        return;

    --n;
    beginRemoveRows(QModelIndex(), n, n);
    for(uint i = 0; i < n; ++i)
        els.remove(index(n-1, i));
    endRemoveRows();
    beginRemoveColumns(QModelIndex(), n, n);
    for(uint i = 0; i < n-1; ++i)
        els.remove(index(i, n-1));
    endRemoveColumns();
}
/*!
    Removes \a count columns from the model starting from position \a
    column. The \a parent parameter must always be an invalid
    QModelIndex, since the model does not support parent-child
    relationships.

    Removing columns effectively hides them. It does not affect the
    underlying QSqlQuery.

    Returns true if the columns were removed; otherwise returns false.
 */
bool QSqlQueryModel::removeColumns(int column, int count, const QModelIndex &parent)
{
    Q_D(QSqlQueryModel);
    if (count <= 0 || parent.isValid() || column < 0 || column >= d->rec.count())
        return false;

    beginRemoveColumns(parent, column, column + count - 1);

    int i;
    for (i = 0; i < count; ++i)
        d->rec.remove(column);
    for (i = column; i < d->colOffsets.count(); ++i)
        d->colOffsets[i] -= count;

    endRemoveColumns();
    return true;
}
void RKVarEditModel::objectRemoved (RObject* object) {
	RK_TRACE (EDITOR);

	int index = objects.indexOf (static_cast<RKVariable*> (object));	// no check for isVariable needed. we only need to look up, if we have this object, and where.
	if (index < var_col_offset) {
		if (index < 0) return;	// e.g. the data.frame object
		// the rownames object should only be deleted, when the whole data.frame is gone)
		RK_ASSERT (objects.size () <= var_col_offset);
	}

	beginRemoveColumns (QModelIndex (), index, index);
	if (meta_model) meta_model->beginRemoveDataObject (index);
	stopListenForObject (objects.takeAt (index));
	if (meta_model) meta_model->endRemoveDataObject ();
	endRemoveColumns ();

	if (objects.size () <= var_col_offset) emit (modelDepleted ());	// editor may or may want to auto-destruct
}
bool MatrixModel::removeColumns(int column, int count, const QModelIndex & parent)
{
	beginRemoveColumns(parent, column, column + count - 1);

    d_cols -= count;
	d_data_block_size = QSize(d_rows, d_cols);

    int size = d_rows*d_cols;
    for (int i = column; i < size; i++){
	    int aux = (i - column)/d_cols + 1;
        d_data[i] = d_data[i + aux*count];
	}

    d_data = (double *)realloc (d_data, size*sizeof(double));

	endRemoveColumns();
	return true;
}
Exemple #14
0
void CSMWorld::RegionMap::updateSize()
{
    std::pair<CellCoordinates, CellCoordinates> size = getSize();

    if (int diff = size.first.getX() - mMin.getX())
    {
        beginInsertColumns (QModelIndex(), 0, std::abs (diff)-1);
        mMin = CellCoordinates (size.first.getX(), mMin.getY());
        endInsertColumns();
    }

    if (int diff = size.first.getY() - mMin.getY())
    {
        beginInsertRows (QModelIndex(), 0, std::abs (diff)-1);
        mMin = CellCoordinates (mMin.getX(), size.first.getY());
        endInsertRows();
    }

    if (int diff = size.second.getX() - mMax.getX())
    {
        int columns = columnCount();

        if (diff>0)
            beginInsertColumns (QModelIndex(), columns, columns+diff-1);
        else
            beginRemoveColumns (QModelIndex(), columns+diff, columns-1);

        mMax = CellCoordinates (size.second.getX(), mMax.getY());
        endInsertColumns();
    }

    if (int diff = size.second.getY() - mMax.getY())
    {
        int rows = rowCount();

        if (diff>0)
            beginInsertRows (QModelIndex(), rows, rows+diff-1);
        else
            beginRemoveRows (QModelIndex(), rows+diff, rows-1);

        mMax = CellCoordinates (mMax.getX(), size.second.getY());
        endInsertRows();
    }
}
Exemple #15
0
void JobshopModel::setOperationsCount(int count)
{
    int cc = Jobshop::instance()->operationsCount();
    if(cc == count)
        return;

    if(cc > count)
    {
        beginRemoveColumns(QModelIndex(), columnCount()-1, m_nonOperationColumns + count);
        Jobshop::instance()->setOperationsCount(count);
        endRemoveColumns();
    }
    else if(cc < count)
    {
        beginInsertColumns(QModelIndex(), columnCount(), m_nonOperationColumns + count - 1);
        Jobshop::instance()->setOperationsCount(count);
        endInsertColumns();
    }
}
void FilterProxyModel::resizeToCfg (logs::LogConfig const & config)
{
  //@TODO: dedup: logtablemodel, findproxy, filterproxy
	if (config.m_columns_setup.size() > m_column_count)
	{
		int const last = config.m_columns_setup.size() - 1;
		beginInsertColumns(QModelIndex(), m_column_count, last);
		insertColumns(m_column_count, last);
		m_column_count = last + 1;
		endInsertColumns();
	}
  else if (config.m_columns_setup.size() < m_column_count)
	{
		int const last = config.m_columns_setup.size() + 1;
		beginRemoveColumns(QModelIndex(), last, m_column_count);
		removeColumns(last, m_column_count);
		m_column_count = last - 1;
		endInsertColumns();
	}
}
void DemandListModel::setNumberOfChoices(int n_choix){

	if(n_choix > 0){
		unsigned int n_c = (unsigned int) n_choix;

		if(_numberOfChoices != n_c){
			if(n_c < _numberOfChoices){
				beginRemoveColumns(QModelIndex(), 2 + n_c, 1 + _numberOfChoices);
				_numberOfChoices = n_c;
				endRemoveColumns();
			} else {
				beginInsertColumns(QModelIndex(), 2 + _numberOfChoices, 1 + n_c);
				_numberOfChoices = n_c;
				endInsertColumns();
			}
			emit(numberOfChoicesChanged(_numberOfChoices));
		}
	}

}
Exemple #18
0
void SparseItemModel::clear()
{
	assert(n_rows>=0);
	if(n_rows>0){
		beginRemoveRows(QModelIndex(), 0, n_rows-1);
		n_rows=0;
		endRemoveRows();
	}
	
	assert(n_columns>=0);
	if(n_columns>0){
		beginRemoveColumns(QModelIndex(), 0, n_columns-1);
		n_columns=0;
		endRemoveColumns();
	}

	items.clear();
	horizontalHeaderItems.clear();
	verticalHeaderItems.clear();
}
Exemple #19
0
bool QxtCsvModel::removeColumns(int col, int count, const QModelIndex& parent)
{
    if (parent!=QModelIndex() || col<0) return false;
    if (col>=columnCount()) return false;
    if (col+count>=columnCount()) count = columnCount()-col;
    emit beginRemoveColumns(parent, col, col+count);
    QxtCsvModelPrivate& d_ptr = qxt_d();
    QString before, after;
    for (int i=0; i<rowCount(); i++) {
        if (col>0)
            before = d_ptr.csvData[i].section(QChar(1),0,col-1)+QChar(1);
        else
            before = "";
        after = d_ptr.csvData[i].section(QChar(1),col+count);
        d_ptr.csvData[i] = before + after;
    }
    for (int i=0; i<count; i++)
        d_ptr.header.removeAt(col);
    emit endRemoveColumns();
    return true;
}
void mainCorrelationModel::remove(const correlationRow &key_)
{
    int x = -1;
    for(int i = 0; i < m_rows.count(); ++i)
        if (*static_cast<correlationRow*>(m_rows.at(i)) == key_)
        {
            x = i;
            break;
        }

    if (x == -1 || x >= m_rows.count() || m_viewableColumns.isEmpty())
        return;

    // remove row and column at the same time to prevent out of index exceptions
    beginRemoveRows(QModelIndex(), x, x);
    beginRemoveColumns(QModelIndex(), x, x);
    m_rows.removeAt(x);
    m_viewableColumns.removeLast();
    endRemoveRows();
    endRemoveColumns();
}
Exemple #21
0
void AkonadiBrowserModel::setItemDisplayMode(AkonadiBrowserModel::ItemDisplayMode itemDisplayMode)
{
    const int oldColumnCount = columnCount();
    m_itemDisplayMode = itemDisplayMode;
    AkonadiBrowserModel::State *newState = Q_NULLPTR;
    switch (itemDisplayMode) {
    case MailMode:
        newState = m_mailState;
        break;
    case ContactsMode:
        newState = m_contactsState;
        break;
    case CalendarMode:
        newState = m_calendarState;
        break;
    case GenericMode:
    default:
        newState = m_genericState;
        break;
    }
    const int newColumnCount = qMax(newState->m_collectionHeaders.count(), newState->m_itemHeaders.count());

    //qCDebug(AKONADICONSOLE_LOG) << "column count changed from" << oldColumnCount << "to" << newColumnCount;
    if (newColumnCount > oldColumnCount) {
        beginInsertColumns(QModelIndex(), oldColumnCount, newColumnCount - 1);
        m_currentState = newState;
        endInsertColumns();
    } else if (newColumnCount < oldColumnCount) {
        beginRemoveColumns(QModelIndex(), newColumnCount, oldColumnCount - 1);
        m_currentState = newState;
        endRemoveColumns();
    } else {
        m_currentState = newState;
    }
    headerDataChanged(Qt::Horizontal, 0, newColumnCount - 1);

    // The above is not enough to see the new headers, because EntityMimeTypeFilterModel gets column count and headers from our data,
    // and doesn't listen to dataChanged/headerDataChanged...
    columnsChanged();
}
void QxtScheduleViewHeaderModel::viewModeChanged(const int viewMode)
{
    Q_UNUSED(viewMode);

    if (this->m_dataSource)
    {
        beginRemoveRows(QModelIndex(), 0, m_rowCountBuffer);
        m_rowCountBuffer = 0;
        endRemoveRows();

        beginInsertRows(QModelIndex(), 0, m_dataSource->rows());
        m_rowCountBuffer = m_dataSource->rows();
        endInsertRows();

        beginRemoveColumns(QModelIndex(), 0, m_colCountBuffer);
        m_colCountBuffer = 0;
        endRemoveColumns();

        beginInsertColumns(QModelIndex(), 0, m_dataSource->cols());
        m_colCountBuffer = m_dataSource->cols();
        endInsertColumns();
    }
}
void ColumnNameResult::setColumnValues(QList<QStringList> columns)
{
	if (rowCount() != 1) {
		beginRemoveRows(QModelIndex(), 1, rowCount()-1);
		columnValues.clear();
		endRemoveRows();
	}
	if (columnCount() != 0) {
		beginRemoveColumns(QModelIndex(), 0, columnCount()-1);
		columnNames.clear();
		endRemoveColumns();
	}

	QStringList first = columns.first();
	beginInsertColumns(QModelIndex(), 0, first.count()-1);
	for(int i = 0; i < first.count(); i++)
		columnNames.append(QString());

	endInsertColumns();

	beginInsertRows(QModelIndex(), 0, columns.count()-1);
	columnValues = columns;
	endInsertRows();
}
void PriceItemDataSetViewModel::beginRemovePriceDataSets( int firstCol, int lastCol ){
    beginRemoveColumns( QModelIndex(), firstCol, lastCol );
}
void QgsAttributeTableFilterModel::setAttributeTableConfig( const QgsAttributeTableConfig& config )
{
  mConfig = config;
  mConfig.update( layer()->fields() );

  QVector<int> newColumnMapping;

  Q_FOREACH ( const QgsAttributeTableConfig::ColumnConfig& columnConfig, mConfig.columns() )
  {
    // Hidden? Forget about this column
    if ( columnConfig.hidden )
      continue;

    // The new value for the mapping (field index or -1 for action column)
    int newValue = ( columnConfig.type == QgsAttributeTableConfig::Action ) ? -1 : layer()->fieldNameIndex( columnConfig.name );
    newColumnMapping << newValue;
  }

  if ( newColumnMapping != mColumnMapping )
  {
    bool requiresReset = false;
    int firstRemovedColumn = -1;
    int removedColumnCount = 0;

    // Check if there have a contiguous set of columns have been removed or if we require a full reset
    for ( int i = 0; i < qMin( newColumnMapping.size(), mColumnMapping.size() - removedColumnCount ); ++i )
    {
      if ( newColumnMapping.at( i ) == mColumnMapping.at( i + removedColumnCount ) )
        continue;

      if ( firstRemovedColumn == -1 )
      {
        firstRemovedColumn = i;

        while ( i < mColumnMapping.size() - removedColumnCount && mColumnMapping.at( i + removedColumnCount ) != newColumnMapping.at( i ) )
        {
          ++removedColumnCount;
        }
      }
      else
      {
        requiresReset = true;
        break;
      }
    }

    // No difference found so far
    if ( firstRemovedColumn == -1 )
    {
      if ( newColumnMapping.size() > mColumnMapping.size() )
      {
        // More columns: appended to the end
        beginInsertColumns( QModelIndex(), mColumnMapping.size(), newColumnMapping.size() - 1 );
        mColumnMapping = newColumnMapping;
        endInsertColumns();
      }
      else
      {
        // Less columns: removed from the end
        beginRemoveColumns( QModelIndex(), newColumnMapping.size(), mColumnMapping.size() - 1 );
        mColumnMapping = newColumnMapping;
        endRemoveColumns();
      }
    }
    else
    {
      if ( newColumnMapping.size() == mColumnMapping.size() - removedColumnCount )
      {
        beginRemoveColumns( QModelIndex(), firstRemovedColumn, firstRemovedColumn + removedColumnCount );
        mColumnMapping = newColumnMapping;
        endRemoveColumns();
      }
      else
      {
        requiresReset = true;
      }
    }

    if ( requiresReset )
    {
      beginResetModel();
      mColumnMapping = newColumnMapping;
      endResetModel();
    }
  }

  sort( config.sortExpression(), config.sortOrder() );
}
void ActionsProxyModel::sourceColumnsAboutToBeRemoved(const QModelIndex &sourceParent, int start, int end)
{
    beginRemoveColumns(mapFromSource(sourceParent), start, end);
}
Exemple #27
0
void WSortFilterProxyModel::sourceColumnsAboutToBeRemoved
  (const WModelIndex& parent, int start, int end)
{ 
  beginRemoveColumns(mapFromSource(parent), start, end);
}
void RKVarEditMetaModel::beginRemoveDataObject (int index) {
	RK_TRACE (EDITOR);

	beginRemoveColumns (QModelIndex (), index, index);
}
void Utils::ModelListModel::handleColumnsAboutToBeRemoved(const QModelIndex& parent, int start, int end)
{
	QAbstractItemModel* senderModel = safeModelCast(sender());
	beginRemoveColumns(mapFromSource(qMakePair(senderModel, parent)), start, end);
}
Exemple #30
0
void NmProxy::onSourceColumnsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
{
    if (root == parent)
        beginRemoveColumns(mapFromSource(parent), first, last);
}