Esempio n. 1
0
void MainWindow::genLineEnding()
{
  resetPlot();
  QMetaEnum endingStyleEnum = QCPLineEnding::staticMetaObject.enumerator(QCPLineEnding::staticMetaObject.indexOfEnumerator("EndingStyle"));
  double offset = -0.2;
  double step = 1.4/((double)endingStyleEnum.keyCount()-1);
  for (int i=0; i<endingStyleEnum.keyCount(); ++i)
  {
    QCPLineEnding ending(static_cast<QCPLineEnding::EndingStyle>(endingStyleEnum.value(i)));
    QString endingName(endingStyleEnum.key(i));
    
    if (ending.style() == QCPLineEnding::esSkewedBar)
      ending.setInverted(true);
    
    QCPItemLine *line = new QCPItemLine(customPlot);
    line->setPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::FlatCap));
    customPlot->addItem(line);
    line->start->setCoords(offset+i*step-0.1, -0.2);
    line->end->setCoords(offset+i*step, 0.5);
    line->setHead(ending);
    QCPItemText *text = new QCPItemText(customPlot);
    customPlot->addItem(text);
    text->position->setParentAnchor(line->end);
    text->position->setCoords(8, -15-(i%2)*15);
    text->setFont(QFont(font().family(), 8));
    text->setText(endingName);
  }

  customPlot->savePng(dir.filePath("QCPLineEnding.png"), 500, 100);
}
Esempio n. 2
0
SkillEdit::SkillEdit(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SkillEdit),
    d(*new SkillEditPrivate)
{
    ui->setupUi(this);

    //Find repository
    Repository *repo = REPOSITORY("Skill");
    Q_ASSERT(repo);

    //Set up the filter model
    d.model = new QSortFilterProxyModel(this);
    d.model->setSourceModel(repo);
    d.model->setFilterKeyColumn(repo->column("name"));
    d.model->setFilterCaseSensitivity(Qt::CaseInsensitive);

    //Create the dock widget
    d.dockWidget = new SkillsDockWidget(d.model);


    //Configure the button box
    ui->buttonBox->setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Cancel);

    //Add skill bases to their combobox
    QMetaEnum skillBaseEnum = ORM()->metaEnum("SkillBase");
    for (int i=0; i<skillBaseEnum.keyCount(); ++i) {
        ui->base->addItem(skillBaseEnum.key(i));
    }

    //Add skill categories to their combobox
    QMetaEnum skillCategoryEnum = ORM()->metaEnum("SkillCategory");
    for (int i=0; i<skillCategoryEnum.keyCount(); ++i) {
        ui->category->addItem(skillCategoryEnum.key(i));
    }

    //Set up the data widget mapper
    d.mapper = new DataWidgetMapper(this);
    d.mapper->setSubmitPolicy(DataWidgetMapper::ManualSubmit);
    d.mapper->setModel(repo);
    d.mapper->addMapping(ui->name, repo->column("name"));
    d.mapper->addMapping(ui->base, repo->column("base"), "currentIndex");
    d.mapper->addMapping(ui->category, repo->column("category"), "currentIndex");
    d.mapper->addMapping(ui->rulesPage, repo->column("rulesPage"));
    d.mapper->addMapping(ui->description, repo->column("description"));
    d.mapper->addMapping(ui->dieResults, repo->column("dieResults"));
    d.mapper->toFirst();
    setStateUnmodified();

    //Connect signals for un/modified data
    connect(d.mapper, SIGNAL(dataChanged()), this, SLOT(setStateModified()));

    //Connect signals for the button box
    connect(ui->buttonBox, SIGNAL(accepted()), d.mapper, SLOT(submit()));
    connect(ui->buttonBox, SIGNAL(rejected()), d.mapper, SLOT(revert()));
    connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(setStateUnmodified()));
    connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(setStateUnmodified()));
}
void GPhotoExposureControl::stateChanged(QCamera::State state)
{
    if (m_state != state) {
        if (m_state == QCamera::UnloadedState && state == QCamera::LoadedState) {
            m_state = state;

            QMetaEnum parameter = metaObject()->enumerator(metaObject()->indexOfEnumerator("ExposureParameter"));
            for (int i = 0; i < parameter.keyCount(); ++i) {
                ExposureParameter p = ExposureParameter(parameter.value(i));

                if (isParameterSupported(p)) {
                    // Set all parameters requested on start to session object
                    if (m_requestedValues.contains(p))
                        setValue(p, m_requestedValues.value(p));
                    // or just notify frontend that it's allowed to get the parameter values from backend
                    else
                        emit actualValueChanged(p);
                }

            }
        } else {
            m_state = state;
        }
    }
}
Esempio n. 4
0
// private:
Phantom::Phantom(QObject *parent)
    : REPLCompletable(parent)
    , m_terminated(false)
    , m_returnValue(0)
    , m_filesystem(0)
    , m_system(0)
{
    // Skip the first argument, i.e. the application executable (phantomjs).
    QStringList args = QApplication::arguments();
    args.removeFirst();

    // Prepare the configuration object based on the command line arguments.
    // Because this object will be used by other classes, it needs to be ready ASAP.
    m_config.init(&args);

    // initialize key map
    QMetaEnum keys = staticQtMetaObject.enumerator( staticQtMetaObject.indexOfEnumerator("Key") );
    for(int i = 0; i < keys.keyCount(); ++i) {
        QString name = keys.key(i);
        if (name.startsWith("Key_")) {
            name.remove(0, 4);
        }
        m_keyMap[name] = keys.value(i);
    }
}
void ThemeSettingsTableModel::toTheme(Theme *t) const
{
    ThemePrivate *theme = t->d;
    // Colors
    {
        QMetaEnum e = Theme::staticMetaObject.enumerator(Theme::staticMetaObject.indexOfEnumerator("Color"));
        for (int i = 0, total = e.keyCount(); i < total; ++i) {
            ColorRole::Ptr role = colors()->colorRole(i);
            ColorVariable::Ptr var = role->colorVariable();
            theme->colors[i] = qMakePair(var->color(), var->variableName());
        }
    }
    // Flags
    {
        QTC_ASSERT(theme->flags.size() == m_flags.size(), return);
        for (int i = 0; i < theme->flags.size(); ++i)
            theme->flags[i] = m_flags[i].second;
    }
    // ImageFiles
    {
        const int nImageFiles = theme->imageFiles.size();
        for (int i = 0; i < nImageFiles; ++i)
            theme->imageFiles[i] = m_imageFiles.at(i).second;
    }

    theme->widgetStyle = m_widgetStyle;
    theme->name = m_name;
    theme->preferredStyles = m_preferredStyles;
}
Esempio n. 6
0
ParamEnum::ParamEnum( QObject *parent, const char* name, int value, const QString& e, int *ptr ) 
    : AbstractParam(parent, name, QVariant::Int)
{
    m_ptr = ptr;

    QStringList L = e.split('|', QString::SkipEmptyParts);
    if (!L.isEmpty()) {
        for (int i = 0; i < L.size(); ++i) {
            m_keys.append(L[i]);
            m_values.append(i);
        }
    } else {
        QObject *p = parent;
        while (p) {
            const QMetaObject *mo = p->metaObject();
            int index = mo->indexOfEnumerator(e.toLatin1().data());
            if (index >= 0) {
                const QMetaEnum me = mo->enumerator(index);
                for (int i = 0; i < me.keyCount(); ++i) {
                    m_keys.append(me.key(i));
                    m_values.append(me.value(i));
                }
                break;
            }
            p = p->parent();
        }
    }

    m_value = m_defaultValue = value;
    if (m_ptr) *m_ptr = m_value;
}
void ThemeSettingsTableModel::toTheme(Theme *t) const
{
    ThemePrivate *theme = t->d;
    // Colors
    {
        QMetaEnum e = Theme::staticMetaObject.enumerator(Theme::staticMetaObject.indexOfEnumerator("ColorRole"));
        for (int i = 0, total = e.keyCount(); i < total; ++i) {
            ColorRole::Ptr role = colors()->colorRole(i);
            ColorVariable::Ptr var = role->colorVariable();
            theme->colors[i] = qMakePair(var->color(), var->variableName());
        }
    }
    // Flags
    {
        QTC_ASSERT(theme->flags.size() == m_flags.size(), return);
        for (int i = 0; i < theme->flags.size(); ++i)
            theme->flags[i] = m_flags[i].second;
    }
    // IconOveralys
    {
        const int nOverlays = theme->iconOverlays.size();
        QTC_ASSERT(nOverlays == m_iconOverlays.size(), return);
        for (int i = 0; i < nOverlays; ++i)
            theme->iconOverlays[i] = m_iconOverlays[i].second;
    }

    theme->widgetStyle = m_widgetStyle;
    theme->name = m_name;
    emit t->changed();
}
Esempio n. 8
0
void UIMenuBarEditorWidget::setRestrictionsOfMenuHelp(UIExtraDataMetaDefs::MenuHelpActionType restrictions)
{
    /* Cache passed restrictions: */
    m_restrictionsOfMenuHelp = restrictions;
    /* Get static meta-object: */
    const QMetaObject &smo = UIExtraDataMetaDefs::staticMetaObject;

    /* We have UIExtraDataMetaDefs::MenuHelpActionType enum registered, so we can enumerate it: */
    const int iEnumIndex = smo.indexOfEnumerator("MenuHelpActionType");
    QMetaEnum metaEnum = smo.enumerator(iEnumIndex);
    /* Handle other enum-values: */
    for (int iKeyIndex = 0; iKeyIndex < metaEnum.keyCount(); ++iKeyIndex)
    {
        /* Get iterated enum-value: */
        const UIExtraDataMetaDefs::MenuHelpActionType enumValue =
            static_cast<const UIExtraDataMetaDefs::MenuHelpActionType>(metaEnum.keyToValue(metaEnum.key(iKeyIndex)));
        /* Skip MenuHelpActionType_Invalid & MenuHelpActionType_All enum-value: */
        if (enumValue == UIExtraDataMetaDefs::MenuHelpActionType_Invalid ||
            enumValue == UIExtraDataMetaDefs::MenuHelpActionType_All)
            continue;
        /* Which key required action registered under? */
        const QString strKey = gpConverter->toInternalString(enumValue);
        if (!m_actions.contains(strKey))
            continue;
        /* Update action 'checked' state: */
        m_actions.value(strKey)->setChecked(!(m_restrictionsOfMenuHelp & enumValue));
    }
}
Esempio n. 9
0
QDebug operator <<(QDebug debug, const Snore::SnorePlugin::PluginTypes &flags)
{
    QMetaEnum e = SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType"));
    debug.nospace() << "PluginTypes(";
    bool needSeparator = false;
    int key;
    for (int i = 0; i < e.keyCount(); ++i)
    {
        key = e.value(i);
        if (flags.testFlag((SnorePlugin::PluginType)key))
        {
            if (needSeparator)
            {
                debug.nospace() << '|';
            }
            else
            {
                needSeparator = true;
            }

            debug.nospace() << e.valueToKey(key);

        }
    }
    debug << ')';
    return debug.space();

}
Esempio n. 10
0
QString flagsToString(const QMetaEnum &aMetaEnum, const int &aValue)
{
    QString res="[";

    for (int i=0; i<aMetaEnum.keyCount(); ++i)
    {
        int aFlag=aMetaEnum.value(i);

        if (((aValue & aFlag)==aFlag) && (aFlag!=0 || aValue==0))
        {
            bool good=true;

            while (aFlag)
            {
                if (aFlag & 1)
                {
                    good=(aFlag==1);
                    break;
                }

                aFlag>>=1;
            }

            if (good)
            {
                if (res.length()>1)
                {
                    res.append(", ");
                }

                res.append(QString::fromLatin1(aMetaEnum.key(i)));
            }
        }
    }
Esempio n. 11
0
 void copyEnumsToProperties(QObject* object) {
     const QMetaObject* meta = object->metaObject();
     for (int i = 0; i < meta->enumeratorCount(); ++i) {
         QMetaEnum metaenum = meta->enumerator(i);
         for (int j = 0; j < metaenum.keyCount(); ++j) {
             object->setProperty(metaenum.key(j), metaenum.value(j));
         }
     }
 }
Esempio n. 12
0
QStringList Scripting::Project::nodePropertyList()
{
    QStringList lst;
    QMetaEnum e = m_nodeModel.columnMap();
    for ( int i = 0; i < e.keyCount(); ++i ) {
        lst << QString( e.key( i ) );
    }
    return lst;
}
int MainWindow::taskCount()
{
    const QMetaObject &metaObject = MainWindow::staticMetaObject;
    int index = metaObject.indexOfEnumerator("Task");
    QMetaEnum metaEnum = metaObject.enumerator(index);
    int count = metaEnum.keyCount();

    return count;
}
Esempio n. 14
0
QWidget *MoveTypeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &/* index */) const
{
    QComboBox *editor = new QComboBox(parent);
    QMetaEnum moveInput =  KeyBind::staticMetaObject.enumerator( KeyBind::staticMetaObject.indexOfEnumerator("MoveInputs") );
    for(int i=0; i<moveInput.keyCount(); ++i) {
        editor->addItem(moveInput.key(i),moveInput.value(i));
    }

    return editor;
}
void ThemeSettingsTableModel::initFrom(Theme *theme)
{
    const QMetaObject &metaObject = Theme::staticMetaObject;
    // Colors
    {
        QMetaEnum e = metaObject.enumerator(metaObject.indexOfEnumerator("Color"));
        QMap<QString, ColorVariable::Ptr> varLookup;
        for (int i = 0, total = e.keyCount(); i < total; ++i) {
            const QString key = QLatin1String(e.key(i));
            QPair<QColor, QString> c = theme->d->colors[static_cast<Theme::Color>(i)];
            if (c.second.isEmpty()) {
                ColorVariable::Ptr v = colors()->createVariable(c.first);
                colors()->createRole(key, v);
            } else if (varLookup.contains(c.second)) {
                colors()->createRole(key, varLookup[c.second]);
            } else {
                ColorVariable::Ptr v = colors()->createVariable(c.first, c.second);
                colors()->createRole(key, v);
                varLookup[c.second] = v;
            }
        }
    }
    // Flags
    {
        QMetaEnum e = metaObject.enumerator(metaObject.indexOfEnumerator("Flag"));
        for (int i = 0, total = e.keyCount(); i < total; ++i) {
            const QString key = QLatin1String(e.key(i));
            m_flags.append(qMakePair(key, theme->flag(static_cast<Theme::Flag>(i))));
        }
    }
    // ImageFiles
    {
        QMetaEnum e = metaObject.enumerator(metaObject.indexOfEnumerator("ImageFile"));
        for (int i = 0, total = e.keyCount(); i < total; ++i) {
            const QString key = QLatin1String(e.key(i));
            m_imageFiles.append(qMakePair(key, theme->imageFile(static_cast<Theme::ImageFile>(i), QString())));
        }
    }

    m_widgetStyle = theme->widgetStyle();
    m_name = theme->d->name;
    m_preferredStyles = theme->d->preferredStyles;
}
Esempio n. 16
0
int ObjectEnumModel::rowCount(const QModelIndex &parent) const
{
  if (!parent.isValid()) {
    return SuperClass::rowCount(parent);
  }
  if (parent.parent().isValid()) {
    return 0;
  }
  const QMetaEnum e = m_metaObject->enumerator(parent.row());
  return e.keyCount();
}
Esempio n. 17
0
QStringList Country::getCountryNames() {
    if (sCountryNames.isEmpty()) {
        Country cc;
        QMetaProperty mp(cc.metaProperty("val"));
        QMetaEnum qmen = mp.enumerator();
        for (int i=0; i<qmen.keyCount(); ++i) {
            sCountryNames += qmen.valueToKey(i);
        }
    }
    return sCountryNames;
}
Esempio n. 18
0
QMap<QString, int> Zpublic::getEnumAutoSendEventTypeMap()
{
    QMetaEnum me = QMetaEnum::fromType<Zpublic::AutoSendEventType>();
//    int index = staticMetaObject.indexOfEnumerator("[AutoSendEventType]");
//    QMetaEnum me = staticMetaObject.enumerator(index);
//    const QMetaObject mo = Zpublic::staticMetaObject;
//    int index = mo.indexOfEnumerator("AutoSendEventType");
//    QMetaEnum me = mo.enumerator(index);
//   QMetaEnum me = QMetaEnum::fromType();
    ZW_LOG_INFO(QString("me count = %1").arg(me.keyCount()));
}
Esempio n. 19
0
QVariant ObjectEnumModel::metaData(const QModelIndex &index,
                               const QMetaEnum &enumerator, int role) const
{
  if (role == Qt::DisplayRole) {
    if (index.column() == 0) {
      return QString::fromLatin1(enumerator.name());
    }
    if (index.column() == 1) {
      return tr("%n element(s)", "", enumerator.keyCount());
    }
  }
  return QVariant();
}
Esempio n. 20
0
void Terrain3D::loadUserSettings()
{
    const QMetaObject &mo = Settings::staticMetaObject;
    const QMetaEnum me = mo.enumerator(mo.indexOfEnumerator("Key"));

    //loop through every Settings::Key and tell ourself that a value has
    //changed to effectively load the value
    for (int i=0; i<me.keyCount(); i++)
    {
        Settings::Key key = static_cast<Settings::Key>(me.value(i));
        settingsValueChanged(key, mMainSettings->value(key));
    }
}
SimpleLoggerRoutingInfo::SimpleLoggerRoutingInfo(QObject *parent) :
  QObject(parent), m_levels(nullptr), m_routing(nullptr), m_locationRegExp(nullptr), m_messageRegExp(nullptr),
  m_locationRegExpPatternSyntax(QRegExp::RegExp2), m_messageRegExpPatternSyntax(QRegExp::RegExp2),
  m_locRegExpCaseSensitivity(Qt::CaseInsensitive), m_messageRegExpCaseSensitivity(Qt::CaseInsensitive),
  m_enabled(true)
{
  const QMetaObject* metaObj = metaObject();
  QMetaEnum metaEnum = metaObj->enumerator(metaObj->indexOfEnumerator("MessageCategory"));

  m_levels = new QMap<MessageCategory, int>();
  for (int i=0; i<metaEnum.keyCount(); ++i)
  {
    m_levels->insert(static_cast<MessageCategory>(metaEnum.value(i)), 0);
  }

  metaEnum = metaObj->enumerator(metaObj->indexOfEnumerator("MessageRouting"));
  m_routing = new QMap<MessageRouting, bool>();
  for (int i=0; i<metaEnum.keyCount(); ++i)
  {
    m_routing->insert(static_cast<MessageRouting>(metaEnum.value(i)), false);
  }
}
Esempio n. 22
0
void MetaInfoPrivate::parseProperties(NodeMetaInfo &nodeMetaInfo, const QMetaObject *qMetaObject) const
{
    Q_ASSERT_X(qMetaObject, Q_FUNC_INFO, "invalid QMetaObject");
    Q_ASSERT_X(nodeMetaInfo.isValid(), Q_FUNC_INFO, "invalid NodeMetaInfo");

    for (int i = qMetaObject->propertyOffset(); i < qMetaObject->propertyCount(); ++i) {
        QMetaProperty qProperty = qMetaObject->property(i);

        PropertyMetaInfo propertyInfo;

        propertyInfo.setName(QLatin1String(qProperty.name()));

        QString typeName(qProperty.typeName());
        QString noStar = typeName;
        bool star = false;
        while (noStar.contains('*')) {//strip star
            noStar.chop(1);
            star = true;
        }
        if (m_QtTypesToQmlTypes.contains(noStar)) {
            typeName = star ? m_QtTypesToQmlTypes.value(noStar) + '*' : m_QtTypesToQmlTypes.value(noStar);
            //### versions
        }
        propertyInfo.setType(typeName);
        propertyInfo.setValid(true);
        propertyInfo.setReadable(qProperty.isReadable());
        propertyInfo.setWritable(qProperty.isWritable());
        propertyInfo.setResettable(qProperty.isResettable());
        propertyInfo.setEnumType(qProperty.isEnumType());
        propertyInfo.setFlagType(qProperty.isFlagType());

        if (propertyInfo.isEnumType()) {
            EnumeratorMetaInfo enumerator;

            QMetaEnum qEnumerator = qProperty.enumerator();
            enumerator.setValid(qEnumerator.isValid());
            enumerator.setIsFlagType(qEnumerator.isFlag());
            enumerator.setScope(qEnumerator.scope());
            enumerator.setName(qEnumerator.name());
            for (int i = 0 ;i < qEnumerator.keyCount(); i++)
            {
                enumerator.addElement(qEnumerator.valueToKey(i), i);
            }

            propertyInfo.setEnumerator(enumerator);
        }

        nodeMetaInfo.addProperty(propertyInfo);
    }
}
Esempio n. 23
0
int ObjectControllerPrivate::enumToInt(const QMetaEnum &metaEnum, int enumValue) const
{
    QMap<int, int> valueMap; // dont show multiple enum values which have the same values
    int pos = 0;
    for (int i = 0; i < metaEnum.keyCount(); i++) {
        int value = metaEnum.value(i);
        if (!valueMap.contains(value)) {
            if (value == enumValue)
                return pos;
            valueMap[value] = pos++;
        }
    }
    return -1;
}
Esempio n. 24
0
void GCF::Components::EnumEditorCreator::initialize(QWidget* editor, QMetaEnum enumStruct)
{
    QComboBox* combo = qobject_cast<QComboBox*>(editor);
    if(!combo)
        return;

    for(int i=enumStruct.keyCount()-1; i>=0; i--)
    {
        QString key = QString("%1").arg(enumStruct.key(i));
        int value = enumStruct.value(i);
        combo->insertItem(0, key);
        combo->setItemData(0, value);
    }
}
void SimpleLoggerRoutingInfo::setRouting(MessageRoutings messageRoutings, bool state)
{
  const QMetaObject* metaObj = metaObject();
  QMetaEnum metaEnum = metaObj->enumerator(metaObj->indexOfEnumerator("MessageRouting"));

  for (int i=0; i<metaEnum.keyCount(); ++i)
  {
    MessageRouting messageRouting = static_cast<MessageRouting>(metaEnum.value(i));
    if ((messageRoutings & messageRouting) == messageRouting)
    {
      m_routing->insert(messageRouting, state);
    }
  }
}
Esempio n. 26
0
int ObjectControllerPrivate::intToEnum(const QMetaEnum &metaEnum, int intValue) const
{
    QMap<int, bool> valueMap; // dont show multiple enum values which have the same values
    QList<int> values;
    for (int i = 0; i < metaEnum.keyCount(); i++) {
        int value = metaEnum.value(i);
        if (!valueMap.contains(value)) {
            valueMap[value] = true;
            values.append(value);
        }
    }
    if (intValue >= values.count())
        return -1;
    return values.at(intValue);
}
Esempio n. 27
0
QString enumToString(const QMetaEnum &aMetaEnum, const int &aValue)
{
    QString res=qApp->translate("Property", "[No enumeration value]");

    for (int i=0; i<aMetaEnum.keyCount(); ++i)
    {
        if (aMetaEnum.value(i)==aValue)
        {
            res=QString::fromLatin1(aMetaEnum.key(i));
            break;
        }
    }

    return res;
}
Esempio n. 28
0
void SaxsviewProperty::setValue(QObject *obj) {
  if (!mProperty) {
    //
    // Find the meta-property information; the passed object must
    // provide the Q_PROPERTY name passed to the constructor.
    //
    int indexOfProperty = obj->metaObject()->indexOfProperty(qPrintable(mPropertyName));
    QMetaProperty metaProperty = obj->metaObject()->property(indexOfProperty);

    if (metaProperty.isValid()) {
      //
      // Create an editor factory if and only if the property is writeable.
      //
      if (metaProperty.isWritable()) {
        mBrowser->setFactoryForManager(mManager, new QtVariantEditorFactory(this));
        connect(mManager, SIGNAL(valueChanged(QtProperty*, const QVariant&)),
                this, SLOT(valueChanged(QtProperty*, const QVariant&)));
      }

      if (!mManager->isPropertyTypeSupported(metaProperty.type()))
        qFatal("internal error: property '%s', property type not supported: '%s'",
               metaProperty.name(), metaProperty.typeName());

      //
      // Check if this is an enum and handle it specially if yes.
      //
      if (metaProperty.isEnumType()) {
        QStringList enumNames;
        QMetaEnum metaEnum = metaProperty.enumerator();

        //
        // WARNING: This only builds a  list of names in the order
        //          as defined. The combobox to display these names
        //          provides the selected index, not the actual enum
        //          value.
        //
        for (int i = 0; i < metaEnum.keyCount(); ++i)
          enumNames << metaEnum.key(i);

        setEnumNames(enumNames);
      }

      if (mAttributes.contains("enumNames"))
        mProperty = mManager->addProperty(mManager->enumTypeId(), mPropertyLabel);
      else
        mProperty = mManager->addProperty(metaProperty.type(), mPropertyLabel);

    } else if (obj->dynamicPropertyNames().contains(qPrintable(mPropertyName))) {
Esempio n. 29
0
QList<QString> enumToKeys(const QMetaObject o, const QString& name, const QString& strip)
{
    QList<QString> list;

    int enumIndex = o.indexOfEnumerator(name.toLatin1().data());
    QMetaEnum enumerator = o.enumerator(enumIndex);

    if (enumerator.isValid()) {
        for (int i = 0; i < enumerator.keyCount(); i++) {
            QString key(enumerator.valueToKey(i));
            list.append(key.remove(strip));
        }
    }

    return list;
}
    void QtScriptEngine::copyEnumsToScriptObject(
        QScriptEngine *engine, const QMetaObject *metaObject, QScriptValue *object)
    {
        for (int enumIndex = 0; enumIndex < metaObject->enumeratorCount(); enumIndex++)
        {
            QMetaEnum metaEnum = metaObject->enumerator(enumIndex);
            QScriptValue enumClass = engine->newObject();

            for (int keyIndex = 0; keyIndex < metaEnum.keyCount(); keyIndex++)
            {
                enumClass.setProperty(metaEnum.key(keyIndex), metaEnum.value(keyIndex));
            }

            object->setProperty(metaEnum.name(), enumClass);
        }
    }