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 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;
}
Exemple #3
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 #4
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 #6
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;
}
void DataFrameModel::endChanges(int oldnr, int oldnc) {
    if (oldnr != -1) {
        int nr = rowCount(QModelIndex());
        int nc = columnCount(QModelIndex());
        if (oldnc > nc)
            endRemoveColumns();
        else if (oldnc < nc)
            endInsertColumns(); // just in case column names/roles changed
        else headerDataChanged(Qt::Horizontal, 0, nc);
        if (oldnr > nr) // insert rows
            endRemoveRows();
        else if (oldnr < nr)
            endInsertRows();
        else headerDataChanged(Qt::Vertical, 0, nr);
        // be lazy and just say everything changed
        // will not matter unless many rows/cols are in view (rare)
        dataChanged(index(0, 0), index(nr, nc));
    }
}
Exemple #11
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 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 #13
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();
}
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 #15
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;
}
Exemple #16
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 DhQAbstractProxyModel::DvhendRemoveColumns() {
  return endRemoveColumns();
}
Exemple #20
0
void WSortFilterProxyModel::sourceColumnsRemoved(const WModelIndex& parent,
						 int start, int end)
{ 
  endRemoveColumns();
}
void DhQAbstractTableModel::DvhendRemoveColumns() {
  return endRemoveColumns();
}
void RKVarEditMetaModel::endRemoveDataObject () {
	RK_TRACE (EDITOR);

	endRemoveColumns ();
}
Exemple #23
0
void WIdentityProxyModel::sourceColumnsRemoved(const WModelIndex &parent, int start, int end)
{
  endRemoveColumns();
}
void PriceItemDataSetViewModel::endRemovePriceDataSets( int firstCol, int lastCol ){
    Q_UNUSED(firstCol);
    Q_UNUSED(lastCol);
    endRemoveColumns();
}
Exemple #25
0
void WGMergeProxy::removeModel(QAbstractItemModel* model)
{
	if (model == nullptr)
	{
		return;
	}

	auto pos = 0;
	auto it = mappings_.begin();
	for (; it != mappings_.end(); ++it)
	{
		if ((*it)->model_ == model)
		{
			break;
		}
		orientation_ == Qt::Horizontal ? pos += (*it)->model_->columnCount() : (*it)->model_->rowCount();
	}
	if (it == mappings_.end())
	{
		return;
	}

	orientation_ == Qt::Horizontal ? beginRemoveColumns(QModelIndex(), pos, pos + model->columnCount() - 1) :
	                                 beginRemoveRows(QModelIndex(), pos, pos + model->rowCount() - 1);
	auto mapping = (*it).release();
	mappings_.erase(it);
	orientation_ == Qt::Horizontal ? endRemoveColumns() : endRemoveRows();

	for (auto mappingEntryIt = mapping->entries_.begin(); mappingEntryIt != mapping->entries_.end(); ++mappingEntryIt)
	{
		auto entryIndex = mappingEntryIt.key();
		auto entryIt = entries_.begin() + entryIndex;
		if (entryIt->second == 1)
		{
			auto pos = 0;
			for (auto i = 0; i < entryIndex; ++i)
			{
				if (entries_[i].second > 0)
				{
					++pos;
				}
			}
			orientation_ == Qt::Horizontal ? beginRemoveRows(QModelIndex(), pos, pos) :
			                                 beginRemoveColumns(QModelIndex(), pos, pos);
			--entryIt->second;
			orientation_ == Qt::Horizontal ? endRemoveRows() : endRemoveColumns();
		}
		else
		{
			--entryIt->second;
		}
	}

	auto rolesChanged = false;
	for (auto mappingRolesIt = mapping->roles_.begin(); mappingRolesIt != mapping->roles_.end(); ++mappingRolesIt)
	{
		auto role = mappingRolesIt.key();
		if (--roles_[role] == 0)
		{
			rolesChanged = true;
			beginResetModel();
			roleNames_.remove(role);
		}
	}

	if (rolesChanged)
	{
		endResetModel();
	}

	delete mapping;
}
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() );
}
Exemple #27
0
void NmProxy::onSourceColumnsRemoved(const QModelIndex &parent, int, int)
{
    if (root == parent)
        endRemoveColumns();
}
void Utils::ModelListModel::handleColumnsRemoved()
{
	endRemoveColumns();
	emit layoutChanged();
}
Exemple #29
0
void DhQDirModel::DvhendRemoveColumns() {
  return endRemoveColumns();
}