/*! \reimp */ QString QAccessibleComboBox::text(QAccessible::Text t) const { QString str; switch (t) { case QAccessible::Name: #ifndef Q_OS_UNIX // on Linux we use relations for this, name is text (fall through to Value) str = QAccessibleWidget::text(t); break; #endif case QAccessible::Value: if (comboBox()->isEditable()) str = comboBox()->lineEdit()->text(); else str = comboBox()->currentText(); break; #ifndef QT_NO_SHORTCUT case QAccessible::Accelerator: str = QKeySequence(Qt::Key_Down).toString(QKeySequence::NativeText); break; #endif default: break; } if (str.isEmpty()) str = QAccessibleWidget::text(t); return str; }
int QAccessibleComboBox::indexOfChild(const QAccessibleInterface *child) const { if (comboBox()->view() == child->object()) return 0; if (comboBox()->isEditable() && comboBox()->lineEdit() == child->object()) return 1; return -1; }
void QAccessibleComboBox::doAction(const QString &actionName) { if (actionName == showMenuAction()) { if (comboBox()->view()->isVisible()) { comboBox()->hidePopup(); } else { comboBox()->showPopup(); } } }
QAccessibleInterface *QAccessibleComboBox::child(int index) const { if (index == 0) { QAbstractItemView *view = comboBox()->view(); //QWidget *parent = view ? view->parentWidget() : 0; return QAccessible::queryAccessibleInterface(view); } else if (index == 1 && comboBox()->isEditable()) { return QAccessible::queryAccessibleInterface(comboBox()->lineEdit()); } return 0; }
CompraBuscar::CompraBuscar(QWidget *parent) :QDialog(parent) ,ui(new Ui::CompraBuscar){ ui->setupUi(this); idCompra=INVALIDO; idPrestador=INVALIDO; idSocio=INVALIDO; ui->dateEditFinal->setDate(QDate::currentDate()); ui->dateEditInicio->setDate(QDate::currentDate().addDays(-28)); socioSeleccionado=false; prestadorSeleccionado=false; BD::buscarCompra(""); ui->tableView->setModel(model); QString styleSheet = "QHeaderView::section {" "spacing: 10px;" "background-color: lightblue;" "color: black;" "border: 1px solid black;" "margin: 1px;" "text-align: right;" "font-family: arialblack;" "height: 30px;" "font-size: 20px; }"; ui->tableView->horizontalHeader()->setStyleSheet(styleSheet); styleSheet = "QTableView::item:selected{ background-color: lightblue; color: black;} "; ui->tableView->setStyleSheet(styleSheet); ui->tableView->horizontalHeader()->setResizeMode(QHeaderView::Fixed); connect(ui->tableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(editarCompra())); connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(comboBox())); connect(ui->dateEditInicio,SIGNAL(dateChanged(QDate)), this, SLOT(comboBox())); connect(ui->dateEditFinal,SIGNAL(dateChanged(QDate)), this, SLOT(comboBox())); connect(ui->radioButton,SIGNAL(toggled(bool)), this, SLOT(comboBox())); ui->tableView->setVisible(false); ui->tableView->resizeColumnsToContents(); ui->tableView->setVisible(true); setTableView(); }
int main(int argc, char *argv[]) { Q_UNUSED(argc) Q_UNUSED(argv) ////////////////////////////////////////////////////////////////// /// Init GraphicSystem singleton GraphicSystem::initialize("GraphicSystemTest", "data/fonts/DejaVuSans.ttf"); ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// /// Get pointers of GraphicSystem sf::RenderWindow *window; window = GraphicSystem::instance()->getWindow(); tgui::Gui *gui; gui = GraphicSystem::instance()->getGUI(); ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// /// Create widgets tgui::Picture::Ptr picture((*gui)); picture->load("data/others/Linux.jpg"); tgui::Button::Ptr button((*gui)); button->load(THEME_CONFIG_FILE); button->setPosition(40, 25); button->setText("Quit"); button->setCallbackId(1); button->bindCallback(tgui::Button::LeftMouseClicked); button->setSize(300, 40); tgui::ChatBox::Ptr chatbox((*gui)); chatbox->load(THEME_CONFIG_FILE); chatbox->setSize(200, 100); chatbox->setTextSize(20); chatbox->setPosition(400, 25); chatbox->addLine("Line 1", sf::Color::Red); chatbox->addLine("Line 2", sf::Color::Blue); chatbox->addLine("Line 3", sf::Color::Green); chatbox->addLine("Line 4", sf::Color::Yellow); chatbox->addLine("Line 5", sf::Color::Cyan); chatbox->addLine("Line 6", sf::Color::Magenta); tgui::Checkbox::Ptr checkbox((*gui)); checkbox->load(THEME_CONFIG_FILE); checkbox->setPosition(40, 80); checkbox->setText("Checkbox"); checkbox->setSize(32, 32); tgui::ChildWindow::Ptr child((*gui)); child->load(THEME_CONFIG_FILE); child->setSize(200, 100); child->setBackgroundColor(sf::Color(80, 80, 80)); child->setPosition(400, 460); child->setTitle("Child window"); child->setIcon("data/others/icon.jpg"); tgui::ComboBox::Ptr comboBox((*gui)); comboBox->load(THEME_CONFIG_FILE); comboBox->setSize(120, 21); comboBox->setPosition(210, 440); comboBox->addItem("Item 1"); comboBox->addItem("Item 2"); comboBox->addItem("Item 3"); comboBox->setSelectedItem("Item 2"); tgui::EditBox::Ptr editBox((*gui)); editBox->load(THEME_CONFIG_FILE); editBox->setPosition(40, 200); editBox->setSize(300, 30); tgui::Label::Ptr label((*gui)); label->load(THEME_CONFIG_FILE); label->setText("Label"); label->setPosition(40, 160); label->setTextColor(sf::Color(200, 200, 200)); label->setTextSize(24); tgui::ListBox::Ptr listBox((*gui)); listBox->load(THEME_CONFIG_FILE); listBox->setSize(150, 120); listBox->setItemHeight(20); listBox->setPosition(40, 440); listBox->addItem("Item 1"); listBox->addItem("Item 2"); listBox->addItem("Item 3"); tgui::LoadingBar::Ptr loadingbar((*gui)); loadingbar->load(THEME_CONFIG_FILE); loadingbar->setPosition(40, 330); loadingbar->setSize(300, 30); loadingbar->setValue(35); tgui::MenuBar::Ptr menu((*gui)); menu->load(THEME_CONFIG_FILE); menu->setSize(window->getSize().x, 20); menu->addMenu("File"); menu->addMenuItem("File", "Load"); menu->addMenuItem("File", "Save"); menu->addMenuItem("File", "Exit"); menu->bindCallback(tgui::MenuBar::MenuItemClicked); menu->setCallbackId(2); sf::Texture texture; texture.loadFromFile("data/others/ThinkLinux.jpg"); tgui::Panel::Ptr panel((*gui)); panel->setSize(200, 140); panel->setPosition(400, 150); panel->setBackgroundTexture(&texture); tgui::RadioButton::Ptr radioButton((*gui)); radioButton->load(THEME_CONFIG_FILE); radioButton->setPosition(40, 120); radioButton->setText("Radio Button"); radioButton->setSize(32, 32); tgui::Slider::Ptr slider((*gui)); slider->load(THEME_CONFIG_FILE); slider->setVerticalScroll(false); slider->setPosition(40, 250); slider->setSize(300, 25); slider->setValue(2); tgui::Scrollbar::Ptr scrollbar((*gui)); scrollbar->load(THEME_CONFIG_FILE); scrollbar->setVerticalScroll(false); scrollbar->setPosition(40, 290); scrollbar->setSize(300, 25); scrollbar->setMaximum(5); scrollbar->setLowValue(3); tgui::Slider2d::Ptr slider2d((*gui)); slider2d->load("data/widgets/Slider2d/Black.conf"); slider2d->setPosition(400, 300); slider2d->setSize(200, 150); tgui::SpinButton::Ptr spinButton((*gui)); spinButton->load(THEME_CONFIG_FILE); spinButton->setPosition(40, 410); spinButton->setVerticalScroll(false); spinButton->setSize(40, 20); tgui::SpriteSheet::Ptr spritesheet((*gui)); spritesheet->load("data/others/ThinkLinux.jpg"); spritesheet->setCells(4, 4); spritesheet->setVisibleCell(2, 3); spritesheet->setSize(160, 120); spritesheet->setPosition(620, 25); tgui::Tab::Ptr tab((*gui)); tab->load(THEME_CONFIG_FILE); tab->setPosition(40, 370); tab->add("Item 1"); tab->add("Item 2"); tab->add("Item 3"); tgui::TextBox::Ptr textBox((*gui)); textBox->load(THEME_CONFIG_FILE); textBox->setPosition(210, 470); textBox->setSize(180, 120); textBox->setTextSize(16); comboBox->moveToFront(); ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// /// Start main loop while(window->isOpen()) { GraphicSystem::instance()->injectPreUpdate(0); sf::Event event; while(GraphicSystem::instance()->pollWindowEvent(event)) { if(event.type == sf::Event::Closed) window->close(); GraphicSystem::instance()->handleGUIEvent(event); } tgui::Callback callback; while(GraphicSystem::instance()->pollGUICallback(callback)) { if(callback.id == 1) window->close(); else if(callback.id == 2) { if(callback.text == "Exit") window->close(); } } GraphicSystem::instance()->injectPostUpdate(0); } ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// /// Destroy GraphicSystem GraphicSystem::shutdown(); ////////////////////////////////////////////////////////////////// return 0; }
QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value, QMap<int, QWidget*> &proxyWidgets ) { if ( !vl ) return 0; QWidget *myWidget = 0; QgsVectorLayer::EditType editType = vl->editType( idx ); const QgsField &field = vl->pendingFields()[idx]; QVariant::Type myFieldType = field.type(); bool synchronized = false; switch ( editType ) { case QgsVectorLayer::UniqueValues: { QList<QVariant> values; vl->dataProvider()->uniqueValues( idx, values ); QComboBox *cb = comboBox( editor, parent ); if ( cb ) { cb->setEditable( false ); for ( QList<QVariant>::iterator it = values.begin(); it != values.end(); it++ ) cb->addItem( it->toString(), it->toString() ); myWidget = cb; } } break; case QgsVectorLayer::Enumeration: { QStringList enumValues; vl->dataProvider()->enumValues( idx, enumValues ); QComboBox *cb = comboBox( editor, parent ); if ( cb ) { QStringList::const_iterator s_it = enumValues.constBegin(); for ( ; s_it != enumValues.constEnd(); ++s_it ) { cb->addItem( *s_it, *s_it ); } myWidget = cb; } } break; case QgsVectorLayer::ValueMap: { const QMap<QString, QVariant> &map = vl->valueMap( idx ); QComboBox *cb = comboBox( editor, parent ); if ( cb ) { for ( QMap<QString, QVariant>::const_iterator it = map.begin(); it != map.end(); it++ ) { cb->addItem( it.key(), it.value() ); } myWidget = cb; } } break; case QgsVectorLayer::ValueRelation: { const QgsVectorLayer::ValueRelationData &data = vl->valueRelation( idx ); QgsVectorLayer *layer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( data.mLayer ) ); QMap< QString, QString > map; int fi = -1; if ( layer ) { int ki = layer->fieldNameIndex( data.mOrderByValue ? data.mValue : data.mKey ); int vi = layer->fieldNameIndex( data.mOrderByValue ? data.mKey : data.mValue ); if ( !data.mFilterAttributeColumn.isNull() ) fi = layer->fieldNameIndex( data.mFilterAttributeColumn ); if ( ki >= 0 && vi >= 0 ) { QgsAttributeList attributes; attributes << ki; attributes << vi; if ( fi >= 0 ) attributes << fi; layer->select( attributes, QgsRectangle(), false ); QgsFeature f; while ( layer->nextFeature( f ) ) { if ( fi >= 0 && f.attributeMap()[ fi ].toString() != data.mFilterAttributeValue ) continue; map.insert( f.attributeMap()[ ki ].toString(), f.attributeMap()[ vi ].toString() ); } } } if ( !data.mAllowMulti ) { QComboBox *cb = comboBox( editor, parent ); if ( cb ) { if ( data.mAllowNull ) { QSettings settings; cb->addItem( tr( "(no selection)" ), settings.value( "qgis/nullValue", "NULL" ).toString() ); } for ( QMap< QString, QString >::const_iterator it = map.begin(); it != map.end(); it++ ) { if ( data.mOrderByValue ) cb->addItem( it.key(), it.value() ); else cb->addItem( it.value(), it.key() ); } myWidget = cb; } } else { QListWidget *lw = listWidget( editor, parent ); if ( lw ) { QStringList checkList = value.toString().remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( "," ); for ( QMap< QString, QString >::const_iterator it = map.begin(); it != map.end(); it++ ) { QListWidgetItem *item; if ( data.mOrderByValue ) { item = new QListWidgetItem( it.key() ); item->setData( Qt::UserRole, it.value() ); item->setCheckState( checkList.contains( it.value() ) ? Qt::Checked : Qt::Unchecked ); } else { item = new QListWidgetItem( it.value() ); item->setData( Qt::UserRole, it.key() ); item->setCheckState( checkList.contains( it.key() ) ? Qt::Checked : Qt::Unchecked ); } lw->addItem( item ); } myWidget = lw; } } } break; case QgsVectorLayer::Classification: { QMap<QString, QString> classes; const QgsUniqueValueRenderer *uvr = dynamic_cast<const QgsUniqueValueRenderer *>( vl->renderer() ); if ( uvr ) { const QList<QgsSymbol *> symbols = uvr->symbols(); for ( int i = 0; i < symbols.size(); i++ ) { QString label = symbols[i]->label(); QString name = symbols[i]->lowerValue(); if ( label == "" ) label = name; classes.insert( name, label ); } } const QgsCategorizedSymbolRendererV2 *csr = dynamic_cast<const QgsCategorizedSymbolRendererV2 *>( vl->rendererV2() ); if ( csr ) { const QgsCategoryList &categories = (( QgsCategorizedSymbolRendererV2 * )csr )->categories(); // FIXME: QgsCategorizedSymbolRendererV2::categories() should be const for ( int i = 0; i < categories.size(); i++ ) { QString label = categories[i].label(); QString value = categories[i].value().toString(); if ( label.isEmpty() ) label = value; classes.insert( value, label ); } } QComboBox *cb = comboBox( editor, parent ); if ( cb ) { for ( QMap<QString, QString>::const_iterator it = classes.begin(); it != classes.end(); it++ ) { cb->addItem( it.value(), it.key() ); } myWidget = cb; } } break; case QgsVectorLayer::DialRange: case QgsVectorLayer::SliderRange: case QgsVectorLayer::EditRange: { if ( myFieldType == QVariant::Int ) { int min = vl->range( idx ).mMin.toInt(); int max = vl->range( idx ).mMax.toInt(); int step = vl->range( idx ).mStep.toInt(); if ( editType == QgsVectorLayer::EditRange ) { QSpinBox *sb = 0; if ( editor ) sb = qobject_cast<QSpinBox *>( editor ); else sb = new QSpinBox( parent ); if ( sb ) { sb->setRange( min, max ); sb->setSingleStep( step ); myWidget = sb; } } else { QAbstractSlider *sl = 0; if ( editor ) { sl = qobject_cast<QAbstractSlider*>( editor ); } else if ( editType == QgsVectorLayer::DialRange ) { sl = new QDial( parent ); } else { sl = new QSlider( Qt::Horizontal, parent ); } if ( sl ) { sl->setRange( min, max ); sl->setSingleStep( step ); myWidget = sl; } } break; } else if ( myFieldType == QVariant::Double ) { QDoubleSpinBox *dsb = 0; if ( editor ) dsb = qobject_cast<QDoubleSpinBox*>( editor ); else dsb = new QDoubleSpinBox( parent ); if ( dsb ) { double min = vl->range( idx ).mMin.toDouble(); double max = vl->range( idx ).mMax.toDouble(); double step = vl->range( idx ).mStep.toDouble(); dsb->setRange( min, max ); dsb->setSingleStep( step ); myWidget = dsb; } break; } } case QgsVectorLayer::CheckBox: { QCheckBox *cb = 0; if ( editor ) cb = qobject_cast<QCheckBox*>( editor ); else cb = new QCheckBox( parent ); if ( cb ) { myWidget = cb; break; } } // fall-through case QgsVectorLayer::LineEdit: case QgsVectorLayer::TextEdit: case QgsVectorLayer::UuidGenerator: case QgsVectorLayer::UniqueValuesEditable: case QgsVectorLayer::Immutable: { QLineEdit *le = 0; QTextEdit *te = 0; QPlainTextEdit *pte = 0; QComboBox * cb = 0; if ( editor ) { le = qobject_cast<QLineEdit *>( editor ); te = qobject_cast<QTextEdit *>( editor ); pte = qobject_cast<QPlainTextEdit *>( editor ); cb = qobject_cast<QComboBox *>( editor ); } else if ( editType == QgsVectorLayer::TextEdit ) { pte = new QPlainTextEdit( parent ); } else { le = new QLineEdit( parent ); } if ( le ) { if ( editType == QgsVectorLayer::UniqueValuesEditable ) { QList<QVariant> values; vl->dataProvider()->uniqueValues( idx, values ); QStringList svalues; for ( QList<QVariant>::const_iterator it = values.begin(); it != values.end(); it++ ) svalues << it->toString(); QCompleter *c = new QCompleter( svalues ); c->setCompletionMode( QCompleter::PopupCompletion ); le->setCompleter( c ); } if ( editType == QgsVectorLayer::UuidGenerator ) { le->setReadOnly( true ); } le->setValidator( new QgsFieldValidator( le, field ) ); myWidget = le; } if ( te ) { te->setAcceptRichText( true ); myWidget = te; } if ( pte ) { myWidget = pte; } if ( cb ) { myWidget = cb; } if ( myWidget ) { myWidget->setDisabled( editType == QgsVectorLayer::Immutable ); QgsStringRelay* relay = NULL; QMap<int, QWidget*>::const_iterator it = proxyWidgets.find( idx ); if ( it != proxyWidgets.end() ) { QObject* obj = qvariant_cast<QObject*>( (*it)->property( "QgisAttrEditProxy" ) ); relay = qobject_cast<QgsStringRelay*>( obj ); } else { relay = new QgsStringRelay( myWidget ); } if ( cb && cb->isEditable() ) { synchronized = connect( relay, SIGNAL( textChanged( QString ) ), myWidget, SLOT( setEditText( QString ) ) ); synchronized &= connect( myWidget, SIGNAL( editTextChanged( QString ) ), relay, SLOT( changeText( QString ) ) ); } else { synchronized = connect( relay, SIGNAL( textChanged( QString ) ), myWidget, SLOT( setText( QString ) ) ); synchronized &= connect( myWidget, SIGNAL( textChanged( QString ) ), relay, SLOT( changeText( QString ) ) ); } if ( !cb || cb->isEditable() ) { myWidget->setProperty( "QgisAttrEditProxy", QVariant( QMetaType::QObjectStar, &relay ) ); } } } break; case QgsVectorLayer::Hidden: myWidget = 0; break; case QgsVectorLayer::FileName: case QgsVectorLayer::Calendar: { QPushButton *pb = 0; QLineEdit *le = qobject_cast<QLineEdit *>( editor ); if ( le ) { if ( le ) myWidget = le; if ( editor->parent() ) { pb = editor->parent()->findChild<QPushButton *>(); } } else { le = new QLineEdit(); pb = new QPushButton( tr( "..." ) ); QHBoxLayout *hbl = new QHBoxLayout(); hbl->addWidget( le ); hbl->addWidget( pb ); myWidget = new QWidget( parent ); myWidget->setBackgroundRole( QPalette::Window ); myWidget->setAutoFillBackground( true ); myWidget->setLayout( hbl ); } if ( pb ) { if ( editType == QgsVectorLayer::FileName ) connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectFileName() ) ); if ( editType == QgsVectorLayer::Calendar ) connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectDate() ) ); } } break; } QMap<int, QWidget*>::const_iterator it = proxyWidgets.find( idx ); if ( it != proxyWidgets.end() ) { if ( !synchronized ) { myWidget->setEnabled( false ); } } else { proxyWidgets.insert( idx, myWidget ); } setValue( myWidget, vl, idx, value ); return myWidget; }
QAccessibleInterface *QAccessibleComboBox::childAt(int x, int y) const { if (comboBox()->isEditable() && comboBox()->lineEdit()->rect().contains(x, y)) return child(1); return 0; }
int QAccessibleComboBox::childCount() const { // list and text edit return comboBox()->isEditable() ? 2 : 1; }
/*! Constructs a QAccessibleComboBox object for \a w. */ QAccessibleComboBox::QAccessibleComboBox(QWidget *w) : QAccessibleWidget(w, QAccessible::ComboBox) { Q_ASSERT(comboBox()); }
/*------------------------------------------------------------------------------ | Dialog::createControlsFromTemplate | ------------------------------------------------------------------------------*/ Dialog& Dialog :: createControlsFromTemplate( ) { PDLGTEMPLATE pdlgt; /* Dialog Template Pointer */ void* pvStart; /* Dialog Template Item Pointer */ register unsigned long cItems, /* Dialog Items Counter */ ulRc, /* Return code */ i; /* Loop Counter */ /* Set mouse pointer to "wait" in case template */ /* is large */ IPointerHandle oldPointer = mousePointer(); ISystemPointerHandle systemPointer( ISystemPointerHandle::wait ); setMousePointer( systemPointer ); /* Try reading in the dialog template for the */ /* given dialog ID */ ulRc = DosGetResource( 0, RT_DIALOG, this->ulId, (void **)&pdlgt ); if ( ulRc != 0 ) { /* Dialog template not found; reset mouse */ /* pointer and throw exception */ setMousePointer( oldPointer ); ITHROWSYSTEMERROR( ulRc, "DosGetResource", IErrorInfo::accessError, IException::recoverable ); } /* Save pointer to the start of the dlg template */ pvStart = (void *)pdlgt; /* Save the number of controls found within the */ /* dialog template */ cItems = pdlgt->adlgti[0].cChildren + 1; /* Read in and create an Open Class Library C++ */ /* object for each of the controls within the */ /* dialog template */ for ( i = 1; i < cItems; i++ ) { /* Obtain the id of the control */ unsigned long ulId = (unsigned long)(pdlgt->adlgti[i].id & 0xffff); /* Skip the control if its id is -1 */ if ( ulId != 0xffff ) { /* Check to see if a custom control is specified */ /* or if a standard PM control class is being */ /* used */ if ( pdlgt->adlgti[i].cchClassName ) { /* Since a length for the class name present, */ /* a custom control class name is being used for */ /* the control. Point to the memory location */ /* where the class name is found within the */ /* dialog template information. */ customControl( ulId, ((char *)pvStart + pdlgt->adlgti[i].offClassName) ); } else { /* No class name length given indicating that a */ /* standard PM class is being used. The class */ /* name is stored as an index value. For */ /* example, the class for static's is defined as */ /* */ /* #define WC_STATIC ((PSZ)0xffff0005L) */ /* */ /* The values within the dialog template for */ /* the static class would be */ /* */ /* adlgti[i].cchClassName = 0 */ /* adlgti[i].offClassName = 5 */ /* */ /* Therefore, the value of offClassName field */ /* must be used as an index that is used to */ /* actually select the class name. */ switch ( pdlgt->adlgti[i].offClassName ) { case WINCLASS_BUTTON : { unsigned long ulStyle = pdlgt->adlgti[i].flStyle & BS_PRIMARYSTYLES; switch ( ulStyle ) { case BS_PUSHBUTTON: { if ( pdlgt->adlgti[i].flStyle & (BS_BITMAP | BS_ICON) ) { IGraphicPushButton* pGraphicPushButton = new IGraphicPushButton( ulId, this ); pGraphicPushButton->setAutoDeleteObject( true ); graphicPushButton( pGraphicPushButton ); } else { IPushButton* pPushButton = new IPushButton( ulId, this ); pPushButton->setAutoDeleteObject( true ); this->pushButton( pPushButton ); } } break; case BS_CHECKBOX: case BS_AUTOCHECKBOX: { ICheckBox* pCheckBox = new ICheckBox( ulId, this ); pCheckBox->setAutoDeleteObject( true ); checkBox( pCheckBox ); } break; case BS_RADIOBUTTON: case BS_AUTORADIOBUTTON: { IRadioButton* pRadioButton = new IRadioButton( ulId, this ); pRadioButton->setAutoDeleteObject( true ); radioButton( pRadioButton ); } break; case BS_3STATE: case BS_AUTO3STATE: { I3StateCheckBox* p3StateCheckBox = new I3StateCheckBox( ulId, this ); p3StateCheckBox->setAutoDeleteObject( true ); threeStateCheckBox( p3StateCheckBox ); } break; case BS_USERBUTTON: { customButton( ulId ); } break; } //end switch } //WINCLASS_BUTTON break; case WINCLASS_SCROLLBAR : { IScrollBar* pScrollBar = new IScrollBar( ulId, this ); pScrollBar->setAutoDeleteObject( true ); scrollBar( pScrollBar ); } break; case WINCLASS_LISTBOX : { IListBox* pListBox = new IListBox( ulId, this ); pListBox->setAutoDeleteObject( true ); listBox( pListBox ); } break; case WINCLASS_ENTRYFIELD : { IEntryField* pEntryField = new IEntryField( ulId, this ); pEntryField->setAutoDeleteObject( true ); entryField( pEntryField ); } break; case WINCLASS_STATIC : { unsigned long ulStyle = pdlgt->adlgti[i].flStyle & (SS_TEXT | SS_GROUPBOX | SS_ICON | SS_BITMAP); switch ( ulStyle ) { case SS_TEXT: { IStaticText* pStaticText = new IStaticText( ulId, this ); pStaticText->setAutoDeleteObject( true ); staticText( pStaticText ); } break; case SS_GROUPBOX: { IGroupBox* pGroupBox = new IGroupBox( ulId, this ); pGroupBox->setAutoDeleteObject( true ); groupBox( pGroupBox ); } break; case SS_ICON: { IIconControl* pIcon = new IIconControl( ulId, this ); pIcon->setAutoDeleteObject( true ); iconControl( pIcon ); } break; case SS_BITMAP: { IBitmapControl* pBitmap = new IBitmapControl( ulId, this ); pBitmap->setAutoDeleteObject( true ); bitmapControl( pBitmap ); } break; } //end switch } //WINCLASS_STATIC break; case WINCLASS_COMBOBOX : { IComboBox* pComboBox = new IComboBox( ulId, this ); pComboBox->setAutoDeleteObject( true ); comboBox( pComboBox ); } break; case WINCLASS_MLE : { IMultiLineEdit* pMLE = new IMultiLineEdit( ulId, this ); pMLE->setAutoDeleteObject( true ); mle( pMLE ); } break; case WINCLASS_SPINBUTTON : { if ( pdlgt->adlgti[i].flStyle & SPBS_NUMERICONLY ) { INumericSpinButton* pNumericSpinButton = new INumericSpinButton( ulId, this ); pNumericSpinButton->setAutoDeleteObject( true ); numericSpinButton( pNumericSpinButton ); } else { ITextSpinButton* pTextSpinButton = new ITextSpinButton( ulId, this ); pTextSpinButton->setAutoDeleteObject( true ); textSpinButton( pTextSpinButton ); } } break; case WINCLASS_CONTAINER : { IContainerControl* pContainer = new IContainerControl( ulId, this ); pContainer->setAutoDeleteObject( true ); container( pContainer ); } break; case WINCLASS_SLIDER : { if ( pdlgt->adlgti[i].flStyle & SLS_READONLY ) { IProgressIndicator* pProgressIndicator = new IProgressIndicator( ulId, this ); pProgressIndicator->setAutoDeleteObject( true ); progressIndicator( pProgressIndicator ); } else { ISlider* pSlider = new ISlider( ulId, this ); pSlider->setAutoDeleteObject( true ); slider( pSlider ); } } break; case WINCLASS_VALUESET : //No valueset class - see OS/2 C++ Class Library Power GUI //Programming with C Set++ for an implementation of a //valueset class. break; case WINCLASS_NOTEBOOK : { INotebook* pNotebook = new INotebook( ulId, this ); pNotebook->setAutoDeleteObject( true ); notebook( pNotebook ); } break; case WINCLASS_CIRCULARSLIDER : { ICircularSlider* pCircularSlider = new ICircularSlider( ulId, this ); pCircularSlider->setAutoDeleteObject( true ); circularSlider( pCircularSlider ); } break; } //end switch } //end if } //end if - id != -1 } //end for /* Release the memory allocated for the dlg */ /* template before returning */ DosFreeResource( pvStart ); /* Reset mouse pointer */ setMousePointer( oldPointer ); return( *this ); } //Dialog::createControlsFromTemplate
QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value ) { if ( !vl ) return NULL; QWidget *myWidget = NULL; QgsVectorLayer::EditType editType = vl->editType( idx ); const QgsField &field = vl->pendingFields()[idx]; QVariant::Type myFieldType = field.type(); switch ( editType ) { case QgsVectorLayer::UniqueValues: { QList<QVariant> values; vl->dataProvider()->uniqueValues( idx, values ); QComboBox *cb = comboBox( editor, parent ); if ( cb ) { cb->setEditable( false ); for ( QList<QVariant>::iterator it = values.begin(); it != values.end(); it++ ) cb->addItem( it->toString(), it->toString() ); myWidget = cb; } } break; case QgsVectorLayer::Enumeration: { QStringList enumValues; vl->dataProvider()->enumValues( idx, enumValues ); QComboBox *cb = comboBox( editor, parent ); if ( cb ) { QStringList::const_iterator s_it = enumValues.constBegin(); for ( ; s_it != enumValues.constEnd(); ++s_it ) { cb->addItem( *s_it, *s_it ); } myWidget = cb; } } break; case QgsVectorLayer::ValueMap: { const QMap<QString, QVariant> &map = vl->valueMap( idx ); QComboBox *cb = comboBox( editor, parent ); if ( cb ) { for ( QMap<QString, QVariant>::const_iterator it = map.begin(); it != map.end(); it++ ) { cb->addItem( it.key(), it.value() ); } myWidget = cb; } } break; case QgsVectorLayer::ValueRelation: { QSettings settings; QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString(); const QgsVectorLayer::ValueRelationData &data = vl->valueRelation( idx ); QgsVectorLayer *layer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( data.mLayer ) ); QMap< QString, QString > map; if ( layer ) { int ki = layer->fieldNameIndex( data.mOrderByValue ? data.mValue : data.mKey ); int vi = layer->fieldNameIndex( data.mOrderByValue ? data.mKey : data.mValue ); if ( data.mAllowNull ) map.insert( nullValue, tr( "(no selection)" ) ); if ( ki >= 0 && vi >= 0 ) { layer->select( QgsAttributeList() << ki << vi, QgsRectangle(), false ); QgsFeature f; while ( layer->nextFeature( f ) ) { map.insert( f.attributeMap()[ ki ].toString(), f.attributeMap()[ vi ].toString() ); } } } QComboBox *cb = comboBox( editor, parent ); if ( cb ) { for ( QMap< QString, QString >::const_iterator it = map.begin(); it != map.end(); it++ ) { if ( data.mOrderByValue ) cb->addItem( it.key(), it.value() ); else cb->addItem( it.value(), it.key() ); } myWidget = cb; } } break; case QgsVectorLayer::Classification: { QMap<QString, QString> classes; const QgsUniqueValueRenderer *uvr = dynamic_cast<const QgsUniqueValueRenderer *>( vl->renderer() ); if ( uvr ) { const QList<QgsSymbol *> symbols = uvr->symbols(); for ( int i = 0; i < symbols.size(); i++ ) { QString label = symbols[i]->label(); QString name = symbols[i]->lowerValue(); if ( label == "" ) label = name; classes.insert( name, label ); } } const QgsCategorizedSymbolRendererV2 *csr = dynamic_cast<const QgsCategorizedSymbolRendererV2 *>( vl->rendererV2() ); if ( csr ) { const QgsCategoryList &categories = (( QgsCategorizedSymbolRendererV2 * )csr )->categories(); // FIXME: QgsCategorizedSymbolRendererV2::categories() should be const for ( int i = 0; i < categories.size(); i++ ) { QString label = categories[i].label(); QString value = categories[i].value().toString(); if ( label.isEmpty() ) label = value; classes.insert( value, label ); } } QComboBox *cb = comboBox( editor, parent ); if ( cb ) { for ( QMap<QString, QString>::const_iterator it = classes.begin(); it != classes.end(); it++ ) { cb->addItem( it.value(), it.key() ); } myWidget = cb; } } break; case QgsVectorLayer::DialRange: case QgsVectorLayer::SliderRange: case QgsVectorLayer::EditRange: { if ( myFieldType == QVariant::Int ) { int min = vl->range( idx ).mMin.toInt(); int max = vl->range( idx ).mMax.toInt(); int step = vl->range( idx ).mStep.toInt(); if ( editType == QgsVectorLayer::EditRange ) { QSpinBox *sb = NULL; if ( editor ) sb = qobject_cast<QSpinBox *>( editor ); else sb = new QSpinBox( parent ); if ( sb ) { sb->setRange( min, max ); sb->setSingleStep( step ); myWidget = sb; } } else { QAbstractSlider *sl = NULL; if ( editor ) { sl = qobject_cast<QAbstractSlider*>( editor ); } else if ( editType == QgsVectorLayer::DialRange ) { sl = new QDial( parent ); } else { sl = new QSlider( Qt::Horizontal, parent ); } if ( sl ) { sl->setRange( min, max ); sl->setSingleStep( step ); myWidget = sl; } } break; } else if ( myFieldType == QVariant::Double ) { QDoubleSpinBox *dsb = NULL; if ( editor ) dsb = qobject_cast<QDoubleSpinBox*>( editor ); else dsb = new QDoubleSpinBox( parent ); if ( dsb ) { double min = vl->range( idx ).mMin.toDouble(); double max = vl->range( idx ).mMax.toDouble(); double step = vl->range( idx ).mStep.toDouble(); dsb->setRange( min, max ); dsb->setSingleStep( step ); myWidget = dsb; } break; } } case QgsVectorLayer::CheckBox: { QCheckBox *cb = NULL; if ( editor ) cb = qobject_cast<QCheckBox*>( editor ); else cb = new QCheckBox( parent ); if ( cb ) { myWidget = cb; break; } } // fall-through case QgsVectorLayer::LineEdit: case QgsVectorLayer::TextEdit: case QgsVectorLayer::UniqueValuesEditable: case QgsVectorLayer::Immutable: { QLineEdit *le = NULL; QTextEdit *te = NULL; QPlainTextEdit *pte = NULL; if ( editor ) { le = qobject_cast<QLineEdit *>( editor ); te = qobject_cast<QTextEdit *>( editor ); pte = qobject_cast<QPlainTextEdit *>( editor ); } else if ( editType == QgsVectorLayer::TextEdit ) { pte = new QPlainTextEdit( parent ); } else { le = new QLineEdit( parent ); } if ( le ) { if ( editType == QgsVectorLayer::UniqueValuesEditable ) { QList<QVariant> values; vl->dataProvider()->uniqueValues( idx, values ); QStringList svalues; for ( QList<QVariant>::const_iterator it = values.begin(); it != values.end(); it++ ) svalues << it->toString(); QCompleter *c = new QCompleter( svalues ); c->setCompletionMode( QCompleter::PopupCompletion ); le->setCompleter( c ); } le->setValidator( new QgsFieldValidator( le, field ) ); myWidget = le; } if ( te ) { te->setAcceptRichText( true ); myWidget = te; } if ( pte ) { myWidget = pte; } if ( myWidget ) { myWidget->setDisabled( editType == QgsVectorLayer::Immutable ); } } break; case QgsVectorLayer::Hidden: myWidget = NULL; break; case QgsVectorLayer::FileName: case QgsVectorLayer::Calendar: { QPushButton *pb = NULL; QLineEdit *le = qobject_cast<QLineEdit *>( editor ); if ( le ) { if ( le ) myWidget = le; if ( editor->parent() ) { pb = editor->parent()->findChild<QPushButton *>(); } } else { le = new QLineEdit(); pb = new QPushButton( tr( "..." ) ); QHBoxLayout *hbl = new QHBoxLayout(); hbl->addWidget( le ); hbl->addWidget( pb ); myWidget = new QWidget( parent ); myWidget->setBackgroundRole( QPalette::Window ); myWidget->setAutoFillBackground( true ); myWidget->setLayout( hbl ); } if ( pb ) { if ( editType == QgsVectorLayer::FileName ) connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectFileName() ) ); if ( editType == QgsVectorLayer::Calendar ) connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectDate() ) ); } } break; } setValue( myWidget, vl, idx, value ); return myWidget; }
//----------------------------------------------------------------------------- int ctkComboBoxTest1(int argc, char * argv [] ) { QApplication app(argc, argv); ctkComboBox comboBox(0); if (!comboBox.defaultText().isEmpty()) { std::cerr << "non empty default defaultText" << std::endl; return EXIT_FAILURE; } comboBox.setDefaultText("Select..."); if (comboBox.defaultText() != "Select...") { std::cerr << "ctkComboBox::setDefaultText() failed" << comboBox.defaultText().toStdString() << std::endl; return EXIT_FAILURE; } if (comboBox.currentText() == "Select...") { std::cerr << "ctkComboBox::setDefaultText() failed" << std::endl; return EXIT_FAILURE; } QIcon icon = comboBox.style()->standardIcon(QStyle::SP_MessageBoxQuestion); comboBox.setDefaultIcon(icon); if (comboBox.defaultIcon().pixmap(20).toImage() != icon.pixmap(20).toImage()) { std::cerr << "ctkComboBox::setDefaultIcon() failed" << std::endl; return EXIT_FAILURE; } if (comboBox.isDefaultForced()) { std::cerr << "default of ctkComboBox::isDefaultForced() failed" << std::endl; return EXIT_FAILURE; } comboBox.forceDefault(true); if (!comboBox.isDefaultForced()) { std::cerr << "ctkComboBox::setDefaultForced() failed" << std::endl; return EXIT_FAILURE; } if (comboBox.elideMode() != Qt::ElideNone) { std::cerr << "Wrong default elide mode" << std::endl; return EXIT_FAILURE; } comboBox.setElideMode(Qt::ElideRight); if (comboBox.elideMode() != Qt::ElideRight) { std::cerr << "ctkComboBox::setElideMode() failed" << std::endl; return EXIT_FAILURE; } comboBox.addItem("Item Item Item Item Item Item Item Item 1"); comboBox.addItem("Item Item Item Item Item Item Item Item 2"); comboBox.addItem("Item Item Item Item Item Item Item Item 3"); // adding items shouldn't change anything to the combobox current text if (comboBox.currentIndex() != 0 || comboBox.currentText() != "Item Item Item Item Item Item Item Item 1") { std::cerr << "ctkComboBox::addItem failed:" << comboBox.currentIndex() << " " << comboBox.currentText().toStdString() << std::endl; return EXIT_FAILURE; } comboBox.show(); if (argc < 2 || QString(argv[1]) != "-I" ) { QTimer::singleShot(200, &app, SLOT(quit())); } return app.exec(); }