示例#1
0
void tst_QHash::keys_values_uniqueKeys()
{
    QHash<QString, int> hash;
    QVERIFY(hash.uniqueKeys().isEmpty());
    QVERIFY(hash.keys().isEmpty());
    QVERIFY(hash.values().isEmpty());

    hash.insertMulti("alpha", 1);
    QVERIFY(sorted(hash.keys()) == (QList<QString>() << "alpha"));
    QVERIFY(hash.keys() == hash.uniqueKeys());
    QVERIFY(hash.values() == (QList<int>() << 1));

    hash.insertMulti("beta", -2);
    QVERIFY(sorted(hash.keys()) == (QList<QString>() << "alpha" << "beta"));
    QVERIFY(hash.keys() == hash.uniqueKeys());
    QVERIFY(sorted(hash.values()) == sorted(QList<int>() << 1 << -2));

    hash.insertMulti("alpha", 2);
    QVERIFY(sorted(hash.uniqueKeys()) == (QList<QString>() << "alpha" << "beta"));
    QVERIFY(sorted(hash.keys()) == (QList<QString>() << "alpha" << "alpha" << "beta"));
    QVERIFY(sorted(hash.values()) == sorted(QList<int>() << 2 << 1 << -2));

    hash.insertMulti("beta", 4);
    QVERIFY(sorted(hash.uniqueKeys()) == (QList<QString>() << "alpha" << "beta"));
    QVERIFY(sorted(hash.keys()) == (QList<QString>() << "alpha" << "alpha" << "beta" << "beta"));
    QVERIFY(sorted(hash.values()) == sorted(QList<int>() << 2 << 1 << 4 << -2));
}
示例#2
0
文件: domain.cpp 项目: parcusDZV/relf
void Domain::computeDomain()
{
    if(parentPosBlock->isConst)
    {
        //domena pro konstanty
        int i = 0;
        this->maksOfEmptyDomain.resize(myExamples->getAllExamples()->size());
        for(vector<one_example>::iterator iexample = myExamples->getAllExamples()->begin(); iexample != myExamples->getAllExamples()->end(); ++iexample)
        {
            int position = myExamples->getTermId(parentPosBlock->predicate);

            QBitArray myBitArray(position+1, false);
            if(position <= (*iexample).termOccurences.size() && (*iexample).termOccurences.testBit(position))
                myBitArray.setBit(position,true);
            else
            {
                myBitArray.setBit(position,false);
                this->maksOfEmptyDomain.setBit(i, true);
            }
            termOccurences4Examples[i] = myBitArray;
            i++;
        }
    }
    else
    {
        //domena pro zbyvajici
        int i = 0;
        for(vector<one_example>::iterator iexample = myExamples->getAllExamples()->begin(); iexample != myExamples->getAllExamples()->end(); ++iexample)
        {
            QHash<int, bool> termsHashOccurences;
            int maxCount = 0;   //maximalni pocet bitu
            for(vector<predicate>::iterator ipred = (*iexample).predicates.begin(); ipred != (*iexample).predicates.end(); ++ipred)
            {
                //shodny nazev predikatu a arita
                if(parentPosBlock->predicate.toStdString() == (*ipred).predicate && parentPosBlock->arity == (*ipred).arity)
                {
                    for(vector<string>::iterator iterm = (*ipred).terms.begin(); iterm != (*ipred).terms.end(); ++iterm)
                    {
                        int termID = myExamples->getTermId(QString::fromStdString(*iterm));
                        termsHashOccurences.insert(termID, true);   //ukladam id termu
                        if(maxCount < termID)
                            maxCount = termID;
                    }
                }
            }

            QBitArray myBitArray(maxCount+1, false);
            QList<int> termsListOccurences = termsHashOccurences.uniqueKeys();
            for(QList<int>::iterator ilist = termsListOccurences.begin(); ilist != termsListOccurences.end(); ++ilist)
            {
                myBitArray.setBit(*ilist, true);    //nastavuji prislusnou pozici v bitarray
            }

            termOccurences4Examples[i] = myBitArray;
            i++;
        }
    }
}
示例#3
0
void TabManagerWidget::closeSelectedTabs(const QHash<BrowserWindow*, WebTab*> &tabsHash)
{
    if (tabsHash.isEmpty()) {
        return;
    }

    const QList<BrowserWindow*> &windows = tabsHash.uniqueKeys();
    foreach (BrowserWindow* mainWindow, windows) {
        QList<WebTab*> tabs = tabsHash.values(mainWindow);

        foreach (WebTab* webTab, tabs) {
            mainWindow->tabWidget()->requestCloseTab(webTab->tabIndex());
        }
示例#4
0
void CAlgorithmPanel::activateAlgorithm()
{
    if (processignImagePath == "NONE")
    {
        if (typeProcessingRadioGroup->checkedButton() == 0)
            messageBox.information(0,"VSDF","Select processing mode (single or multi).");
        else
            messageBox.information(0,"VSDF","Click on image in MDI adrea you want to process.");
    }
    else if(availableAlgorithms->selectedItems().size() == 0)
    {
        messageBox.information(0,"VSDF","Select algorithm from list.");
    }
    else if(processignImagePath == "MULTI_MODE")
    {
        QString algorithm = availableAlgorithms->currentItem()->text();

        QHash<QString, QImage> tempHash;
		QHash<QString, QPoint> tempHashPoint;
		QHash<QString, int> tempHashRadius;
		QPoint tempPoint;
		int radius;

        QHash<QString, QImage>::const_iterator iterator = imageContainer->constBegin();
        while (iterator != imageContainer->constEnd())
        {
            QImage imageWithAlgorithm;
            imageWithAlgorithm = iterator.value();

            if(algorithm == "Gray scale")
                imageWithAlgorithm = COpenCV::toGrayScale(imageWithAlgorithm);
            else if(algorithm == "Negative")
                imageWithAlgorithm = COpenCV::toNegative(imageWithAlgorithm);
			else if(algorithm == "Find and draw circles")
				imageWithAlgorithm = COpenCV::findAndDrawCircles(imageWithAlgorithm, &tempPoint, &radius);
            else{}

            QString nameOfImageWithAlgorithm = iterator.key();
            nameOfImageWithAlgorithm.append("_") += algorithm;

            QString nameOfImageWithAlgorithmChecked = nameOfImageWithAlgorithm;

            int i = 1;
            while(imageContainer->contains(nameOfImageWithAlgorithmChecked))
            {
                  nameOfImageWithAlgorithmChecked = nameOfImageWithAlgorithm + (QString::number(i));
                  i++;
            }

            tempHash.insert(nameOfImageWithAlgorithmChecked, imageWithAlgorithm);
			if(algorithm == "Find and draw circles")
			{
				tempHashPoint.insert(nameOfImageWithAlgorithmChecked, tempPoint);
				tempHashRadius.insert(nameOfImageWithAlgorithmChecked, radius);
			}
            iterator++;
        }

        imageContainer->unite(tempHash);
		pointContainer->unite(tempHashPoint);
		radiusContainer->unite(tempHashRadius);

        QList<QString> newImages = tempHash.uniqueKeys();

        for (int i=0; i < newImages.size(); ++i)
        {
            emit alorithmWasActivated("", newImages.at(i));
        }

        QListWidgetItem newItem(algorithm);
        imageFilters->insert(processignImagePath, newItem);

        refreshUsedAlgorithmList();
    }
    else
    {
		QPoint tempPoint;
		int radius;
        QString algorithm = availableAlgorithms->currentItem()->text();

        QImage imageWithAlgorithm;
        imageWithAlgorithm = imageContainer->value(processignImagePath);

        if(algorithm == "Gray scale")
            imageWithAlgorithm = COpenCV::toGrayScale(imageWithAlgorithm);
        else if(algorithm == "Negative")
            imageWithAlgorithm = COpenCV::toNegative(imageWithAlgorithm);
		else if(algorithm == "Find and draw circles")
			imageWithAlgorithm = COpenCV::findAndDrawCircles(imageWithAlgorithm, &tempPoint, &radius);
        else{}

        QString nameOfImageWithAlgorithm = processignImagePath;
        nameOfImageWithAlgorithm.append("_") += algorithm;

        QString nameOfImageWithAlgorithmChecked = nameOfImageWithAlgorithm;

        int i = 1;
        while(imageContainer->contains(nameOfImageWithAlgorithmChecked))
        {
              nameOfImageWithAlgorithmChecked = nameOfImageWithAlgorithm + (QString::number(i));
              i++;
        }

        QString imageInActiveWindow = processignImagePath;
        QString addText = imageFilters->value(processignImagePath).text();

        if (!addText.isEmpty())
            imageInActiveWindow.append("_") += addText;

        imageContainer->insert(nameOfImageWithAlgorithmChecked, imageWithAlgorithm);
		if(algorithm == "Find and draw circles")
		{
			pointContainer->insert(nameOfImageWithAlgorithmChecked, tempPoint);
			radiusContainer->insert(nameOfImageWithAlgorithmChecked, radius);
		}

        emit alorithmWasActivated(imageInActiveWindow, nameOfImageWithAlgorithmChecked);

        QListWidgetItem newItem(algorithm);
        imageFilters->insert(processignImagePath, newItem);

        refreshUsedAlgorithmList();
    }
}
void QGpgMECryptoConfigComponent::sync( bool runtime )
{
  KTemporaryFile tmpFile;
  tmpFile.open();

  QList<QGpgMECryptoConfigEntry *> dirtyEntries;

  // Collect all dirty entries
  const QList<QString> keylist = mGroupsByName.uniqueKeys();
  Q_FOREACH (const QString & key, keylist) {
    const QHash<QString,QGpgMECryptoConfigEntry*> entry = mGroupsByName[key]->mEntriesByName;
    const QList<QString> keylistentry = entry.uniqueKeys();
    Q_FOREACH (const QString & keyentry, keylistentry) {
      if(entry[keyentry]->isDirty())
      {
       // OK, we can set it.currentKey() to it.current()->outputString()
        QString line = keyentry;
        if ( entry[keyentry]->isSet() ) { // set option
          line += ":0:";
          line += entry[keyentry]->outputString();
        } else {                       // unset option
          line += ":16:";
        }
#ifdef Q_OS_WIN
        line += '\r';
#endif
        line += '\n';
        const QByteArray line8bit = line.toUtf8(); // encode with utf8, and K3ProcIO uses utf8 when reading.
        tmpFile.write( line8bit );
        dirtyEntries.append( entry[keyentry] );

      }
    }
  }

  tmpFile.flush();
  if ( dirtyEntries.isEmpty() )
    return;

  // Call gpgconf --change-options <component>
  const QString gpgconf = QGpgMECryptoConfig::gpgConfPath();
  QString commandLine = gpgconf.isEmpty()
      ? QString::fromLatin1( "gpgconf" )
      : KShell::quoteArg( gpgconf ) ;
  if ( runtime )
    commandLine += " --runtime";
  commandLine += " --change-options ";
  commandLine += KShell::quoteArg( mName );
  commandLine += " < ";
  commandLine += KShell::quoteArg( tmpFile.fileName() );

  //kDebug(5150) << commandLine;
  //system( QCString( "cat " ) + tmpFile.name().toLatin1() ); // DEBUG

  KProcess proc;
  proc.setShellCommand( commandLine );

  // run the process:
  int rc = proc.execute();

  if ( rc == -2 )
  {
    QString wmsg = i18n( "Could not start gpgconf.\nCheck that gpgconf is in the PATH and that it can be started." );
    kWarning(5150) << wmsg;
    KMessageBox::error(0, wmsg);
  }
  else if( rc != 0 ) // Happens due to bugs in gpgconf (e.g. issues 104/115)
  {
    QString wmsg = i18n( "Error from gpgconf while saving configuration: %1", QString::fromLocal8Bit( strerror( rc ) ) );
    kWarning(5150) <<":" << strerror( rc );
    KMessageBox::error(0, wmsg);
  }
  else
  {
    QList<QGpgMECryptoConfigEntry *>::const_iterator it = dirtyEntries.constBegin();
    for( ; it != dirtyEntries.constEnd(); ++it ) {
      (*it)->setDirty( false );
    }
  }
}