当前位置: 首页>>代码示例>>C++>>正文


C++ QList::swap方法代码示例

本文整理汇总了C++中QList::swap方法的典型用法代码示例。如果您正苦于以下问题:C++ QList::swap方法的具体用法?C++ QList::swap怎么用?C++ QList::swap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QList的用法示例。


在下文中一共展示了QList::swap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testor

//@function     testing function
void testor(void)
{

    qDebug() << LEFT(2);
    qDebug() << RIGHT(2);
    qDebug() << PARENT(5);
    qDebug() << PARENT(6);

    QList<QPoint> openlist;
    openlist.push_back(QPoint(1,0));
    openlist.push_back(QPoint(0,1));
    openlist.push_back(QPoint(2,1));
    openlist.push_back(QPoint(2,3));
    openlist.push_back(QPoint(1,1));

    for (int i =0; i< openlist.size(); i++)
        qDebug() << openlist.at(i);

    for (int i=0; i< openlist.size(); i++)
    {
        for(int j=i+1; j< openlist.size(); j++)
        {
            if (openlist.at(i).x()>openlist.at(j).x())
                openlist.swap(i,j);
            else if ((openlist.at(i).x()==openlist.at(j).x()) && openlist.at(i).y()>openlist.at(j).y())
                openlist.swap(i,j);

        }
    }
    qDebug() << "-----------------";
    for (int i =0; i< openlist.size(); i++)
        qDebug() << openlist.at(i);

}
开发者ID:him7777777,项目名称:2DgridSearch,代码行数:35,代码来源:heap.cpp

示例2: if

QList< VdpVideoSurface > MPEGDecoder::getOrderedFrames()
{
   QList< VdpVideoSurface > list;
   int j;
   for ( j=0; j<NUMSURFACES; ++j ) {
      MPEGFrame *frame = frames.at( j );

      frame->info.backward_reference = VDP_INVALID_HANDLE;
      frame->info.forward_reference = VDP_INVALID_HANDLE;
      if ( frame->info.picture_coding_type==P_FRAME )
         frame->info.forward_reference = backwardRef;
      else if ( frame->info.picture_coding_type==B_FRAME ) {
         frame->info.forward_reference = forwardRef;
         frame->info.backward_reference = backwardRef;
      }

      VdpBitstreamBuffer vbit;
      vbit.struct_version = VDP_BITSTREAM_BUFFER_VERSION;
      vbit.bitstream = frame->data;
      vbit.bitstream_bytes = frame->dataLength;
      VdpStatus st = vc->vdp_decoder_render( decoder, surfaces[j], (VdpPictureInfo*)&frame->info, 1, &vbit );
      if ( st != VDP_STATUS_OK )
         fprintf( stderr, "MPEGDecoder: decoding failed: %s!\n", vc->vdp_get_error_string( st ) );


      if ( frame->info.picture_coding_type!=B_FRAME ) {				
         forwardRef = backwardRef;
         backwardRef = surfaces[j];
      }
   }

   QList< int > framesType;
   for ( j=0; j<NUMSURFACES; ++j ) {
      framesType.append( frames.at(j)->info.picture_coding_type );
      list.append( surfaces[j] );
   }

   j = 1;
   while ( j<NUMSURFACES ) {
      if ( framesType.at(j)==B_FRAME ) {
         framesType.swap(j-1, j);
         list.swap(j-1, j);
      }
      else
         ++j;
   }

   vc->vdp_decoder_destroy( decoder );
   decoder = VDP_INVALID_HANDLE;

   return list;
}
开发者ID:Moorviper,项目名称:qvdpautest,代码行数:52,代码来源:mpegdecoder.cpp

示例3: swap

void tst_QList::swap() const
{
    QList<QString> list;
    list << "foo" << "bar" << "baz";

    // swap
    list.swap(0, 2);
    QCOMPARE(list, QList<QString>() << "baz" << "bar" << "foo");

    // swap again
    list.swap(1, 2);
    QCOMPARE(list, QList<QString>() << "baz" << "foo" << "bar");
}
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.vendor,代码行数:13,代码来源:tst_qlist.cpp

示例4: foreach

QList<Experience> SystemeMotivationnel::exp(const Resultat & r) const
{
    QList<Experience> rt;
    QList<Interaction> temp;
    foreach (const Interaction& it, m_systeme)
    {
        if(r == it.resultat())
        {
            temp<<it;
        }
    }

    for(int i = 0; i < temp.size(); i ++)
    {
        for(int j = i; j < temp.size(); j ++)
        {
            //qDebug()<<temp[i].toString()<<temp[i].motivation()<<temp[j].toString()<<temp[j].motivation();

            if(temp[i] < temp[j])
            {
                temp.swap(i,j);
            }
        }
    }

    foreach (const Interaction& it, temp)
    {
        rt<<it.experience();
    }

    return rt;
}
开发者ID:Chewnonobelix,项目名称:IA-devellopemental,代码行数:32,代码来源:systememotivationnel.cpp

示例5:

QList<Media*> Playlist::shufflePlaylist(QList<Media *> media)
{
    for (int i = media.size()-1; i >= 0; i--)
    {

          int j = (int) (((float)qrand()/RAND_MAX) * i);
          media.swap(j, i);
    }
    return media;
}
开发者ID:safri-framework,项目名称:safri-player,代码行数:10,代码来源:playlist.cpp

示例6: BubbleSort

void MReportDataAdapter::BubbleSort(QList<EventInfo *> &list)
{
    for (int i = 0; i < list.count(); i++)
    {
        for (int j = 0; j < list.count() - 1 - i; j++)
        {
            if (list.at(j)->magnitude < list.at(j+1)->magnitude)
            {
                list.swap(j, j+1);
            }
        }
    }
}
开发者ID:liye0005,项目名称:QT_POJ,代码行数:13,代码来源:mdbadapter.cpp

示例7: QPolygonF

QList<QPolygonF> PathSorter::MyFakeTSP(const QList<QPolygonF> inpaths)
{
	QPolygonF zero = QPolygonF(QRectF(0.0,mediaHeight,0.0,0.0)); // able to change the start point

	QList<QPolygonF> outpaths = QList<QPolygonF>(inpaths);

	// find the shortest path
	for (int i = 0; i < (outpaths.size()-1); ++i)
	{
		if(i == 0) // find good start
		{
			qreal dist=10000.0;
			int bestindex=i;
			for (int j = (i+1); j < outpaths.size(); ++j)
			{
				if (getDistance(zero,outpaths[j]) < dist) 
				{
				dist = getDistance(zero,outpaths[j]);
				bestindex = j;
				}
				
			}
			if (dist != 0) outpaths.swap(0,bestindex);
		}
		qreal dist=10000.0;
		int bestindex=i;
		for (int j = (i+1); j < outpaths.size(); ++j)
		{
			if (getDistance(outpaths[i],outpaths[j]) < dist) 
			{
				dist = getDistance(outpaths[i],outpaths[j]);
				bestindex = j;
			}
		}
		if (dist != 0) outpaths.swap((i+1),bestindex);
	}
	return outpaths;
}
开发者ID:Fab-Lab-Fabulous-St-Pauli,项目名称:robocut,代码行数:38,代码来源:PathSorter.cpp

示例8: lock

QList<QVariantList>
ImporterSqlConnection::query( const QString &query, const QVariantMap &bindValues,
                              bool* const ok )
{
    QMutexLocker lock( &m_apiMutex );

    QMetaObject::invokeMethod( this, "slotQuery", blockingConnectionType(),
                               Q_ARG( QString, query ), Q_ARG( QVariantMap, bindValues ),
                               Q_ARG( bool* const, ok ) );

    QList<QVariantList> result;
    result.swap( m_result );
    return result;
}
开发者ID:mikatammi,项目名称:amarok-spotify,代码行数:14,代码来源:ImporterSqlConnection.cpp

示例9: randInt

QList<int>* Util::randomArray(int N)
{
    // http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
    QList<int> *lst = new QList<int>();
    lst->reserve(N);

    for (int i=0; i<N; ++i)
        (*lst)[i] = i;

    for (int i=0; i<N; ++i) {
        int n = randInt(i, N-1);
        lst->swap(i, n);
    }

    return lst;
}
开发者ID:pjmahoney,项目名称:nutmeg,代码行数:16,代码来源:util.cpp

示例10: initHandler

/*!
    \internal
*/
bool QImageReaderPrivate::initHandler()
{
    // check some preconditions
    if (!device || (!deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly))) {
        imageReaderError = QImageReader::DeviceError;
        errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Invalid device"));
        return false;
    }

    // probe the file extension
    if (deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly) && autoDetectImageFormat) {
        QList<QByteArray> extensions = QImageReader::supportedImageFormats();
        if (!format.isEmpty()) {
            // Try the most probable extension first
            int currentFormatIndex = extensions.indexOf(format.toLower());
            if (currentFormatIndex > 0)
                extensions.swap(0, currentFormatIndex);
        }

        int currentExtension = 0;

        QFile *file = static_cast<QFile *>(device);
        QString fileName = file->fileName();

        do {
            file->setFileName(fileName + QLatin1Char('.')
                    + QString::fromLatin1(extensions.at(currentExtension++).constData()));
            file->open(QIODevice::ReadOnly);
        } while (!file->isOpen() && currentExtension < extensions.size());

        if (!device->isOpen()) {
            imageReaderError = QImageReader::FileNotFoundError;
            errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "File not found"));
            file->setFileName(fileName); // restore the old file name
            return false;
        }
    }

    // assign a handler
    if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat, ignoresFormatAndExtension)) == 0) {
        imageReaderError = QImageReader::UnsupportedFormatError;
        errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unsupported image format"));
        return false;
    }
    return true;
}
开发者ID:cedrus,项目名称:qt,代码行数:49,代码来源:qimagereader.cpp

示例11: main

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QList<QString> list;
    list << "aa" << "bb" << "cc";
    if(list[1] == "bb")
    {
        list[1] = "ab";
    }
    list.replace(2,"bc");
    qDebug() << "the list is:";
    for(int i = 0;i<list.size();++i)
    {
        qDebug()<<list.at(i);
    }
    list.append("dd");
    list.prepend("mm");

    QString str = list.takeAt(2);
    qDebug()<<"at(2) item is:"<<str;
    qDebug()<<"the list is:";
    for(int i = 0;i<list.size();++i)
    {
        qDebug()<<list.at(i);
    }
    list.insert(2,"mm");
    list.swap(1,3);
    qDebug()<<"the list is:";
    for(int i = 0;i<list.size();++i)
    {
        qDebug()<<list.at(i);
    }
    qDebug()<<"contains 'mm'?"<<list.contains("mm");
    qDebug()<<"the 'mm' count:"<<list.count("mm");
    qDebug()<<"the first 'mm' index:"<<list.indexOf("mm");
    qDebug()<<"the second 'mm' index:"<<list.indexOf("mm",1);



    return a.exec();
}
开发者ID:Freshield,项目名称:LEARNING_QT,代码行数:42,代码来源:main.cpp

示例12: getTotalDistance

QList<QPolygonF> PathSorter::BbSort (const QList<QPolygonF> inpaths)
{
	QList<QPolygonF> outpaths = QList<QPolygonF>(inpaths);
	for (int i = 0; i < (outpaths.size()-1); i++)
	{
		for (int j = (i+1); j < outpaths.size(); j++)
		{
		if (outpaths[i].boundingRect().intersects(outpaths[j].boundingRect()))
			{
				if (outpaths[i].boundingRect().width() > outpaths[j].boundingRect().width() || outpaths[i].boundingRect().height() > outpaths[j].boundingRect().height()) 
				{
					outpaths.swap(i,j);
					break;
				}
			}
		}
	}
	cout<<"BbSort outpaths: "<< getTotalDistance(outpaths) << endl;
	return outpaths;
}
开发者ID:Fab-Lab-Fabulous-St-Pauli,项目名称:robocut,代码行数:20,代码来源:PathSorter.cpp

示例13: fill

void EncodingTree::fill(){

    QList<EncondingNode *> lista = DList;

    while(lista.size() > 1)
    {

        EncondingNode *tmp = new EncondingNode(lista.at(0)->getFrequency() + lista.at(1)->getFrequency());
        int z = 0;

        tmp->setLeft(lista.at(0));
        tmp->setRight(lista.at(1));
        tmp->setType(1);

        lista.removeAt(0);
        lista.removeAt(0);
        lista.insert(z, tmp);

        root = tmp;

        while(1)
        {
            if(z == lista.size() - 1)
            {
                break;
            }
            if(lista.at(z)->getFrequency() > lista.at(z + 1)->getFrequency())
            {
                lista.swap(z,z+1);
            }
            else
            {
                break;
            }
            z++;
        }
    }
}
开发者ID:BrunoGeorgevich,项目名称:Project-Huffman,代码行数:38,代码来源:encodingTree.cpp

示例14: handleMoveLayer

void LayerListModel::handleMoveLayer(int oldIdx, int newIdx)
{
	// Need at least two layers for this to make sense
	const int count = _items.count();
	if(count < 2)
		return;

	QList<uint16_t> layers;
	layers.reserve(count);
	foreach(const LayerListItem &li, _items)
		layers.append(li.id);

	if(newIdx>oldIdx)
		--newIdx;

	layers.move(oldIdx, newIdx);

	// Layers are shown topmost first in the list but
	// are sent bottom first in the protocol.
	for(int i=0;i<count/2;++i)
		layers.swap(i,count-(1+i));

	emit layerOrderChanged(layers);
}
开发者ID:mlichter,项目名称:Drawpile,代码行数:24,代码来源:layerlist.cpp

示例15: determineChildren

void VListCF::determineChildren()
{
	// Get the single items from the list of composite items.
	QList< Item* > items = extractSingleItems();

	// Inserts elements that are not yet visualized and adjusts the order to match that in 'nodes'.
	for (int i = 0; i < node()->size(); ++i)
	{
		if (i >= items.size() ) items.append( renderer()->render(this, node()->at<Node>(i)));	// This node is new
		else if ( items[i]->node() == node()->at<Node>(i) )	continue;	// This node is already there
		else
		{
			// This node might appear somewhere ahead, we should look for it
			bool found = false;
			for (int k = i + 1; k<items.size(); ++k)
			{
				if ( items[k]->node() == node()->at<Node>(i) )
				{
					// We found this node, swap the visualizations
					items.swap(i, k);
					found = true;
					break;
				}
			}

			// The node was not found, insert a visualization here
			if (!found ) items.insert(i, renderer()->render(this, node()->at<Node>(i)));
		}
	}

	// Remove excess items
	while (items.size() > node()->size()) items.removeLast();

	// Convert the single items list back to a list of composite items.
	buildCompositeItems(items);
}
开发者ID:fiirabig,项目名称:Envision,代码行数:36,代码来源:VListCF.cpp


注:本文中的QList::swap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。