Exemplo n.º 1
0
QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
{
    QList<QSerialPortInfo> serialPortInfoList;

    DEVMGR_DEVICE_INFORMATION di;
    di.dwSize = sizeof(di);
    const HANDLE hSearch = ::FindFirstDevice(DeviceSearchByLegacyName,
                                             L"COM*",
                                             &di);
    if (hSearch != INVALID_HANDLE_VALUE) {
        do {
            QSerialPortInfo serialPortInfo;
            serialPortInfo.d_ptr->device = QString::fromWCharArray(di.szLegacyName);
            serialPortInfo.d_ptr->portName = QSerialPortPrivate::portNameFromSystemLocation(serialPortInfo.d_ptr->device);
            serialPortInfo.d_ptr->description = findDescription(HKEY_LOCAL_MACHINE,
                                                      QString::fromWCharArray(di.szDeviceKey));

            serialPortInfoList.append(serialPortInfo);

        } while (::FindNextDevice(hSearch, &di));
        ::FindClose(hSearch);
    }

    return serialPortInfoList;
}
Exemplo n.º 2
0
QT_BEGIN_NAMESPACE

static QString findDescription(HKEY parentKeyHandle, const QString &subKey)
{
    const static QString valueName(QStringLiteral("FriendlyName"));

    QString result;
    HKEY hSubKey = 0;
    LONG res = ::RegOpenKeyEx(parentKeyHandle, reinterpret_cast<const wchar_t *>(subKey.utf16()),
                              0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &hSubKey);

    if (res == ERROR_SUCCESS) {

        DWORD dataType = 0;
        DWORD dataSize = 0;
        res = ::RegQueryValueEx(hSubKey, reinterpret_cast<const wchar_t *>(valueName.utf16()),
                                NULL, &dataType, NULL, &dataSize);

        if (res == ERROR_SUCCESS) {
            QByteArray data(dataSize, 0);
            res = ::RegQueryValueEx(hSubKey, reinterpret_cast<const wchar_t *>(valueName.utf16()),
                                    NULL, NULL,
                                    reinterpret_cast<unsigned char *>(data.data()),
                                    &dataSize);

            if (res == ERROR_SUCCESS) {
                switch (dataType) {
                case REG_EXPAND_SZ:
                case REG_SZ:
                    if (dataSize)
                        result = QString::fromWCharArray(reinterpret_cast<const wchar_t *>(data.constData()));
                    break;
                default:
                    break;
                }
            }
        } else {
            DWORD index = 0;
            dataSize = 255; // Max. key length (see MSDN).
            QByteArray data(dataSize, 0);
            while (::RegEnumKeyEx(hSubKey, index++,
                                  reinterpret_cast<wchar_t *>(data.data()), &dataSize,
                                  NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {

                result = findDescription(hSubKey,
                                         QString::fromUtf16(reinterpret_cast<ushort *>(data.data()), dataSize));
                if (!result.isEmpty())
                    break;
            }
        }
        ::RegCloseKey(hSubKey);
    }
    return result;
}
Exemplo n.º 3
0
void PComboBox::setValue(const QVariant &value, bool emitChange)
{
#if QT_VERSION >= 0x030100
    if (!value.isNull())
#else
    if (value.canCast(QVariant::String))
#endif
    {
        disconnect(m_edit, SIGNAL(activated(int)), this, SLOT(updateProperty(int)));
        m_edit->setCurrentText(findDescription(value));
        connect(m_edit, SIGNAL(activated(int)), this, SLOT(updateProperty(int)));
        if (emitChange)
            emit propertyChanged(m_property, value);
    }
Exemplo n.º 4
0
 void OperatorKernel::setConnectorType(const unsigned int id, const Description::Type type,
     const Parameter::UpdateBehavior updateBehavior)
 {
     const Description* description = findDescription(id);
     
     if (description->originalType() == Description::PARAMETER)
         throw WrongArgument("Can not set the connector type of parameters which are not originally connectors.");
     
     switch (type)
     {
     case Description::INPUT:
         if (description->originalType() != Description::INPUT)
             throw WrongArgument("Descriptions can only be turned into inputs if their original type is INPUT.");
         break;
     case Description::OUTPUT:
         if (description->originalType() != Description::OUTPUT)
             throw WrongArgument("Descriptions can only be turned into outputs if their original type is OUTPUT.");
         break;
     case Description::PARAMETER:
         if (description->originalType() == Description::INPUT &&
             updateBehavior == Description::PULL)
         {
             throw WrongArgument("Inputs can not be turned into pull parameters.");
         }
         if (description->originalType() == Description::OUTPUT &&
             updateBehavior == Description::PUSH)
         {
             throw WrongArgument("Outputs can not be turned into push parameters.");
         }
         break;
     default:
         break;
     }
     
     m_typeMap[id] = type;
     m_behaviorMap[id] = updateBehavior;
     
     updateVisibleDescriptions(true);
 }
Exemplo n.º 5
0
 const Description& OperatorKernel::description(const unsigned int id) const
 {
     return *findDescription(id);
 }