int main() { QList<int> list; list << 3 << 3 << 6 << 6 << 6 << 8; QList<int>::iterator it; it = qLowerBound(list.begin(), list.end(), 5); list.insert(it, 5); qDebug() << list; // output: ( 3, 3, 5, 6, 6, 6, 8 ) it = qLowerBound(list.begin(), list.end(), 12); list.insert(it, 12); qDebug() << list; // output: ( 3, 3, 5, 6, 6, 6, 8, 12 ) it = qLowerBound(list.begin(), list.end(), 12); list.insert(it, 12); qDebug() << list; // output: ( 3, 3, 5, 6, 6, 6, 8, 12, 12 ) QVector<int> vect; vect << 3 << 3 << 6 << 6 << 6 << 8; QVector<int>::iterator begin6 = qLowerBound(vect.begin(), vect.end(), 6); QVector<int>::iterator end6 = qUpperBound(vect.begin(), vect.end(), 6); QVector<int> vect2(end6-begin6); qCopy(begin6, end6, vect2.begin()); qDebug() << vect2; // output: ( 6, 6, 6 ) int count6 = 0; qCount(vect.begin(), vect.end(), 6, count6); qDebug() << count6; // output: 3 return 0; }
quint32 QGLView::getSelection() { QList<quint32> ids; QList<quint32> sortedIds; int selectionSize = 5; // only odd selection sizes make sense int sizeOffset; QPoint correctedSelectionPoint; sizeOffset = qFloor((float)selectionSize/2.0); // calculate the offset // correct the position of the selection to center the mouse click correctedSelectionPoint.setX(qMin(qMax(m_selectionPoint.x() - sizeOffset, 0), window()->width() - selectionSize)); correctedSelectionPoint.setY(qMin(qMax(m_selectionPoint.y() - sizeOffset, 0), window()->height() - selectionSize)); // read the data for (int i = 0; i < (selectionSize * selectionSize); ++i) { GLcolorRGB colorRGB; quint32 id; glReadPixels(correctedSelectionPoint.x() + (i % selectionSize), correctedSelectionPoint.y() + (i / selectionSize), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &colorRGB); id = ((quint32)colorRGB.r << 16) + ((quint32)colorRGB.g << 8) + (quint32)colorRGB.b; if ((id != 0) && (!ids.contains(id))) // collect all ids in selection { ids.append(id); } } int maxCount = 0; // find the id that is most common in the selection foreach(quint32 id, ids) { int count = 0; qCount(ids.begin(), ids.end(), id, count); if (count > maxCount) { sortedIds.prepend(id); maxCount = count; } else { sortedIds.append(id); } }
nsProbingState UnicodeGroupProber::HandleData(const char* aBuf, unsigned int aLen) { nsSMState codingState; int j; uint i, weight_BOM, counts[5]; static bool disableUTF16LE = false; static bool disableUTF16BE = false; double weight_zero; if (mActiveSM <= 0) { mState = eNotMe; return mState; } if (! (disableUTF16LE || disableUTF16BE)) { if (aLen%2 != 0) { disableUTF16LE = true; disableUTF16BE = true; } weight_BOM = (uint)(sqrt((double)aLen) + aLen/10.0); for (uint i = 0; i < 5; i++) qCount(aBuf, aBuf+aLen, char(i), counts[i]); weight_zero = (2.0*(counts[0] + counts[1] + counts[2] + counts[3] + counts[4]) + weight_BOM)/aLen; if (weight_zero < log(1.4142)) { disableUTF16LE = true; disableUTF16BE = true; } if (4 >= aBuf[1] && aBuf[1] >= 0 && isprint(aBuf[0])) disableUTF16BE = true; else disableUTF16LE = true; if (disableUTF16BE) mActiveSM--; if (disableUTF16LE) { nsCodingStateMachine* t; t = mCodingSM[1]; mCodingSM[1] = mCodingSM[2]; mCodingSM[2] = t; mActiveSM--; } } for (i = 0; i < aLen; ++i) { for (j = mActiveSM-1; j>= 0; --j) { //byte is feed to all active state machine codingState = mCodingSM[j]->NextState(aBuf[i]); if (codingState == eError) { //got negative answer for this state machine, make it inactive mActiveSM--; if (mActiveSM == 0) { mState = eNotMe; return mState; } else if (j != (int)mActiveSM) { nsCodingStateMachine* t; t = mCodingSM[mActiveSM]; mCodingSM[mActiveSM] = mCodingSM[j]; mCodingSM[j] = t; } } else if (codingState == eItsMe) { mState = eFoundIt; mDetectedCharset = mCodingSM[j]->GetCodingStateMachine(); return mState; } else if (mState == eDetecting) mDetectedCharset = mCodingSM[j]->GetCodingStateMachine();; } } return mState; }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QTextCodec::setCodecForLocale(QTextCodec::codecForName("GB2312")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GB2312")); QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312")); QStringList list; list<<"one"<<"two"<<"three"; qDebug()<<QObject::tr("qCopu() methord:"); QVector<QString>vect(3); qCopy(list.begin(),list.end(),vect.begin()); qDebug()<<vect; /****************************************************************************************************/ qDebug()<<endl<<QObject::tr("qEqual() methord:"); bool bl=qEqual(list.begin(),list.end(),vect.begin()); qDebug()<<bl; // QList<QString>::iterator i; // i=qFind(list.begin,list.end(),"two"); /****************************************************************************************************/ qDebug()<<endl<<QObject::tr("qFind() methord:"); QStringList::const_iterator i= qFind(list.begin(), list.end(), "two"); qDebug()<<*i; /****************************************************************************************************/ qDebug()<<endl<<QObject::tr("qFill() methord:"); qFill(list.begin(),list.end(),"eleven"); qDebug()<<list; /****************************************************************************************************/ QList<int>list2; list2<<2<<31<<13<<2<<2<<2<<134<<2<<123<<4<<5<<3<<5<<51; qDebug()<<endl<<QObject::tr("qCount() methord:"); int number=0; qCount(list2.begin(),list2.end(),2,number); qDebug()<<"The number of 2 is:"<<number; qSort(list2); QList<int>::iterator j=qLowerBound(list2.begin(),list2.end(),22); list2.insert(j,22); /****************************************************************************************************/ qDebug()<<list2; qStableSort(list2); qDebug()<<endl<<list2; /****************************************************************************************************/ qSort(list2.begin(),list2.end(),qGreater<int>()); qDebug()<<endl<<list2; /****************************************************************************************************/ qStableSort(list2.begin(),list2.end(),qGreater<int>()); qDebug()<<endl<<list2; /****************************************************************************************************/ double d1=311.3998; double d2=0.231314; qDebug()<<endl<<"before swap:"<<d1<<" "<<d2; qSwap(d1,d2); qDebug()<<"then swap:"<<d1<<" "<<d2; /****************************************************************************************************/ int int_a=qBound(2,49,12); qDebug()<<"int_a="<<int_a; QDateTime time = QDateTime::currentDateTime(); //QString s=time.toString("yyyy-MM-dd hh:mm:ss"); qDebug()<<time.toString(); return a.exec(); }