Esempio n. 1
0
  void TabEdit::changePOTCAR(QListWidgetItem *item)
  {
    QSettings settings; // Already set up in avogadro/src/main.cpp

    // Get symbol and filename
    QStringList strl = item->text().split(":");
    QString symbol   = strl.at(0).trimmed();
    QString filename = strl.at(1).trimmed();

    QStringList files;
    QString path = settings.value("xtalopt/templates/potcarPath", "").toString();
    QFileDialog dialog (NULL, QString("Select pot file for atom %1").arg(symbol), path);
    dialog.selectFile(filename);
    dialog.setFileMode(QFileDialog::ExistingFile);
    if (dialog.exec()) {
      files = dialog.selectedFiles();
      if (files.size() != 1) { return;} // Only one file per element
      filename = files.first();
      settings.setValue("xtalopt/templates/potcarPath", dialog.directory().absolutePath());
    }
    else { return;} // User cancel file selection.
    // "POTCAR info" is of type
    // QList<QHash<QString, QString> >
    // e.g. a list of hashes containing
    // [atomic symbol : pseudopotential file] pairs
    QVariantList potcarInfo = m_opt->optimizer()->getData("POTCAR info").toList();
    QVariantHash hash = potcarInfo.at(ui_list_optStep->currentRow()).toHash();
    hash.insert(symbol,QVariant(filename));
    potcarInfo.replace(ui_list_optStep->currentRow(), hash);
    m_opt->optimizer()->setData("POTCAR info", potcarInfo);
    qobject_cast<VASPOptimizer*>(m_opt->optimizer())->buildPOTCARs();
    updateEditWidget();
  }
Esempio n. 2
0
void QuotesApp::deleteRecord()
{
    QVariantList indexPath = mListView->selected();

    if (!indexPath.isEmpty()) {
        QVariantMap map = mDataModel->data(indexPath).toMap();

        // Delete the item from the database based on unique ID. If successful, remove it
        // from the data model (which will remove the data from the list).
        if (mQuotesDbHelper->deleteById(map["id"])) {

            // Delete is the only operation where the logics for updating which item
            // is selected is handled in code.
            // Before the item is removed, we store how many items there are in the
            // category that the item is removed from, we need this to select a new item.
            QVariantList categoryIndexPath;
            categoryIndexPath.append(indexPath.first());
            int childrenInCategory = mDataModel->childCount(categoryIndexPath);

            mDataModel->remove(map);

            // After removing the selected item, we want another quote to be shown.
            // So we select the next quote relative to the removed one in the list.
            if (childrenInCategory > 1) {
                // If the Category still has items, select within the category.
                int itemInCategory = indexPath.last().toInt();

                if (itemInCategory < childrenInCategory - 1) {
                    mListView->select(indexPath);
                } else {
                    // The last item in the category was removed, select the previous item relative to the removed item.
                    indexPath.replace(1, QVariant(itemInCategory - 1));
                    mListView->select(indexPath);
                }
            } else {
                // If no items left in the category, move to the next category. 
                // If there are no more categories below(next), select the previous category.
                // If no items left at all, navigate to the list.
                QVariantList lastIndexPath = mDataModel->last();

                if (!lastIndexPath.isEmpty()) {
                    if (indexPath.first().toInt() <= lastIndexPath.first().toInt()) {
                        mListView->select(indexPath);
                    } else {
                        mListView->select(mDataModel->last());
                    }
                }
            } // else statment
        } //if statement
    } // top if statement
} // deleteRecord()
void CustomItemProvider::initPickerValues(DataModel* pickerModel)
{
    QVariantList indexPath;
    indexPath << 0;

    // Get the number of columns by checking the child count of the models root element.
    mColumnCount = pickerModel->childCount(QVariantList());

    // The column range correspond to the child count of the models column data elements,
    // this information is reported back in the range function above.
    for (int i = 0; i < mColumnCount; i++) {
        indexPath.replace(0, i);
        mUpperRanges.insert(i, pickerModel->childCount(indexPath) - 1);
    }
}
Esempio n. 4
0
QVariant IgmpProtocol::fieldData(int index, FieldAttrib attrib,
        int streamIndex) const
{
    switch (index)
    {
        case kRsvdMrtCode:
        {
            uint mrt = 0;
            quint8 mrcode = 0;

            if (msgType() == kIgmpV3Query)
            {
                mrt = data.max_response_time();
                mrcode = quint8(mrc(mrt));
            }
            else if (msgType() == kIgmpV2Query)
            {
                mrt = data.max_response_time();
                mrcode = mrt & 0xFF;
            }


            switch(attrib)
            {
            case FieldName:
                if (isQuery())
                    return QString("Max Response Time");
                else
                    return QString("Reserved");
            case FieldValue:
                return mrt;
            case FieldTextValue:
                return QString("%1").arg(mrt);
            case FieldFrameValue:
                return QByteArray(1, mrcode);
            default:
                break;
            }
            break;
        }
        case kGroupAddress:
        {
            quint32 grpIp = ipUtils::ipAddress(
                data.group_address().v4(),
                data.group_prefix(),
                ipUtils::AddrMode(data.group_mode()),
                data.group_count(),
                streamIndex);

            switch(attrib)
            {
            case FieldName:            
                return QString("Group Address");
            case FieldValue:
            case FieldTextValue:
                return QHostAddress(grpIp).toString();
            case FieldFrameValue:
            {
                QByteArray fv;
                fv.resize(4);
                qToBigEndian(grpIp, (uchar*) fv.data());
                return fv;
            }
            default:
                break;
            }
            break;
        }
        case kSources:
        {
            switch(attrib)
            {
            case FieldName:            
                return QString("Source List");
            case FieldValue:
            {
                QStringList list;

                for (int i = 0; i < data.sources_size(); i++)
                    list.append(QHostAddress(data.sources(i).v4()).toString());
                return list;
            }
            case FieldFrameValue:
            {
                QByteArray fv;
                fv.resize(4 * data.sources_size());
                for (int i = 0; i < data.sources_size(); i++)
                    qToBigEndian(data.sources(i).v4(), (uchar*)(fv.data()+4*i));
                return fv;
            }
            case FieldTextValue:
            {
                QStringList list;

                for (int i = 0; i < data.sources_size(); i++)
                    list.append(QHostAddress(data.sources(i).v4()).toString());
                return list.join(", ");
            }
            default:
                break;
            }
            break;
        }
        case kGroupRecords:
        {
            switch(attrib)
            {
            case FieldValue:
            {
                QVariantList grpRecords = GmpProtocol::fieldData(
                        index, attrib, streamIndex).toList();

                for (int i = 0; i < data.group_records_size(); i++)
                {
                    QVariantMap grpRec = grpRecords.at(i).toMap();
                    OstProto::Gmp::GroupRecord rec = data.group_records(i);

                    grpRec["groupRecordAddress"] = QHostAddress(
                                rec.group_address().v4()).toString();

                    QStringList sl;
                    for (int j = 0; j < rec.sources_size(); j++)
                        sl.append(QHostAddress(rec.sources(j).v4()).toString());
                    grpRec["groupRecordSourceList"] = sl;

                    grpRecords.replace(i, grpRec);
                }
                return grpRecords;
            }
            case FieldFrameValue:
            {
                QVariantList list = GmpProtocol::fieldData(
                        index, attrib, streamIndex).toList();
                QByteArray fv;

                for (int i = 0; i < data.group_records_size(); i++)
                {
                    OstProto::Gmp::GroupRecord rec = data.group_records(i);
                    QByteArray rv = list.at(i).toByteArray();

                    rv.insert(4, QByteArray(4+4*rec.sources_size(), char(0)));
                    qToBigEndian(rec.group_address().v4(), 
                            (uchar*)(rv.data()+4));
                    for (int j = 0; j < rec.sources_size(); j++)
                    {
                        qToBigEndian(rec.sources(j).v4(),
                                (uchar*)(rv.data()+8+4*j));
                    }

                    fv.append(rv);
                }
                return fv;
            }
            case FieldTextValue:
            {
                QStringList list = GmpProtocol::fieldData(
                        index, attrib, streamIndex).toStringList();

                for (int i = 0; i < data.group_records_size(); i++)
                {
                    OstProto::Gmp::GroupRecord rec = data.group_records(i);
                    QString recStr = list.at(i);
                    QString str;

                    str.append(QString("Group: %1").arg(
                        QHostAddress(rec.group_address().v4()).toString()));

                    str.append("; Sources: ");
                    QStringList sl;
                    for (int j = 0; j < rec.sources_size(); j++)
                        sl.append(QHostAddress(rec.sources(j).v4()).toString());
                    str.append(sl.join(", "));

                    recStr.replace("XXX", str);
                    list.replace(i, recStr);
                }
                return list.join("\n").insert(0, "\n");
            }
            default:
                break;
            }
            break;
        }
        default:
            break;
    }

    return GmpProtocol::fieldData(index, attrib, streamIndex);
}