Exemplo n.º 1
0
int main(int argc, char **argv) {
    Q_UNUSED(argc);
    Q_UNUSED(argv);

    basicCheck();

    QHash<QString, int> hash;
    Trie<int> t;
    while (hash.count() < 500) {
        qDebug() << hash.count();
        QStringList key = generateKey();
        int value = qrand() % 50000;
        hash[key.join(QLatin1String(","))] = value;
        t.insert(key, value);

        QHashIterator<QString, int> i(hash);
        while (i.hasNext()) {
            i.next();
            if (t.find(i.key().split(QLatin1Char(','))).count() == 0)
                qDebug() << i.key();
            Q_ASSERT(t.find(i.key().split(QLatin1Char(','))).count() > 0);
            if (qrand() % 500 == 0) {
                t.remove(i.key().split(QLatin1Char(',')), i.value());
                hash.remove(i.key());
            }
            //cout << i.key() << ": " << i.value() << endl;
        }
    }
    return 0;
}
Exemplo n.º 2
0
void TagIO::write_images(
        const QDir& output_dir,
        const QHash< QString, QList<TagItem::Elements> >& elts
    )
{
    if( !output_dir.exists() ) {
        return;
    }

    QHash<QString, int> label_counter;

    QProgressDialog progress( "Crop and save images", "Cancel", 0, elts.count() );
    progress.setWindowModality( Qt::WindowModal );
    int c = 0;

    for( QHash< QString, QList<TagItem::Elements> >::const_iterator img_itr = elts.begin(); img_itr != elts.end(); ++img_itr ) {
        progress.setValue( c++ );

        QString fullpath = img_itr.key();
        const QList<TagItem::Elements>& tags = img_itr.value();

        for( QList<TagItem::Elements>::const_iterator tag_itr = tags.begin(); tag_itr != tags.end(); ++tag_itr ) {
            const TagItem::Elements& elt = *tag_itr;
            const QList<QRect>& bboxes = elt._bbox;
            const QString& label = elt._label;

            if( !label_counter.contains( label ) ) {
                label_counter[ label ] = 0;
                if( !output_dir.exists( label ) ) {
                    output_dir.mkdir( label );
                }
            }
            QDir subdir = output_dir.absoluteFilePath( label );

            QString ext = QFileInfo( elt._fullpath ).suffix();
            QPixmap pix;
            if( !pix.load( elt._fullpath ) ) {
                continue;
            }

            for( QList<QRect>::const_iterator bbox_itr = bboxes.begin(); bbox_itr != bboxes.end(); ++bbox_itr ) {
                QPixmap cropped = pix.copy( *bbox_itr );
                cropped.save( subdir.absoluteFilePath( label + "_" + QString::number( ++label_counter[ label ] ) + "." + ext ) );
            }
        }

        if( progress.wasCanceled() ) {
            break;
        }
    }

    progress.setValue( elts.count() );
}
QString roleAsString (int role)
{
  if (rolesAsStringsLookupTable.count () == 0) {

    // Initialize with list from qnamespace.h
    rolesAsStringsLookupTable [Qt::AccessibleDescriptionRole] = "AccessibleDescriptionRole";
    rolesAsStringsLookupTable [Qt::AccessibleTextRole] = "AccessibleTextRole";
    rolesAsStringsLookupTable [Qt::BackgroundRole] = "BackgroundRole";
    rolesAsStringsLookupTable [Qt::BackgroundColorRole] = "BackgroundColorRole";
    rolesAsStringsLookupTable [Qt::CheckStateRole] = "CheckStateRole";
    rolesAsStringsLookupTable [Qt::DecorationRole] = "DecorationRole";
    rolesAsStringsLookupTable [Qt::DisplayRole] = "DisplayRole";
    rolesAsStringsLookupTable [Qt::EditRole] = "EditRole";
    rolesAsStringsLookupTable [Qt::FontRole] = "FontRole";
    rolesAsStringsLookupTable [Qt::ForegroundRole] = "ForegroundRole";
    rolesAsStringsLookupTable [Qt::InitialSortOrderRole] = "InitialSortOrderRole";
    rolesAsStringsLookupTable [Qt::SizeHintRole] = "SizeHintRole";
    rolesAsStringsLookupTable [Qt::StatusTipRole] = "StatusTipRole";
    rolesAsStringsLookupTable [Qt::TextAlignmentRole] = "TextAlignmentRole";
    rolesAsStringsLookupTable [Qt::TextColorRole] = "TextColorRole";
    rolesAsStringsLookupTable [Qt::ToolTipRole] = "ToolTipRole";
    rolesAsStringsLookupTable [Qt::UserRole] = "UserRole";
    rolesAsStringsLookupTable [Qt::WhatsThisRole] = "WhatsThisRole";
  }

  if (rolesAsStringsLookupTable.contains (role)) {

    return rolesAsStringsLookupTable [role];

  } else {

    return QString ("%1?").arg (role);

  }
}
void DClusterTransferDevicePage::handleTransferDeviceList(InputPacket &inpack)
{
    char* data = inpack.getPackData();
    quint16 dataLen = inpack.getPackDataLen();

    SAFE_DELETE(deviceInfoList);
    deviceInfoList = new DClusterDevInfoList;
    deviceInfoList->appendList(data, dataLen);
    QHash<quint64, DClusterDevInfo*> devList = deviceInfoList->fetchList();
    if(devList.count() < 1){
        lblHint->setText(tr("不存在可移交的设备"));
        return;
    }

    QHashIterator<quint64, DClusterDevInfo*> iter(devList);
    while(iter.hasNext())
    {
        iter.next();
        DClusterDevInfo* devInfo = dynamic_cast<DClusterDevInfo*>(iter.value());
        this->setDeviceButton(devInfo);

        if(curFixedContentHeight <= this->bodyPartHeight())
            this->setBodyRealHeight(this->bodyPartHeight());
        else
            this->setBodyRealHeight(curFixedContentHeight);
    }
}
Exemplo n.º 5
0
//******************************************************************************************
//function: doUpdate
//params: const QHash<QString, QString> &params
//return: QJsonObject
//Description:
//******************************************************************************************
QJsonObject WSClient::doUpdate(const QHash<QString, QString> &params)
{
    if (!this->getCheckLogin()) {
        throw WSClientException( this->jsLoginError );
    }

    if (params.count() >= 1)
    {
        QJsonObject item;

        QHashIterator<QString, QString> prm(params);
        while(prm.hasNext()) {
            prm.next();
            item[prm.key()] = prm.value();
        }

        QJsonDocument doc_item(item);

        QHash<QString, QString> parameters;
        parameters.insert("element", QString( doc_item.toJson() ));

        QJsonObject response = Post("update", parameters);
        return response;
    }
    else
    {
        throw "Datos incorrectos";
    }
}
Exemplo n.º 6
0
QHash<QString, int> RawJointState::namesToJoints()
{
    static QHash<QString, int> l = QHash<QString, int>();
    if (l.count() == 0)
    {
        l.insert("neck", 0);
        l.insert("head", 1);
        l.insert("right-shoulder", 2);
        l.insert("left-shoulder", 6);
        l.insert("right-elbow", 3);
        l.insert("left-elbow", 7);
        l.insert("right-wrist", 4);
        l.insert("right-pelvis", 18); //Spine
        l.insert("left-pelvis", 19); //HipCenter
        l.insert("left-wrist", 8);
        l.insert("right-palm", 5);
        l.insert("right-hip", 10);
        l.insert("left-hip", 14);
        l.insert("left-palm", 9);
        l.insert("right-knee", 11);
        l.insert("left-knee", 15);
        l.insert("right-ankle", 12);
        l.insert("right-foot", 13);
        l.insert("left-ankle", 16);
        l.insert("left-foot", 17);
    }
    return l;
}
Exemplo n.º 7
0
void CatalogBuilder::buildCatalog()
{
	progress = CATALOG_PROGRESS_MIN;
	emit catalogIncrement(progress);
	catalog->incrementTimestamp();
    indexed.clear();

	QList<Directory> memDirs = SettingsManager::readCatalogDirectories();
	QHash<uint, PluginInfo> pluginsInfo = plugins->getPlugins();
	totalItems = memDirs.count() + pluginsInfo.count();
    currentItem = 0;

	while (currentItem < memDirs.count())
    {
		QString cur = platform->expandEnvironmentVars(memDirs[currentItem].name);
		indexDirectory(cur, memDirs[currentItem].types, memDirs[currentItem].indexDirs, memDirs[currentItem].indexExe, memDirs[currentItem].depth);
        progressStep(currentItem);
	}

	// Don't call the pluginhandler to request catalog because we need to track progress
	plugins->getCatalogs(catalog, this);

	catalog->purgeOldItems();
	indexed.clear();
	progress = CATALOG_PROGRESS_MAX;
    emit catalogFinished();
}
QString QXmlStreamReaderTokenTypeToString (QXmlStreamReader::TokenType tokenType)
{
  if (xmlTokenTypeLookupTable.count () == 0) {

    // Initialize
    xmlTokenTypeLookupTable [QXmlStreamReader::Characters] = "Characters";
    xmlTokenTypeLookupTable [QXmlStreamReader::Comment] = "Comment";
    xmlTokenTypeLookupTable [QXmlStreamReader::DTD] = "DTD";
    xmlTokenTypeLookupTable [QXmlStreamReader::EndDocument] = "EndDocument";
    xmlTokenTypeLookupTable [QXmlStreamReader::EndElement] = "EndElement";
    xmlTokenTypeLookupTable [QXmlStreamReader::EntityReference] = "EntityReference";
    xmlTokenTypeLookupTable [QXmlStreamReader::Invalid] = "Invalid";
    xmlTokenTypeLookupTable [QXmlStreamReader::NoToken] = "NoToken";
    xmlTokenTypeLookupTable [QXmlStreamReader::ProcessingInstruction] = "ProcessingInstruction";
    xmlTokenTypeLookupTable [QXmlStreamReader::StartDocument] = "StartDocument";
    xmlTokenTypeLookupTable [QXmlStreamReader::StartElement] = "StartElement";
  }

  if (xmlTokenTypeLookupTable.contains (tokenType)) {

    return xmlTokenTypeLookupTable [tokenType];

  } else {

    return "<Unknown>";

  } 
}
// static
QImage GeometricConvolution::convolve(QImage img,
                                      QHash<int, QList<float> > mask,
                                      int filter_offset, float filter_div)
{
    QImage res(img.width(), img.height(), QImage::Format_ARGB32);

    int xfilter_size = mask[0].count();
    int yfilter_size = mask.count();

    int mfilter_size = xfilter_size * yfilter_size;

    int xradius = xfilter_size / 2;
    int yradius = yfilter_size / 2;

    for (int y = 0; y < img.height(); ++y)
    {
        for (int x = 0; x < img.width(); ++x)
        {
            int c_pixel_x = x + xradius;
            int c_pixel_y = y + yradius;

            if (c_pixel_x >= img.width() || c_pixel_y >= img.height())
                continue;

            float new_r, new_g, new_b;
            new_r = new_g = new_b = 1;

            for (int j = 0; j < yfilter_size; j++)
            {
                int yv = min(max(y - yradius + j, 0), img.height() - yradius);

                for (int i = 0; i < xfilter_size; i++)
                {
                    int xv = min(max(x-xradius + i, 0), img.width() - xradius);

                    QColor c(img.pixel(xv, yv));

                    float m = mask[j][i];
                    new_r *= c.red()   * m;
                    new_g *= c.green() * m;
                    new_b *= c.blue()  * m;
                }
            }

            new_r = pow(new_r/filter_div, 1./mfilter_size) + filter_offset;
            new_g = pow(new_g/filter_div, 1./mfilter_size) + filter_offset;
            new_b = pow(new_b/filter_div, 1./mfilter_size) + filter_offset;

            new_r = (new_r > 255) ? 255 : ((new_r < 0) ? 0:new_r);
            new_g = (new_g > 255) ? 255 : ((new_g < 0) ? 0:new_g);
            new_b = (new_b > 255) ? 255 : ((new_b < 0) ? 0:new_b);

            res.setPixel(c_pixel_x, c_pixel_y, QColor((int)new_r,
                         (int)new_g,
                         (int)new_b, 255).rgb());
        }
    }
    return res;
}
// static
QImage MedianConvolution::convolve(QImage img,
                                   QHash<int, QList<float> > mask,
                                   int filter_offset, float filter_div)
{
    QImage res(img.width(), img.height(), QImage::Format_ARGB32);

    int xfilter_size = mask[0].count();
    int yfilter_size = mask.count();

    int mfilter_size = xfilter_size * yfilter_size;

    int xradius = xfilter_size / 2;
    int yradius = yfilter_size / 2;

    for (int y = 0; y < img.height(); ++y)
    {
        for (int x = 0; x < img.width(); ++x)
        {
            int c_pixel_x = x + xradius;
            int c_pixel_y = y + yradius;

            if (c_pixel_x >= img.width() || c_pixel_y >= img.height())
                continue;

            QList<float> r;
            QList<float> g;
            QList<float> b;

            for (int j = 0; j < yfilter_size; j++)
            {
                int yv = min(max(y - yradius + j, 0), img.height() - yradius);

                for (int i = 0; i < xfilter_size; i++)
                {
                    int xv = min(max(x-xradius + i, 0), img.width() - xradius);

                    QColor c(img.pixel(xv, yv));
                    r << c.red()   * mask[j][i];
                    g << c.green() * mask[j][i];
                    b << c.blue()  * mask[j][i];
                }
            }

            qSort(r); qSort(g); qSort(b);
            int new_r = r.at(mfilter_size / 2) / filter_div + filter_offset;
            int new_g = g.at(mfilter_size / 2) / filter_div + filter_offset;
            int new_b = b.at(mfilter_size / 2) / filter_div + filter_offset;

            new_r = (new_r > 255) ? 255 : ((new_r < 0) ? 0:new_r);
            new_g = (new_g > 255) ? 255 : ((new_g < 0) ? 0:new_g);
            new_b = (new_b > 255) ? 255 : ((new_b < 0) ? 0:new_b);

            res.setPixel(x, y, QColor((int)new_r,
                                      (int)new_g,
                                      (int)new_b, 255).rgb());
        }
    }
    return res;
}
Exemplo n.º 11
0
int AtlasUtils::iconTypeSortOrder(int icon)
{
	static QHash<int, int> sortOrder;

	// initialization
	if (sortOrder.count() == 0) {
		for (unsigned i = 0 ;
			i < sizeof(ClassViewConstants::IconSortOrder) / sizeof(ClassViewConstants::IconSortOrder[0]) ; ++i)
			sortOrder.insert(ClassViewConstants::IconSortOrder[i], sortOrder.count());
	}

	// if it is missing - return the same value
	if (!sortOrder.contains(icon))
		return icon;

	return sortOrder[icon];
}
Exemplo n.º 12
0
void GalaGV::hideItems(const QHash<QString, QGraphicsEllipseItem *> &hash)
{
    qDebug() << Q_FUNC_INFO << hash.count();
    QHashIterator<QString, QGraphicsEllipseItem*> it(hash);
    while(it.hasNext()){
        it.next();
        it.value()->hide();
    }
}
Exemplo n.º 13
0
int pid(const QString& s, QHash<QString, int>& pids)
{
	if ( pids.contains(s) )
		return pids.value(s);
	
	int id = (pids.count() + 1) << 12;
	
	pids[s] = id;
	
	return id;
}
Exemplo n.º 14
0
void Journal::setDbValuesImplementation(const QHash<QString, QVariant> &dbValues)
{
    if (dbValues.count() > 0) {
        setId(dbValues[ID].toUInt());
        qDebug()<<dbValues[ID]<<"to Uint"<<dbValues[ID].toUInt();
        setName(dbValues[Name].toString());
        setDate(dbValues[DATE].toString());
        setInventoryID(dbValues[INVENTORYID].toUInt());
        setStatusID(dbValues[STATUSID].toUInt());
        setComment(dbValues[COMMENT].toString());
    }
}
bool saveThemeToBlob(const QString &themeBlob,
                     const QHash<QString, QPicture> &partPictures,
                     const QHash<QPair<QString, int>, QColor> &colors)
{
    QFile blob(themeBlob);
    if (!blob.open(QIODevice::WriteOnly)) {
        qWarning() << __FUNCTION__ << ": Could not create blob: " << themeBlob;
        return false;
    }

    QByteArray data;
    QBuffer dataBuffer(&data);
    dataBuffer.open(QIODevice::WriteOnly);
    QDataStream dataOut(&dataBuffer);

    const int colorsCount = colors.count();
    dataOut << colorsCount;
    const QList<QPair<QString, int> > colorKeys = colors.keys();
    for (int i = 0; i < colorsCount; ++i) {
        const QPair<QString, int> &key = colorKeys.at(i);
        dataOut << key;
        const QColor color = colors.value(key);
        dataOut << color;
    }

    dataOut << partPictures.count();
    QHashIterator<QString, QPicture> i(partPictures);
    while (i.hasNext()) {
        i.next();
        dataOut << i.key();
        dataOut << i.value(); // the QPicture
    }

    QDataStream blobOut(&blob);
    blobOut << blobVersion;
    blobOut << qCompress(data);
    return blobOut.status() == QDataStream::Ok;
}
    void shouldGetItemWithCorrectValues()
    {
        history->add(QUrl("http://example1.org/"), "Example 1 Domain", QUrl());

        QVariantMap item = model->get(0);
        QHash<int, QByteArray> roles = model->roleNames();

        QCOMPARE(roles.count(), item.count());

        Q_FOREACH(int role, roles.keys()) {
            QString roleName = QString::fromUtf8(roles.value(role));
            QCOMPARE(model->data(model->index(0, 0), role), item.value(roleName));
        }
    }
Exemplo n.º 17
0
bool frmPriceImport::validateRow(int row_, const QStringList line_, const QHash<int, int> &columns_, const QString &dateFormat_)
{
    ++row_; // for display
    if (line_.count() != columns_.count())
    {
        QMessageBox::critical(this, "Import", "Incorrect number of columns on row " + QString::number(row_) + ".");
        return false;
    }

    if (line_.at(columns_.value(column_Symbol)).isEmpty())
    {
        QMessageBox::critical(this, "Import", "No symbol specified on row " + QString::number(row_) + ".");
        return false;
    }

    QDate date = QDate::fromString(line_.at(columns_.value(column_Date)), dateFormat_);
    if (!date.isValid())
    {
        QMessageBox::critical(this, "Import", "Incorrect date format on row " + QString::number(row_) +
            ". Date is \"" + line_.at(columns_.value(column_Date)) + "\".");
        return false;
    }
    if (!ui->columnOrderDateIgnore->isChecked() && !tradeDateCalendar::isTradeDate(date.toJulianDay()))
    {
        QMessageBox::critical(this, "Import", "Row " + QString::number(row_) +
            " is not a valid US trade date. Date is \"" + line_.at(columns_.value(column_Date)) + "\".");
        return false;
    }

    QString type = line_.at(columns_.value(column_Type)).toUpper();
    if (type != "PRICE" && type != "DIVIDEND" && type != "SPLIT")
    {
        QMessageBox::critical(this, "Import", "Incorrect price type on row " + QString::number(row_) +
            ". Price type is \"" + line_.at(columns_.value(column_Type)) + "\", but valid choices" +
            " are only Price, Dividend, or Split.");
        return false;
    }

    bool ok;
    line_.at(columns_.value(column_Value)).toDouble(&ok);
    if (!ok)
    {
        QMessageBox::critical(this, "Import", "Incorrect value on row " + QString::number(row_) +
            ". Value is \"" + line_.at(columns_.value(column_Value)) + "\", but could not be" +
            " converted to a number.");
        return false;
    }

    return true;
}
Exemplo n.º 18
0
static void osc_close_editor ( DssiEditor *pDssiEditor )
{
	QMutexLocker locker(&g_oscMutex);

#ifdef CONFIG_DEBUG
	qDebug("osc_close_editor(\"%s\")",
		osc_label(pDssiEditor->plugin).toUtf8().constData());
#endif

	osc_send_hide(pDssiEditor);
	osc_send_quit(pDssiEditor);
	osc_exiting(pDssiEditor);

	if (g_dssiEditors.count() < 1)
		osc_stop();
}
Exemplo n.º 19
0
	void ActionInstance::setArrayKeyValue(const QString &name, const QHash<QString, QString> &hashKeyValue)
	{
		if(hashKeyValue.isEmpty())
			return;

		QScriptValue back = d->scriptEngine->newArray(hashKeyValue.count());

		QHashIterator<QString, QString> it(hashKeyValue);
		while (it.hasNext())
		{
			it.next();
			back.setProperty(it.key(), it.value());
		}

		setVariable(name, back);
	}
Exemplo n.º 20
0
static DssiEditor *osc_open_editor ( qtractorDssiPlugin *pDssiPlugin )
{
	QMutexLocker locker(&g_oscMutex);

#ifdef CONFIG_DEBUG
	qDebug("osc_open_editor(\"%s\")",
		osc_label(pDssiPlugin).toUtf8().constData());
#endif

	if (g_dssiEditors.count() < 1)
		osc_start();

	DssiEditor *pDssiEditor = new DssiEditor(pDssiPlugin);
	g_dssiEditors.insert(osc_label(pDssiPlugin), pDssiEditor);

	return pDssiEditor;
}
void Ut_NotificationPreviewPresenter::testNotificationPreviewsDisabled()
{
    QFETCH(QWaylandSurface *, surface);
    QFETCH(QVariantMap, windowProperties);
    QFETCH(int, urgency);
    QFETCH(int, showCount);

    gLipstickCompositorStub->stubSetReturnValue("surfaceForId", surface);
    qWaylandSurfaceWindowProperties = windowProperties;

    NotificationPreviewPresenter presenter;
    createNotification(1, static_cast<Urgency>(urgency));
    QTest::qWait(0);
    presenter.updateNotification(1);

    QCOMPARE(homeWindowVisible.count(), showCount);
}
QString ImportCroppingUtilBase::importCroppingToString (ImportCropping importCropping)
{
    QHash<ImportCropping, QString> lookupTable;

    lookupTable.insert (IMPORT_CROPPING_NEVER, QObject::tr ("No cropping"));
    lookupTable.insert (IMPORT_CROPPING_MULTIPAGE_PDFS, QObject::tr ("Crop pdf files with multiple pages"));
    lookupTable.insert (IMPORT_CROPPING_ALWAYS, QObject::tr ("Always crop"));

    ENGAUGE_ASSERT (lookupTable.count() == NUMBER_IMPORT_CROPPING);

    QString rtn;

    if (lookupTable.contains (importCropping)) {
        rtn = lookupTable [importCropping];
    }

    return rtn;
}
Exemplo n.º 23
0
void aboutDialog::updateDisplay()
{
    ui->teDiag->clear();

    const QHash<int, sACNListener*> listenerList =
            sACNManager::getInstance()->getListenerList();

    QString data;
    data.append(QString("Reciever Threads : %1\n").arg(listenerList.count()));

    QHashIterator<int, sACNListener*> i(listenerList);
    while (i.hasNext()) {
        i.next();
        data.append(QString("Universe %1\tMerges per second %2\n")
                    .arg(i.key())
                    .arg(i.value()->mergesPerSecond()));
    }

    ui->teDiag->setPlainText(data);
}
Exemplo n.º 24
0
QString QtCursorToString (Qt::CursorShape cursorShape)
{
  if (cursorShapesLookupTable.count () == 0) {

    // Initialize
    cursorShapesLookupTable [Qt::ArrowCursor] = "Qt::ArrowCursor";
    cursorShapesLookupTable [Qt::BitmapCursor] = "Qt::BitmapCursor";
    cursorShapesLookupTable [Qt::CrossCursor] = "Qt::CrossCursor";
    cursorShapesLookupTable [Qt::WaitCursor] = "Qt::WaitCursor";
  }

  if (cursorShapesLookupTable.contains (cursorShape)) {

    return cursorShapesLookupTable [cursorShape];

  } else {

    return "Qt::<unknown>";

  } 
}
void Ut_NotificationPreviewPresenter::testNotificationNotShownIfTouchScreenIsLockedAndDisplayIsOff()
{
    QFETCH(MeeGo::QmDisplayState::DisplayState, displayState);
    QFETCH(MeeGo::QmLocks::State, lockState);
    QFETCH(int, notifications);
    QFETCH(int, presentedCount);

    gQmDisplayStateStub->stubSetReturnValue("get", displayState);
    gQmLocksStub->stubSetReturnValue("getState", lockState);

    NotificationPreviewPresenter presenter;
    QSignalSpy changedSpy(&presenter, SIGNAL(notificationChanged()));
    QSignalSpy presentedSpy(&presenter, SIGNAL(notificationPresented(uint)));

    createNotification(1, Critical);
    QTest::qWait(0);
    presenter.updateNotification(1);
    QCOMPARE(homeWindowVisible.count(), notifications);
    QCOMPARE(changedSpy.count(), notifications);
    QCOMPARE(presentedSpy.count(), presentedCount);
}
Exemplo n.º 26
0
V4L2Control::V4L2Control(uint32_t control_id, const V4L2Device::ptr& camera, const QList<Fix> &fixes) : dptr(camera)
{ 
  v4l2_queryctrl v4l2control{control_id};
  camera->ioctl(VIDIOC_QUERYCTRL, &v4l2control);
  d->control.name = reinterpret_cast<const char*>(v4l2control.name);
  d->control.readonly = (v4l2control.flags & V4L2_CTRL_FLAG_READ_ONLY);
  
  qDebug() << "Found v4l2 control: id=" << control_id << ", name=" << d->control.name << ", flags=" << v4l2control.flags << ", type=" << v4l2control.type << ", range=" << v4l2control.minimum << "-" << v4l2control.maximum << ", step=" << v4l2control.step << ", default value=" << v4l2control.default_value << ", readonly: " << d->control.readonly;
  
  d->control.id = v4l2control.id;
  d->control.set_range(v4l2control.minimum, v4l2control.maximum, v4l2control.step);
  d->control.set_default_value(v4l2control.default_value);
    
  if(v4l2control.flags & V4L2_CTRL_FLAG_DISABLED)
      throw V4L2Exception{ V4L2Exception::control_disabled, stringbuilder() << "Control " << v4l2control.name << " disabled", "V4L2Control()"};
  
  static QHash<int, Imager::Control::Type> types {
        {V4L2_CTRL_TYPE_INTEGER, Imager::Control::Number},
        {V4L2_CTRL_TYPE_INTEGER64, Imager::Control::Number},
        {V4L2_CTRL_TYPE_BOOLEAN, Imager::Control::Bool},
        {V4L2_CTRL_TYPE_MENU, Imager::Control::Combo},
    };
  bool unknown_type = types.count(v4l2control.type) == 0;
    if(unknown_type)
      throw V4L2Exception{ V4L2Exception::control_type_unknown, stringbuilder() << "Unknown control type: " << v4l2control.type, "V4L2Control()"};
    d->control.type = types[v4l2control.type];
    
    if(v4l2control.type == V4L2_CTRL_TYPE_MENU) {
        v4l2_querymenu menu{v4l2control.id};
        for(menu.index = v4l2control.minimum; menu.index <= v4l2control.maximum; menu.index++) {
            QString value;
            if (0 == camera->xioctl (VIDIOC_QUERYMENU, &menu)) {
                value = QString::fromLocal8Bit(reinterpret_cast<const char*>(menu.name));
            }
            d->control.add_choice(value, menu.index);
        }
    }
  for(auto fix: fixes)
    fix(d->control);
}
Exemplo n.º 27
0
void VarParser::treatDefines()
{
    // замена define в указании длины массивов и инициализаци переменных
    QHash<QString,QString> defTab;
    QRegExp defineExpression("#define[\\s\\t]*\\b(\\w*)[\\s\\t]*(\\w*)\\b");
    for(int i=0;i<dataBlock.count();i++){
        QString str = dataBlock.at(i);
        if(defineExpression.indexIn(str) != -1) {
            QString inpStr = defineExpression.cap(1);
            QString resStr = defineExpression.cap(2);
            defTab.insert(inpStr,resStr);
            dataBlock.replace(i,QString());
        }
    }
    for(int i=0;i<dataBlock.count();i++) {
        if(dataBlock.at(i).isEmpty()) continue;
        if(dataBlock.at(i).contains('['))
        for(int j=0;j<defTab.count();j++) {
            QRegExp defExpr("\\b"+defTab.keys().at(j)+"\\b");
            dataBlock[i].replace(defExpr,defTab.values().at(j));
        }
    }
}
Exemplo n.º 28
0
/** Return the atom from the molecules 'molecules' that matches
    this ID
    
    \throw SireMol::missing_residue
    \throw SireMol::duplicate_residue
*/
Residue ResID::selectFrom(const Molecules &molecules, const PropertyMap &map) const
{
    QHash< MolNum,Selector<Residue> > mols = this->selectAllFrom(molecules, map);
    
    if (mols.count() > 1)
        throw SireMol::duplicate_residue( QObject::tr(
            "More than one molecule contains an atom that "
            "matches this ID (%1). These molecules have numbers %2.")
                .arg(this->toString()).arg(Sire::toString(mols.keys())),
                    CODELOC );
                    
    const Selector<Residue> &atoms = *(mols.constBegin());
    
    if (atoms.count() > 1)
        throw SireMol::duplicate_residue( QObject::tr(
            "While only one molecule (MolNum == %1) "
            "contains an atom that matches this ID (%2), it contains "
            "more than one atom that matches.")
                .arg(atoms.data().number()).arg(this->toString()),
                    CODELOC );
                    
    return atoms[0];
}
Exemplo n.º 29
0
ProgramWindow::ProgramWindow(QWidget *parent)
	: FritzingWindow("", untitledFileCount(), "", parent)
{
    QFile styleSheet(":/resources/styles/programwindow.qss");

    this->setObjectName("programmingWindow");
    if (!styleSheet.open(QIODevice::ReadOnly)) {
        qWarning("Unable to open :/resources/styles/programwindow.qss");
    } else {
        QString ss = styleSheet.readAll();
#ifdef Q_WS_MAC
                int paneLoc = 4;
                int tabBarLoc = 0;
#else
                int paneLoc = -1;
                int tabBarLoc = 5;
#endif
                ss = ss.arg(paneLoc).arg(tabBarLoc);
        this->setStyleSheet(ss);
    }

    if (ProgrammerNames.count() == 0) {
		initProgrammerNames();
	}

	if (m_languages.count() == 0) {
		initLanguages();
	}

	if (NoSerialPortName.isEmpty()) {
		NoSerialPortName = tr("No ports found");
	}

	m_savingProgramTab = NULL;
	UntitledIndex--;						// incremented by FritzingWindow
	ProgramWindow::setTitle();				// set to something weird by FritzingWindow
}
Exemplo n.º 30
0
void Xsltproc::setParameters(const QHash<QString,QString> & parameters)
{
    for(int i=0; i<mNParams; i++)
    {
        delete mParams[i];
    }
    if( mParams != 0 ) delete mParams;
    mNParams = parameters.count();
    mParams = new char*[2*mNParams+1];

    QList<QByteArray*> byteArrays;
    QHashIterator<QString,QString> iter(parameters);
    int i=0;
    while(iter.hasNext())
    {
        iter.next();
        byteArrays << new QByteArray(iter.key().toUtf8());
        mParams[i++] = byteArrays.last()->data();
        QString paramValue = "\"" + iter.value() + "\"";
        byteArrays << new QByteArray(paramValue.toUtf8());
        mParams[i++] = byteArrays.last()->data();
    }
    mParams[i] = NULL;
}