示例#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
ShortcutsModel::ShortcutsModel(const QHash<QString, ActionCollection *> &actionCollections, QObject *parent)
  : QAbstractItemModel(parent),
  _changedCount(0)
{
  _showIcons=!QCoreApplication::testAttribute(Qt::AA_DontShowIconsInMenus);
  for(int r = 0; r < actionCollections.values().count(); r++) {
    ActionCollection *coll = actionCollections.values().at(r);
    Item *item = new Item();
    item->row = r;
    item->collection = coll;
    for(int i = 0; i < coll->actions().count(); i++) {
      Action *action = qobject_cast<Action *>(coll->actions().at(i));
      if(!action)
        continue;
      Item *actionItem = new Item();
      actionItem->parentItem = item;
      actionItem->row = i;
      actionItem->collection = coll;
      actionItem->action = action;
      actionItem->shortcut = action->shortcut();
      item->actionItems.append(actionItem);
    }
    _categoryItems.append(item);
  }
}
示例#3
0
QList<ToolChain*> QtOptionsPageWidget::toolChains(const BaseQtVersion *version)
{
    QHash<QString,ToolChain*> toolChains;
    if (!version)
        return toolChains.values();

    foreach (const Abi &a, version->qtAbis())
        foreach (ToolChain *tc, ToolChainManager::findToolChains(a))
            toolChains.insert(tc->id(), tc);

    return toolChains.values();
}
示例#4
0
MessagesDialogs TelegramCache::readDialogs() const
{
    MessagesDialogs result(MessagesDialogs::typeMessagesDialogs);

    const QString filePath = p->path + "/dialogs";
    const QList<QVariant> &list = readList(filePath);
    QList<Dialog> dialogs;

    QHash<QByteArray, Chat> chats;
    QHash<QByteArray, User> users;
    QHash<QByteArray, Message> messages;

    Q_FOREACH(const QVariant &var, list)
    {
        const Dialog &dialog = Dialog::fromMap( var.toMap() );

        const Peer &peer = dialog.peer();
        const QByteArray &key = TelegramTools::identifier(peer);
        switch(static_cast<int>(peer.classType()))
        {
        case Peer::typePeerChannel:
        case Peer::typePeerChat:
            if(!chats.contains(key))
                chats[key] = readChat(peer);
            break;
        case Peer::typePeerUser:
            if(!users.contains(key))
                users[key] = readUser(peer);
            break;
        }

        if(dialog.topMessage())
        {
            QByteArray topMsgKey = TelegramTools::identifier(dialog.peer(), dialog.topMessage());
            const QString &messageFolder = getMessageFolder(peer);
            const QString messageFile = messageFolder + "/" + QString::number(dialog.topMessage());
            messages[topMsgKey] = Message::fromMap( readMap(messageFile) );
        }

        dialogs << dialog;
    }

    result.setDialogs(dialogs);
    result.setChats(chats.values());
    result.setUsers(users.values());
    result.setMessages(messages.values());
    result.setCount(dialogs.count());

    return result;
}
    QByteArray PostPrepareStrategyMultipart::GenerateData(const QHash<QString,ContentData> & params)
    {
        QByteArray data;
        QList<QString> keys = params.keys();
        QList<ContentData> values = params.values();


        for(int i = 0;i<params.size();++i)
        {
            data.append("--" + Boundary + "\r\n");
            ContentData Data = values.at(i);
            data.append("Content-Disposition: form-data; name=\"" + keys.at(i) + "\"; ");
            if(!Data.FileName.isEmpty())
                data.append(QString("filename=\"") + Data.FileName + QString("\""));
            data.append("\r\n");


            if(!Data.ContentType.isEmpty())
                data.append("Content-Type: " + Data.ContentType + "\r\n");

            data.append("\r\n");

            if(!Data.DataString.isEmpty())
                data.append(Data.DataString);
            else if(!Data.DataRaw.isEmpty())
                data.append(Data.DataRaw);

            data.append("\r\n");
        }
        data.append("--" + Boundary + "--\r\n");
        return data;
    }
void QJSDebuggerAgentPrivate::positionChange(qint64 scriptId, int lineNumber, int columnNumber)
{
    Q_UNUSED(columnNumber);

    if (state == StoppedState)
        return; //no re-entrency

    // check breakpoints
    if (!breakpoints.isEmpty()) {
        const QScriptContext *ctx = engine()->currentContext();
        const QScriptContextInfo info(ctx);

        if (info.functionType() == QScriptContextInfo::ScriptFunction) {
            QHash<qint64, QString>::const_iterator it = filenames.constFind(scriptId);
            // It is possible that the scripts are loaded before the agent is attached
            if (it == filenames.constEnd()) {
                it = filenames.insert(scriptId, info.fileName());
            }

            const QString filePath = it.value();
            const JSAgentBreakpoints bps = fileNameToBreakpoints.values(fileName(filePath)).toSet();

            foreach (const JSAgentBreakpointData &bp, bps) {
                if (bp.lineNumber == lineNumber) {
                    stopped();
                    return;
                }
            }
        }
    }
示例#7
0
文件: listcommand.cpp 项目: KDE/simon
bool ListCommand::greedyTrigger(const QString& inputText)
{
  kDebug() << "Triggering greedy " << inputText;

  QHash<CommandListElements::Element, VoiceInterfaceCommand*> adaption = getAdaption();

  QList<CommandListElements::Element> adaptionKeys = adaption.keys();
  foreach (const CommandListElements::Element& element, adaptionKeys) {
    QList<VoiceInterfaceCommand*> interfaceCommands = adaption.values(element);
    foreach (VoiceInterfaceCommand* command, interfaceCommands) {
      if (command->matches(0, inputText)) {
        switch (element) {
          case CommandListElements::Back: return processRequest(0);
          case CommandListElements::One: return processRequest(1);
          case CommandListElements::Two: return processRequest(2);
          case CommandListElements::Three: return processRequest(3);
          case CommandListElements::Four: return processRequest(4);
          case CommandListElements::Five: return processRequest(5);
          case CommandListElements::Six: return processRequest(6);
          case CommandListElements::Seven: return processRequest(7);
          case CommandListElements::Eight: return processRequest(8);
          case CommandListElements::Next: return processRequest(9);
          case CommandListElements::Cancel:
            clw->close();
            return true;
        }
      }

    }

  }
示例#8
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QList<QString> list;
    list.append("Nagavavara");
    list.insert(7,"Bangaluru");
    list.insert(1,"Mysore");
    list.insert(2,"Hubli");
    list.insert(3,"Dharawad");
    list.insert(4,"Belgaum");
    list.insert(5,"Gulbarga");
    list.insert(6,"Raichur");

    QListIterator<QString> it(list);
    while(it.hasNext()) {
        QString str = it.next();
        qDebug() << "Valu =" << str;
    }

    QHash<int,QString> myHash;
    myHash.insert(1,"Bangaloru");
    myHash.insert(2,"Mysuru");
    myHash.insert(3,"Hubli");
    myHash.insert(4,"Raichur");
    myHash.insert(5,"Bidar");
    myHash.insert(6,"Bijapur");

    QString valu = myHash.value(1);
    qDebug() << "Key =" << 1 << " Value="<<valu <<endl;

    QList<int> keys = myHash.keys();
    QList<QString> values = myHash.values();

    return a.exec();
}
示例#9
0
QVector<Feed*> Folder::feeds()
{
    QHash<int, Feed*> feedsById;
    Q_FOREACH( TreeNode* i, d->children )
        Q_FOREACH ( Feed* j, i->feeds() )
            feedsById.insert( j->id(), j );
    return feedsById.values().toVector();
}
示例#10
0
QList<CatItem> TrieNode::filterCurrentNode(QString substr, int numDesired, ItemFilter* filter){

    QHash<qint32,CatItem> alreadyFound;
    int depth = 0;
    int digDepth =0;
    breadthSearch(alreadyFound, substr, numDesired, depth, digDepth, 0, filter);
    return alreadyFound.values();
}
示例#11
0
/**
 * Remove all the zero-error free workspaces
 * @param workspaces :: a map containing the names of all zero-error-free
 * workspaces.
 */
void SaveWorkspaces::removeZeroFreeWorkspaces(
    QHash<QString, QString> workspaces) {
  auto zeroFreeWorkspaceNames = workspaces.values();
  for (auto it = zeroFreeWorkspaceNames.begin();
       it != zeroFreeWorkspaceNames.end(); ++it) {
    emit deleteZeroErrorFreeWorkspace((*it));
  }
}
示例#12
0
QVector<Folder*> Folder::folders()
{
    QHash<int, Folder*> foldersById;
    foldersById.insert( id(), this );
    Q_FOREACH( TreeNode* i, d->children )
        Q_FOREACH ( Folder* j, i->folders() )
            foldersById.insert( j->id(), j );
    return foldersById.values().toVector();
}
示例#13
0
static void removeMenuAllActions(QMenu *pMenu)
{
	QList<QAction*> pActionsList=pMenu->actions();
	QList<QAction*> pActionsListDictValues=actionsDict.values();
	for(int i=0;i<pActionsList.count();i++)
	{
		int iIdx=pActionsListDictValues.indexOf(pActionsList.at(i));
		if (iIdx>=0) actionsDict.remove(actionsDict.key(pActionsList.at(i)));
	}
}
QHash<int,QString> ReceiptsManager::getPercentages()
{
  QHash<int,QString> hash;
  receiptsEngine io;
  QHash<QString,QString> hashFromModel;
  hashFromModel = io.getPercentagesAccordingToUser();
  QStringList values = hashFromModel.values();
  if (hashFromModel.size()==0)
  {
    hash.insert(1,"0.00");
        hash.insert(2,"10.00");
        hash.insert(3,"20.00");
        hash.insert(4,"30.00");
        hash.insert(5,"33.33");
        hash.insert(6,"70.00");
        hash.insert(7,"100.00");
      }
  else{
    int count = values.count();
    QStringList listOfPercents;
    listOfPercents << "0.00";
    while (listOfPercents.size() < count +1)
    {
       QString minValue ;
       for (int i = 0; i < values.size(); ++i)
       {
           for (int j = 0; j < values.size(); j += 1)
           {
            if (values[i].toDouble() < values[j].toDouble())
            {
                minValue = values[i];
                }
               }
            }
        if (values.size()<2)
        {
              minValue = values[0];
            }
        if (WarnDebugMessage)
            qDebug() << __FILE__ << QString::number(__LINE__) << " minValue =" << minValue ;
        if (!listOfPercents.contains(minValue))
        {
              listOfPercents.append(minValue);
              values.removeOne(minValue)  ;
            }
        }
    listOfPercents << "100.00";
    for (int i = 0; i < listOfPercents.size() ; ++i)
    {
        hash.insert(i+1,listOfPercents[i]);
        }
    }

  return hash;
}
示例#15
0
void tst_QDirModel::roleNames()
{
    QDirModel model;
    QHash<int, QByteArray> roles = model.roleNames();

    QFETCH(int, role);
    QVERIFY(roles.contains(role));

    QFETCH(QByteArray, roleName);
    QList<QByteArray> values = roles.values(role);
    QVERIFY(values.contains(roleName));
}
示例#16
0
QList<CatItem> TrieNode::filterChildNodes(QString substr, int numDesired, ItemFilter* filter,
                                          int* beginPoint){
    QHash<qint32,CatItem> alreadyFound;
    int depth = DEFAULT_NODE_SEARCH_DEPTH;
    int digDepth =0;
//    int skipDepth =0;
//    if(beginPoint!=0){
//        skipDepth = *beginPoint;
//    }
    int skipDepth = beginPoint? *beginPoint: 0;
    breadthSearch(alreadyFound, substr, numDesired, depth, digDepth, skipDepth, filter);
    return alreadyFound.values();
}
示例#17
0
int main()
{
    QSet<QString *> s;
    qDeleteAll(s);
    qDeleteAll(s.begin(), s.end());
    qDeleteAll(s.values()); // warning

    QHash<int, QString *> h;
    qDeleteAll(h);
    qDeleteAll(h.begin(), h.end());
    qDeleteAll(h.values()); // warning

    QMap<int*, QString *> m;
    qDeleteAll(m);
    qDeleteAll(m.begin(), m.end());
    qDeleteAll(m.values()); // warning

    QMultiHash<int, QString *> mh;
    qDeleteAll(mh);
    qDeleteAll(mh.begin(), mh.end());
    qDeleteAll(mh.values()); // warning

    QMultiMap<int, QString *> mm;
    qDeleteAll(mm);
    qDeleteAll(mm.begin(), mm.end());
    qDeleteAll(mm.values()); // warning

    qDeleteAll(values());  // ok

    Foo foo;
    qDeleteAll(foo.values());  // ok
    qDeleteAll(foo.doSomethingWithValues(h.values()));  // ok

    qDeleteAll(m.keys()); // warning
    qDeleteAll(keys()); // ok

    qDeleteAll(h.values(1)); // warning

}
示例#18
0
DlgReferenceProperties::DlgReferenceProperties(const QString &name, const QMap<int, QString> &mapIdToName,
                                               const QMap<QString, int> &mapNameToId, const QHash<int, Face3DTemplate *> &database,
                                               QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DlgReferenceProperties)
{
    ui->setupUi(this);

    ui->leName->setText(name);
    int id = mapNameToId[name];
    ui->leId->setText(QString::number(id));
    ui->leReferenceCount->setText(QString::number(database.values(id).count()));
}
示例#19
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());
        }
示例#20
0
static QList<FakeMetaObject::ConstPtr> parseHelper(const QByteArray &qmlTypeDescriptions,
                                                   QString *error,
                                                   QString *warning)
{
    QList<FakeMetaObject::ConstPtr> ret;
    QHash<QString, FakeMetaObject::ConstPtr> newObjects;
    Interpreter::CppQmlTypesLoader::parseQmlTypeDescriptions(qmlTypeDescriptions, &newObjects,
                                                             error, warning);

    if (error->isEmpty()) {
        ret = newObjects.values();
    }
    return ret;
}
示例#21
0
ShortcutsModel::ShortcutsModel(const QHash<QString, ActionCollection*>& actionCollections, QObject* parent)
    : QAbstractItemModel(parent)
    , _changedCount(0)
{
    for (int r = 0; r < actionCollections.values().count(); r++) {
        ActionCollection* coll = actionCollections.values().at(r);
        auto* item = new Item();
        item->row = r;
        item->collection = coll;
        for (int i = 0; i < coll->actions().count(); i++) {
            auto* action = qobject_cast<Action*>(coll->actions().at(i));
            if (!action)
                continue;
            auto* actionItem = new Item();
            actionItem->parentItem = item;
            actionItem->row = i;
            actionItem->collection = coll;
            actionItem->action = action;
            actionItem->shortcut = action->shortcut();
            item->actionItems.append(actionItem);
        }
        _categoryItems.append(item);
    }
}
Settings::Update Settings::updateUserRepositories(const RepoHash &updates)
{
    if (updates.isEmpty())
        return Settings::NoUpdatesApplied;

    QHash <QUrl, Repository> reposToUpdate;
    foreach (const QVariant &variant, d->m_data.values(scUserRepositories)) {
        const Repository repository = variant.value<Repository>();
        reposToUpdate.insert(repository.url(), repository);
    }

    const bool updated = apply(updates, &reposToUpdate);
    if (updated)
        setUserRepositories(reposToUpdate.values().toSet());
    return updated ? Settings::UpdatesApplied : Settings::NoUpdatesApplied;
}
/*
 This is _only_ called when QGeoSatelliteInfoValidator::valid() returns true for the position.
 This means that it is implied that:
 - (data.dwValidFields & GPS_VALID_SATELLITE_COUNT) != 0
 - (data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW) != 0
 - (data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW_PRNS) != 0
 - (data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW_SIGNAL_TO_NOISE_RATIO) != 0

 This guarantees that the newly created position will be valid.
 If the code is changed such that this is no longer guaranteed then this method will need to be
 updated to test for those conditions.
*/
void QGeoSatelliteInfoSourceWinCE::dataUpdated(GPS_POSITION data)
{
    // Satellites in view are hashed on the PRN values since the PRN value is how we
    // determine which of the satellites are in use.
    QHash<int, QGeoSatelliteInfo> satellitesInView;

    for (unsigned int i = 0; i < data.dwSatellitesInView; ++i) {
        QGeoSatelliteInfo satellite;

        satellite.setPrnNumber(data.rgdwSatellitesInViewPRNs[i]);
        satellite.setSignalStrength(data.rgdwSatellitesInViewSignalToNoiseRatio[i]);

        // The following properties are optional, and so are set if the data is present and valid
        // in the GPS_POSITION structure.
        if ((data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW_AZIMUTH) != 0) {
            satellite.setAttribute(QGeoSatelliteInfo::Azimuth,
                                   data.rgdwSatellitesInViewAzimuth[i]);
        }

        if ((data.dwValidFields & GPS_VALID_SATELLITES_IN_VIEW_ELEVATION) != 0) {
            satellite.setAttribute(QGeoSatelliteInfo::Elevation,
                                   data.rgdwSatellitesInViewElevation[i]);
        }

        satellitesInView.insert(satellite.prnNumber(), satellite);
    }

    emit satellitesInViewUpdated(satellitesInView.values());

    // If the PRN data for the satellites which were used is unavailable we are done...
    if ((data.dwValidFields & GPS_VALID_SATELLITES_USED_PRNS) == 0)
        return;

    // ...otherwise we construct the list of satellites which are in use and emit the appropriate
    // signal
    QList<QGeoSatelliteInfo> satellitesInUse;

    for (unsigned int i = 0; i < data.dwSatelliteCount; ++i) {
        int inUsePRN = data.rgdwSatellitesUsedPRNs[i];
        if (satellitesInView.contains(inUsePRN))
            satellitesInUse << satellitesInView.value(inUsePRN);
    }

    emit satellitesInUseUpdated(satellitesInUse);
}
示例#24
0
static void setupIdRenamingHash(const ModelNode &modelNode, QHash<QString, QString> &idRenamingHash, AbstractView *view)
{
    foreach (const ModelNode &node, modelNode.allSubModelNodesAndThisNode()) {
        if (!node.id().isEmpty()) {
            QString newId = node.id();
            QString baseId;
            int number = 1;
            splitIdInBaseNameAndNumber(newId, &baseId, &number);

            while (view->hasId(newId) || idRenamingHash.values().contains(newId)) {
                newId = baseId + QString::number(number);
                number++;
            }

            idRenamingHash.insert(node.id(), newId);
        }
    }
}
示例#25
0
void AdiumThemeView::setChatStyle(ChatWindowStyle *chatStyle)
{
    m_chatStyle = chatStyle;

    //load the first variant
    QHash<QString, QString> variants = chatStyle->getVariants();
    if (!chatStyle->defaultVariantName().isEmpty()
            && variants.keys().contains(chatStyle->defaultVariantName())) {
        m_variantPath = variants.value(chatStyle->defaultVariantName());
        m_variantName = chatStyle->defaultVariantName();
    } else if (variants.keys().length() > 0) {
        m_variantPath = variants.values().first();
        m_variantName = variants.keys().first();
    } else {
        m_variantPath = QLatin1String("");
        m_variantName = QLatin1String("");
    }
}
void RepoTreeModel::setRepos(const std::vector<ServerRepo>& repos)
{
    size_t i, n = repos.size();
    // removeReposDeletedOnServer(repos);

    clear();

    QHash<QString, ServerRepo> map;
    for (i = 0; i < n; i++) {
        const ServerRepo& repo = repos[i];
        if (repo.isPersonalRepo()) {
            if (repo.isVirtual()) {
                checkVirtualRepo(repo);
            } else {
                checkPersonalRepo(repo);
            }
        } else if (repo.isSharedRepo()) {
            checkSharedRepo(repo);
        } else {
            checkGroupRepo(repo);
        }

        if (repo.isSubfolder() || seafApplet->rpcClient()->hasLocalRepo(repo.id))
            checkSyncedRepo(repo);

        // we have a conflicting case, don't use group version if we can
        if (map.contains(repo.id) && repo.isGroupRepo())
            continue;
        map[repo.id] = repo;
    }

    QList<ServerRepo> list = map.values();
    // sort all repos by timestamp
    // use std::sort for qt containers will force additional copy.
    // anyway, we can use qt's alternative qSort for it
    qSort(list.begin(), list.end(), compareRepoByTimestamp);

    n = qMin(list.size(), kMaxRecentUpdatedRepos);
    for (i = 0; i < n; i++) {
        RepoItem *item = new RepoItem(list[i]);
        recent_updated_category_->appendRow(item);
    }
}
    QByteArray PostPrepareStrategyJsonEncode::GenerateData(const QHash<QString,ContentData> & params)
    {
        QByteArray data;
        QList<QString> keys = params.keys();
        QList<ContentData> values = params.values();

        QVariantMap res;
        for(int i = 0;i<params.size();++i)
        {
            res[keys.at(i)] = values.at(i).DataString;
        }
        QJsonObject object = QJsonObject::fromVariantMap(res);

        QJsonDocument document;
        document.setObject(object);

        data = document.toJson();

        return data;
    }
    QByteArray PostPrepareStrategyUrlEncode::GenerateData(const QHash<QString,ContentData> & params)
    {
        QByteArray data;
        QList<QString> keys = params.keys();
        QList<ContentData> values = params.values();

        for(int i = 0;i<params.size();++i)
        {
            if(i)
                data.append("&");
            data.append(QUrl::toPercentEncoding(keys.at(i).toUtf8()));
            data.append("=");

            if(!values.at(i).DataString.isEmpty())
                data.append(QUrl::toPercentEncoding(values.at(i).DataString.toUtf8()));
            else
            {
                data.append(values.at(i).DataRaw.toPercentEncoding());
            }
        }
        return data;
    }
示例#29
0
double AssetsIO::getRate(const QDate &date, double duration) {
    Q_UNUSED(date);
    double rate = 0.00;
    QHash<QString,QDate> hashRatesDates;
    QStringList listChosenOfRanges;
    AssetsRatesModel model(this);
    if (WarnDebugMessage)
        qDebug() << __FILE__ << QString::number(__LINE__) << " model.rowCount() =" << QString::number(model.rowCount()) ;
    for (int i = 0; i < model.rowCount(); i += 1) {
        QDate dateRequest = model.data(model.index(i,ASSETSRATES_DATE),Qt::DisplayRole).toDate();
        QString rangeReq = model.data(model.index(i,ASSETSRATES_YEARS),Qt::DisplayRole).toString();
        QString rate = model.data(model.index(i,ASSETSRATES_RATES),Qt::DisplayRole).toString();
        if (WarnDebugMessage)
            qDebug() << __FILE__ << QString::number(__LINE__) << " rangeReq and rate =" << rangeReq+" "+rate ;
        QStringList listOfRanges = rangeReq.split("_");
        if (int(duration) >= listOfRanges[0].toInt() && int(duration) <= listOfRanges[1].toInt()) {
            hashRatesDates.insertMulti(rate,dateRequest) ;
        }
    }
    QList<QDate> valuesOfDates = hashRatesDates.values();
    if (WarnDebugMessage)
        qDebug() << __FILE__ << QString::number(__LINE__) << " valuesOfDates size =" << QString::number(valuesOfDates.size()) ;
    if (hashRatesDates.size() < 1) {
        Utils::warningMessageBox(tkTr(Trans::Constants::ERROR),
                                 tr("You have to fill defaults for assets rates.\nGo "
                                    "in Configuration>Preferences to do so.\n"
                                    "Otherwise result will be wrong !"));
        return 1.00;
    }
    qSort(valuesOfDates.begin(),valuesOfDates.end());

    QDate nearestDate = valuesOfDates.last();
    QString nearestDateStr = nearestDate.toString("yyyy-MM-dd");
    QString rateStr = hashRatesDates.key(nearestDate);
    rate = rateStr.toDouble();
    qWarning() << __FILE__ << QString::number(__LINE__) << "rate = " << QString::number(rate) ;
    return rate;
}
示例#30
0
void VarParser::treatDefines()
{
    // замена define в указании длины массивов и инициализаци переменных
    QHash<QString,QString> defTab;
    QRegExp defineExpression("#define[\\s\\t]*\\b(\\w*)[\\s\\t]*(\\w*)\\b");
    for(int i=0;i<dataBlock.count();i++){
        QString str = dataBlock.at(i);
        if(defineExpression.indexIn(str) != -1) {
            QString inpStr = defineExpression.cap(1);
            QString resStr = defineExpression.cap(2);
            defTab.insert(inpStr,resStr);
            dataBlock.replace(i,QString());
        }
    }
    for(int i=0;i<dataBlock.count();i++) {
        if(dataBlock.at(i).isEmpty()) continue;
        if(dataBlock.at(i).contains('['))
        for(int j=0;j<defTab.count();j++) {
            QRegExp defExpr("\\b"+defTab.keys().at(j)+"\\b");
            dataBlock[i].replace(defExpr,defTab.values().at(j));
        }
    }
}