QDeclarativeContactRelationshipModel::QDeclarativeContactRelationshipModel(QObject *parent)
    :QAbstractListModel(parent),
    d(new QDeclarativeContactRelationshipModelPrivate)
{
    QHash<int, QByteArray> roleNames;
    roleNames = QAbstractItemModel::roleNames();
    roleNames.insert(RelationshipRole, "relationship");
    setRoleNames(roleNames);


    connect(this, SIGNAL(managerChanged()), SLOT(fetchAgain()));
    connect(this, SIGNAL(participantIdChanged()), SLOT(fetchAgain()));
    connect(this, SIGNAL(relationshipTypeChanged()), SLOT(fetchAgain()));
    connect(this, SIGNAL(roleChanged()), SLOT(fetchAgain()));

}
Exemple #2
0
QVWeather::QVWeather(QDomElement xml_desc, QString container, QWidget *parent) :
    QVElement(xml_desc,container,parent)
{
    if (w < 3) {
        w = 6;
    }
    if (h < 2) {
        h = 3;
    }

    QDomElement xml_elem = xml_desc.firstChildElement("text");
    if (xml_elem.isNull()) {
        w_title = 0;
    } else {
        w_title = new QLabel(xml_elem.text(),this);
    }

    bool ok;
    longitude = latitude = std::numeric_limits<double>::infinity();

    xml_elem = xml_desc.firstChildElement("latitude");
    if (!xml_elem.isNull()) {
        double res = xml_elem.text().toDouble(&ok);
        if (ok) {
            latitude = res;
        }
    }
    xml_elem = xml_desc.firstChildElement("longitude");
    if (!xml_elem.isNull()) {
        double res = xml_elem.text().toDouble(&ok);
        if (ok) {
            longitude = res;
        }
    }

    xml_elem = xml_desc.firstChildElement("days");
    if (xml_elem.isNull()) {
        n_days = 3;
    } else {
        n_days = xml_elem.text().toInt(&ok);
        if (!ok) {
            n_days = 3;
        }
    }

    QFile f_svg_weather(":/icons/weather.svg");
    if (f_svg_weather.open(QIODevice::ReadOnly)) {
        s_svg_weather = f_svg_weather.readAll();
        f_svg_weather.close();
    }

    QFile f_svg_wind(":/icons/weather_wind.svg");
    if (f_svg_wind.open(QIODevice::ReadOnly)) {
        s_svg_wind = f_svg_wind.readAll();
        f_svg_wind.close();
    }

    /* Generate widgets for displaying today´s forecast */
    for (int n=1; n < 4; n++) {
        w_separator.append(new QLabel(this));
        w_separator.last()->setStyleSheet("QLabel { background-color:#ffffff }");
        w_separator.last()->setFixedWidth(2);
    }

    for (int n=0; n < 4; n++) {
        w_times.append(new QLabel(this));
        w_times.last()->setAlignment(Qt::AlignHCenter);
        w_times.last()->setStyleSheet("QLabel { background:none }");
    }

    for (int n=0; n < 4; n++) {
        w_clouds.append(new QVSvgWidget(this));
    }

    for (int n=0; n < 4; n++) {
        w_winddir.append(new QVSvgWidget(this));
    }

    for (int n=0; n < 4; n++) {
        w_temp.append(new QLabel(this));
        w_temp.last()->setAlignment(Qt::AlignRight);
        w_temp.last()->setObjectName("mini");
        w_temp.last()->setStyleSheet("QLabel { background-color:none }");
        w_temp.append(new QLabel(this));
        w_temp.last()->setAlignment(Qt::AlignRight);
        w_temp.last()->setObjectName("mini");
        w_temp.last()->setStyleSheet("QLabel { background-color:none }");
    }

    /* ...and widgets for the next n_days days */
    for (int n=1; n < n_days; n++) {
        w_separator.append(new QLabel(this));
        w_separator.last()->setStyleSheet("QLabel { background-color:#ffffff }");
        w_separator.last()->setFixedWidth(2);
    }

    for (int n=0; n < n_days; n++) {
        w_times.append(new QLabel(this));
        w_times.last()->setAlignment(Qt::AlignHCenter);
        w_times.last()->setStyleSheet("QLabel { background:none }");
    }

    for (int n=0; n < n_days; n++) {
        w_clouds.append(new QVSvgWidget(this));
    }

    for (int n=0; n < n_days; n++) {
        w_temp.append(new QLabel(this));
        w_temp.last()->setAlignment(Qt::AlignRight);
        w_temp.last()->setObjectName("mini");

        w_temp.append(new QLabel(this));
        w_temp.last()->setAlignment(Qt::AlignRight);
        w_temp.last()->setObjectName("mini");
    }

    w_separator.append(new QLabel(this));
    w_separator.last()->setStyleSheet("QLabel { background-color:#ffffff }");
    w_separator.last()->setFixedHeight(2);


#if 1
    if ((longitude != std::numeric_limits<double>::infinity()) && (latitude != std::numeric_limits<double>::infinity())) {
        network_manager = new QNetworkAccessManager();
        QObject::connect(network_manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(dataReceived(QNetworkReply*)));
        network_manager->get(QNetworkRequest(QUrl("http://api.yr.no/weatherapi/locationforecast/1.9/?lat=" + QString::number(latitude,'f',2) + ";lon=" + QString::number(longitude,'f',2))));
        fetch_timer = new QTimer();
        QObject::connect(fetch_timer,SIGNAL(timeout()),this,SLOT(fetchAgain()));
    }