コード例 #1
0
bool ChannelModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
    if (m_currentLayer.isValid() && index.isValid())
    {
        QList<KoChannelInfo*> channels = m_currentLayer->colorSpace()->channels();
        int channelIndex = KoChannelInfo::displayPositionToChannelIndex(index.row(), channels);
        
        if (role == Qt::CheckStateRole) {
            Q_ASSERT(index.row() < rowCount());
            Q_ASSERT(index.column() < columnCount());
            
            if (index.column() == 0) {
                QBitArray flags = m_currentLayer->channelFlags();

                flags = flags.isEmpty() ? m_currentLayer->colorSpace()->channelFlags(true, true) : flags;
                flags.setBit(channelIndex, value.toInt() == Qt::Checked);
                m_currentLayer->setChannelFlags(flags);
            }
            else { //if (index.column() == 1)
                KisPaintLayer* paintLayer = dynamic_cast<KisPaintLayer*>(m_currentLayer.data());
                QBitArray      flags      = paintLayer->channelLockFlags();
                flags = flags.isEmpty() ? m_currentLayer->colorSpace()->channelFlags(true, true) : flags;
                flags.setBit(channelIndex, value.toInt() == Qt::Unchecked);
                paintLayer->setChannelLockFlags(flags);
            }
            
            m_currentLayer->setDirty();
            return true;
        }
    }
    return false;
}
コード例 #2
0
quint32 CBerBitStringStorage::deserialize(CBerByteArrayInputStream& iStream, QObject* obj, CBerLength& length, quint32 codeLength)
{
	length.decode(iStream);
	qDebug() << "CBerBitStringStorage::deserialize, length extracted: " << length.getVal();

	qint32 lenVal = length.getVal();

	QByteArray data(lenVal, Qt::Initialization::Uninitialized);

	if (data.size() > 0)
	{
		QBitArray val;

		qint32 rdLength = iStream.read(data, 0, lenVal);
		if (rdLength == lenVal)
		{
			val.resize(rdLength);
			for (qint32 i=0; i<rdLength; ++i)
			{
				if (data[i]) val.setBit(i);
				else val.clearBit(i);
			}

			codeLength += rdLength + 1;

			QBitArray* pVal = &val;
			QVariant wrvar(PtrMetaTypes::s_QBitArrayPtrMetaType, &pVal);
			obj->metaObject()->property(3).write(obj, wrvar);
		}
	}

	return codeLength;
}
コード例 #3
0
    /**
     * Spread contacts in the blockmap to any touched neighbors.
     *
     * @param box   Map space region in which to perform spreading.
     */
    void spread(AABoxd const &box)
    {
        BlockmapCellBlock const cellBlock = _blockmap.toCellBlock(box);

        BlockmapCell cell;
        for(cell.y = cellBlock.min.y; cell.y < cellBlock.max.y; ++cell.y)
        for(cell.x = cellBlock.min.x; cell.x < cellBlock.max.x; ++cell.x)
        {
            if(_spreadBlocks)
            {
                // Should we skip this cell?
                int cellIndex = _blockmap.toCellIndex(cell.x, cell.y);
                if(_spreadBlocks->testBit(cellIndex))
                    continue;

                // Mark the cell as processed.
                _spreadBlocks->setBit(cellIndex);
            }

            _blockmap.forAllInCell(cell, [this] (void *element)
            {
                spreadContact(*static_cast<Contact *>(element));
                return LoopContinue;
            });
        }
    }
コード例 #4
0
ファイル: huffman.cpp プロジェクト: Etrnls/etrnlabs
QByteArray dehuffman(QByteArray data, MainWindow *mainWindow)
{
	QHash<quint8, QBitArray> codes;
	qint32 size;
	QBitArray bits;
	{
		QDataStream stream(data);
		stream >> codes >> size >> bits;
		Q_ASSERT(stream.status() == QDataStream::Ok);
	}

	QHash<QBitArray, quint8> table;
	for (int i = 0; i < tableSize; ++i)
		if (codes.contains(i))	table[codes[i]] = i;

	QByteArray result;
	result.reserve(data.size());

	int index = 0;
	for (int i = 0; i < size; ++i)
	{
		mainWindow->setProgress(qRound(static_cast<qreal>(100 * i) / size));

		QBitArray b;
		while (!table.contains(b))
		{
			b.resize(b.size() + 1);
			if (bits[index])	b.setBit(b.size() - 1);
			++index;
		}
		result.append(table[b]);
	}

	return result;
}
コード例 #5
0
QRect ImageOverlayRegionFinder::growRegion(int row, int column, QBitArray &mask)
{
    QRect region;
    region.setCoords(column, row, column, row);

    QQueue<int> queue;
    queue.enqueue(getDataIndex(row, column));

    while (!queue.isEmpty())
    {
        int i = queue.dequeue();

        if (m_overlay.getData()[i] > 0 && !mask.testBit(i))
        {
            mask.setBit(i);
            row = getRowIndex(i);
            column = getColumnIndex(i);
            
            if (row < region.top())
            {
                region.setTop(row);
            }
            if (row > region.bottom())
            {
                region.setBottom(row);
            }
            if (column < region.left())
            {
                region.setLeft(column);
            }
            if (column > region.right())
            {
                region.setRight(column);
            }

            if (column - 1 >= 0)
            {
                queue.enqueue(getDataIndex(row, column - 1));
            }
            if (column + 1 < static_cast<signed>(m_overlay.getColumns()))
            {
                queue.enqueue(getDataIndex(row, column + 1));
            }
            if (row - 1 >= 0)
            {
                queue.enqueue(getDataIndex(row - 1, column));
            }
            if (row + 1 < static_cast<signed>(m_overlay.getRows()))
            {
                queue.enqueue(getDataIndex(row + 1, column));
            }
        }
    }

    return region;
}
コード例 #6
0
void QtBinaryCalc::slot_test()
{
	QBitArray *a = new QBitArray();
	QBitArray *b = new QBitArray();
	QBitArray *result = new QBitArray();

	QString *resultString = new QString();

	a->fill(0, 16);
	b->fill(0, 16);
	result->fill(0, 16);

	for(int i = 0 ; i < this->numberA->getBytesAsBin().count() ; i++)
	{
		a->setBit(i, this->numberA->getBytesAsBin().at(i).digitValue() );
	}

	for(int i = 0 ; i < this->numberB->getBytesAsBin().count() ; i++)
	{
		b->setBit(i, this->numberB->getBytesAsBin().at(i).digitValue() );
	}


	*result = ~(*a);
	SHOWVALUE(result, *result);

	for ( int i = result->count()-1 ; i >= 0 ; i-- )
	{
		resultString->append( QString::number( (int)result->at(i) ) );
	}

	SHOWVALUE(resultString, *resultString);
	SHOWVALUE(resultString->toInt(0, 2), resultString->toInt(0,2));//tu trzeba zrobic invert bitow 0->16, 1->15 itd

	this->numberResult->slot_setValue(resultString->toInt());

	SHOWVALUE(a, *a);
	SHOWVALUE(b, *b);

}
コード例 #7
0
ファイル: tst_qbitarray.cpp プロジェクト: RS102839/qt
/**
 * Helper function to initialize a bitarray from a string
 */
static QBitArray QStringToQBitArray(const QString &str)
{
    QBitArray ba;
    ba.resize(str.length());
    int i;
    QChar tru('1');
    for (i = 0; i < str.length(); i++)
    {
        if (str.at(i) == tru)
        {
            ba.setBit(i, true);
        }
    }
    return ba;
}
コード例 #8
0
ファイル: pagemodel.cpp プロジェクト: arunjalota/paperman
err_info *Pagemodel::commit (void)
   {
   Desktopmodel *contents = (Desktopmodel *)_contents;
   QModelIndex index = _stackindex;   // may be invalid
   int del_count = 0;
   QVector<Pageinfo> *pages = &_pages;
   bool lost = _lost_scan;

   if (lost)
      {
      pages = &_scan_pages;
      _lost_scan = false;
      contents = (Desktopmodel *)_lost_contents;
      _lost_contents = 0;
      }
   if (!contents)
      return NULL;

   // delete any pages marked for deletion
   QBitArray ba (pages->size ());

   for (int i = 0; i < pages->size (); i++)
      if ((*pages) [i].toRemove ())
         {
         ba.setBit (i);
         del_count++;
         }

   // process on our local model (reverse order)
   if (!lost) for (int i = pages->size () - 1; i >= 0; i--)
      if (ba.testBit (i))
         removeRow (i, QModelIndex ());

   // update any annotation data
   if (!lost && index.isValid ())
      contents->updateAnnot (index, _annot_updates);

   //FIXME: need to write ocr text somewhere also, but needs to be page-based
   //FIXME: should only update annotations if they have changed
   //FIXME: what happens if they delete all pages? Should delete the stack

   /* now delete the pages we don't want, or trash the whole stack if
      we want none of them. This function also handles the case where
      contents points to another directory */
   // this may invalidate _stackIndex
   // also this function copes with an invalid index
   return contents->scanCommitPages (index, del_count, ba, !lost);
   }
コード例 #9
0
void EventWinRecurrence::getCheckedDays(QBitArray &rDays) {
    rDays.fill(FALSE);
    if (mondayBox->isChecked())
        rDays.setBit(0, 1);
    if (tuesdayBox->isChecked())
        rDays.setBit(1, 1);
    if (wednesdayBox->isChecked())
        rDays.setBit(2, 1);
    if (thursdayBox->isChecked())
        rDays.setBit(3, 1);
    if (fridayBox->isChecked())
        rDays.setBit(4, 1);
    if (saturdayBox->isChecked())
        rDays.setBit(5, 1);
    if (sundayBox->isChecked())
        rDays.setBit(6, 1);
}
コード例 #10
0
ファイル: KoList.cpp プロジェクト: KDE/koffice
void KoList::setContinueNumbering(int level, bool enable)
{
    Q_ASSERT(level > 0 && level <= 10);
    level = qMax(qMin(level, 10), 1);

    QBitArray bitArray = d->properties[ContinueNumbering].toBitArray();
    if (bitArray.isEmpty())
        bitArray.resize(10);
    bitArray.setBit(level-1, enable);
    d->properties[ContinueNumbering] = bitArray;

    QTextList *textList = d->textLists.value(level-1).data();
    if (!textList)
        return;
    QTextListFormat format = textList->format();
    if (enable) {
        format.setProperty(KListStyle::ContinueNumbering, true);
    } else {
        format.clearProperty(KListStyle::ContinueNumbering);
    }
    textList->setFormat(format);
}
コード例 #11
0
ファイル: tst_qbitarray.cpp プロジェクト: RS102839/qt
void tst_QBitArray::resize()
{
    // -- check that a resize handles the bits correctly
    QBitArray a = QStringToQBitArray(QString("11"));
    a.resize(10);
    QVERIFY(a.size() == 10);
    QCOMPARE( a, QStringToQBitArray(QString("1100000000")) );

    a.setBit(9);
    a.resize(9);
    // now the bit in a should have been gone:
    QCOMPARE( a, QStringToQBitArray(QString("110000000")) );

    // grow the array back and check the new bit
    a.resize(10);
    QCOMPARE( a, QStringToQBitArray(QString("1100000000")) );

    // other test with and
    a.resize(9);
    QBitArray b = QStringToQBitArray(QString("1111111111"));
    b &= a;
    QCOMPARE( b, QStringToQBitArray(QString("1100000000")) );

}
コード例 #12
0
//FUNKCJA ODPOWIADA ZA AKTUALIZOWANIE WYNIKU PO ZMIANIE OPERATORA PO LEWEJ STRONIE i za zmiane pol w numberA lub B.
//Dokladniejszy opis w kilkulinijkowym komentarzu pod koniec konstruktora QtBinaryCalc
void QtBinaryCalc::slot_operatorChanged(int op)
{
//int op - identyfikator operatora bitowego (1-NOT, 2-AND itd)
/////////////////////////////////////////////////////////

	QBitArray a;
	QBitArray b;
	QBitArray result;

	QString resultString;

	a.fill(0, 16);
	b.fill(0, 16);
	result.fill(0, 16);

	for(int i = 0 ; i < this->numberA->getBytesAsBin().count() ; i++)
	{
		a.setBit(i, this->numberA->getBytesAsBin().at(i).digitValue() );
	}

	for(int i = 0 ; i < this->numberB->getBytesAsBin().count() ; i++)
	{
		b.setBit(i, this->numberB->getBytesAsBin().at(i).digitValue() );
	}

/////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////

	if(op == -1)
	{
		op = chooser->getOperator();
	}


	if (op == 1)
	{
		result = ~(a);
	}
	else
	if (op == 2)
	{
		result = a&b;
	}
	else
	if (op == 3)
	{
		result = a|b;
	}
	else
	if (op == 4)
	{
		result = a^b;
	}

	QString resultQString;

//	SHOWLINE();
	for(int i = 0 ; i <= 15 ; i++)
	{
		SHOWONLYVALUE((int)result.at(i));
		resultQString.append( QString::number(result.at(i)) );
	}

	this->numberResult->slot_setValue( resultQString.toInt(0, 2) );
}
コード例 #13
0
ファイル: cfilltool.cpp プロジェクト: TravisNoles/CMap
void CFillTool::doFill() {
	// This is not the nicest code, but.. it works?

	auto map = widget()->map();
	int toReplace = map->get(m_whatType, m_hovered);

	if (toReplace == m_whatValue)
		return;

	QBitArray checked;
	checked.resize(map->width() * map->height());

	QQueue<CMapPoint> queue;
	queue.enqueue(m_hovered);

	while (!queue.isEmpty()) {
		CMapPoint point = queue.dequeue();

		int bitID = ((point.x / 2) * map->width()) + point.y;
		checked.setBit(bitID);

		CEditCommand::Change change;
		change.before = toReplace;
		change.after = m_whatValue;
		change.type = m_whatType;
		change.pos = point;
		m_command->changes.append(change);

		// Check every side to see what we've got to add to the list
		CMapPoint nw = point;
		nw.moveNW();
		int nwBit = ((nw.x / 2) * map->width()) + nw.y;
		if (map->positionValid(nw) && !checked.testBit(nwBit) && map->get(m_whatType, nw) == toReplace) {
			checked.setBit(nwBit);
			queue.enqueue(nw);
		}

		CMapPoint ne = point;
		ne.moveNE();
		int neBit = ((ne.x / 2) * map->width()) + ne.y;
		if (map->positionValid(ne) && !checked.testBit(neBit) && map->get(m_whatType, ne) == toReplace) {
			checked.setBit(neBit);
			queue.enqueue(ne);
		}

		CMapPoint sw = point;
		sw.moveSW();
		int swBit = ((sw.x / 2) * map->width()) + sw.y;
		if (map->positionValid(sw) && !checked.testBit(swBit) && map->get(m_whatType, sw) == toReplace) {
			checked.setBit(swBit);
			queue.enqueue(sw);
		}

		CMapPoint se = point;
		se.moveSE();
		int seBit = ((se.x / 2) * map->width()) + se.y;
		if (map->positionValid(se) && !checked.testBit(seBit) && map->get(m_whatType, se) == toReplace) {
			checked.setBit(seBit);
			queue.enqueue(se);
		}
	}

/*	while (!queue.isEmpty()) {
		CMapPoint point = queue.dequeue();

		// First off, check the NW side of this point
		CMapPoint check = point;

		while (true) {
			check.moveNW();
			if (!map->positionValid(check))
				break;
			if (map->get(m_whatType, check) != toReplace)
				break;

			int bitID = ((check.x / 2) * map->width()) + check.y;
			if (checked.testBit(bitID))
				break;
			checked.setBit(bitID);

			CEditCommand::Change change;
			change.before = toReplace;
			change.after = m_whatValue;
			change.type = m_whatType;
			change.pos = check;
			m_command->changes.append(change);

			// Check if we need to add anything SW/NE of this one
			CMapPoint checkSW = check;
			checkSW.moveSW();
			if (map->positionValid(checkSW) && map->get(m_whatType, checkSW) == toReplace)
				queue.enqueue(checkSW);

			CMapPoint checkNE = check;
			checkNE.moveNE();
			if (map->positionValid(checkNE) && map->get(m_whatType, checkNE) == toReplace)
				queue.enqueue(checkNE);
		}

		// Now check the SE side
		check = point;

		while (true) {
			check.moveSE();
			if (!map->positionValid(check))
				break;
			if (map->get(m_whatType, check) != toReplace)
				break;

			int bitID = ((check.x / 2) * map->width()) + check.y;
			if (checked.testBit(bitID))
				break;
			checked.setBit(bitID);

			CEditCommand::Change change;
			change.before = toReplace;
			change.after = m_whatValue;
			change.type = m_whatType;
			change.pos = check;
			m_command->changes.append(change);

			// Check if we need to add anything SW/NE of this one
			CMapPoint checkSW = check;
			checkSW.moveSW();
			if (map->positionValid(checkSW) && map->get(m_whatType, checkSW) == toReplace)
				queue.enqueue(checkSW);

			CMapPoint checkNE = check;
			checkNE.moveNE();
			if (map->positionValid(checkNE) && map->get(m_whatType, checkNE) == toReplace)
				queue.enqueue(checkNE);
		}
	}*/
}
コード例 #14
0
ファイル: huffman.cpp プロジェクト: Etrnls/etrnlabs
QByteArray huffman(QByteArray data, MainWindow *mainWindow)
{
	// count
	int count[tableSize];
	qFill(&count[0], &count[tableSize - 1], 0);
	for (int i = 0; i < data.size(); ++i)
		++count[static_cast<quint8>(data[i])];

	QMultiMap<int, QList<QPair<quint8, QBitArray> > > p; // <count, <symbol, code> >
	for (int i = 0; i < tableSize; ++i)
	{
		if (count[i] == 0)	continue;

		QList<QPair<quint8, QBitArray> > list;
		list.append(qMakePair(static_cast<quint8>(i), QBitArray()));
		p.insert(count[i], list);
	}

	// caculate codes from bottom to top
	while (p.size() > 1)
	{
		const int count0 = p.begin().key();
		QList<QPair<quint8, QBitArray> > list0 = p.begin().value();
		p.erase(p.begin());

		const int count1 = p.begin().key();
		QList<QPair<quint8, QBitArray> > list1 = p.begin().value();
		p.erase(p.begin());

		for (QList<QPair<quint8, QBitArray> >::Iterator iter = list0.begin(); iter != list0.end(); ++iter)
		{
			iter->second.resize(iter->second.size() + 1);
			iter->second.setBit(iter->second.size() - 1, false);
		}

		for (QList<QPair<quint8, QBitArray> >::Iterator iter = list1.begin(); iter != list1.end(); ++iter)
		{
			iter->second.resize(iter->second.size() + 1);
			iter->second.setBit(iter->second.size() - 1, true);
		}
		p.insert(count0 + count1, list0 + list1);
	}

	// extract codes
	QHash<quint8, QBitArray> codes;
	for (QList<QPair<quint8, QBitArray> >::ConstIterator iter = p.begin().value().constBegin(); iter != p.begin().value().constEnd(); ++iter)
	{
		QBitArray code;
		code.resize(iter->second.size());
		for (int j = 0; j < code.size(); ++j)
			if (iter->second[code.size() - j - 1])
				code.setBit(j);
		codes[iter->first] = code;
	}

	// encode
	QBitArray bits;
	for (int i = 0; i < data.size(); ++i)
	{
		mainWindow->setProgress(qRound(static_cast<qreal>(100 * i) / data.size()));

		const QBitArray &code = codes[static_cast<quint8>(data[i])];
		const int oldSize = bits.size();
		bits.resize(oldSize + code.size());

		for (int i = 0; i < code.size(); ++i)
			if (code[i])	bits.setBit(oldSize + i);
	}

	QByteArray result;
	{
		QDataStream stream(&result, QIODevice::WriteOnly);
		stream << codes << static_cast<qint32>(data.size()) << bits;
	}

	return result;
}
コード例 #15
0
ファイル: serialdecodernode.cpp プロジェクト: bigfug/Fugio
void SerialDecoderNode::inputsUpdated( qint64 pTimeStamp )
{
	if( mPinInputBits->isUpdated( pTimeStamp ) )
	{
		QBitArray	InpDat = variant( mPinInputBits ).toBitArray();

		if( !InpDat.isEmpty() )
		{
			QBitArray		SrcDat;
			QByteArray		DstDat;

			// Prepend any buffered data

			if( !mBitBuf.isEmpty() )
			{
				int		InpSze = InpDat.size();
				int		BufSze = mBitBuf.size();

				SrcDat.resize( BufSze + InpSze );

				for( int i = 0 ; i < BufSze ; i++ )
				{
					SrcDat.setBit( i, mBitBuf.testBit( i ) );
				}

				for( int i = 0 ; i < InpSze ; i++ )
				{
					SrcDat.setBit( BufSze + i, InpDat.testBit( i ) );
				}

				mBitBuf.clear();
			}
			else
			{
				SrcDat.swap( InpDat );
			}

			// Look for data

//			qDebug() << "R:" << SrcDat;

			int SrcOff;

			for( SrcOff = 0 ; SrcOff < SrcDat.size() - 9 ; )
			{
				if( SrcDat.testBit( SrcOff ) || !SrcDat.testBit( SrcOff + 9 ) )
				{
					SrcOff++;

					continue;
				}

				QBitArray	T( 8 );

				quint8		C = 0;

				for( int j = 0 ; j < 8 ; j++ )
				{
					C |= ( SrcDat.testBit( SrcOff + 1 + j ) ? 0x01 : 0x00 ) << j;

					T.setBit( j, SrcDat.testBit( SrcOff + 1 + j ) );
				}

//				qDebug() << SrcOff << T;

				DstDat.append( C );

				SrcOff += 10;
			}

			if( SrcOff < SrcDat.size() )
			{
				if( SrcOff > 0 )
				{
					mBitBuf.resize( SrcDat.size() - SrcOff );

					for( int i = 0 ; i < mBitBuf.size() ; i++ )
					{
						mBitBuf.setBit( i, SrcDat.testBit( SrcOff + i ) );
					}
				}
				else
				{
					SrcDat.swap( mBitBuf );
				}

//				qDebug() << "B" << mBitBuf;
			}

			if( !DstDat.isEmpty() )
			{
				mValOutputData->setVariant( DstDat );

				pinUpdated( mPinOutputData );
			}
		}
	}
}