示例#1
0
void Image::postSave(QMap<QString, Image::SaveResult> result, bool addMd5, bool startCommands, int count)
{
	const QString &path = result.firstKey();
	Image::SaveResult res = result[path];

	postSaving(path, addMd5 && res == SaveResult::Saved, startCommands, count);
}
示例#2
0
bool BloombergVector::SetVector(const QList<QDate>& Dates, const QList<double>& Values) {
    Q_D(BloombergVector);
	if (
		Dates.size() != Values.size() //Each date has a value and vice versa
		|| Values.isEmpty() //The vectors are not empty
		|| Dates.toSet().size()!=Dates.size() //There are no duplicates in the dates
	) return false;
	QMap<QDate, double> SortedValues;
	for (int i = 0; i <Dates.size(); i++) {
		if (Dates.at(i).isNull())
            return false;
		if (Values.at(i)<0.0)
            return false;
		SortedValues.insert(Dates.at(i), Values.at(i));
	}
	d->m_AnchorDate = SortedValues.firstKey();
    d->m_VectVal.clear();
	int NumMonths;
	for (auto i = SortedValues.constBegin()+1; i != SortedValues.constEnd(); i++) {
		NumMonths = MonthDiff(i.key(), (i - 1).key());
		for (int j = 0; j < NumMonths; j++)
            d->m_VectVal.append((i - 1).value());
	}
    d->m_VectVal.append(SortedValues.last());

	RepackVector();
	return true;
}
示例#3
0
// 显示在线音乐搜索结果
void NetWorkWidget::showSearchResult(QMap<QString, QStringList> musicList)
{
    musicUrls = musicList.first();
    QString musicName = musicList.firstKey();

    while(tableWidget->rowCount())
    {
        tableWidget->removeRow(tableWidget->rowCount()-1);
    }

    for (int i=0; i<musicUrls.count(); ++i)
    {
        tableWidget->insertRow(tableWidget->rowCount());
        tableWidget->setItem(tableWidget->rowCount()-1, 0, new QTableWidgetItem(musicName));
        tableWidget->setItem(tableWidget->rowCount()-1, 1, new QTableWidgetItem("试听"));
        tableWidget->setItem(tableWidget->rowCount()-1, 2, new QTableWidgetItem("下载"));
    }
}
void TileCache::expireCacheLocked() {
    if (m_cache.size() > CACHE_ITEMS) {
        //    qDebug() << "Cache size" << m_cache.size() << "and maximum is" << CACHE_ITEMS;

        QMap<qint64, int> map;
        for (QSet<CacheItem>::const_iterator iter = m_cache.constBegin();
                iter != m_cache.constEnd(); iter++) {
            map.insert(iter->ts, 0);
        }

        while (m_cache.size() >= CACHE_ITEMS) {
            if (!map.isEmpty()) {
                qint64 ts = map.firstKey();
                map.remove(ts);
                expireCacheTsLocked(ts);
            } else {
                break;
            }
        }

        //    qDebug() << "Cache size" << m_cache.size();
    }
}
示例#5
0
void PluginGauss::loadRefDatas()//const ProjectSettings& settings)
{
    mRefDatas.clear();
    
    QString calibPath = getRefsPath();
    QDir calibDir(calibPath);
    
    QFileInfoList files = calibDir.entryInfoList(QStringList(), QDir::Files);
    for(int i=0; i<files.size(); ++i)
    {
        if(files[i].suffix().toLower() == "csv")
        {
            QFile file(files[i].absoluteFilePath());
            if(file.open(QIODevice::ReadOnly | QIODevice::Text))
            {
                QMap<QString, QMap<double, double> > curves;
                
                QMap<double, double> curveG;
                QMap<double, double> curveG95Sup;
                QMap<double, double> curveG95Inf;
                
                QTextStream stream(&file);
                while(!stream.atEnd())
                {
                    QString line = stream.readLine();
                    if(!isComment(line))
                    {
                        QStringList values = line.split(",");
                        if(values.size() >= 3)
                        {
                            double t = values[0].toDouble();
                            
                            double g = values[1].toDouble();
                            double gSup = g + 1.96 * values[2].toDouble();
                            double gInf = g - 1.96 * values[2].toDouble();
                            
                            curveG[t] = g;
                            curveG95Sup[t] = gSup;
                            curveG95Inf[t] = gInf;
                        }
                    }
                }
                file.close();
                
                // The curves do not have 1-year precision!
                // We have to interpolate in the blanks
                
                double tmin = curveG.firstKey();
                double tmax = curveG.lastKey();
                
                for(double t=tmin; t<tmax; ++t)//t+=settings.mStep)//++t)
                {
                    if(curveG.find(t) == curveG.end())
                    {
                        // This actually return the iterator with the nearest greater key !!!
                        QMap<double, double>::const_iterator iter = curveG.lowerBound(t);
                        if(iter != curveG.end())
                        {
                            double t_upper = iter.key();
                            --iter;
                            if(iter != curveG.begin())
                            {
                                double t_under = iter.key();
                                
                                //qDebug() << t_under << " < " << t << " < " << t_upper;
                                
                                double g_under = curveG[t_under];
                                double g_upper = curveG[t_upper];
                                
                                double gsup_under = curveG95Sup[t_under];
                                double gsup_upper = curveG95Sup[t_upper];
                                
                                double ginf_under = curveG95Inf[t_under];
                                double ginf_upper = curveG95Inf[t_upper];
                                
                                curveG[t] = interpolate(t, t_under, t_upper, g_under, g_upper);
                                curveG95Sup[t] = interpolate(t, t_under, t_upper, gsup_under, gsup_upper);
                                curveG95Inf[t] = interpolate(t, t_under, t_upper, ginf_under, ginf_upper);
                            }
                            else
                            {
                                curveG[t] = 0;
                                curveG95Sup[t] = 0;
                                curveG95Inf[t] = 0;
                            }
                        }
                        else
                        {
                            curveG[t] = 0;
                            curveG95Sup[t] = 0;
                            curveG95Inf[t] = 0;
                        }
                    }
                }
                
                // Store the resulting curves :
                
                curves["G"] = curveG;
                curves["G95Sup"] = curveG95Sup;
                curves["G95Inf"] = curveG95Inf;
                
                mRefDatas[files[i].fileName().toLower()] = curves;
            }
        }
    }
}
示例#6
0
文件: Level.cpp 项目: adderly/VoltAir
void Level::rubeB2DLevel(b2dJson& mBox2dJson)
{
    if(mJsonFilePath.isEmpty()){
        qDebug() << " mJsonFilePath is empty ";
    }

    if(!Util::fileExists(mJsonFilePath)){
        qDebug() << " Level: "  << mJsonFilePath << " does not exists. ";
        return;
    }
    std::string worldJson = Util::readFileAsStdString(mJsonFilePath);

    std::string errorstring;
    b2World* w = mBox2dJson.readFromString(worldJson,errorstring,mWorld.get());

    if(w){
        //custom properties to be read
        int useWorldGravity = mBox2dJson.getCustomInt(w,"use_world_gravity",0);
        float grav_x ;
        float grav_y ;
        if(useWorldGravity){
            grav_x = mBox2dJson.getCustomFloat(w,"world_gravity_x",0);
            grav_y = mBox2dJson.getCustomFloat(w,"world_gravity_y",0);
             w->SetGravity(b2Vec2(grav_x,grav_y));
        }

        qDebug() << " Reading jsonfile Complete!  \n\t ";


        //check if there is a camera body
        //used for camera bounds. (Square body)
        b2Body* cam_body = mBox2dJson.getBodyByName("camera");
        if(cam_body){
            b2Fixture* cam_fixture = cam_body->GetFixtureList();
            if(cam_fixture){
                QRectF bbox = Box2dUtil::toQRectF(cam_fixture->GetAABB(0));
                this->setCameraBoundary(bbox);
                cam_body->SetActive(false);
#ifdef D_PARSE
                qDebug() << "Bounding box "<< bbox;
#endif
            }
#ifdef D_PARSE
            qDebug() << "camera found!";
#endif
        }

        //TODO: this is sooooo lazy,
        for(QVariant v:mLevelActorMapping){
            QMap<QString,QVariant> tmp = v.toMap();
            qDebug() << " Mapped LevelActorrr  " << tmp;

            mLevelActorMap.insert(tmp.firstKey(),tmp.first().toString());
        }


        Engine* engine = Engine::getInstance();
        QQmlEngine* qmlEngine = engine->getQmlEngine();

        // Check if bodies are referenced in the Actor Mapping Category
        Body* b = nullptr;
        std::string actorTypeString;
        b2Body* body = mWorld->GetBodyList();
        while(body){
            actorTypeString = mBox2dJson.getCustomString(body,"actorType");
            if(actorTypeString.empty() || actorTypeString == "none"){
                b = Body::BodyFromb2Body(body);
                if(b) b->setParent(this);
            }else{
                actorFromMapping(body,actorTypeString,qmlEngine);
            }
            body = body->GetNext();
        }

        // Use Nodes for parsing the specific type of node
        //QList<LevelNode*> nodes = findChildren<LevelNode*>();
        for(LevelNode* node: findChildren<LevelNode*>())  {
            switch(node->type())  {
                case LevelNode::BODY_REFERENCE:{
                    actorReferenceBody(node);
                }break;
                case LevelNode::ACTOR_COMPONENT_W_BODY:{
                    actorComponentWithBody(node,qmlEngine);
                }break;
                default:{
                    qDebug() << " unknown LevelNode type = " << node->type();
                }
            }
        }

       //check for images associated with the body.
       int imageCount = 0;
       body = nullptr;
       b = nullptr;
       QString image_path;
       Actor* actor = nullptr;
       ImageRenderer* img_renderer = nullptr;
       std::vector<b2dJsonImage*> world_images;
       imageCount = mBox2dJson.getAllImages(world_images);

       for(b2dJsonImage* img: world_images)
       {
           if((body = img->body))
           {
               b = static_cast<Body*>(img->body->GetUserData());
               if(b)
               {
                   image_path = Util::getPathToLevel(QString::fromStdString(img->file));
                   actor = new Actor(b);
                   actor->setPosition(b->getPosition());
                   actor->setParent(this);
                   actor->setParentItem(this);
                   img_renderer = new ImageRenderer(actor);
                   img_renderer->setSource(image_path);
                   img_renderer->setSizeScale(img->scale);
                   img_renderer->setVisible(true);
                   img_renderer->setCacheRenderParams(body->GetType() == Body::StaticBody);

                   QRectF c;
                   c.setTopLeft(Box2dUtil::toQPointF(img->corners[0]));
                   c.setTopRight(Box2dUtil::toQPointF(img->corners[1]));
                   c.setBottomRight(Box2dUtil::toQPointF(img->corners[2]));
                   c.setBottomLeft(Box2dUtil::toQPointF(img->corners[3]));
                   img_renderer->setCustomLocalBox(c);

#ifdef D_PARSE
                   qDebug() << image_path << " box2d " << Box2dUtil::toQPointF(img->corners[0]);
                   qDebug() << image_path << " box2d " << Box2dUtil::toQPointF(img->corners[1]);
                   qDebug() << image_path << " box2d " << Box2dUtil::toQPointF(img->corners[2]);
                   qDebug() << image_path << " box2d " << Box2dUtil::toQPointF(img->corners[3]);
                   qDebug() << image_path << " render localbox " << c;
                   //TODO: fixe the scale ratio, to match box2d.
                   b2AABB aabb = img->getAABB();
                   qDebug() <<"Image aabb = " << Box2dUtil::toQRectF(aabb);
                  // img_renderer->setPosition(QPointF(img->center.x,img->center.y ));
                   qDebug() << "Image pos = " <<img_renderer->position();
#endif
               }
           }
       }
    }else{
        qDebug() << "World null, Error Reading jsonfile: \n\t " << errorstring.c_str();
    }
    w = nullptr;
}