void vrpn_Qt::AddWidget(QWidget* widget) { // Ignore widgets called vrpn_Qt_ignore if (widget->objectName() == "vrpn_Qt_ignore") { return; } // Check if widget is derived from abstract button if (qobject_cast<QAbstractButton*>(widget)) { QAbstractButton* button = qobject_cast<QAbstractButton*>(widget); connect(button, SIGNAL(pressed()), this, SLOT(ButtonChanged())); connect(button, SIGNAL(released()), this, SLOT(ButtonChanged())); buttonWidgets.append(button); buttons[num_buttons] = button->isChecked(); num_buttons++; } // Check if widget is derived from abstract slider else if (qobject_cast<QAbstractSlider*>(widget)) { QAbstractSlider* slider = qobject_cast<QAbstractSlider*>(widget); connect(slider, SIGNAL(valueChanged(int)), this, SLOT(AnalogChanged())); analogWidgets.append(slider); channel[num_channel] = slider->value(); num_channel++; } // Check for double spin box else if (qobject_cast<QDoubleSpinBox*>(widget)) {
virtual dyn_t getGuiValue(void){ QAbstractButton *button = dynamic_cast<QAbstractButton*>(_widget); if (button!=NULL) return DYN_create_bool(button->isChecked()); QAbstractSlider *slider = dynamic_cast<QAbstractSlider*>(_widget); if (slider!=NULL) return DYN_create_int(slider->value()); QLabel *label = dynamic_cast<QLabel*>(_widget); if (label!=NULL) return DYN_create_string(label->text()); QLineEdit *line_edit = dynamic_cast<QLineEdit*>(_widget); if (line_edit!=NULL) return DYN_create_string(line_edit->text()); QTextEdit *text_edit = dynamic_cast<QTextEdit*>(_widget); if (text_edit!=NULL) return DYN_create_string(text_edit->toPlainText()); QSpinBox *spinbox = dynamic_cast<QSpinBox*>(_widget); if (spinbox!=NULL) return DYN_create_int(spinbox->value()); QDoubleSpinBox *doublespinbox = dynamic_cast<QDoubleSpinBox*>(_widget); if (doublespinbox!=NULL) return DYN_create_float(doublespinbox->value()); handleError("Gui #%d does not have a getValue method", _gui_num); return DYN_create_bool(false); }
bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value ) { if ( !widget ) return false; const QgsField &theField = vl->pendingFields()[idx]; QgsVectorLayer::EditType editType = vl->editType( idx ); bool modified = false; QString text; QSettings settings; QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString(); QLineEdit *le = qobject_cast<QLineEdit *>( widget ); if ( le ) { text = le->text(); modified = le->isModified(); if ( text == nullValue ) { text = QString::null; } } QTextEdit *te = qobject_cast<QTextEdit *>( widget ); if ( te ) { text = te->toHtml(); modified = te->document()->isModified(); if ( text == nullValue ) { text = QString::null; } } QPlainTextEdit *pte = qobject_cast<QPlainTextEdit *>( widget ); if ( pte ) { text = pte->toPlainText(); modified = pte->document()->isModified(); if ( text == nullValue ) { text = QString::null; } } QComboBox *cb = qobject_cast<QComboBox *>( widget ); if ( cb ) { if ( editType == QgsVectorLayer::UniqueValues || editType == QgsVectorLayer::ValueMap || editType == QgsVectorLayer::Classification || editType == QgsVectorLayer::ValueRelation ) { text = cb->itemData( cb->currentIndex() ).toString(); if ( text == nullValue ) { text = QString::null; } } else { text = cb->currentText(); } modified = true; } QListWidget *lw = qobject_cast<QListWidget *>( widget ); if ( lw ) { if ( editType == QgsVectorLayer::ValueRelation ) { text = '{'; for ( int i = 0, n = 0; i < lw->count(); i++ ) { if ( lw->item( i )->checkState() == Qt::Checked ) { if ( n > 0 ) { text.append( ',' ); } text.append( lw->item( i )->data( Qt::UserRole ).toString() ); n++; } } text.append( '}' ); } else { text = QString::null; } modified = true; } QSpinBox *sb = qobject_cast<QSpinBox *>( widget ); if ( sb ) { text = QString::number( sb->value() ); } QAbstractSlider *slider = qobject_cast<QAbstractSlider *>( widget ); if ( slider ) { text = QString::number( slider->value() ); } QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox *>( widget ); if ( dsb ) { text = QString::number( dsb->value() ); } QCheckBox *ckb = qobject_cast<QCheckBox *>( widget ); if ( ckb ) { QPair<QString, QString> states = vl->checkedState( idx ); text = ckb->isChecked() ? states.first : states.second; } QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( widget ); if ( cw ) { text = cw->selectedDate().toString(); } le = widget->findChild<QLineEdit *>(); if ( le ) { text = le->text(); } switch ( theField.type() ) { case QVariant::Int: { bool ok; int myIntValue = text.toInt( &ok ); if ( ok && !text.isEmpty() ) { value = QVariant( myIntValue ); modified = true; } else if ( modified ) { value = QVariant(); } } break; case QVariant::LongLong: { bool ok; qlonglong myLongValue = text.toLong( &ok ); if ( ok && !text.isEmpty() ) { value = QVariant( myLongValue ); modified = true; } else if ( modified ) { value = QVariant(); } } case QVariant::Double: { bool ok; double myDblValue = text.toDouble( &ok ); if ( ok && !text.isEmpty() ) { value = QVariant( myDblValue ); modified = true; } else if ( modified ) { value = QVariant(); } } break; case QVariant::Date: { QDate myDateValue = QDate::fromString( text, Qt::ISODate ); if ( myDateValue.isValid() && !text.isEmpty() ) { value = myDateValue; modified = true; } else if ( modified ) { value = QVariant(); } } break; default: //string modified = true; value = QVariant( text ); break; } return modified; }