Ejemplo n.º 1
0
// The actual magic shouldn't be hard. Once we trap the signal, find the
// recipe, remove it from the parent and add it to the target folder.
// It is not easy. Indexes are ephemeral things. We MUST calculate the insert
// index after we have removed the recipe. BAD THINGS happen otherwise.
// 
void BtTreeModel::folderChanged(QString name)
{
   BeerXMLElement* test = qobject_cast<BeerXMLElement*>(sender());
   QModelIndex ndx, pIndex;
   bool expand = true;

   if ( ! test )
      return;

   // Find it.
   ndx = findElement(test);
   if ( ! ndx.isValid() )
   {
      Brewtarget::logW("folderChanged:: could not find element");
      return;
   }

   pIndex = parent(ndx); // Get the parent
   // If the parent isn't valid, its the root
   if ( ! pIndex.isValid() )
      pIndex = createIndex(0,0,rootItem->child(0));
   
   int i = item(ndx)->childNumber();

   // Remove it
   if ( ! removeRows(i, 1, pIndex) )
   {
      Brewtarget::logW("folderChanged:: could not remove row");
      return;
   }

   // Find the new parent
   // That's awkward, but dropping a folder prolly does need a the folder
   // created.
   QModelIndex newNdx = findFolder(test->folder(), rootItem->child(0), true);
   if ( ! newNdx.isValid() )
   {
      newNdx = createIndex(0,0,rootItem->child(0));
      expand = false;
   }
   
   BtTreeItem* local = item(newNdx);
   int j = local->childCount();

   if ( !  insertRow(j,newNdx,test,_type) )
   {
      Brewtarget::logW("folderChanged:: could not insert row");
      return;
   }
   // If we have brewnotes, set them up here.
   if ( treeMask & RECIPEMASK )
      addBrewNoteSubTree(qobject_cast<Recipe*>(test),j,local);

   if ( expand )
      emit expandFolder(treeMask,newNdx);
   return;
}
Ejemplo n.º 2
0
void pgpid_item_model::data_updated(std::list<RsPgpId> &new_neighs)
{

    //shit code follow (rewrite this please)
    size_t old_size = neighs.size(), new_size = 0;
    std::list<RsPgpId> old_neighs = neighs;

    new_size = new_neighs.size();
    //set model data to new cleaned up data
    neighs = new_neighs;
    neighs.sort();
    neighs.unique(); //remove possible dups

    //reflect actual row count in model
    if(old_size < new_size)
    {
        beginInsertRows(QModelIndex(), old_size, new_size);
        insertRows(old_size, new_size - old_size);
        endInsertRows();
    }
    else if(new_size < old_size)
    {
        beginRemoveRows(QModelIndex(), new_size, old_size);
        removeRows(old_size, old_size - new_size);
        endRemoveRows();
    }
    //update data in ui, to avoid unnecessary redraw and ui updates, updating only changed elements
    //TODO: libretroshare should implement a way to obtain only changed elements via some signalling non-blocking api.
    {
        size_t ii1 = 0;
        for(auto i1 = neighs.begin(), end1 = neighs.end(), i2 = old_neighs.begin(), end2 = old_neighs.end(); i1 != end1; ++i1, ++i2, ii1++)
        {
            if(i2 == end2)
                break;
            if(*i1 != *i2)
            {
                QModelIndex topLeft = createIndex(ii1,0), bottomRight = createIndex(ii1, COLUMN_COUNT-1);
                emit dataChanged(topLeft, bottomRight);
            }
        }
    }
    if(new_size > old_size)
    {
        QModelIndex topLeft = createIndex(old_size ? old_size -1 : 0 ,0), bottomRight = createIndex(new_size -1, COLUMN_COUNT-1);
        emit dataChanged(topLeft, bottomRight);
    }
    //dirty solution for initial data fetch
    //TODO: do it properly!
    if(!old_size)
    {
        beginResetModel();
        endResetModel();
    }

    //shit code end
}
Ejemplo n.º 3
0
//SLOT:setVar : changement de l'id de la variable et traçage du Tri à plat
void TaP::setVar(QIntList id)
{
    //On prend la première variable si plusieurs sont sélectionnées
    var_courante=this->population->pVar(id.at(0));
    this->setNom(var_courante->Nom());
    this->typeVar=var_courante->Type();

        while(columnCount()>3)
        {removeColumn(columnCount()-1);}

        if(rowCount()>0)
        {
            removeRows(0,rowCount());
        }
        setNomVar(0, "Modalités");
        setNomVar(1, "Effectifs");
        setNomVar(2, "Fréquences");

        TAP_DONNEES donnees;
        donnees.Charger(var_courante);

        switch(typeVar)
        {
            case TYPES::QUALITATIF_ORDINAL:
                addColumn();
                setNomVar(3, "Fréquences Cumulées");
                setTypeVar(3, TYPES::QUALITATIF_PURE);
                break;
            case TYPES::QUANTITATIF_DISCRET:
                addColumn();
                setNomVar(3, "Fréquences Cumulées");
                setTypeVar(3, TYPES::QUALITATIF_PURE);
                break;
            case TYPES::QUANTITATIF_CONTINU_PURE:
                addColumn();
                setNomVar(3, "Fréquences Cumulées");
                setTypeVar(3, TYPES::QUALITATIF_PURE);
                break;
        }
        for(int i=0; i<donnees.Modalites().size();i++)
        {
            if(i==rowCount())
            {
                addRows();
            }
            setData(0, i, donnees.Modalites().at(i));
            setData(1, i, donnees.Effectifs().at(i));
            setData(2, i, donnees.Frequences().at(i));
            if(donnees.FrequencesCumulees().size())
            {setData(3,i, donnees.FrequencesCumulees().at(i));}
        }
        addRows();
        setData(0,rowCount()-1,"TOTAL");
        setData(1,rowCount()-1,population->NbValideString(id.at(0)));
        setData(2,rowCount()-1,"1,00");
}
Ejemplo n.º 4
0
    void IdCollection<ESXRecordT>::load (ESM::ESMReader& reader, bool base)
    {
        std::string id = reader.getHNOString ("NAME");

        if (reader.isNextSub ("DELE"))
        {
            int index = searchId (id);

            reader.skipRecord();

            if (index==-1)
            {
                // deleting a record that does not exist

                // ignore it for now

                /// \todo report the problem to the user
            }
            else if (base)
            {
                removeRows (index, 1);
            }
            else
            {
                mRecords[index].mState = RecordBase::State_Deleted;
            }
        }
        else
        {
            ESXRecordT record;
            record.mId = id;
            record.load (reader);

            int index = searchId (record.mId);

            if (index==-1)
            {
                // new record
                Record<ESXRecordT> record2;
                record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
                (base ? record2.mBase : record2.mModified) = record;

                appendRecord (record2);
            }
            else
            {
                // old record
                Record<ESXRecordT>& record2 = mRecords[index];

                if (base)
                    record2.mBase = record;
                else
                    record2.setModified (record);
            }
        }
    }
Ejemplo n.º 5
0
bool NotifyTableModel::dropMimeData( const QMimeData * data, Qt::DropAction action, int row,
                   int column, const QModelIndex& parent)
{
    if (action == Qt::IgnoreAction)
        return true;

    if (!data->hasFormat(mime_type_notify_table))
        return false;

    int beginRow = -1;

    if (row != -1)
        beginRow = row;
    else {
        if (parent.isValid())
            beginRow = parent.row();
        else
            beginRow = rowCount(QModelIndex());
    }

    if (-1 == beginRow)
        return false;

    QByteArray encodedData = data->data(mime_type_notify_table);
    QDataStream stream(&encodedData, QIODevice::ReadOnly);
    int rows = beginRow;
    // read next item from input MIME and drop into the table line by line
    while(!stream.atEnd()) {
        quintptr ptr;
        stream >> ptr;
        NotificationItem* item = reinterpret_cast<NotificationItem*>(ptr);
        int dragged = _list.indexOf(item);
        // we can drag item from top rows to bottom (DOWN_DIRECTION),
        // or from bottom rows to top rows (UP_DIRECTION)
        enum { UP_DIRECTION, DOWN_DIRECTION };
        int direction = (dragged < rows) ? DOWN_DIRECTION : (dragged += 1, UP_DIRECTION);
        // check drop bounds
        if (dragged < 0 || ((dragged + 1) >= _list.size() && direction == DOWN_DIRECTION)  || dragged == rows) {
            qNotifyDebug() << "no such item";
            continue;
        }
        // addiional check in case dropping of multiple rows
        if(rows + direction > _list.size()) continue;

        Q_ASSERT(insertRows(rows + direction, 1, QModelIndex()));
        _list.replace(rows + direction, item);
        Q_ASSERT(removeRows(dragged, 1, QModelIndex()));
        if (direction == UP_DIRECTION)
            ++rows;
    };

    QModelIndex idxTopLeft = index(beginRow, 0, QModelIndex());
    QModelIndex idxBotRight = index(beginRow, columnCount(QModelIndex()), QModelIndex());
    emit dataChanged(idxTopLeft, idxBotRight);
    return true;
}
void LibrarySourcesTableModel::set(const QList<LibrarySource>& sources)
{
    if (!this->sources.empty())
        removeRows(0, this->sources.size(), QModelIndex());
    if (sources.empty())
        return;
    beginInsertRows(QModelIndex(), 0, sources.size() - 1);
    this->sources = sources;
    endInsertRows();
}
Ejemplo n.º 7
0
void ConfMat::setRowCount(int newRowCount)
{
    int curRowCount = this->getRowCount();
    if (curRowCount == newRowCount)
        return;
    if (curRowCount < newRowCount)
        insertRows(qMax(curRowCount, 0), newRowCount - curRowCount);
    else
        removeRows(qMax(newRowCount, 0), curRowCount - newRowCount);
}
Ejemplo n.º 8
0
void ObjectModel::removeItem(QModelIndex &index)
{
    if (!index.isValid())
    {
        return;
    }

    qDebug() << "removeItem row:" << index.row() << "p:" << index.internalPointer();
    removeRows(index.row(), 1, index.parent());
}
Ejemplo n.º 9
0
void DbGpfsInfo::upsertInfo(SQLHSTMT sqlStmt)
{
    removeRows(sqlStmt,tmptableName);     //clear all related temp tables at first
    fillTable(sqlStmt,tmptableName); //fill temp table
    
    queryTable(sqlStmt,tmptableName,&tempInfo);//query temp table
    queryTable(sqlStmt,tableName,&lastInfo); //query regular table

    updateRegularTable(sqlStmt,tableName, tempInfo, lastInfo); //update regular table
    
}
Ejemplo n.º 10
0
    void MagnetModel::onUpdateQueue(bt::Uint32 idx, bt::Uint32 count)
    {
        int rows = mman->count();
        if (currentRows < rows)  // add new rows
            insertRows(idx, rows - currentRows, QModelIndex());
        else if (currentRows > rows) // delete rows
            removeRows(idx, currentRows - rows, QModelIndex());

        currentRows = rows;
        emit dataChanged(index(idx, 0), index(count, columnCount(QModelIndex())));
    }
Ejemplo n.º 11
0
int QAbstractItemModel_removeRows(lua_State* const state)
{
    auto self = lua::get<QAbstractItemModel*>(state, 1);

    // virtual bool     removeRows(int row, int count, const QModelIndex & parent = QModelIndex())
    if (lua_gettop(state) == 3) {
        lua::push(state, self->removeRows(
            lua::get<int>(state, 2),
            lua::get<int>(state, 3)
        ));
    } else {
        lua::push(state, self->removeRows(
            lua::get<int>(state, 2),
            lua::get<int>(state, 3),
            lua::get<const QModelIndex&>(state, 4)
        ));
    }

    return 1;
}
Ejemplo n.º 12
0
bool CQCompartmentDM::clear()
{
  QModelIndexList rows;

  for (int i = 0; i < mpCompartments->size(); i++)
    {
      rows.append(index(i, 0));
    }

  return removeRows(rows);
}
Ejemplo n.º 13
0
void QgsAttributeTableModel::layerDeleted()
{
  mLayerCache = nullptr;
  removeRows( 0, rowCount() );

  mAttributeWidgetCaches.clear();
  mAttributes.clear();
  mWidgetFactories.clear();
  mWidgetConfigs.clear();
  mFieldFormatters.clear();
}
Ejemplo n.º 14
0
void FXTabSim::sacarCTRL(void) {

	printf("indexCtrl: %d tope: %d\n", indexCtrl, tope);

	// removeRows(indexCtrl, tope-indexCtrl+1);
	removeRows(indexCtrl);

	tope = indexCtrl-1;

	printf("Nuevo tope: %d\n", tope);
	}
Ejemplo n.º 15
0
/**
 * Removes the TreeItem with the given name including all its children
 */
void GeoTreeModel::removeGeoList(const std::string &name, GeoLib::GEOTYPE type)
{
	for (size_t i = 0; i < _lists.size(); i++)
		if ( name.compare( _lists[i]->data(0).toString().toStdString() ) == 0 )
		{
			for (int j = 0; j < _lists[i]->childCount(); j++)
				if (type ==
				    static_cast<GeoObjectListItem*>(_lists[i]->child(j))->getType())
				{
					QModelIndex index = createIndex(j, 0, _lists[i]->child(j));
					removeRows(0, _lists[i]->child(j)->childCount(), index);
					removeRows(j, 1, parent(index));
					break;
				}
			if (_lists[i]->childCount() == 0)
			{
				_lists.erase(_lists.begin() + i);
				removeRows(i, 1, QModelIndex());
			}
		}
}
Ejemplo n.º 16
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;
}
Ejemplo n.º 17
0
void
TableModel::setRowCount(int rows)
{
    if ( (rows < 0) || (_imp->rowCount == rows) ) {
        return;
    }
    if (_imp->rowCount < rows) {
        insertRows(std::max(_imp->rowCount, 0), rows - _imp->rowCount);
    } else {
        removeRows(std::max(rows, 0), _imp->rowCount - rows);
    }
}
Ejemplo n.º 18
0
    void  Collection<ESXRecordT, IdAccessorT>::purge()
    {
        int i = 0;

        while (i<static_cast<int> (mRecords.size()))
        {
            if (mRecords[i].isErased())
                removeRows (i, 1);
            else
                ++i;
        }
    }
Ejemplo n.º 19
0
void LabelView::Refresh(void)
{
  _mutex.lock();
  auto pModel = model();
  pModel->removeRows(0, pModel->rowCount());
  _mutex.unlock();

  m_rDoc.ForEachLabel([&](medusa::Address const& rAddr, medusa::Label const& rLbl)
  {
    emit labelAdded(rAddr, rLbl);
  });
}
Ejemplo n.º 20
0
void MatrixModel::setRowCount(int rows) {
  if (d_rows == rows)
    return;

  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));

  if (rows > d_rows)
    insertRows(d_rows, rows - d_rows);
  else if (rows < d_rows)
    removeRows(rows, d_rows - rows);

  QApplication::restoreOverrideCursor();
}
void QgsAttributeTableModel::layerDeleted()
{
  QgsDebugMsg( "entered." );

  beginRemoveRows( QModelIndex(), 0, rowCount() - 1 );
  removeRows( 0, rowCount() );
  endRemoveRows();

  mAttributeWidgetCaches.clear();
  mAttributes.clear();
  mWidgetFactories.clear();
  mWidgetConfigs.clear();
}
Ejemplo n.º 22
0
void XModel::deleteRecordById(QString id){
	setFilter(QString("%1.id = '%2'").arg(m_tbl).arg(id));
	if (rowCount() == 1) {
	    bool b = removeRows(0, 1);
	    if(b == false){
	    	QSqlError err = lastError();
	    	yERROR(err.text());
	    }
	    submit();
	} else {
		yERROR(QString("Can't find %1 to delete.").arg(id));
	}
}
Ejemplo n.º 23
0
bool BtTreeModel::renameFolder(BtFolder* victim, QString newName)
{
   QModelIndex ndx = findFolder(victim->fullPath(), 0, false);
   QModelIndex pInd; 
   QString targetPath = newName % "/" % victim->name();
   QPair<QString,BtTreeItem*> f;
   QList<QPair<QString, BtTreeItem*> > folders;
   // This space is important       ^
   int i;

   if ( ! ndx.isValid() )
      return false;

   pInd = parent(ndx);
   if ( ! pInd.isValid() )
      return false;

   BtTreeItem* start = item(ndx);
   f.first  = targetPath;
   f.second = start;

   folders.append(f);

   while ( ! folders.isEmpty() )
   {
      // This looks weird, but it is needed for later
      f = folders.takeFirst();
      targetPath = f.first;
      BtTreeItem* target = f.second;

      // Ok. We have a start and an index.
      for (i=0; i < target->childCount(); ++i)
      {
         BtTreeItem* next = target->child(i);
         // If a folder, push it onto the folders stack for latter processing
         if ( next->type() == BtTreeItem::FOLDER ) 
         {
            QPair<QString,BtTreeItem*> newTarget;
            newTarget.first = targetPath % "/" % next->name();
            newTarget.second = next;
            folders.append(newTarget);
         }
         else // Leafnode
            next->thing()->setFolder(targetPath);
      }
   }
   // Last thing is to remove the victim. 
   i = start->childNumber();
   return removeRows(i, 1, pInd); 
}
Ejemplo n.º 24
0
bool
IssueModel::removeRowsFrom( int row )
{
    ENTER()(row);

    int end = rowCount() - 1;

    if( row > end )
        RETURN( false );

    int count = end - row + 1;

    RETURN( removeRows(row, count) );
}
Ejemplo n.º 25
0
void MatrixModel::setDimensions(int rows, int cols) {
  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));

  if (rows < d_rows) { // first remove rows (faster)
    removeRows(rows, d_rows - rows);
    setColumnCount(cols);
  } else {
    setColumnCount(cols);
    if (rows > d_rows)
      insertRows(d_rows, rows - d_rows);
  }

  QApplication::restoreOverrideCursor();
}
Ejemplo n.º 26
0
void MSimularCuotas::setCuotas( int c )
{
    int ant = cantidad;
    cantidad = c;
    if( ant < c ) {
        emit beginInsertRows( QModelIndex(), ant, c );
        insertRows( ant, c );
        emit endInsertRows();
    } else {
        emit beginRemoveRows( QModelIndex(), c, ant );
        removeRows( c, ant );
        emit endRemoveRows();
    }
}
Ejemplo n.º 27
0
void StatusModel::populate()
{
    if ( rowCount() < maxStatusCount ) {
        for ( int i = rowCount(); i < maxStatusCount; ++i ) {
            StatusWidget *status = new StatusWidget( this );
            QStandardItem *newItem = new QStandardItem;
            newItem->setSizeHint( status->size() );
            appendRow( newItem );
            view->setIndexWidget( newItem->index(), status );
        }
    } else {
        removeRows( maxStatusCount, rowCount() - maxStatusCount );
    }
}
Ejemplo n.º 28
0
    /**
     * @brief ProjectTreeModel::removeScope
     * @param scopeId
     * @param projectId
     */
    void ProjectTreeModel::removeScope(const common::ID &scopeId, const QString &projectName)
    {
        if (auto &&pr = find(projectName)) {
            auto &&projectIndex = index(indexOf(pr), 0);
            Q_ASSERT(projectIndex.isValid());

            if (auto &&scope = pr->itemById(QVariant::fromValue(scopeId))) {
                auto &&scopeIndex = projectIndex.child(pr->rowForItem(scope), 0);
                Q_ASSERT(scopeIndex.isValid());

                removeRows(scopeIndex.row(), 0, projectIndex);
            }
        }
    }
Ejemplo n.º 29
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;
    }
Ejemplo n.º 30
0
void CLlinesDoc::afterMove(int x, int y) {
      int numRows = checkRows(x, y);

        if (numRows > 0)
		{
           bonusMove = true;
         //   Toolkit.getDefaultToolkit().beep();
           // pView->drawCell(pDC,x, y);
            removeRows(x, y);
        }
		else 
		{
            bonusMove = false;
        }
    }