Example #1
0
enum SetResponse customCommand::set( const ParameterList & pParams )
{
    XDialog::set(pParams);
    QVariant param;
    bool     valid;

    param = pParams.value("mode", &valid);
    if(valid)
    {
        QString mode = param.toString();
        if("new" == mode)
            setMode(cNew);
        else if("edit" == mode)
            setMode(cEdit);
        else if("view" == mode)
            setMode(cView);
    }

    // after setMode because populate() may change mode
    param = pParams.value("cmd_id", &valid);
    if(valid)
    {
        _cmdid = param.toInt();
        populate();
    }

    return NoError;
}
void MainWindow::uploadDirectories()
{
	QSettings settings;
	QFileDialog d(this);
	{
		QVariant ld = settings.value("the-latest-directory");
		if (ld.isValid())
			d.setDirectory(ld.toString());
	}

	d.setAcceptMode(QFileDialog::AcceptOpen);
	d.setFileMode(QFileDialog::Directory);
	d.setOption(QFileDialog::ShowDirsOnly, true);
	d.setOption(QFileDialog::ReadOnly, true);
	restoreGeometry("upload-directories", d);
	if (!d.exec())
		return;

	saveGeometry("upload-directories", d);
	settings.setValue("the-latest-directory", d.directory().absolutePath());

	QStringList dirs(d.selectedFiles());
	if (dirs.isEmpty())
		return;

	uploadFiles(dirs);
}
//-----------------------------------------------------------------------------
void SetupTabMatrix::operationAdd()
{
    QAction *a = qobject_cast<QAction *>(sender());
    QVariant var = a->data();
    bool ok;
    int shift = var.toInt(&ok);

    if (ok)
    {
        QItemSelectionModel *selection = this->ui->tableViewOperations->selectionModel();
        QModelIndexList list = selection->selectedIndexes();

        bool left = shift < 0;
        shift = qAbs(shift);

        quint32 mask = 0;
        for (int i = 0; i < list.length(); i++)
        {
            if (list.at(i).row() == 0)
            {
                mask |= 0x00000001 << (31 - list.at(i).column());
            }
        }
        this->mPreset->matrix()->operationAdd(mask, shift, left);
    }
}
Example #4
0
bool PhraseModel::setData(const QModelIndex & index, const QVariant & value, int role)
{
    int row = index.row();
    int column = index.column();

    if (!index.isValid() || row >= plist.count() || role != Qt::EditRole)
        return false;

    Phrase *phrase = plist.at(row);

    switch (column) {
    case 0:
        phrase->setSource(value.toString());
        break;
    case 1:
        phrase->setTarget(value.toString());
        break;
    case 2:
        phrase->setDefinition(value.toString());
        break;
    default:
        return false;
    }

    emit dataChanged(index, index);
    return true;
}
void MainWindow::restoreGeometry(const QString &name, QWidget &widget)
{
	QSettings settings;
	QVariant geometry = settings.value("geometry/" + name);
	if (geometry.isValid())
		widget.restoreGeometry(geometry.toByteArray());
}
Example #6
0
bool QgsField::convertCompatible( QVariant& v ) const
{
  if ( v.isNull() )
  {
    v.convert( d->type );
    return true;
  }

  if ( d->type == QVariant::Int && v.toInt() != v.toLongLong() )
  {
    v = QVariant( d->type );
    return false;
  }

  //String representations of doubles in QVariant will return false to convert( QVariant::Int )
  //work around this by first converting to double, and then checking whether the double is convertible to int
  if ( d->type == QVariant::Int && v.canConvert( QVariant::Double ) )
  {
    bool ok = false;
    double dbl = v.toDouble( &ok );
    if ( !ok )
    {
      //couldn't convert to number
      v = QVariant( d->type );
      return false;
    }

    double round = qgsRound( dbl );
    if ( round  > INT_MAX || round < -INT_MAX )
    {
      //double too large to fit in int
      v = QVariant( d->type );
      return false;
    }
    v = QVariant( qRound( dbl ) );
    return true;
  }

  if ( !v.convert( d->type ) )
  {
    v = QVariant( d->type );
    return false;
  }

  if ( d->type == QVariant::Double && d->precision > 0 )
  {
    double s = qPow( 10, d->precision );
    double d = v.toDouble() * s;
    v = QVariant(( d < 0 ? ceil( d - 0.5 ) : floor( d + 0.5 ) ) / s );
    return true;
  }

  if ( d->type == QVariant::String && d->length > 0 && v.toString().length() > d->length )
  {
    v = v.toString().left( d->length );
    return false;
  }

  return true;
}
void FSettingsDialog::on_cb_Folder_LauncherList_currentIndexChanged(int index)
{
    if(selectedFolder) {
        QVariant lID = ui->cb_Folder_LauncherList->itemData(index);
        selectedFolder->setLauncherID(lID.toInt());
    }
}
// test case to test Setting Values
// 1. default values of setting keys
// 2. set values to setting keys
// 3. checking if set values are set correctly
// 4. covers also cases where we test with invalid cases
void UnitTestCxeSettingsModelImp::testSettingValues()
{
    CxeError::Id error;
    QVariant result;

    // case 0: check default value of a real setting for e.g. FNAME_IMAGE_COUNTER
    error = mSettingsModel->getSettingValue(CxeSettingIds::FNAME_IMAGE_COUNTER, result);
    QVERIFY(error == CxeError::None);
    QCOMPARE(result.toInt(), 0);

    // case 1: setting a value to a valid key
    error = mSettingsModel->set(CxeSettingIds::FNAME_IMAGE_COUNTER, 12);
    QVERIFY(error == CxeError::None);

    // case 2: testing if the value set is right to sharpness key
    error = mSettingsModel->getSettingValue(CxeSettingIds::FNAME_IMAGE_COUNTER, result);
    QVERIFY(error == CxeError::None);
    QCOMPARE(result.toInt(), 12);

    // case 3: trying to set a value to an invalid key which doesnt exit
    error = mSettingsModel->set(INVALID_KEY, QVariant(10));
    QVERIFY(error == CxeError::NotFound);

    // case 4: trying to get a value from invalid key
    error = mSettingsModel->getSettingValue(INVALID_KEY, result);
    QVERIFY(error == CxeError::NotFound);

    // case 5: try with an empty string
    error = mSettingsModel->set(EMPTY_KEY, QVariant(10));
    QVERIFY(error == CxeError::NotFound);

    // case 6: try with an empty string
    error = mSettingsModel->getSettingValue(EMPTY_KEY, result);
    QVERIFY(error == CxeError::NotFound);
}
Example #9
0
void
IrcAbstractChannel::UserSend ()
{
  qDebug () << " User sending " ;
  bool sendout (true);
  if (qmlItem) {
    QVariant userData;
    QMetaObject::invokeMethod (qmlItem, "userData",
        Q_RETURN_ARG (QVariant, userData));
    QString data = userData.toString();
    qDebug () << "   user data " << data;
    if (data.trimmed().length() > 0) {
      QMetaObject::invokeMethod (qmlItem, "clearUserData");
      if (raw) {
        AlmostRaw (data);
      } else if (data == "/part") {
        Part ();
        sendout = false;
      } else if (data.startsWith ("/whois")) {
        data.remove (0, 6);
        Whois (data.trimmed());
        sendout = false;
      }
      if (sendout) {
        emit Outgoing (chanName, data);
      }
      history.append (data);
      history.removeDuplicates ();
      historyIndex = history.size();
    }
  }
}
Example #10
0
void URDFProperty::on_propertyWidget_linkNameChanged(LinkProperty *property, const QVariant &val)
{
    QString orig_name = link_property_to_ltree_[property]->text(0);
    int idx = link_names_.indexOf(orig_name);
    link_names_.replace(idx, val.toString());
    link_property_to_ltree_[property]->setText(0, val.toString());
}
Example #11
0
void URDFProperty::on_propertyWidget_jointNameChanged(JointProperty *property, const QVariant &val)
{
    QString orig_name = joint_property_to_ctree_[property]->text(0);
    int idx = joint_names_.indexOf(orig_name);
    joint_names_.replace(idx, val.toString());
    joint_property_to_ctree_[property]->setText(0, val.toString());
}
Example #12
0
void SendToAddressTest::testSend()
{
    GethSimulator & geth = _context.getGeth();
    _context.getKeyStore().registerAccount("0x0000000000000000000000000000000000000000", "asdasd123");
    geth.setBalance("0x0000000000000000000000000000000000000000", BigInt("1000000000000000000"));

    QString from = "0x0000000000000000000000000000000000000000";
    QString to = "0x0000000000000000000000000000000000000001";
    QVariantMap request;
    request.insert("from", from);
    request.insert("to", to);
    request.insert("amount", "100000000000000000");
    request.insert("password", "asdasd123");

    QVariant result = _command(request);
    QString txid = result.toString();

    QVERIFY(geth.getBalance("0x0000000000000000000000000000000000000001") == BigInt("100000000000000000"));
    QVERIFY(geth.getBalance("0x0000000000000000000000000000000000000000") == BigInt("900000000000000000"));

    QJsonObject transaction = _context.getDataBase().getTransactions().get(txid.toStdString().c_str());
    QCOMPARE(transaction["hash"].toString(), txid);
    QCOMPARE(transaction["from"].toString(), from);
    QCOMPARE(transaction["to"].toString(), to);
    QCOMPARE(transaction["amount"].toString(), QString("100000000000000000"));
}
Example #13
0
 void eval_feature_id()
 {
     QgsFeature f( 100 );
     QgsExpression exp( "$id * 2" );
     QVariant v = exp.evaluate( &f );
     QCOMPARE( v.toInt(), 200 );
 }
Example #14
0
    void eval_columns()
    {
        QgsFieldMap fields;
        fields[4] = QgsField( "foo", QVariant::Int );

        QgsFeature f;
        f.addAttribute( 4, QVariant( 20 ) );

        // good exp
        QgsExpression exp( "foo + 1" );
        bool prepareRes = exp.prepare( fields );
        QCOMPARE( prepareRes, true );
        QCOMPARE( exp.hasEvalError(), false );
        QVariant res = exp.evaluate( &f );
        QCOMPARE( res.type(), QVariant::Int );
        QCOMPARE( res.toInt(), 21 );

        // bad exp
        QgsExpression exp2( "bar + 1" );
        bool prepareRes2 = exp2.prepare( fields );
        QCOMPARE( prepareRes2, false );
        QCOMPARE( exp2.hasEvalError(), true );
        QVariant res2 = exp2.evaluate( &f );
        QCOMPARE( res2.type(), QVariant::Invalid );
    }
Example #15
0
void KDEProjectsReaderTest::testsProperParse()
{
    KDEProjectsModel m;
    KDEProjectsReader reader(&m, 0);

    if(reader.hasErrors())
        qDebug() << "errors:" << reader.errors();

    QVERIFY(!reader.hasErrors());

    WAIT_FOR_SIGNAL(&reader,downloadDone());

    for(int i=0; i<m.rowCount(); i++) {
        QStandardItem* item = m.item(i,0);
        qDebug() << ":::::" << item->text() << item->icon() << item->data(KDEProjectsModel::VcsLocationRole);

        QVERIFY(item);
        QVERIFY(!item->text().isEmpty());

        QVariant urls = item->data(KDEProjectsModel::VcsLocationRole);
        QVERIFY(urls.isValid());
        QVERIFY(urls.canConvert(QVariant::Map));
        QVariantMap mapurls=urls.toMap();
        for(QVariantMap::const_iterator it=mapurls.constBegin(), itEnd=mapurls.constEnd(); it!=itEnd; ++it) {
            QVERIFY(!it.key().isEmpty());
            QVERIFY(!it.value().toString().isEmpty());
        }

        QVERIFY(!item->data(KDEProjectsModel::VcsLocationRole).toMap().isEmpty());
    }
}
Example #16
0
QString Asterisk::encodeValue(QVariant value)
{
    if ((QMetaType::Type) value.type() == QMetaType::Bool)
        return value.toBool() ? "true" : "false";

    return value.toString();
}
Example #17
0
void KDSoapValue::writeElementContents(KDSoapNamespacePrefixes &namespacePrefixes, QXmlStreamWriter &writer, KDSoapValue::Use use, const QString &messageNamespace) const
{
    const QVariant value = this->value();

    if (isNil() && d->m_nillable) {
        writer.writeAttribute(KDSoapNamespaceManager::xmlSchemaInstance2001(), QLatin1String("nil"), QLatin1String("true"));
    }

    if (use == EncodedUse) {
        // use=encoded means writing out xsi:type attributes. http://www.eherenow.com/soapfight.htm taught me that.
        QString type;
        if (!this->type().isEmpty()) {
            type = namespacePrefixes.resolve(this->typeNs(), this->type());
        }
        if (type.isEmpty() && !value.isNull()) {
            type = variantToXMLType(value);    // fallback
        }
        if (!type.isEmpty()) {
            writer.writeAttribute(KDSoapNamespaceManager::xmlSchemaInstance2001(), QLatin1String("type"), type);
        }

        // cppcheck-suppress redundantCopyLocalConst
        const KDSoapValueList list = this->childValues();
        const bool isArray = !list.arrayType().isEmpty();
        if (isArray) {
            writer.writeAttribute(KDSoapNamespaceManager::soapEncoding(), QLatin1String("arrayType"), namespacePrefixes.resolve(list.arrayTypeNs(), list.arrayType()) + QLatin1Char('[') + QString::number(list.count()) + QLatin1Char(']'));
        }
    }
    writeChildren(namespacePrefixes, writer, use, messageNamespace, false);

    if (!value.isNull()) {
        writer.writeCharacters(variantToTextValue(value, this->typeNs(), this->type()));
    }
}
Example #18
0
Node::Node(QChar key) {
    Node();
    QVariant v = key;
    bool ok;
    this->key = v.toInt(&ok);

}
void AELoadedResourcesTreeView::resourceSelectionChanged(const QItemSelection& current, const QItemSelection& previous)
{
	const QModelIndex index = selectionModel()->currentIndex();
	QVariant var = index.data(ModelRole);
	if (var.isValid())
	{
		Anima::AnimaModel* model = var.value<Anima::AnimaModel*>();
		_resourcesViewer->setSelectedObject(model);
		return;
	}
	var = index.data(ModelInstanceRole);
	if (var.isValid())
	{
		Anima::AnimaModelInstance* instance = var.value<Anima::AnimaModelInstance*>();
		_resourcesViewer->setSelectedObject(instance);
		return;
	}
	var = index.data(MeshRole);
	if (var.isValid())
	{
		Anima::AnimaMesh* mesh = var.value<Anima::AnimaMesh*>();
		_resourcesViewer->setSelectedObject(mesh);
		return;
	}
	var = index.data(MeshInstanceRole);
	if (var.isValid())
	{
		Anima::AnimaMeshInstance* instance = var.value<Anima::AnimaMeshInstance*>();
		_resourcesViewer->setSelectedObject(instance);
		return;
	}
}
Example #20
0
void Q3SqlCursor::sync()
{
    if (isActive() && isValid() && d->lastAt != at()) {
        d->lastAt = at();
        int i = 0;
        int j = 0;
        bool haveCalculatedFields = false;
        for (; i < count(); ++i) {
            if (!haveCalculatedFields && d->infoBuffer[i].isCalculated()) {
                haveCalculatedFields = true;
            }
            if (QSqlRecord::isGenerated(i)) {
                QVariant v = QSqlQuery::value(j);
                if ((v.type() == QVariant::String) &&
                        d->infoBuffer[i].isTrim()) {
                    v = qTrim(v.toString());
                }
                QSqlRecord::setValue(i, v);
                if (QSqlQuery::isNull(j))
                    QSqlRecord::field(i).clear();
                j++;
            }
        }
        if (haveCalculatedFields) {
            for (i = 0; i < count(); ++i) {
                if (d->infoBuffer[i].isCalculated())
                    QSqlRecord::setValue(i, calculateField(fieldName(i)));
            }
        }
    }
}
bool DialogCallbacks::eventFilter(QObject *object, QEvent *event)
{
    if (event->type() == QEvent::Close)
    {
        int index = m_view->metaObject()->indexOfMethod("dialogCanClose()");
        if (index != -1)
        {
            QVariant returnedValue; returnedValue.setValue<bool>(true);
            QMetaMethod metaMethod = m_view->metaObject()->method(index);
            metaMethod.invoke(m_view, Q_RETURN_ARG(QVariant, returnedValue));

            if (!returnedValue.toBool())
            {
                event->ignore();
                return true;
            }
        }

        QMainWindow* mainWindow = qobject_cast<QMainWindow*>(object);
        if (mainWindow)
            mainWindowGeometry = mainWindow->saveGeometry();
    }

    return false;
}
enum SetResponse itemSourceList::set(const ParameterList &pParams)
{
  XDialog::set(pParams);
  QVariant param;
  bool     valid;

  param = pParams.value("item_id", &valid);
  if (valid)
  {
    _item->setId(param.toInt());
    _item->setEnabled(FALSE);
  }

  param = pParams.value("vend_id", &valid);
  if (valid)
  {
    _vendor->setId(param.toInt());
    _vendor->setEnabled(FALSE);
  }

  param = pParams.value("qty", &valid);

  sFillList();
  connect(_item, SIGNAL(newId(int)), this, SLOT(sFillList()));
  connect(_vendor, SIGNAL(newId(int)), this, SLOT(sFillList()));

  return NoError;
}
Example #23
0
bool Layer::setProperty(const QVariant &data, int role)
{
	switch (role)
	{
		case PaintField::RoleName:
			_name = data.toString();
			return true;
		case PaintField::RoleVisible:
			_isVisible = data.toBool();
			return true;
		case PaintField::RoleLocked:
			_isLocked = data.toBool();
			return true;
		case PaintField::RoleThumbnail:
			_thumbnail = data.value<QPixmap>();
			return true;
		case PaintField::RoleOpacity:
			_opacity = data.toDouble();
			return true;
		case PaintField::RoleBlendMode:
			_blendMode = data.toInt();
			return true;
		default:
			return false;
	}
}
Example #24
0
QXmppRemoteMethodResult QXmppClient::callRemoteMethod( const QString &jid,
                                          const QString &interface,
                                          const QVariant &arg1,
                                          const QVariant &arg2,
                                          const QVariant &arg3,
                                          const QVariant &arg4,
                                          const QVariant &arg5,
                                          const QVariant &arg6,
                                          const QVariant &arg7,
                                          const QVariant &arg8,
                                          const QVariant &arg9,
                                          const QVariant &arg10 )
{
    QVariantList args;
    if( arg1.isValid() ) args << arg1;
    if( arg2.isValid() ) args << arg2;
    if( arg3.isValid() ) args << arg3;
    if( arg4.isValid() ) args << arg4;
    if( arg5.isValid() ) args << arg5;
    if( arg6.isValid() ) args << arg6;
    if( arg7.isValid() ) args << arg7;
    if( arg8.isValid() ) args << arg8;
    if( arg9.isValid() ) args << arg9;
    if( arg10.isValid() ) args << arg10;

    QXmppRemoteMethod method( jid, interface, args, this );
    connect( d->stream, SIGNAL(rpcCallResponse(QXmppRpcResponseIq)),
             &method, SLOT(gotResult(QXmppRpcResponseIq)));
    connect( d->stream, SIGNAL(rpcCallError(QXmppRpcErrorIq)),
             &method, SLOT(gotError(QXmppRpcErrorIq)));


    return method.call();
}
void MainWindow::downloadFiles(const QVector<mtp::ObjectId> &objects)
{
	if (objects.isEmpty())
		return;

	QFileDialog d(this);
	QSettings settings;
	{
		QVariant ld = settings.value("the-latest-download-directory");
		if (ld.isValid())
			d.setDirectory(ld.toString());
	}

	d.setAcceptMode(QFileDialog::AcceptSave);
	d.setFileMode(QFileDialog::Directory);
	d.setOption(QFileDialog::ShowDirsOnly, true);
	restoreGeometry("download-files", d);
	if (!d.exec())
		return;

	QStringList selected = d.selectedFiles();
	if (selected.isEmpty())
		return;

	QString path = selected.at(0);
	saveGeometry("download-files", d);
	settings.setValue("the-latest-download-directory", path);
	downloadFiles(path, objects);
}
Example #26
0
void PgSQLTypeWidget::updateTypeFormat(void)
{
	try
	{
		QVariant data;

		//Gets the data related to the current selected data type
		data=type_cmb->itemData(type_cmb->currentIndex());

		//If the data value (index) is 0 indicates that the type is a built-in one
		if(data.toUInt()==0)
			type=type_cmb->currentText();
		else
			//Case the index is greated than zero indicates that the type is a user-defined one
			type=data.toUInt();

		length_sb->setEnabled(type.hasVariableLength());
		timezone_chk->setVisible(type==QString("timestamp") || type==QString("time"));
		timezone_lbl->setVisible(timezone_chk->isVisible());
		precision_sb->setEnabled(type.acceptsPrecision());
		dimension_sb->setEnabled(type!=QString("void"));
		interval_cmb->setVisible(type==QString("interval"));
		interval_lbl->setVisible(interval_cmb->isVisible());

		spatial_cmb->setVisible(type.isGiSType());
		spatial_lbl->setVisible(type.isGiSType());
		variation_lbl->setVisible(type.isGiSType());
		srid_lbl->setVisible(type.isGiSType());
		srid_spb->setVisible(type.isGiSType());
		var_m_chk->setVisible(type.isGiSType());
		var_z_chk->setVisible(type.isGiSType());

		if(spatial_cmb->isVisible())
		{
			SpatialType spatial_tp;
			spatial_tp=SpatialType(spatial_cmb->currentText(), srid_spb->value());

			if(var_z_chk->isChecked() && var_m_chk->isChecked())
				spatial_tp.setVariation(SpatialType::var_zm);
			else if(var_m_chk->isChecked())
				spatial_tp.setVariation(SpatialType::var_m);
			else if(var_z_chk->isChecked())
				spatial_tp.setVariation(SpatialType::var_z);

			type.setSpatialType(spatial_tp);
		}

		type.setLength(length_sb->value());
		type.setPrecision(precision_sb->value());
		type.setDimension(dimension_sb->value());
		type.setIntervalType(interval_cmb->currentText());
		type.setWithTimezone(timezone_chk->isChecked());

		format_txt->setPlainText(*type);
	}
	catch(Exception &e)
	{
		throw Exception(e.getErrorMessage(),e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
	}
}
void MainWindow::uploadAlbum()
{
	QFileDialog d(this);
	QSettings settings;
	{
		QVariant ld = settings.value("the-latest-directory");
		if (ld.isValid())
			d.setDirectory(ld.toString());
	}

	d.setAcceptMode(QFileDialog::AcceptOpen);
	d.setFileMode(QFileDialog::Directory);
	d.setOption(QFileDialog::ShowDirsOnly, true);
	d.setOption(QFileDialog::ReadOnly, true);
	restoreGeometry("upload-albums", d);
	if (!d.exec())
		return;

	saveGeometry("upload-albums", d);
	settings.setValue("the-latest-directory", d.directory().absolutePath());
	QStringList selected = d.selectedFiles();
	if (selected.isEmpty())
		return;

	for(const auto &path : selected)
	{
		uploadAlbum(path);
		back();
	}
}
QVariant ObjectNodeInstance::property(const PropertyName &name) const
{
    if (ignoredProperties().contains(name))
        return QVariant();

    // TODO: handle model nodes

    if (QmlPrivateGate::isPropertyBlackListed(name))
        return QVariant();

    QQmlProperty property(object(), QString::fromUtf8(name), context());
    if (property.property().isEnumType()) {
        QVariant value = property.read();
        return property.property().enumerator().valueToKey(value.toInt());
    }

    if (property.propertyType() == QVariant::Url) {
        QUrl url = property.read().toUrl();
        if (url.isEmpty())
            return QVariant();

        if (url.scheme() == "file") {
            int basePathLength = nodeInstanceServer()->fileUrl().toLocalFile().lastIndexOf('/');
            return QUrl(url.toLocalFile().mid(basePathLength + 1));
        }
    }

    return property.read();
}
Example #29
0
bool Articulation::setProperty(P_ID propertyId, const QVariant& v)
      {
      score()->addRefresh(canvasBoundingRect());
      switch (propertyId) {
            case P_DIRECTION:
                  setDirection(MScore::Direction(v.toInt()));
                  break;
            case P_ARTICULATION_ANCHOR:
                  anchorStyle = PropertyStyle::UNSTYLED;
                  setAnchor(ArticulationAnchor(v.toInt()));
                  break;
            case P_TIME_STRETCH:
                  setTimeStretch(v.toDouble());
                  score()->fixTicks();
                  break;
            default:
                  return Element::setProperty(propertyId, v);
            }
      score()->addRefresh(canvasBoundingRect());

      // layout:
      if (chordRest())
            chordRest()->layoutArticulations();
      else if (parent() && parent()->type() == BAR_LINE)
            static_cast<BarLine*>(parent())->layout();

      score()->addRefresh(canvasBoundingRect());
      score()->setLayoutAll(false);       //DEBUG
      return true;
      }
Example #30
0
void OperationsDelegate::setEditorData(QWidget *editor,
                                       const QModelIndex &index) const
      {
      const QVariant value = index.data(Qt::EditRole);
      if (value.type() == QVariant::StringList) {
            QListWidget *lw = qobject_cast<QListWidget *>(editor);
            const auto items = lw->findItems(index.data(Qt::DisplayRole).toString(), Qt::MatchExactly);
            if (!items.empty())
                  lw->setCurrentItem(items.first());
            else
                  lw->setCurrentItem(lw->item(0));

            const int extraWidth = 25;
            const int extraHeight = 6;
            lw->setMinimumWidth(lw->sizeHintForColumn(0) + extraWidth);
                        // to prevent possible hiding bottom part of the list
            const int h = lw->count() * (lw->visualItemRect(lw->currentItem()).height() + extraHeight);
            const int y = (lw->parentWidget() && (lw->parentWidget()->rect().bottom() < lw->y() + h))
                        ? lw->parentWidget()->rect().bottom() - h - extraHeight : lw->y();
            lw->setGeometry(lw->x(), y, lw->width(), h);
                        // now lw can be partially hidden behind the tree view
                        // if tree view has small rect, so set parent of lw
                        // to app window and map coordinates accordingly to leave lw in place
            const auto globalCoord = lw->parentWidget()->mapToGlobal(lw->geometry().topLeft());
            lw->setParent(appWindow);
            const auto newLocalCoord = appWindow->mapFromGlobal(globalCoord);
            lw->setGeometry(newLocalCoord.x(), newLocalCoord.y(), lw->width(), h);
            }
      else        // single value
            QStyledItemDelegate::setEditorData(editor, index);
      }