void filterNetworkAccessModule::extractObjects()
{
    if(!this->parseQnStack.isEmpty())
    {
        if( this->parseQnStack.front() == this->ObjectLevel)
        {
            while(!this->parseQnStack.isEmpty())
            {
                std::cout << "Processing..." << std::endl;

                QXmlStreamReader::TokenType tempType = this->parseTypeStack.front();
                this->parseTypeStack.pop_front();
                QString tempQn = this->parseQnStack.front();
                this->parseQnStack.pop_front();
                QString tempText = this->parseTextStack.front();
                this->parseTextStack.pop_front();

                std::cout << "QN : " << tempQn.toAscii().data() <<  " : " << tempType << std::endl;

                //create a new object for the stack
                QMultiMap<QString, QString> *temp = new QMultiMap<QString, QString>;
                do
                {
                    //get the next item from the stack
                    tempType = this->parseTypeStack.front();
                    this->parseTypeStack.pop_front();

                    tempQn = this->parseQnStack.front();
                    this->parseQnStack.pop_front();

                    tempText = this->parseTextStack.front();
                    this->parseTextStack.pop_front();

                    //DEBUG
                    std::cout << "Adding: (" << tempQn.toAscii().data() << "," << tempText.toAscii().data() << ")" << std::endl;

                    //create object
                    temp->insert(tempQn, tempText);


                }while(!this->parseQnStack.isEmpty() && this->parseQnStack.front() != this->ObjectLevel);

                //add object to list
                std::cout << "adding record for " << temp->count() << " submaps" << std::endl;
                std::cout << "block: " << temp->value(QString("name")).toAscii().data() << std::endl;
                this->finalObjects->push_back(temp);
            }
//            std::cout << "Number of Objects:" << this->finalObjects->size() << std::endl;

        }
        else
        {
            std::cerr << "Empty Status: " << this->parseQnStack.size() << std::endl;
            std::cerr << "Back Item: " << this->parseQnStack.back().toAscii().data() << std::endl;
            std::cerr << ":EXTRACTION LOOP EXITS WITHOUT EXECUTING:" << std::endl;
        }
    }
}
Example #2
0
QStringList Statistics::ranking(QString key){
    QMultiMap<quint64, QString> *map = this->_rankings.value(key);
    QStringList rankedList;
    QList<quint64> keys = map->keys();

    for(int i = keys.length()-1; i >= 0;--i){
        rankedList.append(map->value(keys.at(i)));
    }

    return rankedList;
}
QString BlackBerryCertificate::command() const
{
    QString command;
    // TOOD: Give user choice to select NDK from where to get commands
    QMultiMap<QString, QString> qnxEnv = BlackBerryConfigurationManager::instance().defaultQnxEnv();
    if (!qnxEnv.isEmpty()) {
        command = qnxEnv.value(QLatin1String("QNX_HOST"))
                + QLatin1String("/usr/bin/blackberry-keytool");

        if (Utils::HostOsInfo::isWindowsHost())
            command += QLatin1String(".bat");
    }

    return command;
}
void CalculateTaskScore::run()
{

    qDebug() << "CalculateTaskScore: Starting new thread";

    ConfigParser settings;
    QDateTime started = QDateTime::currentDateTime();
    ctemplate::TemplateDictionary dict("user_task_score");
    db = MySQLHandler::getInstance();
    QMultiMap<int, LCCode> users = UserDao::getUserNativeLCCodes(db);
    QList<QSharedPointer<Task> > tasks = this->getTasks();  //Must use custom function to check message for task id

    QMultiMap<int, LCCode> userSecondaryLanguages = UserDao::getUserLCCodes(db);
    QMultiMap<int, int> userTags = UserDao::getUserTagIds(db);
    QMultiMap<int, int> taskTags = TaskDao::getTaskTagIds(db);

    if(users.count() > 0) {
        for(QMultiMap<int, LCCode>::ConstIterator usersIter = users.constBegin(); usersIter != users.constEnd(); ++usersIter) {
            if(tasks.length() > 0) {
                const LCCode userNativeLCCode = users.value(usersIter.key());
                QList<TaskScore> taskScores;
                foreach(QSharedPointer<Task> task, tasks) {
                    int score = 0;

                    Locale taskSourceLocale = task->sourcelocale();

                    if(userNativeLCCode.first == taskSourceLocale.languagecode()) {
                        score += 750;
                        if(userNativeLCCode.second == taskSourceLocale.countrycode()) {
                            score += 75;
                        }
                    }

                    Locale taskTargetLocale = task->targetlocale();

                    if(userNativeLCCode.first == taskTargetLocale.languagecode()) {
                        score += 1000;
                        if(userNativeLCCode.second == taskTargetLocale.countrycode()) {
                            score += 100;
                        }
                    }

                    if(userSecondaryLanguages.contains(usersIter.key())) {
                        const QList<LCCode> lcCodes = userSecondaryLanguages.values(usersIter.key());
                        if(lcCodes.end() != std::find_if(lcCodes.begin(), lcCodes.end(), LidMatch(taskSourceLocale.languagecode()))) {
                            score += 500;
                            if(lcCodes.end() != std::find_if(lcCodes.begin(), lcCodes.end(), CidMatch(taskSourceLocale.countrycode())) ) {
                                score += 50;
                            }
                        }
                        if(lcCodes.end() != std::find_if(lcCodes.begin(), lcCodes.end(), LidMatch(taskTargetLocale.languagecode()))) {
                            score += 500;
                            if(lcCodes.end() != std::find_if(lcCodes.begin(), lcCodes.end(), CidMatch(taskTargetLocale.countrycode())) ) {
                                score += 50;
                            }
                        }
                    }

                    if(userTags.contains(usersIter.key()) && taskTags.contains(task->id())) {
                        int increment_value = 250;
                        QList<int> userTagIds = userTags.values(usersIter.key());
                        QList<int> userTaskTagIds = taskTags.values(task->id());

                        foreach(int userTagId, userTagIds) {
                            if(userTaskTagIds.contains(userTagId)) {
                                    score += increment_value;
                                    increment_value *= 0.75;
                            }
                        }
                    }

                    QDateTime created_time = QDateTime::fromString(
                                            QString::fromStdString(task->createdtime()), Qt::ISODate);
                    //increase score by one per day since created time
                    score += created_time.daysTo(QDateTime::currentDateTime());
                    taskScores.append(TaskScore(task->id(), score));
                }

                    this->saveUserTaskScore(usersIter.key(),taskScores);

            } else {
Example #5
0
void MuseScore::editInstrList()
      {
      if (cs == 0)
            return;
      if (!instrList)
            instrList = new InstrumentsDialog(this);
      else if (instrList->isVisible()) {
            instrList->done(0);
            return;
            }
      instrList->init();
      MasterScore* masterScore = cs->masterScore();
      instrList->genPartList(masterScore);
      masterScore->startCmd();
      masterScore->deselectAll();
      int rv = instrList->exec();

      if (rv == 0) {
            masterScore->endCmd();
            return;
            }
      ScoreView* csv = currentScoreView();
      if (csv && csv->noteEntryMode()) {
		csv->cmd(getAction("escape"));
            qApp->processEvents();
            updateInputState(csv->score());
            }
      masterScore->inputState().setTrack(-1);

      // keep the keylist of the first pitched staff to apply it to new ones
      KeyList tmpKeymap;
      Staff* firstStaff = 0;
      for (Staff* s : masterScore->staves()) {
            KeyList* km = s->keyList();
            if (!s->isDrumStaff(Fraction(0,1))) {     // TODO
                  tmpKeymap.insert(km->begin(), km->end());
                  firstStaff = s;
                  break;
                  }
            }
      Key normalizedC = Key::C;
      // normalize the keyevents to concert pitch if necessary
      if (firstStaff && !masterScore->styleB(Sid::concertPitch) && firstStaff->part()->instrument()->transpose().chromatic ) {
            int interval = firstStaff->part()->instrument()->transpose().chromatic;
            normalizedC = transposeKey(normalizedC, interval);
            for (auto i = tmpKeymap.begin(); i != tmpKeymap.end(); ++i) {
                  int tick = i->first;
                  Key oKey = i->second.key();
                  tmpKeymap[tick].setKey(transposeKey(oKey, interval));
                  }
            }
      // create initial keyevent for transposing instrument if necessary
      auto i = tmpKeymap.begin();
      if (i == tmpKeymap.end() || i->first != 0)
            tmpKeymap[0].setKey(normalizedC);

      //
      // process modified partitur list
      //
      QTreeWidget* pl = instrList->partiturList();
      Part* part   = 0;
      int staffIdx = 0;

      QTreeWidgetItem* item = 0;
      for (int idx = 0; (item = pl->topLevelItem(idx)); ++idx) {
            PartListItem* pli = static_cast<PartListItem*>(item);
            // check if the part contains any remaining staves
            // mark to remove part if not
            QTreeWidgetItem* ci = 0;
            int staves = 0;
            for (int cidx = 0; (ci = pli->child(cidx)); ++cidx) {
                  StaffListItem* sli = static_cast<StaffListItem*>(ci);
                  if (sli->op() != ListItemOp::I_DELETE)
                        ++staves;
                  }
            if (staves == 0)
                  pli->op = ListItemOp::I_DELETE;
            }

      item = 0;
      for (int idx = 0; (item = pl->topLevelItem(idx)); ++idx) {
            int rstaff = 0;
            PartListItem* pli = static_cast<PartListItem*>(item);
            if (pli->op == ListItemOp::I_DELETE)
                  masterScore->cmdRemovePart(pli->part);
            else if (pli->op == ListItemOp::ADD) {
                  const InstrumentTemplate* t = ((PartListItem*)item)->it;
                  part = new Part(masterScore);
                  part->initFromInstrTemplate(t);
                  masterScore->undo(new InsertPart(part, staffIdx));

                  pli->part = part;
                  QList<Staff*> linked;
                  for (int cidx = 0; pli->child(cidx); ++cidx) {
                        StaffListItem* sli = static_cast<StaffListItem*>(pli->child(cidx));
                        Staff* staff       = new Staff(masterScore);
                        staff->setPart(part);
                        sli->setStaff(staff);

                        staff->init(t, sli->staffType(), cidx);
                        staff->setDefaultClefType(sli->defaultClefType());
                        if (staffIdx > 0)
                              staff->setBarLineSpan(masterScore->staff(staffIdx - 1)->barLineSpan());

                        masterScore->undoInsertStaff(staff, cidx);
                        ++staffIdx;

                        Staff* linkedStaff = part->staves()->front();
                        if (sli->linked() && linkedStaff != staff) {
                              Excerpt::cloneStaff(linkedStaff, staff);
                              linked.append(staff);
                              }
                        }

                  //insert keysigs
                  int sidx = masterScore->staffIdx(part);
                  int eidx = sidx + part->nstaves();
                  if (firstStaff)
                        masterScore->adjustKeySigs(sidx, eidx, tmpKeymap);
                  }
            else {
                  part = pli->part;
                  if (part->show() != pli->visible())
                        part->undoChangeProperty(Pid::VISIBLE, pli->visible());
                  for (int cidx = 0; pli->child(cidx); ++cidx) {
                        StaffListItem* sli = static_cast<StaffListItem*>(pli->child(cidx));
                        if (sli->op() == ListItemOp::I_DELETE) {
                              Staff* staff = sli->staff();
                              int sidx = staff->idx();
                              masterScore->cmdRemoveStaff(sidx);
                              }
                        else if (sli->op() == ListItemOp::ADD) {
                              Staff* staff = new Staff(masterScore);
                              staff->setPart(part);
                              staff->initFromStaffType(sli->staffType());
                              sli->setStaff(staff);
                              staff->setDefaultClefType(sli->defaultClefType());
                              if (staffIdx > 0)
                                    staff->setBarLineSpan(masterScore->staff(staffIdx - 1)->barLineSpan());

                              KeySigEvent ke;
                              if (part->staves()->empty())
                                    ke.setKey(Key::C);
                              else
                                    ke = part->staff(0)->keySigEvent(Fraction(0,1));

                              staff->setKey(Fraction(0,1), ke);

                              Staff* linkedStaff = 0;
                              if (sli->linked()) {
                                    if (rstaff > 0)
                                          linkedStaff = part->staves()->front();
                                    else {
                                          for (Staff* st : *part->staves()) {
                                                if (st != staff) {
                                                      linkedStaff = st;
                                                      break;
                                                      }
                                                }
                                          }
                                    }
                              if (linkedStaff) {
                                    // do not create a link if linkedStaff will be removed,
                                    for (int k = 0; pli->child(k); ++k) {
                                          StaffListItem* li = static_cast<StaffListItem*>(pli->child(k));
                                          if (li->op() == ListItemOp::I_DELETE && li->staff() == linkedStaff) {
                                                linkedStaff = 0;
                                                break;
                                                }
                                          }
                                    }
                              masterScore->undoInsertStaff(staff, rstaff, linkedStaff == 0);
                              if (linkedStaff)
                                    Excerpt::cloneStaff(linkedStaff, staff);
                              else {
                                    if (firstStaff)
                                          masterScore->adjustKeySigs(staffIdx, staffIdx+1, tmpKeymap);
                                    }
                              ++staffIdx;
                              ++rstaff;
                              }
                        else if (sli->op() == ListItemOp::UPDATE) {
                              // check changes in staff type
                              Staff* staff = sli->staff();
                              const StaffType* stfType = sli->staffType();

                              // use selected staff type
                              if (stfType->name() != staff->staffType(Fraction(0,1))->name())
                                    masterScore->undo(new ChangeStaffType(staff, *stfType));
                              }
                        else {
                              ++staffIdx;
                              ++rstaff;
                              }
                        }
                  }
            }

      //
      //    sort staves
      //
      QList<Staff*> dst;
      for (int idx = 0; idx < pl->topLevelItemCount(); ++idx) {
            PartListItem* pli = (PartListItem*)pl->topLevelItem(idx);
            if (pli->op == ListItemOp::I_DELETE)
                  continue;
            QTreeWidgetItem* ci = 0;
            for (int cidx = 0; (ci = pli->child(cidx)); ++cidx) {
                  StaffListItem* sli = (StaffListItem*) ci;
                  if (sli->op() == ListItemOp::I_DELETE)
                        continue;
                  dst.push_back(sli->staff());
                  }
            }

      QList<int> dl;
      int idx2 = 0;
      bool sort = false;
      for (Staff* staff : dst) {
            int idx = masterScore->staves().indexOf(staff);
            if (idx == -1)
                  qDebug("staff in dialog(%p) not found in score", staff);
            else
                  dl.push_back(idx);
            if (idx != idx2)
                  sort = true;
            ++idx2;
            }

      if (sort)
            masterScore->undo(new SortStaves(masterScore, dl));

      //
      // check for valid barLineSpan and bracketSpan
      // in all staves
      //
      for (Score* s : masterScore->scoreList()) {
            int n = s->nstaves();
            int curSpan = 0;
            for (int j = 0; j < n; ++j) {
                  Staff* staff = s->staff(j);
                  int span = staff->barLineSpan();
                  int setSpan = -1;

                  // determine if we need to update barline span
                  if (curSpan == 0) {
                        // no current span; this staff must start a new one
                        if (span == 0) {
                              // no span; this staff must have been within a span
                              // update it to a span of 1
                              setSpan = j;
                              }
                        else if (span > (n - j)) {
                              // span too big; staves must have been removed
                              // reduce span to last staff
                              setSpan = n - j;
                              }
                        else if (span > 1 && staff->barLineTo() > 0) {
                              // TODO: check if span is still valid
                              // (true if the last staff is the same as it was before this edit)
                              // the code here fixes https://musescore.org/en/node/41786
                              // but by forcing an update,
                              // we lose custom modifications to staff barLineTo
                              // at least this happens only for span > 1, and not for Mensurstrich (barLineTo<=0)
                              setSpan = span;   // force update to pick up new barLineTo value
                              }
                        else {
                              // this staff starts a span
                              curSpan = span;
                              }
                        }
                  else if (span && staff->barLineTo() > 0) {
                        // within a current span; staff must have span of 0
                        // except for Mensurstrich (barLineTo<=0)
                        // for consistency with Barline::endEdit,
                        // don't special case 1-line staves
//TODO                        s->undoChangeBarLineSpan(staff, 0, 0, (staff->lines() - 1) * 2);
                        }

                  // update barline span if necessary
                  if (setSpan > 0) {
                        // this staff starts a span
                        curSpan = setSpan;
                        // calculate spanFrom and spanTo values
//                        int spanFrom = staff->lines() == 1 ? BARLINE_SPAN_1LINESTAFF_FROM : 0;
//                        int linesTo = masterScore->staff(i + setSpan - 1)->lines();
//                        int spanTo = linesTo == 1 ? BARLINE_SPAN_1LINESTAFF_TO : (linesTo - 1) * 2;
//TODO                         s->undoChangeBarLineSpan(staff, setSpan, spanFrom, spanTo);
                        }

                  // count off one from barline span
                  --curSpan;

                  // update brackets
                  for (BracketItem* bi : staff->brackets()) {
                        if ((bi->bracketSpan() > (n - j)))
                              bi->undoChangeProperty(Pid::BRACKET_SPAN, n - j);
                        }
                  }
            }

      //
      // there should be at least one measure
      //
      if (masterScore->measures()->size() == 0)
            masterScore->insertMeasure(ElementType::MEASURE, 0, false);

      const QList<Excerpt*> excerpts(masterScore->excerpts()); // excerpts list may change in the loop below
      for (Excerpt* excerpt : excerpts) {
            QList<Staff*> sl       = excerpt->partScore()->staves();
            QMultiMap<int, int> tr = excerpt->tracks();
            if (sl.size() == 0)
                  masterScore->undo(new RemoveExcerpt(excerpt));
            else {
                  for (Staff* s : sl) {
                        const LinkedElements* sll = s->links();
                        for (auto le : *sll) {
                              Staff* ss = toStaff(le);
                              if (ss->primaryStaff()) {
                                    for (int j = s->idx() * VOICES; j < (s->idx() + 1) * VOICES; j++) {
                                          int strack = tr.key(j, -1);
                                          if (strack != -1 && ((strack & ~3) == ss->idx()))
                                                break;
                                          else if (strack != -1)
                                                tr.insert(ss->idx() + strack % VOICES, tr.value(strack, -1));
                                          }
                                    }
                              }
                        }
                  }
            }

      masterScore->setLayoutAll();
      masterScore->endCmd();
      masterScore->rebuildAndUpdateExpressive(MuseScore::synthesizer("Fluid"));
      seq->initInstruments();
      }
void tst_QWebPluginDatabase::preferredPlugin()
{
    QMultiMap<QString, QWebPluginInfo> pluginsMap;
    QWebPluginDatabase* database = QWebSettings::pluginDatabase();
    QList<QWebPluginInfo> plugins = database->plugins();

    for (int i = 0; i < plugins.count(); ++i) {
        QWebPluginInfo plugin = plugins.at(i);

        QList<MimeType> mimeTypes = plugin.mimeTypes();
        for (int j = 0; j < mimeTypes.count(); ++j) {
            QString mimeType = mimeTypes.at(j).name;
            pluginsMap.insert(mimeType, plugin);
        }
    }

    QMultiMap<QString, QWebPluginInfo>::iterator it = pluginsMap.begin();
    while (it != pluginsMap.end()) {
        QString mimeType = it.key();

        if (pluginsMap.count(mimeType) > 1) {
            QList<QWebPluginInfo> pluginsForMimeType = pluginsMap.values(mimeType);
            QWebPluginInfo plugin = database->pluginForMimeType(mimeType);
            QVERIFY(plugin.supportsMimeType(mimeType));

            pluginsForMimeType.removeAll(plugin);
            for (int i = 0; i < pluginsForMimeType.count(); ++i) {
                QWebPluginInfo anotherPlugin = pluginsForMimeType.at(i);
                QVERIFY(plugin.supportsMimeType(mimeType));
                QVERIFY(plugin != anotherPlugin);

                QCOMPARE(database->pluginForMimeType(mimeType), plugin);
                database->setPreferredPluginForMimeType(mimeType, anotherPlugin);
                QCOMPARE(database->pluginForMimeType(mimeType), anotherPlugin);

                anotherPlugin.setEnabled(false);
                QCOMPARE(database->pluginForMimeType(mimeType), plugin);

                anotherPlugin.setEnabled(true);
                QCOMPARE(database->pluginForMimeType(mimeType), anotherPlugin);
                database->setSearchPaths(database->searchPaths());
                QCOMPARE(database->pluginForMimeType(mimeType), anotherPlugin);

                database->setPreferredPluginForMimeType(mimeType, QWebPluginInfo());
                QCOMPARE(database->pluginForMimeType(mimeType), plugin);
            }
        } else {
            QWebPluginInfo plugin = database->pluginForMimeType(mimeType);
            QCOMPARE(pluginsMap.value(mimeType), plugin);

            database->setPreferredPluginForMimeType(mimeType, plugin);
            QCOMPARE(database->pluginForMimeType(mimeType), plugin);

            plugin.setEnabled(false);
            QCOMPARE(database->pluginForMimeType(mimeType), QWebPluginInfo());
            plugin.setEnabled(true);

            database->setPreferredPluginForMimeType(mimeType, QWebPluginInfo());
            QCOMPARE(database->pluginForMimeType(mimeType), plugin);
        }

        ++it;
    }

    if (pluginsMap.keys().count() >= 2) {
        QStringList mimeTypes = pluginsMap.uniqueKeys();

        QString mimeType1 = mimeTypes.at(0);
        QString mimeType2 = mimeTypes.at(1);
        QWebPluginInfo plugin1 = database->pluginForMimeType(mimeType1);
        QWebPluginInfo plugin2 = database->pluginForMimeType(mimeType2);

        int i = 2;
        while (plugin2.supportsMimeType(mimeType1)
               && !mimeType2.isEmpty()
               && i < mimeTypes.count()) {
            mimeType2 = mimeTypes.at(i);
            plugin2 = database->pluginForMimeType(mimeType2);
            ++i;
        }

        plugin1 = database->pluginForMimeType(mimeType1);
        QVERIFY(plugin1.supportsMimeType(mimeType1));
        QVERIFY(!plugin1.isNull());
        plugin2 = database->pluginForMimeType(mimeType2);
        QVERIFY(plugin2.supportsMimeType(mimeType2));
        QVERIFY(!plugin2.isNull());

        database->setPreferredPluginForMimeType(mimeType2, plugin1);
        QVERIFY(!plugin1.supportsMimeType(mimeType2));
        QCOMPARE(database->pluginForMimeType(mimeType2), plugin2);

        database->setPreferredPluginForMimeType(mimeType1, plugin1);
        QVERIFY(!plugin2.supportsMimeType(mimeType1));
        QCOMPARE(database->pluginForMimeType(mimeType2), plugin2);
    }
}