Example #1
0
/**
 * @brief cwRegionLoadTask::loadSurveyChunk
 * @param protoChunk
 * @param chunk
 */
void cwRegionLoadTask::loadSurveyChunk(const CavewhereProto::SurveyChunk& protoChunk, cwSurveyChunk *chunk)
{
    QList<cwStation> stations;
    stations.reserve(protoChunk.stations_size());
    for(int i = 0 ; i < protoChunk.stations_size(); i++) {
        cwStation station = loadStation(protoChunk.stations(i));
        stations.append(station);
    }

    QList<cwShot> shots;
    shots.reserve(protoChunk.shots_size());
    for(int i = 0; i < protoChunk.shots_size(); i++) {
        cwShot shot = loadShot(protoChunk.shots(i));
        shots.append(shot);
    }

    if(stations.count() - 1 != shots.count()) {
        qDebug() << "Shot, station count mismatch, survey chunk invalid:" << stations.count() << shots.count();
        return;
    }

    for(int i = 0; i < stations.count() - 1; i++) {
        cwStation fromStation = stations[i];
        cwStation toStation = stations[i + 1];
        cwShot shot = shots[i];

        chunk->appendShot(fromStation, toStation, shot);
    }
}
Example #2
0
/**
 * @brief cwRegionLoadTask::loadScrap
 * @param protoScrap
 * @param scrap
 */
void cwRegionLoadTask::loadScrap(const CavewhereProto::Scrap& protoScrap, cwScrap *scrap)
{
    QVector<QPointF> outlinePoint;
    outlinePoint.resize(protoScrap.outlinepoints_size());
    for(int i = 0; i < protoScrap.outlinepoints_size(); i++) {
        outlinePoint[i] = loadPointF(protoScrap.outlinepoints(i));
    }
    scrap->setPoints(outlinePoint);

    QList<cwNoteStation> stations;
    stations.reserve(protoScrap.notestations_size());
    for(int i = 0; i < protoScrap.notestations_size(); i++) {
        stations.append(loadNoteStation(protoScrap.notestations(i)));
    }
    scrap->setStations(stations);

    QList<cwLead> leads;
    leads.reserve(protoScrap.leads_size());
    for(int i = 0; i < protoScrap.leads_size(); i++) {
        leads.append(loadLead(protoScrap.leads(i)));
    }
    scrap->setLeads(leads);

    loadNoteTranformation(protoScrap.notetransformation(), scrap->noteTransformation());
    scrap->setCalculateNoteTransform(protoScrap.calculatenotetransform());
    scrap->setTriangulationData(loadTriangulatedData(protoScrap.triangledata()));
    scrap->setType((cwScrap::ScrapType)protoScrap.type());
}
Example #3
0
QList<TextShaper::TextRun> TextShaper::itemizeBiDi()
{
	QList<TextRun> textRuns;
	UBiDi *obj = ubidi_open();
	UErrorCode err = U_ZERO_ERROR;

	UBiDiLevel parLevel = UBIDI_LTR;
	ParagraphStyle style = m_story.paragraphStyle(m_firstChar);
	if (style.direction() == ParagraphStyle::RTL)
		parLevel = UBIDI_RTL;

	ubidi_setPara(obj, (const UChar*) m_text.utf16(), m_text.length(), parLevel, NULL, &err);
	if (U_SUCCESS(err))
	{
		int32_t count = ubidi_countRuns(obj, &err);
		if (U_SUCCESS(err))
		{
			textRuns.reserve(count);
			for (int32_t i = 0; i < count; i++)
			{
				int32_t start, length;
				UBiDiDirection dir = ubidi_getVisualRun(obj, i, &start, &length);
				textRuns.append(TextRun(start, length, dir));
			}
		}
	}

	ubidi_close(obj);
	return textRuns;
}
void FollowupReminderInfoDialogTest::shouldAddItemInTreeList()
{
    FollowUpReminderInfoDialog dlg;
    FollowUpReminderInfoWidget *infowidget = dlg.findChild<FollowUpReminderInfoWidget *>(QStringLiteral("FollowUpReminderInfoWidget"));
    QTreeWidget *treeWidget = infowidget->findChild<QTreeWidget *>(QStringLiteral("treewidget"));
    QList<FollowUpReminder::FollowUpReminderInfo *> lstInfo;
    lstInfo.reserve(10);
    for (int i = 0; i < 10; ++i) {
        FollowUpReminder::FollowUpReminderInfo *info = new FollowUpReminder::FollowUpReminderInfo();
        lstInfo.append(info);
    }
    dlg.setInfo(lstInfo);
    //We load invalid infos.
    QCOMPARE(treeWidget->topLevelItemCount(), 0);

    //Load valid infos
    for (int i = 0; i < 10; ++i) {
        FollowUpReminder::FollowUpReminderInfo *info = new FollowUpReminder::FollowUpReminderInfo();
        info->setOriginalMessageItemId(42);
        info->setMessageId(QStringLiteral("foo"));
        info->setFollowUpReminderDate(QDate::currentDate());
        info->setTo(QStringLiteral("To"));
        lstInfo.append(info);
    }

    dlg.setInfo(lstInfo);
    QCOMPARE(treeWidget->topLevelItemCount(), 10);
}
Example #5
0
int ClipboardBrowser::removeIndexes(const QModelIndexList &indexes)
{
    if ( indexes.isEmpty() )
        return -1;

    Q_ASSERT(m_itemLoader);
    m_itemLoader->itemsRemovedByUser(indexes);

    QList<int> rows;
    rows.reserve( indexes.size() );

    foreach (const QModelIndex &index, indexes) {
        if ( index.isValid() )
            rows.append( index.row() );
    }

    qSort( rows.begin(), rows.end(), qGreater<int>() );

    ClipboardBrowser::Lock lock(this);
    foreach (int row, rows) {
        if ( !isRowHidden(row) )
            m.removeRow(row);
    }

    return rows.last();
}
std::shared_ptr<OsmAnd::ObfDataInterface> OsmAnd::ObfsCollection_P::obtainDataInterface() const
{
    // Check if sources were invalidated
    if (_collectedSourcesInvalidated.loadAcquire() > 0)
        collectSources();

    // Create ObfReaders from collected sources
    QList< std::shared_ptr<const ObfReader> > obfReaders;
    {
        QReadLocker scopedLocker(&_collectedSourcesLock);

        for(const auto& collectedSources : constOf(_collectedSources))
        {
            obfReaders.reserve(obfReaders.size() + collectedSources.size());
            for(const auto& obfFile : constOf(collectedSources))
            {
                std::shared_ptr<const ObfReader> obfReader(new ObfReader(obfFile));
                if (!obfReader->isOpened() || !obfReader->obtainInfo())
                    continue;
                obfReaders.push_back(qMove(obfReader));
            }
        }
    }

    return std::shared_ptr<ObfDataInterface>(new ObfDataInterface(obfReaders));
}
bool GenericEditableTableModel::insertRows ( int row, int count, const QModelIndex & parent)
{
    if(row<0 || row>rowCount()){
        return false;
    }

    beginInsertRows(parent, row, row+count-1);

    modelData.reserve(rowCount()+count);


    int colCount=columnCount();
    int currentRowCount=rowCount();


    for(int i=0; i<count; i++){
        QList<QHash<int,QVariant> > newCols;
        newCols.reserve(colCount);
        for(int j=0; j<colCount; j++){
            newCols.append(QHash<int,QVariant>());
        }
        if(row==currentRowCount){
            modelData.append(newCols);
        }else{
            modelData.insert(row+i, newCols);
        }
    }


    endInsertRows();

    return true;
}
Example #8
0
void QgsRasterShader::readXML( const QDomElement& elem )
{
  //only colorrampshader
  QDomElement colorRampShaderElem = elem.firstChildElement( "colorrampshader" );
  if ( !colorRampShaderElem.isNull() )
  {
    QgsColorRampShader* colorRampShader = new QgsColorRampShader();
    colorRampShader->setColorRampType( colorRampShaderElem.attribute( "colorRampType", "INTERPOLATED" ) );
    colorRampShader->setClip( colorRampShaderElem.attribute( "clip", "0" ) == "1" );

    QList<QgsColorRampShader::ColorRampItem> itemList;
    QDomElement itemElem;
    QString itemLabel;
    double itemValue;
    QColor itemColor;

    QDomNodeList itemNodeList = colorRampShaderElem.elementsByTagName( "item" );
    itemList.reserve( itemNodeList.size() );
    for ( int i = 0; i < itemNodeList.size(); ++i )
    {
      itemElem = itemNodeList.at( i ).toElement();
      itemValue = itemElem.attribute( "value" ).toDouble();
      itemLabel = itemElem.attribute( "label" );
      itemColor.setNamedColor( itemElem.attribute( "color" ) );
      itemColor.setAlpha( itemElem.attribute( "alpha", "255" ).toInt() );

      itemList.push_back( QgsColorRampShader::ColorRampItem( itemValue, itemColor, itemLabel ) );
    }
    colorRampShader->setColorRampItemList( itemList );
    setRasterShaderFunction( colorRampShader );
  }
}
Example #9
0
void CookieJar::load()
{
    QFile cookieFile(m_cookieFileName);
    if (!cookieFile.open(QIODevice::ReadOnly))
        return;

    QDataStream stream(&cookieFile);
    quint8 version;
    stream >> version;
    if (version != cookieFileVersion)
        return;

    QList<QNetworkCookie> cookies;
    qint32 count;
    stream >> count;

#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
    cookies.reserve(count);
#endif
    for (int i = 0; i < count && !stream.atEnd(); ++i) {
        QByteArray rawCookie;
        stream >> rawCookie;
        cookies += QNetworkCookie::parseCookies(rawCookie);
    }

    setAllCookies(cookies);

    expireCookies();
}
Example #10
0
/**
 * @brief cwRegionLoadTask::loadCave
 * @param protoCave
 * @param cave
 */
void cwRegionLoadTask::loadCave(const CavewhereProto::Cave& protoCave, cwCave *cave)
{
    QString name = loadString(protoCave.name());
    cwUnits::LengthUnit lengthUnit = (cwUnits::LengthUnit)protoCave.lengthunit();
    cwUnits::LengthUnit depthUnit = (cwUnits::LengthUnit)protoCave.depthunit();

    QList<cwTrip*> trips;
    trips.reserve(protoCave.trips_size());

    cave->setName(name);
    cave->length()->setUnit(lengthUnit);
    cave->depth()->setUnit(depthUnit);

    for(int i = 0; i < protoCave.trips_size(); i++) {
        cwTrip* trip = new cwTrip();
        loadTrip(protoCave.trips(i), trip);
        cave->addTrip(trip);
    }

    cwStationPositionLookup stationLookup = loadStationPositionLookup(protoCave.stationpositionlookup());
    cave->setStationPositionLookup(stationLookup);

    if(protoCave.has_stationpositionlookup()) {
        cave->setStationPositionLookupStale(protoCave.stationpositionlookupstale());
    }
}
Example #11
0
QList<QRectF> OpenCVUtils::fromRects(const QList<Rect> &cvRects)
{
    QList<QRectF> qRects;
    qRects.reserve(cvRects.size());
    foreach (const Rect &cvRect, cvRects)
        qRects.append(fromRect(cvRect));
    return qRects;
}
Example #12
0
QList<int> fromAsebaVector(const std::vector<sint16>& values)
{
	QList<int> data;
	data.reserve(values.size());
	for (auto value = values.begin(); value != values.end(); ++value)
		data.push_back(*value);
	return data;
}
Example #13
0
QList<QPointF> OpenCVUtils::fromPoints(const QList<Point2f> &cvPoints)
{
    QList<QPointF> qPoints;
    qPoints.reserve(cvPoints.size());
    foreach (const Point2f &cvPoint, cvPoints)
        qPoints.append(fromPoint(cvPoint));
    return qPoints;
}
Example #14
0
QList<Rect> OpenCVUtils::toRects(const QList<QRectF> &qRects)
{
    QList<Rect> cvRects;
    cvRects.reserve(qRects.size());
    foreach (const QRectF &qRect, qRects)
        cvRects.append(toRect(qRect));
    return cvRects;
}
Example #15
0
static QList<QString> contactNames(const QList<Event::Contact> &contacts)
{
    QList<QString> re;
    re.reserve(contacts.size());
    foreach (const Event::Contact &c, contacts)
        re.append(c.second);
    return re;
}
Example #16
0
static QList<int> contactIds(const QList<Event::Contact> &contacts)
{
    QList<int> re;
    re.reserve(contacts.size());
    foreach (const Event::Contact &c, contacts)
        re.append(c.first);
    return re;
}
Example #17
0
::DosQVariant *dos_qvariant_create_array(int size, ::DosQVariant **array)
{
    QList<QVariant> data;
    data.reserve(size);
    for (int i = 0; i < size; ++i)
        data << *(static_cast<QVariant *>(array[i]));
    return new QVariant(data);
}
Example #18
0
QList<Point2f> OpenCVUtils::toPoints(const QList<QPointF> &qPoints)
{
    QList<Point2f> cvPoints;
    cvPoints.reserve(qPoints.size());
    foreach (const QPointF &qPoint, qPoints)
        cvPoints.append(toPoint(qPoint));
    return cvPoints;
}
Example #19
0
double QgsDistanceArea::measurePerimeter( const QgsGeometry* geometry ) const
{
  if ( !geometry )
    return 0.0;

  const QgsAbstractGeometryV2* geomV2 = geometry->geometry();
  if ( !geomV2 || geomV2->dimension() < 2 )
  {
    return 0.0;
  }

  if ( !mEllipsoidalMode || mEllipsoid == GEO_NONE )
  {
    return geomV2->perimeter();
  }

  //create list with (single) surfaces
  QList< const QgsSurfaceV2* > surfaces;
  const QgsSurfaceV2* surf = dynamic_cast<const QgsSurfaceV2*>( geomV2 );
  if ( surf )
  {
    surfaces.append( surf );
  }
  const QgsMultiSurfaceV2* multiSurf = dynamic_cast<const QgsMultiSurfaceV2*>( geomV2 );
  if ( multiSurf )
  {
    surfaces.reserve(( surf ? 1 : 0 ) + multiSurf->numGeometries() );
    for ( int i = 0; i  < multiSurf->numGeometries(); ++i )
    {
      surfaces.append( static_cast<const QgsSurfaceV2*>( multiSurf->geometryN( i ) ) );
    }
  }

  double length = 0;
  QList<const QgsSurfaceV2*>::const_iterator surfaceIt = surfaces.constBegin();
  for ( ; surfaceIt != surfaces.constEnd(); ++surfaceIt )
  {
    if ( !*surfaceIt )
    {
      continue;
    }

    QgsPolygonV2* poly = ( *surfaceIt )->surfaceToPolygon();
    const QgsCurveV2* outerRing = poly->exteriorRing();
    if ( outerRing )
    {
      length += measure( outerRing );
    }
    int nInnerRings = poly->numInteriorRings();
    for ( int i = 0; i < nInnerRings; ++i )
    {
      length += measure( poly->interiorRing( i ) );
    }
    delete poly;
  }
  return length;
}
Example #20
0
QList<QPlatformScreen *> QWaylandScreen::virtualSiblings() const
{
    QList<QPlatformScreen *> list;
    const QList<QWaylandScreen*> screens = mWaylandDisplay->screens();
    list.reserve(screens.count());
    foreach (QWaylandScreen *screen, screens)
        list << screen;
    return list;
}
Example #21
0
QList<ListDigraph::Node> ProcessModel::topolSortReachableFrom(const QList<ListDigraph::Node>& s) {
	ListDigraph::NodeMap<bool > nodevisited(graph, false);
	QList<ListDigraph::Node> res;
	QStack<ListDigraph::Node> stack;
	ListDigraph::Node curnode;
	ListDigraph::Node pnode;
	ListDigraph::Node snode;
	QList<ListDigraph::Node> reachable = reachableFrom(s);

	// Reserve memory
	res.reserve(countNodes(graph));
	stack.reserve(countNodes(graph));

	for (int i = 0; i < s.size(); i++) {
		if (s[i] != INVALID) {
			stack.push(s[i]);
		}
	}

	bool psched;
	while (!stack.empty()) {
		curnode = stack.pop();

		if (!nodevisited[curnode]) { // This node has not been visited yet

			// Check whether all predecessors in reachable are scheduled
			psched = true;
			for (ListDigraph::InArcIt iait(graph, curnode); iait != INVALID; ++iait) {
				pnode = graph.source(iait);
				if (reachable.contains(pnode)) { // Consider only nodes which can be reached from s
					if (!nodevisited[pnode]) {
						psched = false;
						break;
					}
				}
			}

			if (psched) { // All predecessors have been visited
				res.append(curnode);
				nodevisited[curnode] = true;

				// Push the succeeding nodes
				for (ListDigraph::OutArcIt oait(graph, curnode); oait != INVALID; ++oait) {
					snode = graph.target(oait);
					if (!nodevisited[snode]) {
						stack.push(snode);
					}
				}
			} else {
				stack.prepend(curnode);
			}

		} // Else ignore the visited node
	}

	return res;
}
void TDMetricCollector::run()
{
    while (true) {
        QList<int> &unprocessed = fOwner.unprocessedAreas;
        fOwner.mutex.lock();
        if (unprocessed.contains(++currentArea)) {
            unprocessed.removeOne(currentArea);
        } else if (!unprocessed.empty()) {
            currentArea = unprocessed.takeAt((qrand() * unprocessed.count()) / RAND_MAX);
        } else {
            fOwner.mutex.unlock();
            msleep(500);
            continue;
        }
        fOwner.mutex.unlock();

        int start = fOwner.blockSize * currentArea;
        int end = start + fOwner.blockSize;
        for (int i = start; i < end; ++i) {
            if (fOwner.metrics[i].dmetric >= 0)
                continue;

            const TFrameInfo &f1 = fOwner.fMatches[i];
            const TFrameInfo &f2 = fOwner.fMatches[qMax(i - 1, 0)];

            QList<int> framesNeeded;
            framesNeeded.reserve(4);
            framesNeeded.append(f1.top);
            framesNeeded.append(f1.bottom);
            framesNeeded.append(f2.top);
            framesNeeded.append(f2.bottom);
            qSort(framesNeeded);

            // make sure the new frames always fit in the cache so they won't be deleted prematurely
            cache.setMaxCost(cache.maxCost() + 4);
            QListIterator<int> j(framesNeeded);
            while (j.hasNext())
                if (!cache.contains(j.next()))
                    cache.insert(j.peekPrevious(), video->getFrame(j.peekPrevious()));

            int dmetric = 0;
            int sad = 0;
            calculateSAD(cache[f1.top], cache[f1.bottom],
                         cache[f2.top], cache[f2.bottom],
                         video->videoInfo(), dmetric, sad);

            fOwner.metrics[i].dmetric = dmetric;
            fOwner.metrics[i].sad = sad;
            // shrink the cache again to remove the oldest frames
            cache.setMaxCost(cache.maxCost() - 4);
        }

    }

    // no more work to do for the moment, reduce the cache size?
}
Example #23
0
/**
 * @brief cwRegionLoadTask::loadTeam
 * @param protoTeam
 * @param team
 */
void cwRegionLoadTask::loadTeam(const CavewhereProto::Team& protoTeam, cwTeam *team)
{
    QList<cwTeamMember> members;
    members.reserve(protoTeam.teammembers_size());
    for(int i = 0; i < protoTeam.teammembers_size(); i++) {
        cwTeamMember member = loadTeamMember(protoTeam.teammembers(i));
        members.append(member);
    }
    team->setTeamMembers(members);
}
Example #24
0
 QList<MetaData> MetaDataStore::modifiedExcludingOnlyRenamed() const {
     QList<MetaData> modified;
     modified.reserve(_backup.count() - _only_path_changed.count());
     foreach (const MetaData meta, _data) {
         if (isModified(meta) && !_only_path_changed.contains(meta.id())) {
             modified << meta;
         }
     }
     return modified;
 }
QList<QWidget*> QgsDataDefinedButton::registeredCheckedWidgets()
{
  QList<QWidget*> wdgtList;
  wdgtList.reserve( mCheckedWidgets.size() );
  for ( int i = 0; i < mCheckedWidgets.size(); ++i )
  {
    wdgtList << mCheckedWidgets.at( i );
  }
  return wdgtList;
}
Example #26
0
void SearchEngine::listSearchResFromScriptVal(const QScriptValue& value, QList<SearchResult*>& list)
{
	int len = value.property("length").toInt32();
	list.reserve(len);

	for (int i = 0; i < len; i++)
	{
		list.append(qobject_cast<SearchResult*>(value.property(QString::number(i)).toQObject()));
	}
}
Example #27
0
QVariant Response::getEntries() const
{
    if (m_count < 0 || m_entries.isEmpty())
        return QVariant();

    QList<QVariant> res;
    res.reserve(m_entries.size());
    Q_FOREACH (const Entry &entry, m_entries)
	res.append(QJson::QObjectHelper::qobject2qvariant(&entry));
    return res;
}
SetMarkedObjectPropertyDlg::SetMarkedObjectPropertyDlg(QWidget* parent)
    : QDialog(parent)
    , Ui::SetMarkedObjectPropertyDlg()
    , mMarkedObjectTreeRoot(NULL)
    , mColorSelectorLocked(false)
{
    setupUi(this);

    //设置初始值
    setMarkedTypeItems(QStringList());
    setMarkedTypeName(QString());
    setMarkedObjectName(QString());
    setMarkedObjectColor(QColor(0, 0, 255));

    //为不同类别预生成颜色列表
    //颜色分配方案说明:按灰度从0.0到1.0对应到伪彩色(从蓝到红),灰度依次为0.0、1.0、0.5、0.25、0.75、0.125、0.375、0.625、0.875……
    const unsigned PRE_CREATE_COLOR_NUM = 100; //默认预分配100个类型的颜色
    QList<float> grayValueList;
    grayValueList.reserve(PRE_CREATE_COLOR_NUM);
    grayValueList.push_back(0.0);
    grayValueList.push_back(1.0);
    unsigned level = 1;
    while (grayValueList.size() < PRE_CREATE_COLOR_NUM)
    {
        const float grayValueStep = 1.0 / (1 << level);
        for (unsigned colorIndexPerLevel = 1; colorIndexPerLevel < (1 << level); colorIndexPerLevel += 2)
        {
            grayValueList.push_back(grayValueStep * colorIndexPerLevel);
            if (grayValueList.size() >= PRE_CREATE_COLOR_NUM)
            {
                break;
            }
        }
        level++;
    }
    //qSort(grayValueList);
    mColorList.reserve(PRE_CREATE_COLOR_NUM);
    for (unsigned colorIndex = 0; colorIndex < PRE_CREATE_COLOR_NUM; colorIndex++)
    {
        mColorList.push_back(gray2PseudoColor(grayValueList.at(colorIndex)));
    }

    //设置选择颜色按钮响应
    connect(colorSelectButton, SIGNAL(clicked()), this, SLOT(selectColor()));

    //标记类型输入框内容改变时,名称输入框相应改变
    connect(typeComboBox, SIGNAL(editTextChanged(const QString &)), this, SLOT(autoSetMarkedObjectName(const QString &)));

    //标记类型输入框内容改变时,颜色相应改变
    connect(typeComboBox, SIGNAL(editTextChanged(const QString &)), this, SLOT(autoSetMarkedObjectColor(const QString &)));

    //“确定”按钮点击事件
    connect(okButton, SIGNAL(clicked()), this, SLOT(checkInputAndCommit()));
}
Example #29
0
LayerOrder *LayerOrder::deserialize(const uchar *data, uint len)
{
	if(len<2 || len>256)
		return 0;

	QList<uint8_t> order;
	order.reserve(len);
	for(uint i=1;i<len;++i)
		order.append(data[i]);

	return new LayerOrder(data[0], order);
}
Example #30
0
/*!
    Returns the MIME types for the file name \a fileName.

    If the file name doesn't match any known pattern, an empty list is returned.
    If multiple MIME types match this file, they are all returned.

    This function does not try to open the file. To also use the content
    when determining the MIME type, use mimeTypeForFile() or
    mimeTypeForFileNameAndData() instead.

    \sa mimeTypeForFile()
*/
QList<QMimeType> QMimeDatabase::mimeTypesForFileName(const QString &fileName) const
{
    QMutexLocker locker(&d->mutex);

    QStringList matches = d->mimeTypeForFileName(fileName);
    QList<QMimeType> mimes;
    matches.sort(); // Make it deterministic
    mimes.reserve(matches.count());
    foreach (const QString &mime, matches)
        mimes.append(d->mimeTypeForName(mime));
    return mimes;
}