本文整理汇总了C++中QList::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ QList::clear方法的具体用法?C++ QList::clear怎么用?C++ QList::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QList
的用法示例。
在下文中一共展示了QList::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: newLinesPalette
Palette* MuseScore::newLinesPalette()
{
Palette* sp = new Palette;
sp->setName(QT_TRANSLATE_NOOP("Palette", "Lines"));
sp->setMag(.8);
sp->setGrid(82, 35);
sp->setDrawGrid(true);
qreal w = gscore->spatium() * 8;
Slur* slur = new Slur(gscore);
slur->setId(0);
sp->append(slur, qApp->translate("lines", "Slur"));
Hairpin* gabel0 = new Hairpin(gscore);
gabel0->setHairpinType(Hairpin::CRESCENDO);
gabel0->setLen(w);
sp->append(gabel0, qApp->translate("lines", "Crescendo"));
Hairpin* gabel1 = new Hairpin(gscore);
gabel1->setHairpinType(Hairpin::DECRESCENDO);
gabel1->setLen(w);
sp->append(gabel1, QT_TRANSLATE_NOOP("Palette", "Diminuendo"));
Volta* volta = new Volta(gscore);
volta->setVoltaType(VoltaType::CLOSED);
volta->setLen(w);
volta->setText("1.");
QList<int> il;
il.append(1);
volta->setEndings(il);
sp->append(volta, QT_TRANSLATE_NOOP("Palette", "Prima volta"));
volta = new Volta(gscore);
volta->setVoltaType(VoltaType::CLOSED);
volta->setLen(w);
volta->setText("2.");
il.clear();
il.append(2);
volta->setEndings(il);
sp->append(volta, QT_TRANSLATE_NOOP("Palette", "Seconda volta"));
volta = new Volta(gscore);
volta->setVoltaType(VoltaType::CLOSED);
volta->setLen(w);
volta->setText("3.");
il.clear();
il.append(3);
volta->setEndings(il);
sp->append(volta, QT_TRANSLATE_NOOP("Palette", "Terza volta"));
volta = new Volta(gscore);
volta->setVoltaType(VoltaType::OPEN);
volta->setLen(w);
volta->setText("2.");
il.clear();
il.append(2);
volta->setEndings(il);
sp->append(volta, QT_TRANSLATE_NOOP("Palette", "Seconda volta 2"));
Ottava* ottava = new Ottava(gscore);
ottava->setOttavaType(OttavaType::OTTAVA_8VA);
ottava->setLen(w);
sp->append(ottava, QT_TRANSLATE_NOOP("Palette", "8va"));
ottava = new Ottava(gscore);
ottava->setOttavaType(OttavaType::OTTAVA_8VB);
ottava->setLen(w);
ottava->setPlacement(Element::BELOW);
sp->append(ottava, QT_TRANSLATE_NOOP("Palette", "8vb"));
ottava = new Ottava(gscore);
ottava->setOttavaType(OttavaType::OTTAVA_15MA);
ottava->setLen(w);
sp->append(ottava, QT_TRANSLATE_NOOP("Palette", "15ma"));
ottava = new Ottava(gscore);
ottava->setOttavaType(OttavaType::OTTAVA_15MB);
ottava->setLen(w);
ottava->setPlacement(Element::BELOW);
sp->append(ottava, QT_TRANSLATE_NOOP("Palette", "15mb"));
ottava = new Ottava(gscore);
ottava->setOttavaType(OttavaType::OTTAVA_22MA);
ottava->setLen(w);
sp->append(ottava, QT_TRANSLATE_NOOP("Palette", "22ma"));
ottava = new Ottava(gscore);
ottava->setOttavaType(OttavaType::OTTAVA_22MB);
ottava->setLen(w);
sp->append(ottava, QT_TRANSLATE_NOOP("Palette", "22mb"));
Pedal* pedal = new Pedal(gscore);
pedal->setLen(w);
sp->append(pedal, QT_TRANSLATE_NOOP("Palette", "Pedal"));
pedal = new Pedal(gscore);
pedal->setLen(w);
pedal->setEndHookType(HOOK_45);
//.........这里部分代码省略.........
示例2: createGui
void StandGrapher::createGui()
{
//--------------------------------------------------
// Universal button creator for the navigation bars
//--------------------------------------------------
class ButtonCreator
{
public:
static QPushButton * create(QWidget * parent, const QString & objName, const QIcon & icon,
const QKeySequence & key, QString toolTip, QWidget * target, const char * slot)
{
QPushButton * button = new QPushButton(parent);
button->setObjectName(objName);
button->setFocusPolicy(Qt::NoFocus);
connect(button, SIGNAL(pressed()), target, slot);
button->setIconSize(QSize(32, 32));
button->setIcon(QIcon(icon));
if (!key.isEmpty())
toolTip += " " + tr("(Shortcut: <b>%1</b>)").arg(key.toString());
button->setToolTip(toolTip);
QShortcut * shortcut = new QShortcut(key, target);
connect(shortcut, SIGNAL(activated()), target, slot);
return button;
}
};
QList<QPushButton *> buttons;
//-------------------------------------------
// Horizontal tool box
//-------------------------------------------
hToolBox = new QFrame(this);
hToolBox->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
hToolBox->setAutoFillBackground(true);
hToolBox->setCursor(Qt::ArrowCursor);
hToolBox->installEventFilter(this);
// Create buttons
buttons << ButtonCreator::create(hToolBox, "Start_button", QIcon(":/start.png"),
Qt::Key_Home, tr("Start"), this, SLOT(slotStart()));
buttons << ButtonCreator::create(hToolBox, "Prev_button", QIcon(":/previous.png"),
Qt::Key_Left, tr("Previous"), this, SLOT(slotPrevious()));
buttons << ButtonCreator::create(hToolBox, "HFit_button", QIcon(":/fit.png"),
QKeySequence(), tr("Fit horizontally"), this, SLOT(slotFit()));
buttons << ButtonCreator::create(hToolBox, "Next_button", QIcon(":/next.png"),
Qt::Key_Right, tr("Next"), this, SLOT(slotNext()));
buttons << ButtonCreator::create(hToolBox, "Finish_button", QIcon(":/finish.png"),
Qt::Key_End, tr("End"), this, SLOT(slotEnd()));
buttons << ButtonCreator::create(hToolBox, "HZoomIn_button", QIcon(":/plus.png"),
Qt::Key_Plus, tr("Wider"), this, SLOT(slotZoomIn()));
buttons << ButtonCreator::create(hToolBox, "HZoomOut_button", QIcon(":/minus.png"),
Qt::Key_Minus, tr("Narrower"), this, SLOT(slotZoomOut()));
// Layout buttons
QHBoxLayout * hLayout = new QHBoxLayout(hToolBox);
foreach(QPushButton * button, buttons)
hLayout->addWidget(button);
hToolBox->setLayout(hLayout);
//-------------------------------------------
// Vertical tool box
//-------------------------------------------
vToolBox = new QFrame(this);
vToolBox->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
vToolBox->setAutoFillBackground(true);
vToolBox->setCursor(Qt::ArrowCursor);
vToolBox->installEventFilter(this);
buttons.clear();
buttons << ButtonCreator::create(vToolBox, "Up_button", QIcon(":/up.png"),
Qt::Key_Up, tr("Up"), this, SLOT(slotUp()));
buttons << ButtonCreator::create(vToolBox, "VFit_button", QIcon(":/fit_vert.png"),
QKeySequence(), tr("Fit vertically"), this, SLOT(slotVFit()));
buttons << ButtonCreator::create(vToolBox, "Down_button", QIcon(":/down.png"),
Qt::Key_Down, tr("Down"), this, SLOT(slotDown()));
buttons << ButtonCreator::create(vToolBox, "VZoomIn_button", QIcon(":/plus.png"),
Qt::SHIFT+Qt::Key_Plus, tr("Wider"), this, SLOT(slotVZoomIn()));
buttons << ButtonCreator::create(vToolBox, "VZoomOut_button", QIcon(":/minus.png"),
Qt::SHIFT+Qt::Key_Minus, tr("Narrower"), this, SLOT(slotVZoomOut()));
// Layout buttons
QVBoxLayout * vLayout = new QVBoxLayout(vToolBox);
foreach(QPushButton * button, buttons)
vLayout->addWidget(button);
vToolBox->setLayout(vLayout);
//-------------------------------------------
// Tool Box
//-------------------------------------------
toolBox = new QFrame(this);
toolBox->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
toolBox->setAutoFillBackground(true);
toolBox->setCursor(Qt::ArrowCursor);
//.........这里部分代码省略.........
示例3: refreshEscrowTable
void refreshEscrowTable(EscrowModelType type)
{
cachedEscrowTable.clear();
{
string strMethod = string("escrowlist");
UniValue params(UniValue::VARR);
UniValue result ;
string name_str;
string time_str;
string seller_str;
string arbiter_str;
string status_str;
string offeraccept_str;
string offer_str;
string offertitle_str;
string total_str;
string buyer_str;
int unixTime;
QDateTime dateTime;
try {
result = tableRPC.execute(strMethod, params);
if (result.type() == UniValue::VARR)
{
name_str = "";
time_str = "";
seller_str = "";
arbiter_str = "";
status_str = "";
offeraccept_str = "";
offer_str = "";
offertitle_str = "";
total_str = "";
buyer_str = "";
const UniValue &arr = result.get_array();
for (unsigned int idx = 0; idx < arr.size(); idx++) {
const UniValue& input = arr[idx];
if (input.type() != UniValue::VOBJ)
continue;
const UniValue& o = input.get_obj();
name_str = "";
name_str = "";
seller_str = "";
arbiter_str = "";
status_str = "";
offeraccept_str = "";
offer_str = "";
total_str = "";
const UniValue& name_value = find_value(o, "escrow");
if (name_value.type() == UniValue::VSTR)
name_str = name_value.get_str();
const UniValue& time_value = find_value(o, "time");
if (time_value.type() == UniValue::VSTR)
time_str = time_value.get_str();
const UniValue& seller_value = find_value(o, "seller");
if (seller_value.type() == UniValue::VSTR)
seller_str = seller_value.get_str();
const UniValue& arbiter_value = find_value(o, "arbiter");
if (arbiter_value.type() == UniValue::VSTR)
arbiter_str = arbiter_value.get_str();
const UniValue& buyer_value = find_value(o, "buyer");
if (buyer_value.type() == UniValue::VSTR)
buyer_str = buyer_value.get_str();
const UniValue& offer_value = find_value(o, "offer");
if (offer_value.type() == UniValue::VSTR)
offer_str = offer_value.get_str();
const UniValue& offertitle_value = find_value(o, "offertitle");
if (offertitle_value.type() == UniValue::VSTR)
offertitle_str = offertitle_value.get_str();
const UniValue& offeraccept_value = find_value(o, "offeracceptlink");
if (offeraccept_value.type() == UniValue::VSTR)
offeraccept_str = offeraccept_value.get_str();
const UniValue& total_value = find_value(o, "total");
if (total_value.type() == UniValue::VSTR)
total_str = total_value.get_str();
const UniValue& status_value = find_value(o, "status");
if (status_value.type() == UniValue::VSTR)
status_str = status_value.get_str();
unixTime = atoi(time_str.c_str());
dateTime.setTime_t(unixTime);
time_str = dateTime.toString().toStdString();
updateEntry(QString::fromStdString(name_str), QString::fromStdString(time_str), QString::fromStdString(seller_str), QString::fromStdString(arbiter_str), QString::fromStdString(offer_str), QString::fromStdString(offertitle_str), QString::fromStdString(offeraccept_str), QString::fromStdString(total_str), QString::fromStdString(status_str), QString::fromStdString(buyer_str), type, CT_NEW);
}
}
}
catch (UniValue& objError)
{
return;
}
catch(std::exception& e)
{
return;
}
}
// qLowerBound() and qUpperBound() require our cachedEscrowTable list to be sorted in asc order
qSort(cachedEscrowTable.begin(), cachedEscrowTable.end(), EscrowTableEntryLessThan());
//.........这里部分代码省略.........
示例4: RemoveSeam
//! This function corrects the DNs in a given brick.
//! It also stores results in frameletOffsetsForBand every time the
//! band changes so it doesn't have to re-project at every framelet.
//! Equivalent changes are calculated for the next framelet... that is,
//! equivalent pixels. This function both calculates and applies these.
void RemoveSeam(Buffer &out, int framelet, int band,
bool matchIsEven) {
// Apply fixes from last pass. Basically all changes happen in two
// places, because the DNs exist in two cubes, this is the second
// place.
for(int fix = 0; fix < nextFrameletFixes.size(); fix ++) {
QPair<int, int> fixLoc = nextFrameletFixes[fix].first;
double fixDn = nextFrameletFixes[fix].second;
try {
int outIndex = out.Index(fixLoc.first, fixLoc.second, band);
out[outIndex] = fixDn;
}
catch(IException &) {
}
}
nextFrameletFixes.clear();
// Match == goodData. "goodData" is the top of the next framelet.
Cube *goodDataCube = (matchIsEven) ? evenCube : oddCube;
// "badData" is the bottom of the current framelet, what we were given.
Cube *badDataCube = (matchIsEven) ? oddCube : evenCube;
Camera *goodCam = goodDataCube->camera();
Camera *badCam = badDataCube->camera();
// Verify we're at the correct band
goodCam->SetBand(band);
badCam->SetBand(band);
// Absolute line number for top of framelets.
int goodDataStart = frameletSize * (framelet + 1);
int badDataStart = frameletSize * framelet;
// Start corrections to the current brick at this line
int badLineStart = goodDataStart - overlapSize - 1;
// End corrections to the current brick at this line
int badLineEnd = goodDataStart - 1;
int offsetSample = 0;
int offsetLine = 0;
// Loop left to right, top to bottom of problematic area at bottom of framelet
for(int badLine = badLineStart; badLine <= badLineEnd; badLine ++) {
for(int sample = 1; sample <= out.SampleDimension(); sample ++) {
// A fair good data weight is the % across problematic area so fair
double goodDataWeight = (double)(badLine - badLineStart) /
(double)(badLineEnd - badLineStart);
// But good data is good, so let's bias it towards the good data
goodDataWeight *= 2;
if(goodDataWeight > 1) goodDataWeight = 1;
// Bad data weight is the inverse of the good data's weight.
double badDataWeight = 1.0 - goodDataWeight;
int outIndex = out.Index(sample, badLine, band);
// This is the indexing scheme for frameletOffsetsForBand
int optimizeIndex = (badLine - badLineStart) * out.SampleDimension() +
sample - 1;
// Does the optimized (pre-calculated) translation from bad to good
// exist?
if(optimizeIndex < frameletOffsetsForBand.size()) {
// This offset any good? If not then do nothing.
if(!frameletOffsetsForBand[optimizeIndex].Valid())
continue;
// Use optimization!
offsetSample = frameletOffsetsForBand[optimizeIndex].SampleOffset();
offsetLine = frameletOffsetsForBand[optimizeIndex].LineOffset();
ASSERT(frameletOffsetsForBand[optimizeIndex].Sample() == sample);
}
// There is no pre-calculated translation, calculate it
else if(badCam->SetImage(sample, badLine)) {
double lat = badCam->UniversalLatitude();
double lon = badCam->UniversalLongitude();
if(goodCam->SetUniversalGround(lat, lon)) {
double goodSample = goodCam->Sample();
double goodLine = goodCam->Line();
// Set the current offset for correction
offsetSample = (int)(goodSample - sample + 0.5);
offsetLine = (int)(goodLine - badLine + 0.5);
// Remember this calculation for future passes
frameletOffsetsForBand.push_back(Offset(sample, badLine - badDataStart,
offsetSample, offsetLine));
}
else {
// Don't do anything since we failed at this pixel; it will be copied
// from the input directly
//.........这里部分代码省略.........
示例5: qDBusParametersForMethod
// calculates the metatypes for the method
// the slot must have the parameters in the following form:
// - zero or more value or const-ref parameters of any kind
// - zero or one const ref of QDBusMessage
// - zero or more non-const ref parameters
// No parameter may be a template.
// this function returns -1 if the parameters don't match the above form
// this function returns the number of *input* parameters, including the QDBusMessage one if any
// this function does not check the return type, so metaTypes[0] is always 0 and always present
// metaTypes.count() >= retval + 1 in all cases
//
// sig must be the normalised signature for the method
int qDBusParametersForMethod(const QMetaMethod &mm, QList<int>& metaTypes)
{
QDBusMetaTypeId::init();
QList<QByteArray> parameterTypes = mm.parameterTypes();
metaTypes.clear();
metaTypes.append(0); // return type
int inputCount = 0;
bool seenMessage = false;
QList<QByteArray>::ConstIterator it = parameterTypes.constBegin();
QList<QByteArray>::ConstIterator end = parameterTypes.constEnd();
for ( ; it != end; ++it) {
const QByteArray &type = *it;
if (type.endsWith('*')) {
//qWarning("Could not parse the method '%s'", mm.signature());
// pointer?
return -1;
}
if (type.endsWith('&')) {
QByteArray basictype = type;
basictype.truncate(type.length() - 1);
int id = qDBusNameToTypeId(basictype);
if (id == 0) {
//qWarning("Could not parse the method '%s'", mm.signature());
// invalid type in method parameter list
return -1;
} else if (QDBusMetaType::typeToSignature(id) == 0)
return -1;
metaTypes.append( id );
seenMessage = true; // it cannot appear anymore anyways
continue;
}
if (seenMessage) { // && !type.endsWith('&')
//qWarning("Could not parse the method '%s'", mm.signature());
// non-output parameters after message or after output params
return -1; // not allowed
}
int id = qDBusNameToTypeId(type);
if (id == 0) {
//qWarning("Could not parse the method '%s'", mm.signature());
// invalid type in method parameter list
return -1;
}
if (id == QDBusMetaTypeId::message)
seenMessage = true;
else if (QDBusMetaType::typeToSignature(id) == 0)
return -1;
metaTypes.append(id);
++inputCount;
}
return inputCount;
}
示例6: SetDefaultSettings
void Settings::SetDefaultSettings()
{
pMain->showMaximized();
QList<int> intList;
intList.append(qRound(pMain->GetUi()->splitter->height()*.5));
intList.append(qRound(pMain->GetUi()->splitter->height()*.25));
intList.append(qRound(pMain->GetUi()->splitter->height()*.25));
pMain->GetUi()->splitter->setSizes(intList);
intList.clear();
intList.append(qRound(pMain->GetUi()->splitter->width()*.25));
intList.append(qRound(pMain->GetUi()->splitter->width()*.75));
pMain->GetUi()->rulesSplitter->setSizes(intList);
intList.clear();
intList.append(qRound(pMain->GetUi()->splitter->width()*.80));
intList.append(qRound(pMain->GetUi()->splitter->width()*.20));
pMain->GetUi()->browserSplitter->setSizes(intList);
intList.clear();
intList.append(50);
intList.append(25);
intList.append(25);
intList.append(25);
intList.append(600);
intList.append(150);
intList.append(100);
intList.append(70);
for(int i = 0; i < intList.size(); i++)
pMain->GetUi()->browserTable->setColumnWidth(i, intList.at(i));
pMain->GetUi()->browserTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed);
pMain->GetUi()->browserTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Fixed);
pMain->GetUi()->browserTable->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Fixed);
pMain->GetUi()->browserTable->horizontalHeaderItem(5)->setTextAlignment(Qt::AlignLeft);
pMain->GetUi()->browserTable->horizontalHeaderItem(6)->setTextAlignment(Qt::AlignLeft);
intList.clear();
intList.append(125);
intList.append(125);
for(int i = 0; i < intList.size(); i++)
pMain->GetUi()->rulesTable->setColumnWidth(i, intList.at(i));
intList.clear();
intList.append(75);
intList.append(225);
intList.append(100);
intList.append(150);
intList.append(200);
for(int i = 0; i < intList.size(); i++)
pMain->GetUi()->playerTable->setColumnWidth(i, intList.at(i));
qsrand((uint)(QTime::currentTime()).msec());
pMain->u16logPort = qrand() % ((PORT_MAX + 1) - PORT_MIN) + PORT_MIN;
pMain->showLoggingInfo = true;
}
示例7: snapMapPoint
int QgsSnapper::snapMapPoint( const QgsPoint& mapCoordPoint, QList<QgsSnappingResult>& snappingResult, const QList<QgsPoint>& excludePoints )
{
snappingResult.clear();
QMultiMap<double, QgsSnappingResult> snappingResultList;//all snapping results
QMultiMap<double, QgsSnappingResult> currentResultList; //snapping results of examined layer
//start point in (output) map coordinates
QgsPoint layerCoordPoint; //start point in layer coordinates
QgsSnappingResult newResult;
QList<QgsSnapper::SnapLayer>::iterator snapLayerIt;
for ( snapLayerIt = mSnapLayers.begin(); snapLayerIt != mSnapLayers.end(); ++snapLayerIt )
{
if ( !snapLayerIt->mLayer->hasGeometryType() )
continue;
currentResultList.clear();
//transform point from map coordinates to layer coordinates
layerCoordPoint = mMapSettings.mapToLayerCoordinates( snapLayerIt->mLayer, mapCoordPoint );
double tolerance = QgsTolerance::toleranceInMapUnits( snapLayerIt->mTolerance, snapLayerIt->mLayer, mMapSettings, snapLayerIt->mUnitType );
if ( snapLayerIt->mLayer->snapWithContext( layerCoordPoint, tolerance,
currentResultList, snapLayerIt->mSnapTo ) != 0 )
{
//error
}
//transform each result from layer crs to map crs (including distance)
QMultiMap<double, QgsSnappingResult>::iterator currentResultIt;
for ( currentResultIt = currentResultList.begin(); currentResultIt != currentResultList.end(); ++currentResultIt )
{
//for each snapping result: transform start point, snap point and other points into map coordinates to find out distance
//store results in snapping result list
newResult = currentResultIt.value();
newResult.snappedVertex = mMapSettings.layerToMapCoordinates( snapLayerIt->mLayer, currentResultIt.value().snappedVertex );
newResult.beforeVertex = mMapSettings.layerToMapCoordinates( snapLayerIt->mLayer, currentResultIt.value().beforeVertex );
newResult.afterVertex = mMapSettings.layerToMapCoordinates( snapLayerIt->mLayer, currentResultIt.value().afterVertex );
snappingResultList.insert( sqrt( newResult.snappedVertex.sqrDist( mapCoordPoint ) ), newResult );
}
}
//excluded specific points from result
cleanResultList( snappingResultList, excludePoints );
//evaluate results according to snap mode
QMultiMap<double, QgsSnappingResult>::iterator evalIt = snappingResultList.begin();
if ( evalIt == snappingResultList.end() )
{
return 0;
}
//Gives a priority to vertex snapping over segment snapping
QgsSnappingResult returnResult = evalIt.value();
for ( evalIt = snappingResultList.begin(); evalIt != snappingResultList.end(); ++evalIt )
{
if ( evalIt.value().snappedVertexNr != -1 )
{
returnResult = evalIt.value();
snappingResultList.erase( evalIt );
break;
}
}
//We return the preferred result
snappingResult.push_back( returnResult );
if ( mSnapMode == QgsSnapper::SnapWithOneResult )
{
//return only a single result, nothing more to do
}
else if ( mSnapMode == QgsSnapper::SnapWithResultsForSamePosition )
{
//take all snapping results within a certain tolerance because rounding differences may occur
double tolerance = 0.000001;
for ( evalIt = snappingResultList.begin(); evalIt != snappingResultList.end(); ++evalIt )
{
if ( returnResult.snappedVertex.sqrDist( evalIt.value().snappedVertex ) < tolerance*tolerance )
{
snappingResult.push_back( evalIt.value() );
}
}
}
else //take all results
{
for ( evalIt = snappingResultList.begin(); evalIt != snappingResultList.end(); ++evalIt )
{
snappingResult.push_back( evalIt.value() );
}
}
return 0;
}
示例8: index
// The index timer has expired. Look for any unindexed notes or resources
void IndexRunner::index() {
if (disableIndexing)
return;
if (!keepRunning || pauseIndexing) {
return;
}
if (!init)
initialize();
indexTimer->stop(); // Stop the timer because we are already working
indexTimer->setInterval(global.minIndexInterval);
QList<qint32> lids;
NoteTable noteTable(&db->conn);
ResourceTable resourceTable(&db->conn);
bool endMsgNeeded = false;
int countPause = global.indexNoteCountPause;
QList<qint32> finishedLids;
// Get any unindexed notes
if (keepRunning && !pauseIndexing && noteTable.getIndexNeeded(lids) > 0) {
QApplication::processEvents();
endMsgNeeded = true;
QLOG_DEBUG() << "Unindexed Notes found: " << lids.size();
// Index any undindexed note content.
for (int i=0; keepRunning && !pauseIndexing && i<lids.size(); i++) {
QApplication::processEvents();
Note n;
noteTable.get(n, lids[i], false, false);
indexNote(lids[i],n);
finishedLids.append(lids[i]);
if (countPause <=0) {
flushCache();
for (int j=0; j<finishedLids.size(); j++)
noteTable.setIndexNeeded(finishedLids[j], false);
indexTimer->start();
return;
}
countPause--;
}
}
if (keepRunning && !pauseIndexing)
flushCache();
for (int j=0; !pauseIndexing && keepRunning && j<finishedLids.size(); j++)
noteTable.setIndexNeeded(finishedLids[j], false);
lids.clear(); // Clear out the list so we can start on resources
if (!keepRunning || pauseIndexing) {
indexTimer->start();
return;
}
countPause = global.indexResourceCountPause;
finishedLids.clear();
// Start indexing resources
if (keepRunning && !pauseIndexing && resourceTable.getIndexNeeded(lids) > 0) {
endMsgNeeded = true;
// Index each resource that is needed.
for (int i=0; keepRunning && !pauseIndexing && i<lids.size(); i++) {
QApplication::processEvents();
Resource r;
resourceTable.get(r, lids.at(i), false);
qint32 noteLid = noteTable.getLid(r.noteGuid);
indexRecognition(noteLid, r);
QString mime = "";
if (r.mime.isSet())
mime = r.mime;
if (mime == "application/pdf")
indexPdf(noteLid, r);
else {
if (mime.startsWith("application", Qt::CaseInsensitive))
indexAttachment(noteLid, r);
}
finishedLids.append(lids[i]);
if (countPause <=0) {
flushCache();
for (int j=0; keepRunning && !pauseIndexing && j<finishedLids.size(); j++) {
resourceTable.setIndexNeeded(finishedLids[j], false);
}
indexTimer->start();
return;
}
countPause--;
}
}
if (!keepRunning || pauseIndexing) {
indexTimer->start();
return;
}
if (keepRunning && !pauseIndexing)
flushCache();
//.........这里部分代码省略.........
示例9: processAlgorithm
QVariantMap QgsDissolveAlgorithm::processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) const
{
std::unique_ptr< QgsFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
if ( !source )
return QVariantMap();
QString dest;
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, source->fields(), QgsWkbTypes::multiType( source->wkbType() ), source->sourceCrs(), dest ) );
if ( !sink )
return QVariantMap();
QStringList fields = parameterAsFields( parameters, QStringLiteral( "FIELD" ), context );
long count = source->featureCount();
if ( count <= 0 )
return QVariantMap();
QgsFeature f;
QgsFeatureIterator it = source->getFeatures();
double step = 100.0 / count;
int current = 0;
if ( fields.isEmpty() )
{
// dissolve all - not using fields
bool firstFeature = true;
// we dissolve geometries in blocks using unaryUnion
QList< QgsGeometry > geomQueue;
QgsFeature outputFeature;
while ( it.nextFeature( f ) )
{
if ( feedback->isCanceled() )
{
break;
}
if ( firstFeature )
{
outputFeature = f;
firstFeature = false;
}
if ( f.hasGeometry() && f.geometry() )
{
geomQueue.append( f.geometry() );
if ( geomQueue.length() > 10000 )
{
// queue too long, combine it
QgsGeometry tempOutputGeometry = QgsGeometry::unaryUnion( geomQueue );
geomQueue.clear();
geomQueue << tempOutputGeometry;
}
}
feedback->setProgress( current * step );
current++;
}
outputFeature.setGeometry( QgsGeometry::unaryUnion( geomQueue ) );
sink->addFeature( outputFeature );
}
else
{
QList< int > fieldIndexes;
Q_FOREACH ( const QString &field, fields )
{
int index = source->fields().lookupField( field );
if ( index >= 0 )
fieldIndexes << index;
}
QHash< QVariant, QgsAttributes > attributeHash;
QHash< QVariant, QList< QgsGeometry > > geometryHash;
while ( it.nextFeature( f ) )
{
if ( feedback->isCanceled() )
{
break;
}
if ( f.hasGeometry() && f.geometry() )
{
QVariantList indexAttributes;
Q_FOREACH ( int index, fieldIndexes )
{
indexAttributes << f.attribute( index );
}
if ( !attributeHash.contains( indexAttributes ) )
{
// keep attributes of first feature
attributeHash.insert( indexAttributes, f.attributes() );
}
geometryHash[ indexAttributes ].append( f.geometry() );
}
示例10: read
//.........这里部分代码省略.........
geom->setCoordinates( GeoDataCoordinates( longitude , latitude , 0 , GeoDataCoordinates::Degree ) );
geometryList.append( geom );
}
} else if (geometryType == QLatin1String("MULTIPOINT")) {
// Check first that there are coordinates
const QJsonValue coordinatesValue = geometryObject.value(QStringLiteral("coordinates"));
if (coordinatesValue.isArray()) {
const QJsonArray coordinateArray = coordinatesValue.toArray();
for (int pointIndex = 0; pointIndex < coordinateArray.size(); ++pointIndex) {
const QJsonArray coordinatePairArray = coordinateArray[pointIndex].toArray();
GeoDataPoint * geom = new GeoDataPoint();
const qreal longitude = coordinatePairArray.at(0).toDouble();
const qreal latitude = coordinatePairArray.at(1).toDouble();
geom->setCoordinates( GeoDataCoordinates( longitude , latitude , 0 , GeoDataCoordinates::Degree ) );
geometryList.append( geom );
}
}
}
// Parse the features properties
const QJsonValue propertiesValue = featureObject.value(QStringLiteral("properties"));
if (!geometryList.isEmpty() && propertiesValue.isObject()) {
const QJsonObject propertiesObject = propertiesValue.toObject();
// First create a placemark for each geometry, there could be multi geometries
// that are translated into more than one geometry/placemark
for ( int numberGeometries = 0 ; numberGeometries < geometryList.length() ; numberGeometries++ ) {
GeoDataPlacemark * placemark = new GeoDataPlacemark();
placemarkList.append( placemark );
}
OsmPlacemarkData osmData;
QJsonObject::ConstIterator it = propertiesObject.begin();
const QJsonObject::ConstIterator end = propertiesObject.end();
for ( ; it != end; ++it) {
if (it.value().isObject() || it.value().isArray()) {
qDebug() << "Skipping property, values of type arrays and objects not supported:" << it.key();
continue;
}
// pass value through QVariant to also get bool & numbers
osmData.addTag(it.key(), it.value().toVariant().toString());
}
// If the property read, is the features name
const auto tagIter = osmData.findTag(QStringLiteral("name"));
if (tagIter != osmData.tagsEnd()) {
const QString& name = tagIter.value();
for (int pl = 0 ; pl < placemarkList.length(); ++pl) {
placemarkList.at(pl)->setName(name);
}
}
const GeoDataPlacemark::GeoDataVisualCategory category = StyleBuilder::determineVisualCategory(osmData);
if (category != GeoDataPlacemark::None) {
// Add the visual category to all the placemarks
for (int pl = 0 ; pl < placemarkList.length(); ++pl) {
placemarkList.at(pl)->setVisualCategory(category);
placemarkList.at(pl)->setOsmData(osmData);
}
}
}
// Add the geometry to the document
if ( geometryList.length() == placemarkList.length() ) {
while( placemarkList.length() > 0 ) {
GeoDataPlacemark * placemark = placemarkList.last();
placemarkList.pop_back();
GeoDataGeometry * geom = geometryList.last();
geometryList.pop_back();
placemark->setGeometry( geom );
placemark->setVisible( true );
m_document->append( placemark );
}
}
// If geometries or placemarks missing inside the lists, delete them
qDeleteAll( geometryList.begin(), geometryList.end() );
geometryList.clear();
qDeleteAll( placemarkList.begin(), placemarkList.end() );
placemarkList.clear();
}
}
}
return true;
}
示例11: warning
void
AbstractTrackTableCommitter::commit( const QList<Meta::SqlTrackPtr> &tracks )
{
// Note: The code is greatly inspired by the old ScanResultProcessor
// by jeffrai
// Note2: The code is optimized for batch update.
// Reason: a single update is completely harmless and not frequent.
// The real difficulty is the collection scanner and it's runtime
// Especially with collections larger than 30000 tracks.
if( tracks.isEmpty() )
return;
m_storage = tracks.first()->sqlCollection()->sqlStorage();
// -- get the maximum size for our commit
static int maxSize = 0;
if( maxSize == 0 )
{
QStringList res = m_storage->query( "SHOW VARIABLES LIKE 'max_allowed_packet';" );
if( res.size() < 2 || res[1].toInt() == 0 )
{
warning() << "Uh oh! For some reason MySQL thinks there isn't a max allowed size!";
return;
}
debug() << "obtained max_allowed_packet is " << res[1];
maxSize = res[1].toInt() / 3; //for safety, due to multibyte encoding
}
QStringList fields = getFields();
const QString updateQueryStart = "UPDATE LOW_PRIORITY "+tableName()+" SET ";
const QString insertQueryStart = "INSERT INTO "+tableName()+
" ("+fields.join(",")+") VALUES ";
QList< Meta::SqlTrackPtr > insertedTracks;
QString insertQuery;
insertQuery.reserve( 1024 ); // a sensible initial size
foreach( Meta::SqlTrackPtr track, tracks )
{
QStringList values = getValues( track.data() );
// -- update
if( getId( track.data() ) > 0 )
{
// we just commit all values to save code complexity.
// we would need to track the real changed fields otherwise
QString updateQuery;
updateQuery.reserve( 256 ); // a sensible initial size
for( int i = 0; i < fields.count() && i < values.count(); i++ )
{
if( !updateQuery.isEmpty() )
updateQuery += ", ";
updateQuery += fields.at( i );
updateQuery += '=';
updateQuery += values.at( i );
}
updateQuery = updateQueryStart + updateQuery +
" WHERE id=" + QString::number( getId( track.data() ) ) + ';';
m_storage->query( updateQuery );
}
else
// -- insert
{
QString newValues = '(' + values.join(",") + ')';
// - if the insertQuery is long enough, commit it.
if( insertQueryStart.length() + insertQuery.length() + newValues.length() + 1 >= maxSize - 3 ) // ";"
{
// commit
insertQuery = insertQueryStart + insertQuery + ';';
int firstId = m_storage->insert( insertQuery, tableName() );
// set the resulting ids
if( firstId <= 0 )
warning() << "Insert failed.";
for( int i = 0; i < insertedTracks.count(); i++ )
setId( const_cast<Meta::SqlTrack*>(insertedTracks.at( i ).data()),
firstId + i );
insertQuery.clear();
insertedTracks.clear();
}
if( !insertQuery.isEmpty() )
insertQuery += ',';
insertQuery += newValues;
insertedTracks.append( track );
}
}
示例12: getChildList
void SymbolNode::getChildList( QList<Ptr>& childList ) const
{
childList.clear();
for (ConstChildIterator pChild = childConstBegin(); pChild != childConstEnd(); ++pChild)
childList.push_back(pChild.value());
}
示例13: measurePolygon
unsigned char* QgsDistanceArea::measurePolygon( unsigned char* feature, double* area, double* perimeter, bool hasZptr )
{
// get number of rings in the polygon
unsigned int numRings = *(( int* )( feature + 1 + sizeof( int ) ) );
if ( numRings == 0 )
return 0;
// Set pointer to the first ring
unsigned char* ptr = feature + 1 + 2 * sizeof( int );
QList<QgsPoint> points;
QgsPoint pnt;
double x, y;
if ( area )
*area = 0;
if ( perimeter )
*perimeter = 0;
try
{
for ( unsigned int idx = 0; idx < numRings; idx++ )
{
int nPoints = *(( int* )ptr );
ptr += 4;
// Extract the points from the WKB and store in a pair of
// vectors.
for ( int jdx = 0; jdx < nPoints; jdx++ )
{
x = *(( double * ) ptr );
ptr += sizeof( double );
y = *(( double * ) ptr );
ptr += sizeof( double );
if ( hasZptr )
{
// totally ignore Z value
ptr += sizeof( double );
}
pnt = QgsPoint( x, y );
if ( mProjectionsEnabled && ( mEllipsoid != "NONE" ) )
{
pnt = mCoordTransform->transform( pnt );
}
points.append( pnt );
}
if ( points.size() > 2 )
{
if ( area )
{
double areaTmp = computePolygonArea( points );
if ( idx == 0 )
{
// exterior ring
*area += areaTmp;
}
else
{
*area -= areaTmp; // interior rings
}
}
if ( perimeter )
{
*perimeter += measureLine( points );
}
}
points.clear();
if ( !area )
{
break;
}
}
}
catch ( QgsCsException &cse )
{
Q_UNUSED( cse );
QgsMessageLog::logMessage( QObject::tr( "Caught a coordinate system exception while trying to transform a point. Unable to calculate polygon area or perimeter." ) );
}
return ptr;
}
示例14: addData
bool DigitizerSetTreeItem::addData(const FIFFLIB::FiffDigPointSet& tDigitizer, Qt3DCore::QEntity* parent)
{
bool state = false;
//parsing the digitizer List
QList<FIFFLIB::FiffDigPoint> tNasion;
QList<FIFFLIB::FiffDigPoint> tLAP;
QList<FIFFLIB::FiffDigPoint> tRAP;
QList<FIFFLIB::FiffDigPoint> tHpi;
QList<FIFFLIB::FiffDigPoint> tEeg;
QList<FIFFLIB::FiffDigPoint> tExtra;
for(int i = 0; i < tDigitizer.size(); ++i){
switch (tDigitizer[i].kind) {
case FIFFV_POINT_CARDINAL:
switch (tDigitizer[i].ident) {
case FIFFV_POINT_LPA:
tLAP.append(tDigitizer[i]);
break;
case FIFFV_POINT_NASION:
tNasion.append(tDigitizer[i]);
break;
case FIFFV_POINT_RPA:
tRAP.append(tDigitizer[i]);
break;
default:
break;
}
break;
case FIFFV_POINT_HPI:
tHpi.append(tDigitizer[i]);
break;
case FIFFV_POINT_EEG:
tEeg.append(tDigitizer[i]);
break;
case FIFFV_POINT_EXTRA:
tExtra.append(tDigitizer[i]);
break;
default:
break;
}
}
// Find the Digitizer Items
QList<QStandardItem*> itemList = this->findChildren(Data3DTreeModelItemTypes::DigitizerItem);
if (!tLAP.empty()){
//Create a LAP digitizer item
DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(Data3DTreeModelItemTypes::DigitizerItem,"LAP");
state = digitizerItem->addData(tLAP, parent);
itemList << digitizerItem;
itemList << new QStandardItem(digitizerItem->toolTip());
this->appendRow(itemList);
itemList.clear();
}
if (!tNasion.empty()){
//Create a Nasion digitizer item
DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(Data3DTreeModelItemTypes::DigitizerItem,"Nasion");
state = digitizerItem->addData(tNasion, parent);
itemList << digitizerItem;
itemList << new QStandardItem(digitizerItem->toolTip());
this->appendRow(itemList);
itemList.clear();
}
if (!tRAP.empty()){
//Create a RAO digitizer item
DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(Data3DTreeModelItemTypes::DigitizerItem,"RAP");
state = digitizerItem->addData(tRAP, parent);
itemList << digitizerItem;
itemList << new QStandardItem(digitizerItem->toolTip());
this->appendRow(itemList);
itemList.clear();
}
if (!tHpi.empty()){
//Create a HPI digitizer item
DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(Data3DTreeModelItemTypes::DigitizerItem,"HPI");
state = digitizerItem->addData(tHpi, parent);
itemList << digitizerItem;
itemList << new QStandardItem(digitizerItem->toolTip());
this->appendRow(itemList);
itemList.clear();
}
if (!tEeg.empty()){
//Create a EEG digitizer item
DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(Data3DTreeModelItemTypes::DigitizerItem,"EEG/ECG");
state = digitizerItem->addData(tEeg, parent);
itemList << digitizerItem;
itemList << new QStandardItem(digitizerItem->toolTip());
this->appendRow(itemList);
itemList.clear();
}
if (!tExtra.empty()){
//Create a extra digitizer item
DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(Data3DTreeModelItemTypes::DigitizerItem,"Extra");
state = digitizerItem->addData(tExtra, parent);
itemList << digitizerItem;
itemList << new QStandardItem(digitizerItem->toolTip());
this->appendRow(itemList);
itemList.clear();
}
//.........这里部分代码省略.........
示例15: loadListFile
void MainWindow::loadListFile()
{
qDebug() << "Loading list file:" << listFile->text();
QFile lf(listFile->text());
if (!lf.open(QFile::ReadOnly)) {
qWarning("Cannot open list file!");
return;
}
QTextStream ts(&lf);
ts.setCodec("UTF-8");
if (ts.status() != QTextStream::Ok) {
lf.close();
qWarning("Cannot construct text stream!");
return;
}
tree->clear();
QTreeWidgetItem *item = tree->invisibleRootItem();
while (!ts.atEnd()) {
QString line = ts.readLine();
if (line.isEmpty())
continue;
if (!filter->text().isEmpty())
if (QRegExp(filter->text(), Qt::CaseInsensitive).indexIn(line) == -1)
continue;
QStringList lv = line.split('/', QString::SkipEmptyParts);
// Extract parent path
QList<QTreeWidgetItem *> list;
while (item && item != tree->invisibleRootItem()) {
list.push_front(item);
item = item->parent();
}
while (!lv.isEmpty()) {
QString str = lv.takeFirst();
// TODO: parent folder .. support
if (str.isEmpty() || str == ".")
continue;
// Remove common path from parent path
if (!list.isEmpty()) {
QTreeWidgetItem *it = list.takeFirst();
if (it->text(0) == str) {
item = it;
continue;
} else
list.clear();
}
// Find entry
if (!item)
item = tree->invisibleRootItem();
int i;
for (i = 0; i < item->childCount(); i++)
if (item->child(i)->text(0) == str)
break;
if (i == item->childCount())
item = new QTreeWidgetItem(item, QStringList(str));
else
item = item->child(i);
}
}
// Sort entries
tree->sortByColumn(0, Qt::AscendingOrder);
// Add file icons
QFileIconProvider fip;
QMap<QString, QIcon> iconMap;
QTreeWidgetItemIterator it(tree->invisibleRootItem());
while (*++it) // Ignore root
if ((*it)->childCount())
(*it)->setIcon(0, fip.icon(fip.Folder));
else {
QFileInfo fi((*it)->text(0));
QString sfx = fi.suffix();
#if 0 // FIXME: File icon retrieval not working
QIcon icon = iconMap[sfx];
if (icon.isNull()) {
QTemporaryFile tf(QDir::tempPath() + "/XXXXXX." + sfx);
tf.open();
iconMap[sfx] = icon = fip.icon(fip.File/*QFileInfo(tf)*/);
}
(*it)->setIcon(0, icon);
#else
iconMap[sfx] = fip.icon(fip.File);
#endif
}
qDebug() << "List file loaded.";
lf.close();
}