本文整理汇总了C++中QLinkedList::takeFirst方法的典型用法代码示例。如果您正苦于以下问题:C++ QLinkedList::takeFirst方法的具体用法?C++ QLinkedList::takeFirst怎么用?C++ QLinkedList::takeFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLinkedList
的用法示例。
在下文中一共展示了QLinkedList::takeFirst方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main ()
{
QLinkedList<QString> list;
list << "A" << "B" << "C" << "D" << "E" << "F";
assert(list.takeFirst() == "A");
assert(list.size() == 5);
return 0;
}
示例2: joinConnectedFeatures
void Layer::joinConnectedFeatures()
{
// go through all label texts
QString labelText;
while ( !connectedTexts->isEmpty() )
{
labelText = connectedTexts->takeFirst();
//std::cerr << "JOIN: " << labelText << std::endl;
QHash< QString, QLinkedList<FeaturePart*>* >::const_iterator partsPtr = connectedHashtable->find( labelText );
if ( partsPtr == connectedHashtable->constEnd() )
continue; // shouldn't happen
QLinkedList<FeaturePart*>* parts = *partsPtr;
// go one-by-one part, try to merge
while ( !parts->isEmpty() )
{
// part we'll be checking against other in this round
FeaturePart* partCheck = parts->takeFirst();
FeaturePart* otherPart = _findConnectedPart( partCheck, parts );
if ( otherPart )
{
//std::cerr << "- connected " << partCheck << " with " << otherPart << std::endl;
// remove partCheck from r-tree
double bmin[2], bmax[2];
partCheck->getBoundingBox( bmin, bmax );
rtree->Remove( bmin, bmax, partCheck );
featureParts->removeOne( partCheck );
otherPart->getBoundingBox( bmin, bmax );
// merge points from partCheck to p->item
if ( otherPart->mergeWithFeaturePart( partCheck ) )
{
// reinsert p->item to r-tree (probably not needed)
rtree->Remove( bmin, bmax, otherPart );
otherPart->getBoundingBox( bmin, bmax );
rtree->Insert( bmin, bmax, otherPart );
}
}
}
// we're done processing feature parts with this particular label text
delete parts;
}
// we're done processing connected fetures
delete connectedHashtable;
connectedHashtable = NULL;
delete connectedTexts;
connectedTexts = NULL;
}
示例3: geosContext
QLinkedList<const GEOSGeometry *>* pal::Util::unmulti( const GEOSGeometry *the_geom )
{
QLinkedList<const GEOSGeometry*> *queue = new QLinkedList<const GEOSGeometry*>;
QLinkedList<const GEOSGeometry*> *final_queue = new QLinkedList<const GEOSGeometry*>;
const GEOSGeometry *geom;
queue->append( the_geom );
int nGeom;
int i;
GEOSContextHandle_t geosctxt = geosContext();
while ( !queue->isEmpty() )
{
geom = queue->takeFirst();
int type = GEOSGeomTypeId_r( geosctxt, geom );
switch ( type )
{
case GEOS_MULTIPOINT:
case GEOS_MULTILINESTRING:
case GEOS_MULTIPOLYGON:
nGeom = GEOSGetNumGeometries_r( geosctxt, geom );
for ( i = 0; i < nGeom; i++ )
{
queue->append( GEOSGetGeometryN_r( geosctxt, geom, i ) );
}
break;
case GEOS_POINT:
case GEOS_LINESTRING:
case GEOS_POLYGON:
final_queue->append( geom );
break;
default:
QgsDebugMsg( QString( "unexpected geometry type:%1" ).arg( type ) );
delete final_queue;
delete queue;
return nullptr;
}
}
delete queue;
return final_queue;
}
示例4: while
QLinkedList<const GEOSGeometry *> *unmulti( const GEOSGeometry *the_geom )
{
QLinkedList<const GEOSGeometry*> *queue = new QLinkedList<const GEOSGeometry*>;
QLinkedList<const GEOSGeometry*> *final_queue = new QLinkedList<const GEOSGeometry*>;
const GEOSGeometry *geom;
queue->append( the_geom );
int nGeom;
int i;
while ( !queue->isEmpty() )
{
geom = queue->takeFirst();
GEOSContextHandle_t geosctxt = geosContext();
switch ( GEOSGeomTypeId_r( geosctxt, geom ) )
{
case GEOS_MULTIPOINT:
case GEOS_MULTILINESTRING:
case GEOS_MULTIPOLYGON:
nGeom = GEOSGetNumGeometries_r( geosctxt, geom );
for ( i = 0; i < nGeom; i++ )
{
queue->append( GEOSGetGeometryN_r( geosctxt, geom, i ) );
}
break;
case GEOS_POINT:
case GEOS_LINESTRING:
case GEOS_POLYGON:
final_queue->append( geom );
break;
default:
delete final_queue;
delete queue;
return NULL;
}
}
delete queue;
return final_queue;
}
示例5: mapBoundaryGeos
//.........这里部分代码省略.........
prob->nblp = 0;
prob->featNbLp = new int [prob->nbft];
prob->featStartId = new int [prob->nbft];
prob->inactiveCost = new double[prob->nbft];
Feats *feat = nullptr;
// Filtering label positions against obstacles
amin[0] = amin[1] = std::numeric_limits<double>::lowest();
amax[0] = amax[1] = std::numeric_limits<double>::max();
FilterContext filterCtx;
filterCtx.cdtsIndex = prob->candidates;
filterCtx.pal = this;
obstacles->Search( amin, amax, filteringCallback, static_cast< void * >( &filterCtx ) );
if ( isCanceled() )
{
const auto constFFeats = *fFeats;
for ( Feats *feat : constFFeats )
{
qDeleteAll( feat->lPos );
feat->lPos.clear();
}
qDeleteAll( *fFeats );
delete fFeats;
delete obstacles;
return nullptr;
}
int idlp = 0;
for ( i = 0; i < prob->nbft; i++ ) /* foreach feature into prob */
{
feat = fFeats->takeFirst();
prob->featStartId[i] = idlp;
prob->inactiveCost[i] = std::pow( 2, 10 - 10 * feat->priority );
switch ( feat->feature->getGeosType() )
{
case GEOS_POINT:
max_p = point_p;
break;
case GEOS_LINESTRING:
max_p = line_p;
break;
case GEOS_POLYGON:
max_p = poly_p;
break;
}
// sort candidates by cost, skip less interesting ones, calculate polygon costs (if using polygons)
max_p = CostCalculator::finalizeCandidatesCosts( feat, max_p, obstacles, bbx, bby );
// only keep the 'max_p' best candidates
while ( feat->lPos.count() > max_p )
{
// TODO remove from index
feat->lPos.last()->removeFromIndex( prob->candidates );
delete feat->lPos.takeLast();
}
// update problem's # candidate
prob->featNbLp[i] = feat->lPos.count();
prob->nblp += feat->lPos.count();
示例6: registerFeature
bool Layer::registerFeature( QgsLabelFeature* lf )
{
if ( lf->size().width() < 0 || lf->size().height() < 0 )
return false;
mMutex.lock();
if ( mHashtable.contains( lf->id() ) )
{
mMutex.unlock();
//A feature with this id already exists. Don't throw an exception as sometimes,
//the same feature is added twice (dateline split with otf-reprojection)
return false;
}
// assign label feature to this PAL layer
lf->setLayer( this );
// Split MULTI GEOM and Collection in simple geometries
bool addedFeature = false;
double geom_size = -1, biggest_size = -1;
FeaturePart* biggest_part = nullptr;
// break the (possibly multi-part) geometry into simple geometries
QLinkedList<const GEOSGeometry*>* simpleGeometries = Util::unmulti( lf->geometry() );
if ( !simpleGeometries ) // unmulti() failed?
{
mMutex.unlock();
throw InternalException::UnknownGeometry();
}
GEOSContextHandle_t geosctxt = geosContext();
bool featureGeomIsObstacleGeom = !lf->obstacleGeometry();
while ( !simpleGeometries->isEmpty() )
{
const GEOSGeometry* geom = simpleGeometries->takeFirst();
// ignore invalid geometries (e.g. polygons with self-intersecting rings)
if ( GEOSisValid_r( geosctxt, geom ) != 1 ) // 0=invalid, 1=valid, 2=exception
{
continue;
}
int type = GEOSGeomTypeId_r( geosctxt, geom );
if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON )
{
mMutex.unlock();
throw InternalException::UnknownGeometry();
}
FeaturePart* fpart = new FeaturePart( lf, geom );
// ignore invalid geometries
if (( type == GEOS_LINESTRING && fpart->nbPoints < 2 ) ||
( type == GEOS_POLYGON && fpart->nbPoints < 3 ) )
{
delete fpart;
continue;
}
// polygons: reorder coordinates
if ( type == GEOS_POLYGON && GeomFunction::reorderPolygon( fpart->nbPoints, fpart->x, fpart->y ) != 0 )
{
delete fpart;
continue;
}
// is the feature well defined? TODO Check epsilon
bool labelWellDefined = ( lf->size().width() > 0.0000001 && lf->size().height() > 0.0000001 );
if ( lf->isObstacle() && featureGeomIsObstacleGeom )
{
//if we are not labelling the layer, only insert it into the obstacle list and avoid an
//unnecessary copy
if ( mLabelLayer && labelWellDefined )
{
addObstaclePart( new FeaturePart( *fpart ) );
}
else
{
addObstaclePart( fpart );
fpart = nullptr;
}
}
// feature has to be labeled?
if ( !mLabelLayer || !labelWellDefined )
{
//nothing more to do for this part
delete fpart;
continue;
}
if ( mMode == LabelPerFeature && ( type == GEOS_POLYGON || type == GEOS_LINESTRING ) )
{
//.........这里部分代码省略.........
示例7: joinConnectedFeatures
void Layer::joinConnectedFeatures()
{
// go through all label texts
int connectedFeaturesId = 0;
Q_FOREACH ( const QString& labelText, mConnectedTexts )
{
if ( !mConnectedHashtable.contains( labelText ) )
continue; // shouldn't happen
connectedFeaturesId++;
QLinkedList<FeaturePart*>* parts = mConnectedHashtable.value( labelText );
// go one-by-one part, try to merge
while ( !parts->isEmpty() && parts->count() > 1 )
{
// part we'll be checking against other in this round
FeaturePart* partCheck = parts->takeFirst();
FeaturePart* otherPart = _findConnectedPart( partCheck, parts );
if ( otherPart )
{
// remove partCheck from r-tree
double checkpartBMin[2], checkpartBMax[2];
partCheck->getBoundingBox( checkpartBMin, checkpartBMax );
double otherPartBMin[2], otherPartBMax[2];
otherPart->getBoundingBox( otherPartBMin, otherPartBMax );
// merge points from partCheck to p->item
if ( otherPart->mergeWithFeaturePart( partCheck ) )
{
// remove the parts we are joining from the index
mFeatureIndex->Remove( checkpartBMin, checkpartBMax, partCheck );
mFeatureIndex->Remove( otherPartBMin, otherPartBMax, otherPart );
// reinsert merged line to r-tree (probably not needed)
otherPart->getBoundingBox( otherPartBMin, otherPartBMax );
mFeatureIndex->Insert( otherPartBMin, otherPartBMax, otherPart );
mConnectedFeaturesIds.insert( partCheck->featureId(), connectedFeaturesId );
mConnectedFeaturesIds.insert( otherPart->featureId(), connectedFeaturesId );
mFeatureParts.removeOne( partCheck );
delete partCheck;
}
}
}
// we're done processing feature parts with this particular label text
delete parts;
mConnectedHashtable.remove( labelText );
}
// we're done processing connected features
//should be empty, but clear to be safe
qDeleteAll( mConnectedHashtable );
mConnectedHashtable.clear();
mConnectedTexts.clear();
}
示例8: write
bool KNMusicPlaylistiTunesXMLParser::write(KNMusicPlaylistModel *playlist,
const QString &filePath)
{
//Generate the plist document.
QDomDocument plistDocument;
//Initial the plist element.
QDomElement plistRoot=plistDocument.createElement("plist");
plistRoot.setAttribute("version", "1.0");
plistDocument.appendChild(plistRoot);
//Initial the dict element.
QDomElement dictElement=plistDocument.createElement("dict");
plistRoot.appendChild(dictElement);
appendDictValue(plistDocument, dictElement, "Major Version", 1);
appendDictValue(plistDocument, dictElement, "Minor Version", 1);
appendDictValue(plistDocument, dictElement, "Date",
QDateTime::currentDateTime());
appendDictValue(plistDocument, dictElement, "Features", 5);
appendDictValue(plistDocument, dictElement, "Show Content Ratings", true);
//Generate database and song index list.
QHash<QString, int> filePathIndex;
QLinkedList<int> playlistIndexList;
//Add paths to hash keys.
for(int i=0; i<playlist->rowCount(); i++)
{
//Get current path.
QString currentPath=playlist->rowProperty(i, FilePathRole).toString();
//Check the path in the index hash.
int currentIndex=filePathIndex.value(currentPath, -1);
//If we never insert this path to the index,
if(currentIndex==-1)
{
//Get the new index.
currentIndex=i;
//Insert the path to the hash.
filePathIndex.insert(currentPath, currentIndex);
}
//Append the list.
playlistIndexList.append(currentIndex);
}
//Output the database info to dict.
//Initial the elements.
QDomElement tracksKey=plistDocument.createElement("key"),
tracksDict=plistDocument.createElement("dict");
QDomText tracksKeyValue=plistDocument.createTextNode("Tracks");
tracksKey.appendChild(tracksKeyValue);
//Add to dict elements.
dictElement.appendChild(tracksKey);
dictElement.appendChild(tracksDict);
//Write database info.
QList<int> songIndexList=filePathIndex.values();
while(!songIndexList.isEmpty())
{
int currentRow=songIndexList.takeFirst(),
trackID=currentRow+100;
//Generate current row key and dict.
QDomElement trackKey=plistDocument.createElement("key"),
trackDict=plistDocument.createElement("dict");
//Generate the track key value.
QDomText trackKeyValue=
plistDocument.createTextNode(QString::number(trackID));
trackKey.appendChild(trackKeyValue);
//Get the detail info.
const KNMusicDetailInfo detailInfo=playlist->rowDetailInfo(currentRow);
//Generate the dict.
appendDictValue(plistDocument, trackDict, "Track ID",
trackID);
appendDictValue(plistDocument, trackDict, "Name",
detailInfo.textLists[Name]);
appendDictValue(plistDocument, trackDict, "Artist",
detailInfo.textLists[Artist]);
appendDictValue(plistDocument, trackDict, "Album Artist",
detailInfo.textLists[AlbumArtist]);
appendDictValue(plistDocument, trackDict, "Genre",
detailInfo.textLists[Genre]);
appendDictValue(plistDocument, trackDict, "Kind",
detailInfo.textLists[Kind]);
appendDictValue(plistDocument, trackDict, "Size",
detailInfo.size);
appendDictValue(plistDocument, trackDict, "Total Time",
detailInfo.duration);
appendDictValue(plistDocument, trackDict, "Track Number",
detailInfo.textLists[TrackNumber].toString().toInt());
appendDictValue(plistDocument, trackDict, "Track Count",
detailInfo.textLists[TrackCount].toString().toInt());
appendDictValue(plistDocument, trackDict, "Year",
detailInfo.textLists[Year].toString().toInt());
appendDictValue(plistDocument, trackDict, "Date Modified",
detailInfo.dateModified);
appendDictValue(plistDocument, trackDict, "Date Added",
detailInfo.dateAdded);
appendDictValue(plistDocument, trackDict, "Bit Rate",
detailInfo.bitRate);
appendDictValue(plistDocument, trackDict, "Sample Rate",
detailInfo.samplingRate);
appendDictValue(plistDocument, trackDict, "Track Type", "File");
QString fileLocate=QUrl::fromLocalFile(detailInfo.filePath).toString();
#ifdef Q_OS_WIN
//.........这里部分代码省略.........
示例9: registerFeature
bool Layer::registerFeature( const QString& geom_id, PalGeometry *userGeom, double label_x, double label_y, const QString &labelText,
double labelPosX, double labelPosY, bool fixedPos, double angle, bool fixedAngle,
int xQuadOffset, int yQuadOffset, double xOffset, double yOffset, bool alwaysShow, double repeatDistance )
{
if ( geom_id.isEmpty() || label_x < 0 || label_y < 0 )
return false;
mMutex.lock();
if ( hashtable->contains( geom_id ) )
{
mMutex.unlock();
//A feature with this id already exists. Don't throw an exception as sometimes,
//the same feature is added twice (dateline split with otf-reprojection)
return false;
}
// Split MULTI GEOM and Collection in simple geometries
const GEOSGeometry *the_geom = userGeom->getGeosGeometry();
Feature* f = new Feature( this, geom_id, userGeom, label_x, label_y );
if ( fixedPos )
{
f->setFixedPosition( labelPosX, labelPosY );
}
if ( xQuadOffset != 0 || yQuadOffset != 0 )
{
f->setQuadOffset( xQuadOffset, yQuadOffset );
}
if ( xOffset != 0.0 || yOffset != 0.0 )
{
f->setPosOffset( xOffset, yOffset );
}
if ( fixedAngle )
{
f->setFixedAngle( angle );
}
// use layer-level defined rotation, but not if position fixed
if ( !fixedPos && angle != 0.0 )
{
f->setFixedAngle( angle );
}
f->setRepeatDistance( repeatDistance );
f->setAlwaysShow( alwaysShow );
bool first_feat = true;
double geom_size = -1, biggest_size = -1;
FeaturePart* biggest_part = NULL;
// break the (possibly multi-part) geometry into simple geometries
QLinkedList<const GEOSGeometry*>* simpleGeometries = unmulti( the_geom );
if ( simpleGeometries == NULL ) // unmulti() failed?
{
mMutex.unlock();
throw InternalException::UnknownGeometry();
}
GEOSContextHandle_t geosctxt = geosContext();
while ( simpleGeometries->size() > 0 )
{
const GEOSGeometry* geom = simpleGeometries->takeFirst();
// ignore invalid geometries (e.g. polygons with self-intersecting rings)
if ( GEOSisValid_r( geosctxt, geom ) != 1 ) // 0=invalid, 1=valid, 2=exception
{
// std::cerr << "ignoring invalid feature " << geom_id << std::endl;
continue;
}
int type = GEOSGeomTypeId_r( geosctxt, geom );
if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON )
{
mMutex.unlock();
throw InternalException::UnknownGeometry();
}
FeaturePart* fpart = new FeaturePart( f, geom );
// ignore invalid geometries
if (( type == GEOS_LINESTRING && fpart->nbPoints < 2 ) ||
( type == GEOS_POLYGON && fpart->nbPoints < 3 ) )
{
delete fpart;
continue;
}
// polygons: reorder coordinates
if ( type == GEOS_POLYGON && reorderPolygon( fpart->nbPoints, fpart->x, fpart->y ) != 0 )
{
delete fpart;
continue;
}
if ( mMode == LabelPerFeature && ( type == GEOS_POLYGON || type == GEOS_LINESTRING ) )
{
if ( type == GEOS_LINESTRING )
//.........这里部分代码省略.........
示例10: parseData
bool KNMusicLRCLyricsParser::parseData(const QString &lyricsTextData,
QList<qint64> &positionList,
QStringList &textList)
{
//Clear the position list and text list.
positionList.clear();
textList.clear();
//Split the lyrics text data.
QStringList lyricsRawData=lyricsTextData.split(QRegExp("\n"),
QString::SkipEmptyParts);
QList<LyricsLine> lyricsLineList;
//Remove the same line in the lyrics raw data.
lyricsRawData.removeDuplicates();
//Parse the lyrics raw data.
while(!lyricsRawData.isEmpty())
{
//Get the first line of the current list and remove all spaces.
QString currentLine=lyricsRawData.takeFirst().simplified();
//Find frames in the current line.
QRegularExpressionMatchIterator frameMatcher=
m_frameCatchRegExp.globalMatch(currentLine);
int lastPosition=0;
QLinkedList<QString> frameLists;
//Get all the frames.
while(frameMatcher.hasNext())
{
QRegularExpressionMatch matchedFrame=frameMatcher.next();
//Check is the current matched frame is at the last position.
//An example is:
// [00:00:01] Won't chu kiss me![00:00:03]Saikou no
if(matchedFrame.capturedStart()!=lastPosition)
{
//Then we should pick out the data before the current start and
//last position.
//Like 'Won't chu kiss me!' in the example.
QString text=currentLine.mid(lastPosition,
matchedFrame.capturedStart()-lastPosition);
//Parse the datas to frame lists.
while(!frameLists.isEmpty())
{
parseFrames(frameLists.takeFirst(),
text,
lyricsLineList);
}
}
//Add current frame to frame list.
frameLists.append(currentLine.mid(matchedFrame.capturedStart(),
matchedFrame.capturedLength()));
//Update the last position.
lastPosition=matchedFrame.capturedEnd();
}
//Remove the previous datas, and parse the left datas to frame lists.
currentLine.remove(0, lastPosition);
while(!frameLists.isEmpty())
{
parseFrames(frameLists.takeFirst(),
currentLine,
lyricsLineList);
}
}
//Check is the lyrics line list is empty or not, if it's empty, means we
//can't parse it.
if(lyricsLineList.isEmpty())
{
return false;
}
//Sorr the lyrics line.
//- Why stable sort?
// Because there might be some frames at the same time. Display them with
//their exist order.
qStableSort(lyricsLineList.begin(), lyricsLineList.end(), frameLessThan);
//Combine the same timestamp lyrics.
QMap<qint64, QString> lyricsCombineMap;
for(QList<LyricsLine>::iterator i=lyricsLineList.begin();
i!=lyricsLineList.end();
++i)
{
lyricsCombineMap.insert((*i).position,
lyricsCombineMap.contains((*i).position)?
lyricsCombineMap.value((*i).position)+'\n'+(*i).text:
(*i).text);
}
//Export the position and the text.
positionList=lyricsCombineMap.keys();
textList=lyricsCombineMap.values();
return true;
}