void ValueEdit::setValue( const NifValue & v ) { typ = v.type(); if ( edit ) { // segfaults with Qt 4.5: //delete edit; edit = nullptr; resize( this->baseSize() ); } switch ( typ ) { case NifValue::tByte: { QSpinBox * be = new QSpinBox( this ); be->setFrame( false ); be->setRange( 0, 0xff ); be->setValue( v.toCount() ); edit = be; } break; case NifValue::tWord: case NifValue::tFlags: { QSpinBox * we = new QSpinBox( this ); we->setFrame( false ); we->setRange( 0, 0xffff ); we->setValue( v.toCount() ); edit = we; } break; case NifValue::tShort: { QSpinBox * we = new QSpinBox( this ); we->setFrame( false ); we->setRange( SHRT_MIN, SHRT_MAX ); we->setValue( (short)v.toCount() ); edit = we; } break; case NifValue::tInt: { QSpinBox * ie = new QSpinBox( this ); ie->setFrame( false ); ie->setRange( INT_MIN, INT_MAX ); ie->setValue( (int)v.toCount() ); edit = ie; } break; case NifValue::tStringIndex: { QSpinBox * ie = new QSpinBox( this ); ie->setFrame( false ); ie->setRange( -1, INT_MAX ); ie->setValue( (int)v.toCount() ); edit = ie; } break; case NifValue::tUInt: { QSpinBox * ie = new UIntSpinBox( this ); ie->setFrame( false ); ie->setValue( v.toCount() ); edit = ie; } break; case NifValue::tLink: case NifValue::tUpLink: { QLineEdit * le = new QLineEdit( this ); int tmp = v.toLink(); if ( tmp > 0 ) { le->setText( QString::number( tmp ) ); } edit = le; } break; case NifValue::tFloat: { FloatEdit * fe = new FloatEdit( this ); /* fe->setFrame(false); fe->setRange( -1e10, +1e10 ); fe->setDecimals( 4 ); */ fe->setValue( v.toFloat() ); edit = fe; } break; case NifValue::tText: case NifValue::tSizedString: { TextEdit * te = new TextEdit( v.toString(), this ); te->resize( size() ); connect( te, &TextEdit::sigResized, this, &ValueEdit::childResized ); edit = te; } break; case NifValue::tLineString: case NifValue::tShortString: case NifValue::tChar8String: { QLineEdit * le = new QLineEdit( this ); le->setText( v.toString() ); edit = le; } break; //case NifValue::tText: //{ // TextEdit * te = new TextEdit( v.toString(), this ); // te->setMinimumSize( width(), height() ); // te->setBaseSize( width(), height() * 5); // edit = te; //} break; case NifValue::tColor4: { ColorEdit * ce = new ColorEdit( this ); ce->setColor4( v.get<Color4>() ); edit = ce; } break; case NifValue::tColor3: { ColorEdit * ce = new ColorEdit( this ); ce->setColor3( v.get<Color3>() ); edit = ce; } break; case NifValue::tVector4: { VectorEdit * ve = new VectorEdit( this ); ve->setVector4( v.get<Vector4>() ); edit = ve; } break; case NifValue::tVector3: { VectorEdit * ve = new VectorEdit( this ); ve->setVector3( v.get<Vector3>() ); edit = ve; } break; case NifValue::tVector2: { VectorEdit * ve = new VectorEdit( this ); ve->setVector2( v.get<Vector2>() ); edit = ve; } break; case NifValue::tMatrix: { RotationEdit * re = new RotationEdit( this ); re->setMatrix( v.get<Matrix>() ); edit = re; } break; case NifValue::tQuat: case NifValue::tQuatXYZW: { RotationEdit * re = new RotationEdit( this ); re->setQuat( v.get<Quat>() ); edit = re; } break; case NifValue::tTriangle: { TriangleEdit * te = new TriangleEdit( this ); te->setTriangle( v.get<Triangle>() ); edit = te; } break; case NifValue::tString: { if ( /*???*/ false ) { QSpinBox * ie = new UIntSpinBox( this ); ie->setFrame( false ); ie->setValue( v.toCount() ); edit = ie; } else { QLineEdit * le = new QLineEdit( this ); le->setText( v.toString() ); edit = le; } } break; case NifValue::tFilePath: { if ( /*???*/ false ) { QSpinBox * ie = new UIntSpinBox( this ); ie->setFrame( false ); ie->setValue( v.toCount() ); edit = ie; } else { QLineEdit * le = new QLineEdit( this ); le->setText( v.toString() ); edit = le; } } break; default: edit = nullptr; break; } resizeEditor(); setFocusProxy( edit ); }
void qjackctlInterfaceComboBox::populateModel (void) { bool bBlockSignals = QComboBox::blockSignals(true); QComboBox::setUpdatesEnabled(false); QComboBox::setDuplicatesEnabled(false); QLineEdit *pLineEdit = QComboBox::lineEdit(); // FIXME: Only valid for ALSA, Sun and OSS devices, // for the time being... and also CoreAudio ones too. const QString& sDriver = m_pDriverComboBox->currentText(); bool bAlsa = (sDriver == "alsa"); bool bSun = (sDriver == "sun"); bool bOss = (sDriver == "oss"); #ifdef CONFIG_COREAUDIO bool bCoreaudio = (sDriver == "coreaudio"); std::map<QString, AudioDeviceID> coreaudioIdMap; #endif #ifdef CONFIG_PORTAUDIO bool bPortaudio = (sDriver == "portaudio"); #endif QString sCurName = pLineEdit->text(); QString sName, sSubName; int iCards = 0; clearCards(); int iCurCard = -1; if (bAlsa) { #ifdef CONFIG_ALSA_SEQ // Enumerate the ALSA cards and PCM harfware devices... snd_ctl_t *handle; snd_ctl_card_info_t *info; snd_pcm_info_t *pcminfo; snd_ctl_card_info_alloca(&info); snd_pcm_info_alloca(&pcminfo); const QString sPrefix("hw:%1"); const QString sSuffix(" (%1)"); const QString sSubSuffix("%1,%2"); QString sName2, sSubName2; bool bCapture, bPlayback; int iCard = -1; while (snd_card_next(&iCard) >= 0 && iCard >= 0) { sName = sPrefix.arg(iCard); if (snd_ctl_open(&handle, sName.toUtf8().constData(), 0) >= 0 && snd_ctl_card_info(handle, info) >= 0) { sName2 = sPrefix.arg(snd_ctl_card_info_get_id(info)); addCard(sName2, snd_ctl_card_info_get_name(info) + sSuffix.arg(sName)); if (sCurName == sName || sCurName == sName2) iCurCard = iCards; ++iCards; int iDevice = -1; while (snd_ctl_pcm_next_device(handle, &iDevice) >= 0 && iDevice >= 0) { // Capture devices.. bCapture = false; if (m_iAudio == QJACKCTL_CAPTURE || m_iAudio == QJACKCTL_DUPLEX) { snd_pcm_info_set_device(pcminfo, iDevice); snd_pcm_info_set_subdevice(pcminfo, 0); snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_CAPTURE); bCapture = (snd_ctl_pcm_info(handle, pcminfo) >= 0); } // Playback devices.. bPlayback = false; if (m_iAudio == QJACKCTL_PLAYBACK || m_iAudio == QJACKCTL_DUPLEX) { snd_pcm_info_set_device(pcminfo, iDevice); snd_pcm_info_set_subdevice(pcminfo, 0); snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_PLAYBACK); bPlayback = (snd_ctl_pcm_info(handle, pcminfo) >= 0); } // List iif compliant with the audio mode criteria... if ((m_iAudio == QJACKCTL_CAPTURE && bCapture && !bPlayback) || (m_iAudio == QJACKCTL_PLAYBACK && !bCapture && bPlayback) || (m_iAudio == QJACKCTL_DUPLEX && bCapture && bPlayback)) { sSubName = sSubSuffix.arg(sName).arg(iDevice); sSubName2 = sSubSuffix.arg(sName2).arg(iDevice); addCard(sSubName2, snd_pcm_info_get_name(pcminfo) + sSuffix.arg(sSubName)); if (sCurName == sSubName || sCurName == sSubName2) iCurCard = iCards; ++iCards; } } snd_ctl_close(handle); } } #endif // CONFIG_ALSA_SEQ } else if (bSun) { QFile file("/var/run/dmesg.boot"); if (file.open(QIODevice::ReadOnly)) { QTextStream stream(&file); QString sLine; QRegExp rxDevice("audio([0-9]) at (.*)"); while (!stream.atEnd()) { sLine = stream.readLine(); if (rxDevice.exactMatch(sLine)) { sName = "/dev/audio" + rxDevice.cap(1); addCard(sName, rxDevice.cap(2)); if (sCurName == sName) iCurCard = iCards; ++iCards; } } file.close(); } } else if (bOss) { // Enumerate the OSS Audio devices... QFile file("/dev/sndstat"); if (file.open(QIODevice::ReadOnly)) { QTextStream stream(&file); QString sLine; bool bAudioDevices = false; QRegExp rxHeader("Audio devices.*", Qt::CaseInsensitive); QRegExp rxDevice("([0-9]+):[ ]+(.*)"); while (!stream.atEnd()) { sLine = stream.readLine(); if (bAudioDevices) { if (rxDevice.exactMatch(sLine)) { sName = "/dev/dsp" + rxDevice.cap(1); addCard(sName, rxDevice.cap(2)); if (sCurName == sName) iCurCard = iCards; ++iCards; } else break; } else if (rxHeader.exactMatch(sLine)) bAudioDevices = true; } file.close(); } } #ifdef CONFIG_COREAUDIO else if (bCoreaudio) { // Find out how many Core Audio devices are there, if any... // (code snippet gently "borrowed" from Stephane Letz jackdmp;) OSStatus err; Boolean isWritable; UInt32 outSize = sizeof(isWritable); err = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &outSize, &isWritable); if (err == noErr) { // Calculate the number of device available... int numCoreDevices = outSize / sizeof(AudioDeviceID); // Make space for the devices we are about to get... AudioDeviceID *coreDeviceIDs = new AudioDeviceID [numCoreDevices]; err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &outSize, (void *) coreDeviceIDs); if (err == noErr) { // Look for the CoreAudio device name... char coreDeviceName[256]; UInt32 nameSize = 256; for (int i = 0; i < numCoreDevices; i++) { err = AudioDeviceGetPropertyInfo(coreDeviceIDs[i], 0, true, kAudioDevicePropertyDeviceName, &outSize, &isWritable); if (err == noErr) { err = AudioDeviceGetProperty(coreDeviceIDs[i], 0, true, kAudioDevicePropertyDeviceName, &nameSize, (void *) coreDeviceName); if (err == noErr) { char drivername[128]; UInt32 dnsize = 128; // this returns the unique id for the device // that must be used on the commandline for jack if (getDeviceUIDFromID(coreDeviceIDs[i], drivername, dnsize) == noErr) { sName = drivername; } else { sName = "Error"; } coreaudioIdMap[sName] = coreDeviceIDs[i]; // TODO: hide this ugly ID from the user, // only show human readable name // humanreadable \t UID sSubName = QString(coreDeviceName); addCard(sSubName, sName); if (sCurName == sName || sCurName == sSubName) iCurCard = iCards; ++iCards; } } } } delete [] coreDeviceIDs; } } #endif // CONFIG_COREAUDIO #ifdef CONFIG_PORTAUDIO else if (bPortaudio) { if (Pa_Initialize() == paNoError) { // Fill hostapi info... PaHostApiIndex iNumHostApi = Pa_GetHostApiCount(); QString *pHostName = new QString[iNumHostApi]; for (PaHostApiIndex i = 0; i < iNumHostApi; ++i) pHostName[i] = QString(Pa_GetHostApiInfo(i)->name); // Fill device info... PaDeviceIndex iNumDevice = Pa_GetDeviceCount(); PaDeviceInfo **ppDeviceInfo = new PaDeviceInfo * [iNumDevice]; for (PaDeviceIndex i = 0; i < iNumDevice; ++i) { ppDeviceInfo[i] = const_cast<PaDeviceInfo *> (Pa_GetDeviceInfo(i)); sName = pHostName[ppDeviceInfo[i]->hostApi] + "::" + QString(ppDeviceInfo[i]->name); addCard(sName, QString()); if (sCurName == sName) iCurCard = iCards; ++iCards; } Pa_Terminate(); } } #endif // CONFIG_PORTAUDIO addCard(m_sDefName, QString()); if (sCurName == m_sDefName || sCurName.isEmpty()) iCurCard = iCards; ++iCards; QTreeView *pTreeView = static_cast<QTreeView *> (QComboBox::view()); pTreeView->setMinimumWidth( pTreeView->sizeHint().width() + QComboBox::iconSize().width()); QComboBox::setCurrentIndex(iCurCard); pLineEdit->setText(sCurName); QComboBox::setUpdatesEnabled(true); QComboBox::blockSignals(bBlockSignals); }
QWidget * CIPEditDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem &, const QModelIndex &) const { QLineEdit * editor = new QLineEdit(parent); editor->setFrame(false); editor->setInputMask("000.000.000.000;_"); return editor; }
void PropertiesEditorItem::prepareWidget() { QWidget *editor = 0; if (mProperty.type() == QVariant::BitArray) { } else if (mProperty.type() == QVariant::Bitmap) { } else if (mProperty.type() == QVariant::Bool) { QCheckBox *checkBox = new QCheckBox(parent()); checkBox->setText(QString()); checkBox->setChecked(mProperty.read(mObject.data()).toBool()); editor = qobject_cast< QWidget* >(checkBox); connect(checkBox, SIGNAL(toggled(bool)), SLOT(slotCheckBoxToggled())); } else if (mProperty.type() == QVariant::Brush) { } else if (mProperty.type() == QVariant::ByteArray) { } else if (mProperty.type() == QVariant::Char) { } else if (mProperty.type() == QVariant::Color) { QPushButton *button = new QPushButton(parent()); button->setText(mProperty.read(mObject.data()).value<QColor>().name()); connect(button, SIGNAL(clicked(bool)), SLOT(slotOpenColorEditor())); editor = qobject_cast< QWidget* >(button); } else if (mProperty.type() == QVariant::Cursor) { } else if (mProperty.type() == QVariant::Date) { } else if (mProperty.type() == QVariant::DateTime) { } else if (mProperty.type() == QVariant::Double) { QDoubleSpinBox *spinBox = new QDoubleSpinBox(parent()); spinBox->setMaximum(LONG_MAX); spinBox->setMinimum(LONG_MIN); spinBox->setSingleStep(0.01); spinBox->setValue(mProperty.read(mObject.data()).toDouble()); editor = qobject_cast< QWidget* >(spinBox); connect(spinBox, SIGNAL(valueChanged(double)), SLOT(slotDoubleSpinBoxValueChanged())); } else if (mProperty.type() == QVariant::EasingCurve) { QPushButton *button = new QPushButton(parent()); QEasingCurve curve = mProperty.read(mObject.data()).toEasingCurve(); button->setText(curve.staticMetaObject.enumerator(0).valueToKey(curve.type())); connect(button, SIGNAL(clicked(bool)), SLOT(slotOpenEasingCurveEditor())); editor = qobject_cast< QWidget* >(button); } else if (mProperty.type() == QVariant::Font) { QFontComboBox *comboBox = new QFontComboBox(parent()); comboBox->setCurrentFont(mProperty.read(mObject.data()).value<QFont>()); editor = qobject_cast< QWidget* >(comboBox); connect(comboBox, SIGNAL(currentFontChanged(QFont)), SLOT(slotFontComboChanged())); } else if (mProperty.type() == QVariant::Hash) { } else if (mProperty.type() == QVariant::Icon) { } else if (mProperty.type() == QVariant::Image) { } else if (mProperty.type() == QVariant::Int) { QSpinBox *spinBox = new QSpinBox(parent()); spinBox->setMinimum(INT_MIN); spinBox->setMaximum(INT_MAX); spinBox->setValue(mProperty.read(mObject.data()).toInt()); editor = qobject_cast< QWidget* >(spinBox); connect(spinBox, SIGNAL(valueChanged(int)), SLOT(slotSpinBoxValueChanged())); } else if (mProperty.type() == QVariant::KeySequence) { } else if (mProperty.type() == QVariant::Line) { } else if (mProperty.type() == QVariant::LineF) { } else if (mProperty.type() == QVariant::List) { } else if (mProperty.type() == QVariant::Locale) { } else if (mProperty.type() == QVariant::LongLong) { QDoubleSpinBox *spinBox = new QDoubleSpinBox(parent()); spinBox->setSingleStep(1.0); spinBox->setDecimals(0); spinBox->setMaximum(LONG_MAX); spinBox->setMinimum(LONG_MIN); spinBox->setValue(mProperty.read(mObject.data()).toLongLong()); editor = qobject_cast< QWidget* >(spinBox); connect(spinBox, SIGNAL(valueChanged(int)), SLOT(slotDoubleSpinBoxValueChanged())); } else if (mProperty.type() == QVariant::Map) { } else if (mProperty.type() == QVariant::Matrix) { } else if (mProperty.type() == QVariant::Matrix4x4) { } else if (mProperty.type() == QVariant::Palette) { } else if (mProperty.type() == QVariant::Pen) { } else if (mProperty.type() == QVariant::Pixmap) { } else if (mProperty.type() == QVariant::Point) { } else if (mProperty.type() == QVariant::PointF) { } else if (mProperty.type() == QVariant::Polygon) { } else if (mProperty.type() == QVariant::Quaternion) { } else if (mProperty.type() == QVariant::Rect) { } else if (mProperty.type() == QVariant::RectF) { } else if (mProperty.type() == QVariant::RegExp) { } else if (mProperty.type() == QVariant::Region) { } else if (mProperty.type() == QVariant::Size) { } else if (mProperty.type() == QVariant::SizeF) { } else if (mProperty.type() == QVariant::SizePolicy) { } else if (mProperty.type() == QVariant::String) { QLineEdit *lineEdit = new QLineEdit(parent()); lineEdit->setText(mProperty.read(mObject.data()).toString()); editor = qobject_cast< QWidget* >(lineEdit); connect(lineEdit, SIGNAL(textChanged(QString)), SLOT(slotLineEditChanged())); } else if (mProperty.type() == QVariant::StringList) { } else if (mProperty.type() == QVariant::TextFormat) { } else if (mProperty.type() == QVariant::TextLength) { } else if (mProperty.type() == QVariant::Time) { } else if (mProperty.type() == QVariant::Transform) { } else if (mProperty.type() == QVariant::UInt) { QSpinBox *spinBox = new QSpinBox(parent()); spinBox->setMaximum(UINT_MAX); spinBox->setMinimum(0); spinBox->setValue(mProperty.read(mObject.data()).toUInt()); editor = qobject_cast< QWidget* >(spinBox); connect(spinBox, SIGNAL(valueChanged(int)), SLOT(slotSpinBoxValueChanged())); } else if (mProperty.type() == QVariant::ULongLong) { QDoubleSpinBox *spinBox = new QDoubleSpinBox(parent()); spinBox->setSingleStep(1.0); spinBox->setDecimals(0); spinBox->setMinimum(0); spinBox->setMaximum(ULONG_MAX); spinBox->setValue(mProperty.read(mObject.data()).toULongLong()); editor = qobject_cast< QWidget* >(spinBox); connect(spinBox, SIGNAL(valueChanged(int)), SLOT(slotDoubleSpinBoxValueChanged())); } else if (mProperty.type() == QVariant::Url) { QPushButton *button = new QPushButton(parent()); QUrl url = mProperty.read(mObject.data()).toUrl(); setButtonUrl(button, url); editor = qobject_cast< QWidget* >(button); connect(button, SIGNAL(clicked(bool)), SLOT(slotUrlButtonClicked())); } else if (mProperty.type() == QVariant::UserType) { } else if (mProperty.type() == QVariant::Vector2D) { } else if (mProperty.type() == QVariant::Vector3D) { } else if (mProperty.type() == QVariant::Vector4D) { } mWidget = editor; }
// Parse "Solver specific tab" //----------------------------------------------------------------------------- bool SifGenerator::parseSolverSpecificTab(DynamicEditor *solEditor, const QString &solverName) { // Returns true if there is a matrix involved. otherwise returns false. if ( !solEditor ) return false; bool hasMatrix = true; QScriptEngine engine; QScriptValue dim_QSV = QScriptValue(&engine,dim); engine.globalObject().setProperty( "dim", dim_QSV ); QScriptValue cdim_QSV = QScriptValue(&engine,cdim); engine.globalObject().setProperty( "cdim", cdim_QSV ); for(int i = 0; i < solEditor->hash.count(); i++) { hash_entry_t entry = solEditor->hash.values().at(i); QString key = solEditor->hash.keys().at(i); QStringList keySplitted = key.split("/"); QString tabName = keySplitted.at(1).trimmed(); QString labelName = keySplitted.at(3).trimmed(); if ( tabName != solverName ) continue; // Has matrix? if(labelName == "No Matrix Equation") { if(entry.elem.attribute("Widget", "") == "CheckBox") { QCheckBox *cb = static_cast<QCheckBox*>(entry.widget); hasMatrix = !cb->isChecked(); } } // variable names handled separately... // ------------------------------------ if ( labelName=="Variable" || labelName.mid(0,17)=="Exported Variable" ) { if( entry.elem.attribute("Widget", "") != "Edit") continue; QLineEdit *l = static_cast<QLineEdit*>(entry.widget); QString varName = l->text().trimmed(); if ( varName == "" ) continue; int dofs=1; QStringList dofsplit = varName.split("["); if ( dofsplit.count()>1 ) { varName = dofsplit.at(0).trimmed() + "["; QString dof = dofsplit.at(1).trimmed(); dof = dof.split("]").at(0).trimmed(); dofsplit = dof.split(":"); QString subVarName = dofsplit.at(0).trimmed(); for( int i=1; i<dofsplit.count(); i++) { dof = dofsplit.at(i).trimmed(); QStringList subDofSplit = dof.split(" "); QString subDof = subDofSplit.at(0).trimmed(); dofs = engine.evaluate(subDof).toInt32(); if (i>1) varName = varName + " "; varName = varName + subVarName + ":" + QString::number(dofs); if ( subDofSplit.count() > 1 ) subVarName = subDofSplit.at(1).trimmed(); } varName = varName + "]"; addSifLine( " " + labelName + " = ", varName ); } else { dofsplit = varName.split("("); if ( dofsplit.count()>1 ) { varName = dofsplit.at(0).trimmed(); QString dof = dofsplit.at(1).trimmed(); dofsplit = dof.split(")"); dof = dofsplit.at(0).trimmed(); dofs = engine.evaluate(dof).toInt32(); } // Don't write the the trivial dof==1 case as this leaves possibility to define the number of // dofs internally within the solver. if ( dofs <= 1 ) { addSifLine( " "+labelName+" = ", varName ); dofs = 1; } else { addSifLine( " "+labelName+" = -dofs ", QString::number(dofs) + " " + varName ); } } continue; } QWidget *widget = entry.widget; QDomElement elem; if ( widget->isEnabled() ) { elem = entry.elem; if(elem.attribute("Widget", "") == "CheckBox") handleCheckBox(elem, widget); if(elem.attribute("Widget", "") == "Edit") handleLineEdit(elem, widget); if(elem.attribute("Widget", "") == "Combo") handleComboBox(elem, widget); if(elem.attribute("Widget", "") == "TextEdit") handleTextEdit(elem, widget); } } return hasMatrix; }
void NetworkConfig::paramsFromConfig(int network_id) { int i, res; edit_network_id = network_id; getEapCapa(); char reply[1024], cmd[256], *pos; size_t reply_len; snprintf(cmd, sizeof(cmd), "GET_NETWORK %d ssid", network_id); reply_len = sizeof(reply) - 1; if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 && reply[0] == '"') { reply[reply_len] = '\0'; pos = strchr(reply + 1, '"'); if (pos) *pos = '\0'; ssidEdit->setText(reply + 1); } snprintf(cmd, sizeof(cmd), "GET_NETWORK %d proto", network_id); reply_len = sizeof(reply) - 1; int wpa = 0; if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) { reply[reply_len] = '\0'; if (strstr(reply, "RSN") || strstr(reply, "WPA2")) wpa = 2; else if (strstr(reply, "WPA")) wpa = 1; } int auth = AUTH_NONE_OPEN, encr = 0; snprintf(cmd, sizeof(cmd), "GET_NETWORK %d key_mgmt", network_id); reply_len = sizeof(reply) - 1; if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) { reply[reply_len] = '\0'; if (strstr(reply, "WPA-EAP")) auth = wpa & 2 ? AUTH_WPA2_EAP : AUTH_WPA_EAP; else if (strstr(reply, "WPA-PSK")) auth = wpa & 2 ? AUTH_WPA2_PSK : AUTH_WPA_PSK; else if (strstr(reply, "IEEE8021X")) { auth = AUTH_IEEE8021X; encr = 1; } } snprintf(cmd, sizeof(cmd), "GET_NETWORK %d pairwise", network_id); reply_len = sizeof(reply) - 1; if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) { reply[reply_len] = '\0'; if (strstr(reply, "CCMP") && auth != AUTH_NONE_OPEN && auth != AUTH_NONE_WEP && auth != AUTH_NONE_WEP_SHARED) encr = 1; else if (strstr(reply, "TKIP")) encr = 0; else if (strstr(reply, "WEP")) encr = 1; else encr = 0; } snprintf(cmd, sizeof(cmd), "GET_NETWORK %d psk", network_id); reply_len = sizeof(reply) - 1; res = wpagui->ctrlRequest(cmd, reply, &reply_len); if (res >= 0 && reply_len >= 2 && reply[0] == '"') { reply[reply_len] = '\0'; pos = strchr(reply + 1, '"'); if (pos) *pos = '\0'; pskEdit->setText(reply + 1); } else if (res >= 0 && key_value_isset(reply, reply_len)) { pskEdit->setText(WPA_GUI_KEY_DATA); } snprintf(cmd, sizeof(cmd), "GET_NETWORK %d identity", network_id); reply_len = sizeof(reply) - 1; if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 && reply[0] == '"') { reply[reply_len] = '\0'; pos = strchr(reply + 1, '"'); if (pos) *pos = '\0'; identityEdit->setText(reply + 1); } snprintf(cmd, sizeof(cmd), "GET_NETWORK %d password", network_id); reply_len = sizeof(reply) - 1; res = wpagui->ctrlRequest(cmd, reply, &reply_len); if (res >= 0 && reply_len >= 2 && reply[0] == '"') { reply[reply_len] = '\0'; pos = strchr(reply + 1, '"'); if (pos) *pos = '\0'; passwordEdit->setText(reply + 1); } else if (res >= 0 && key_value_isset(reply, reply_len)) { passwordEdit->setText(WPA_GUI_KEY_DATA); } snprintf(cmd, sizeof(cmd), "GET_NETWORK %d ca_cert", network_id); reply_len = sizeof(reply) - 1; if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 && reply[0] == '"') { reply[reply_len] = '\0'; pos = strchr(reply + 1, '"'); if (pos) *pos = '\0'; cacertEdit->setText(reply + 1); } enum { NO_INNER, PEAP_INNER, TTLS_INNER, FAST_INNER } eap = NO_INNER; snprintf(cmd, sizeof(cmd), "GET_NETWORK %d eap", network_id); reply_len = sizeof(reply) - 1; if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 1) { reply[reply_len] = '\0'; for (i = 0; i < eapSelect->count(); i++) { if (eapSelect->itemText(i).compare(reply) == 0) { eapSelect->setCurrentIndex(i); if (strcmp(reply, "PEAP") == 0) eap = PEAP_INNER; else if (strcmp(reply, "TTLS") == 0) eap = TTLS_INNER; else if (strcmp(reply, "FAST") == 0) eap = FAST_INNER; break; } } } if (eap != NO_INNER) { snprintf(cmd, sizeof(cmd), "GET_NETWORK %d phase2", network_id); reply_len = sizeof(reply) - 1; if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 1) { reply[reply_len] = '\0'; eapChanged(eapSelect->currentIndex()); } else eap = NO_INNER; } char *val; val = reply + 1; while (*(val + 1)) val++; if (*val == '"') *val = '\0'; switch (eap) { case PEAP_INNER: if (strncmp(reply, "\"auth=", 6)) break; val = reply + 2; memcpy(val, "EAP-", 4); break; case TTLS_INNER: if (strncmp(reply, "\"autheap=", 9) == 0) { val = reply + 5; memcpy(val, "EAP-", 4); } else if (strncmp(reply, "\"auth=", 6) == 0) val = reply + 6; break; case FAST_INNER: if (strncmp(reply, "\"auth=", 6)) break; if (strcmp(reply + 6, "GTC auth=MSCHAPV2") == 0) { val = (char *) "GTC(auth) + MSCHAPv2(prov)"; break; } val = reply + 2; memcpy(val, "EAP-", 4); break; case NO_INNER: break; } for (i = 0; i < phase2Select->count(); i++) { if (phase2Select->itemText(i).compare(val) == 0) { phase2Select->setCurrentIndex(i); break; } } for (i = 0; i < 4; i++) { QLineEdit *wepEdit; switch (i) { default: case 0: wepEdit = wep0Edit; break; case 1: wepEdit = wep1Edit; break; case 2: wepEdit = wep2Edit; break; case 3: wepEdit = wep3Edit; break; } snprintf(cmd, sizeof(cmd), "GET_NETWORK %d wep_key%d", network_id, i); reply_len = sizeof(reply) - 1; res = wpagui->ctrlRequest(cmd, reply, &reply_len); if (res >= 0 && reply_len >= 2 && reply[0] == '"') { reply[reply_len] = '\0'; pos = strchr(reply + 1, '"'); if (pos) *pos = '\0'; if (auth == AUTH_NONE_OPEN || auth == AUTH_IEEE8021X) { if (auth == AUTH_NONE_OPEN) auth = AUTH_NONE_WEP; encr = 1; } wepEdit->setText(reply + 1); } else if (res >= 0 && key_value_isset(reply, reply_len)) { if (auth == AUTH_NONE_OPEN || auth == AUTH_IEEE8021X) { if (auth == AUTH_NONE_OPEN) auth = AUTH_NONE_WEP; encr = 1; } wepEdit->setText(WPA_GUI_KEY_DATA); } } if (auth == AUTH_NONE_WEP) { snprintf(cmd, sizeof(cmd), "GET_NETWORK %d auth_alg", network_id); reply_len = sizeof(reply) - 1; if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) { reply[reply_len] = '\0'; if (strcmp(reply, "SHARED") == 0) auth = AUTH_NONE_WEP_SHARED; } } snprintf(cmd, sizeof(cmd), "GET_NETWORK %d wep_tx_keyidx", network_id); reply_len = sizeof(reply) - 1; if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 1) { reply[reply_len] = '\0'; switch (atoi(reply)) { case 0: wep0Radio->setChecked(true); break; case 1: wep1Radio->setChecked(true); break; case 2: wep2Radio->setChecked(true); break; case 3: wep3Radio->setChecked(true); break; } } snprintf(cmd, sizeof(cmd), "GET_NETWORK %d id_str", network_id); reply_len = sizeof(reply) - 1; if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 && reply[0] == '"') { reply[reply_len] = '\0'; pos = strchr(reply + 1, '"'); if (pos) *pos = '\0'; idstrEdit->setText(reply + 1); } snprintf(cmd, sizeof(cmd), "GET_NETWORK %d priority", network_id); reply_len = sizeof(reply) - 1; if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 1) { reply[reply_len] = '\0'; prioritySpinBox->setValue(atoi(reply)); } authSelect->setCurrentIndex(auth); authChanged(auth); encrSelect->setCurrentIndex(encr); wepEnabled(auth == AUTH_NONE_WEP || auth == AUTH_NONE_WEP_SHARED); removeButton->setEnabled(true); addButton->setText("Save"); }
void PropertiesEditorItem::slotLineEditChanged() { QLineEdit *lineEdit = qobject_cast<QLineEdit*>(mWidget.data()); mProperty.write(mObject.data(), lineEdit->text()); }
void KWQTableView::slotSpecChar(const QChar & c) { if (state() == QAbstractItemView::EditingState) { if (QApplication::focusWidget()) { QLineEdit *l = static_cast<QLineEdit*>(QApplication::focusWidget()); if (l->hasSelectedText()) { QString ls = l->text(); QString s = l->selectedText(); int len = s.length(); int ss = l->selectionStart(); ls = ls.replace(ss, len, c); l->setText(ls); l->setSelection(ss, 1); } else { QString s = l->text(); int i = l->cursorPosition(); s.insert(i, c); l->setText(s); l->setCursorPosition(i + 1); } } } else { edit(currentIndex()); if (QApplication::focusWidget()) { QLineEdit *l = static_cast<QLineEdit*>(QApplication::focusWidget()); l->setText(QString(c)); l->setCursorPosition(1); } } }
void setupUi(QDialog *MemberEditDialog) { p = MemberEditDialog; mainWidget = new QWidget(MemberEditDialog); horizontalLayout = new QHBoxLayout(mainWidget); tabWidget = new QTabWidget(mainWidget); generalTab = new QWidget(); generalHLayout = new QHBoxLayout(generalTab); formWidget = new QWidget(generalTab); formTab1LeftLayout = new QFormLayout(formWidget); titleLabel = new QLabel(formWidget); firstNameLabel = new QLabel(formWidget); firstNameLineEdit = new QLineEdit(formWidget); lastNameLabel = new QLabel(formWidget); lastNameLineEdit = new QLineEdit(formWidget); streetLabel = new QLabel(formWidget); zipLabel = new QLabel(formWidget); streetHorizontalWidget = new QWidget(formWidget); streetHLayout = new QHBoxLayout(streetHorizontalWidget); streetLineEdit = new QLineEdit(streetHorizontalWidget); numberLabel = new QLabel(streetHorizontalWidget); numberLineEdit = new QLineEdit(streetHorizontalWidget); cityHorizontalWidget = new QWidget(formWidget); cityHLayout = new QHBoxLayout(cityHorizontalWidget); zipLineEdit = new QLineEdit(cityHorizontalWidget); cityLabel = new QLabel(cityHorizontalWidget); cityLineEdit = new QLineEdit(cityHorizontalWidget); titleHorizontalWidget = new QWidget(formWidget); titleHLayout = new QHBoxLayout(titleHorizontalWidget); comboBox = new QComboBox(titleHorizontalWidget); titleExtLabel = new QLabel(titleHorizontalWidget); titleExtLineEdit = new QLineEdit(titleHorizontalWidget); formTab1Right = new QWidget(generalTab); formTab1RightLayout = new QFormLayout(formTab1Right); phoneLabel = new QLabel(formTab1Right); phoneEdit = new QLineEdit(formTab1Right); cellLabel = new QLabel(formTab1Right); cellEdit = new QLineEdit(formTab1Right); emailLabel = new QLabel(formTab1Right); emailEdit = new QLineEdit(formTab1Right); maritalLabel = new QLabel(formTab1Right); maritalCBox = new QComboBox(formTab1Right); accountTab = new QWidget(); accountVLayout = new QVBoxLayout(accountTab); tableView = new QTableView(accountTab); tab2BottomLayout = new QHBoxLayout(); formTab2BottomLayout = new QFormLayout(); ibanLabel = new QLabel(accountTab); ibanLineEdit = new QLineEdit(accountTab); bicLabel = new QLabel(accountTab); bicLineEdit = new QLineEdit(accountTab); ownerLabel = new QLabel(accountTab); ownerLineEdit = new QLineEdit(accountTab); noteLabel = new QLabel(accountTab); noteLineEdit = new QLineEdit(accountTab); buttonsTab2BottomLayout = new QVBoxLayout(); addButton = new QPushButton(accountTab); editButton = new QPushButton(accountTab); deleteButton = new QPushButton(accountTab); verticalLayout = new QVBoxLayout(); okButton = new QPushButton(mainWidget); applyButton = new QPushButton(mainWidget); verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); leaveButton = new QPushButton(mainWidget); verticalSpacer_2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); cancelButton = new QPushButton(mainWidget); // # layout definitions # // tabs on left, buttons on the right horizontalLayout->addWidget(tabWidget); horizontalLayout->addLayout(verticalLayout); // set up buttons on right verticalLayout->addWidget(okButton); verticalLayout->addWidget(applyButton); verticalLayout->addItem(verticalSpacer); verticalLayout->addWidget(leaveButton); verticalLayout->addItem(verticalSpacer_2); verticalLayout->addWidget(cancelButton); // set up tabs tabWidget->addTab(generalTab, QString()); tabWidget->addTab(accountTab, QString()); tabWidget->setCurrentIndex(0); // set up general tab generalHLayout->addWidget(formWidget); generalHLayout->addWidget(formTab1Right); // set up account tab accountVLayout->addWidget(tableView); accountVLayout->addLayout(tab2BottomLayout); accountVLayout->setContentsMargins(0, 0, 0, 0); // set up lazout of bottom part of account tab // form and buttons to add entries to table in a h-box tab2BottomLayout->addLayout(formTab2BottomLayout); tab2BottomLayout->addLayout(buttonsTab2BottomLayout); // buttons column of bottom part of account tab buttonsTab2BottomLayout->addWidget(addButton); buttonsTab2BottomLayout->addWidget(editButton); buttonsTab2BottomLayout->addWidget(deleteButton); // ## forms of general tab / general personal data ## // left side - personal data, address, etc. formTab1LeftLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow); formTab1LeftLayout->setWidget(0, QFormLayout::LabelRole, titleLabel); formTab1LeftLayout->setWidget(0, QFormLayout::FieldRole, titleHorizontalWidget); formTab1LeftLayout->setWidget(1, QFormLayout::LabelRole, firstNameLabel); formTab1LeftLayout->setWidget(1, QFormLayout::FieldRole, firstNameLineEdit); formTab1LeftLayout->setWidget(2, QFormLayout::LabelRole, lastNameLabel); formTab1LeftLayout->setWidget(2, QFormLayout::FieldRole, lastNameLineEdit); formTab1LeftLayout->setWidget(3, QFormLayout::LabelRole, streetLabel); formTab1LeftLayout->setWidget(3, QFormLayout::FieldRole, streetHorizontalWidget); formTab1LeftLayout->setWidget(4, QFormLayout::LabelRole, zipLabel); formTab1LeftLayout->setWidget(4, QFormLayout::FieldRole, cityHorizontalWidget); // right side - phone, email, formTab1RightLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow); formTab1RightLayout->setWidget(0, QFormLayout::LabelRole, phoneLabel); // phone formTab1RightLayout->setWidget(0, QFormLayout::FieldRole, phoneEdit); formTab1RightLayout->setWidget(1, QFormLayout::LabelRole, cellLabel); // mobile / cell phone number formTab1RightLayout->setWidget(1, QFormLayout::FieldRole, cellEdit); formTab1RightLayout->setWidget(2, QFormLayout::LabelRole, emailLabel); // email formTab1RightLayout->setWidget(2, QFormLayout::FieldRole, emailEdit); formTab1RightLayout->setWidget(3, QFormLayout::LabelRole, maritalLabel); // marital status formTab1RightLayout->setWidget(3, QFormLayout::FieldRole, maritalCBox); // form on bottom of account tab formTab2BottomLayout->setWidget(0, QFormLayout::LabelRole, ibanLabel); formTab2BottomLayout->setWidget(0, QFormLayout::FieldRole, ibanLineEdit); formTab2BottomLayout->setWidget(1, QFormLayout::LabelRole, bicLabel); formTab2BottomLayout->setWidget(1, QFormLayout::FieldRole, bicLineEdit); formTab2BottomLayout->setWidget(2, QFormLayout::LabelRole, ownerLabel); formTab2BottomLayout->setWidget(2, QFormLayout::FieldRole, ownerLineEdit); formTab2BottomLayout->setWidget(3, QFormLayout::LabelRole, noteLabel); formTab2BottomLayout->setWidget(3, QFormLayout::FieldRole, noteLineEdit); // street and number next to each other in one cell // so put them in a hbox and that into the form streetHLayout->addWidget(streetLineEdit); streetHLayout->addWidget(numberLabel); streetHLayout->addWidget(numberLineEdit); streetHLayout->setContentsMargins(0, 0, 0, 0); streetHLayout->setStretch(0, 5); streetHLayout->setStretch(2, 1); // zip and city in one cell like above cityHLayout->addWidget(zipLineEdit); cityHLayout->addWidget(cityLabel); cityHLayout->addWidget(cityLineEdit); cityHLayout->setContentsMargins(0, 0, 0, 0); // title and titleext like above titleHLayout->addWidget(comboBox); titleHLayout->addWidget(titleExtLabel); titleHLayout->addWidget(titleExtLineEdit); titleHLayout->setContentsMargins(0, 0, 0, 0); // zip codes have only 5 digits, also define appropriate size zipLineEdit->setMaxLength(5); zipLineEdit->setMaximumSize(QSize(80, 16777215)); // initial siye of dialog. TODO: Save in conf on quit. Restore here. MemberEditDialog->resize(1200, 700); updateGeometry(); retranslateUi(MemberEditDialog); QMetaObject::connectSlotsByName(MemberEditDialog); if (MemberEditDialog->objectName().isEmpty()) MemberEditDialog->setObjectName(QStringLiteral("MemberEditDialog")); mainWidget->setObjectName(QStringLiteral("mainWidget")); horizontalLayout->setObjectName(QStringLiteral("horizontalLayout")); tabWidget->setObjectName(QStringLiteral("tabWidget")); generalTab->setObjectName(QStringLiteral("generalTab")); generalHLayout->setObjectName(QStringLiteral("generalHLayout")); formWidget->setObjectName(QStringLiteral("formWidget")); formTab1LeftLayout->setObjectName(QStringLiteral("formTab1LeftLayout")); titleLabel->setObjectName(QStringLiteral("titleLabel")); firstNameLabel->setObjectName(QStringLiteral("firstNameLabel")); firstNameLineEdit->setObjectName(QStringLiteral("firstNameLineEdit")); lastNameLabel->setObjectName(QStringLiteral("lastNameLabel")); lastNameLineEdit->setObjectName(QStringLiteral("lastNameLineEdit")); streetLabel->setObjectName(QStringLiteral("streetLabel")); zipLabel->setObjectName(QStringLiteral("zipLabel")); streetHorizontalWidget->setObjectName(QStringLiteral("streetHorizontalWidget")); streetHLayout->setObjectName(QStringLiteral("streetHLayout")); streetLineEdit->setObjectName(QStringLiteral("streetLineEdit")); numberLabel->setObjectName(QStringLiteral("numberLabel")); numberLineEdit->setObjectName(QStringLiteral("numberLineEdit")); cityHorizontalWidget->setObjectName(QStringLiteral("cityHorizontalWidget")); cityHLayout->setObjectName(QStringLiteral("cityHLayout")); zipLineEdit->setObjectName(QStringLiteral("zipLineEdit")); cityLabel->setObjectName(QStringLiteral("cityLabel")); cityLineEdit->setObjectName(QStringLiteral("cityLineEdit")); titleHorizontalWidget->setObjectName(QStringLiteral("titleHorizontalWidget")); titleHLayout->setObjectName(QStringLiteral("titleHLayout")); comboBox->setObjectName(QStringLiteral("comboBox")); titleExtLabel->setObjectName(QStringLiteral("titleExtLabel")); titleExtLineEdit->setObjectName(QStringLiteral("titleExtLineEdit")); formTab1Right->setObjectName(QStringLiteral("formTab1Right")); formTab1RightLayout->setObjectName(QStringLiteral("formTab1RightLayout")); phoneLabel->setObjectName(QStringLiteral("phoneLabel")); phoneEdit->setObjectName(QStringLiteral("phoneEdit")); cellLabel->setObjectName(QStringLiteral("cellLabel")); cellEdit->setObjectName(QStringLiteral("cellEdit")); emailLabel->setObjectName(QStringLiteral("emailLabel")); emailEdit->setObjectName(QStringLiteral("emailEdit")); maritalLabel->setObjectName(QStringLiteral("maritalLabel")); maritalCBox->setObjectName(QStringLiteral("maritalCBox")); accountTab->setObjectName(QStringLiteral("accountTab")); accountVLayout->setObjectName(QStringLiteral("accountVLayout")); tableView->setObjectName(QStringLiteral("tableView")); tab2BottomLayout->setObjectName(QStringLiteral("tab2BottomLayout")); formTab2BottomLayout->setObjectName(QStringLiteral("formTab2BottomLayout")); ibanLabel->setObjectName(QStringLiteral("ibanLabel")); ibanLineEdit->setObjectName(QStringLiteral("ibanLineEdit")); bicLabel->setObjectName(QStringLiteral("bicLabel")); bicLineEdit->setObjectName(QStringLiteral("bicLineEdit")); ownerLabel->setObjectName(QStringLiteral("ownerLabel")); ownerLineEdit->setObjectName(QStringLiteral("ownerLineEdit")); noteLabel->setObjectName(QStringLiteral("noteLabel")); noteLineEdit->setObjectName(QStringLiteral("noteLineEdit")); buttonsTab2BottomLayout->setObjectName(QStringLiteral("buttonsTab2BottomLayout")); addButton->setObjectName(QStringLiteral("addButton")); editButton->setObjectName(QStringLiteral("editButton")); deleteButton->setObjectName(QStringLiteral("deleteButton")); verticalLayout->setObjectName(QStringLiteral("verticalLayout")); okButton->setObjectName(QStringLiteral("okButton")); applyButton->setObjectName(QStringLiteral("applyButton")); leaveButton->setObjectName(QStringLiteral("leaveButton")); cancelButton->setObjectName(QStringLiteral("cancelButton")); } // setupUi
void KWQTableView::doEditMarkBlank() { if (state() == QAbstractItemView::EditingState) { if (QApplication::focusWidget()) { QLineEdit *l = static_cast<QLineEdit*>(QApplication::focusWidget()); if (l->text().length() > 0) { QString s = l->text(); int cp = l->cursorPosition(); if (!l->hasSelectedText()) { if (!s[cp].isSpace() && !s[cp - 1].isSpace()) { l->cursorWordBackward(false); int cp1 = l->cursorPosition(); l->cursorWordForward(false); if (l->cursorPosition() != (int) s.length()) { while(l->text()[l->cursorPosition()].isSpace()) l->cursorBackward(false, 1); } int cp2 = l->cursorPosition(); if (cp2 == (int) s.length()) l->setSelection(cp1, cp2 - cp1); else l->setSelection(cp1, cp2 - cp1 - 1); } else return; } if (l->hasSelectedText()) { QString st = l->selectedText(); int len = st.length(); st = st.prepend(delim_start); st = st.append(delim_end); int ss = l->selectionStart(); s = s.replace(ss, len, st); l->setText(s); l->setSelection(ss, st.length()); } } } } }
void KWQTableView::doEditUnmarkBlank() { QString s; if (state() == QAbstractItemView::EditingState) { if (QApplication::focusWidget()) { QLineEdit *l = static_cast<QLineEdit*>(QApplication::focusWidget()); if (l->hasSelectedText()) { QString ls = l->text(); s = l->selectedText(); int len = s.length(); s.remove(delim_start); s.remove(delim_end); int ss = l->selectionStart(); ls = ls.replace(ss, len, s); l->setText(ls); l->setSelection(ss, s.length()); } else { if (l->text().length() > 0) { s = l->text(); int cs = l->cursorPosition(); int fr = s.lastIndexOf(delim_start, cs); if (fr > 0) { s = s.replace(fr, 1, QLatin1String("")); cs--; } int ff = s.indexOf(delim_end, cs); if (ff > 0) s = s.replace(ff, 1, QLatin1String("")); l->setText(s); l->setCursorPosition(cs); } } } } else { KWQCommandUnmarkBlank *kwqc = new KWQCommandUnmarkBlank(this); m_undoStack->push(kwqc); } }
//Reading ad writing parameters from/to selected widget to/from parameters container void SynchronizeInterfaceWindow(QWidget *window, cParameterContainer *par, enumReadWrite mode) { WriteLog("cInterface::SynchronizeInterface: QLineEdit", 3); //----------- QLineEdit ------------------- { QList<QLineEdit *> widgetListLineEdit = window->findChildren<QLineEdit *>(); QList<QLineEdit *>::iterator it; for (it = widgetListLineEdit.begin(); it != widgetListLineEdit.end(); ++it) { //qDebug() << "QLineEdit:" << (*it)->objectName() << " Type:" << (*it)->metaObject()->className() << endl; QString name = (*it)->objectName(); QString className = (*it)->metaObject()->className(); if (name.length() > 1 && (className == QString("QLineEdit") || className == QString("MyLineEdit"))) { QLineEdit *lineEdit = *it; // QString text = lineEdit->text(); //qDebug() << name << " - text: " << text << endl; QString type, parameterName; GetNameAndType(name, ¶meterName, &type); //qDebug() << name << " - type: " << type << endl; if (className == QString("MyLineEdit")) { MyLineEdit *mylineedit = (MyLineEdit*) *it; mylineedit->AssignParameterContainer(par); mylineedit->AssingParameterName(parameterName); } //----- get vectors ------------ if (type == QString("vect3") || type == QString("logvect3")) { char lastChar = (parameterName.at(parameterName.length() - 1)).toLatin1(); QString nameVect = parameterName.left(parameterName.length() - 2); if (mode == read) { double value = systemData.locale.toDouble(lineEdit->text()); //qDebug() << nameVect << " - " << lastChar << " axis = " << value << endl; CVector3 vect = par->Get<CVector3>(nameVect); switch (lastChar) { case 'x': vect.x = value; break; case 'y': vect.y = value; break; case 'z': vect.z = value; break; default: qWarning() << "cInterface::SynchronizeInterfaceWindow(): edit field " << nameVect << " has wrong axis name (is " << lastChar << ")" << endl; break; } par->Set(nameVect, vect); } else if (mode == write) { CVector3 vect = par->Get<CVector3>(nameVect); QString qtext; switch (lastChar) { case 'x': qtext = QString("%L1").arg(vect.x, 0, 'g', 16); break; case 'y': qtext = QString("%L1").arg(vect.y, 0, 'g', 16); break; case 'z': qtext = QString("%L1").arg(vect.z, 0, 'g', 16); break; default: qWarning() << "cInterface::SynchronizeInterfaceWindow(): edit field " << nameVect << " has wrong axis name (is " << lastChar << ")" << endl; break; } lineEdit->setText(qtext); lineEdit->setCursorPosition(0); } } //----- get vectors 4D ------------ if (type == QString("vect4")) { char lastChar = (parameterName.at(parameterName.length() - 1)).toLatin1(); QString nameVect = parameterName.left(parameterName.length() - 2); if (mode == read) { double value = systemData.locale.toDouble(lineEdit->text()); //qDebug() << nameVect << " - " << lastChar << " axis = " << value << endl; CVector4 vect = par->Get<CVector4>(nameVect); switch (lastChar) { case 'x': vect.x = value; break; case 'y': vect.y = value; break; case 'z': vect.z = value; break; case 'w': vect.w = value; break; default: qWarning() << "cInterface::SynchronizeInterfaceWindow(): edit field " << nameVect << " has wrong axis name (is " << lastChar << ")" << endl; break; } par->Set(nameVect, vect); } else if (mode == write) { CVector4 vect = par->Get<CVector4>(nameVect); QString qtext; switch (lastChar) { case 'x': qtext = QString("%L1").arg(vect.x, 0, 'g', 16); break; case 'y': qtext = QString("%L1").arg(vect.y, 0, 'g', 16); break; case 'z': qtext = QString("%L1").arg(vect.z, 0, 'g', 16); break; case 'w': qtext = QString("%L1").arg(vect.w, 0, 'g', 16); break; default: qWarning() << "cInterface::SynchronizeInterfaceWindow(): edit field " << nameVect << " has wrong axis name (is " << lastChar << ")" << endl; break; } lineEdit->setText(qtext); lineEdit->setCursorPosition(0); } } //---------- get double scalars -------- else if (type == QString("edit") || type == QString("logedit")) { if (mode == read) { double value = systemData.locale.toDouble(lineEdit->text()); par->Set(parameterName, value); } else if (mode == write) { double value = par->Get<double>(parameterName); lineEdit->setText(QString("%L1").arg(value, 0, 'g', 16)); lineEdit->setCursorPosition(0); } } //----------- get texts ------------ else if (type == QString("text")) { if (mode == read) { QString value = lineEdit->text(); par->Set(parameterName, value); } else if (mode == write) { QString value = par->Get<QString>(parameterName); lineEdit->setText(value); } } } } //end foreach } WriteLog("cInterface::SynchronizeInterface: QDoubleSpinBox", 3); //------------ Double spin-box -------------- { QList<QDoubleSpinBox *> widgetListDoubleSpinBox = window->findChildren<QDoubleSpinBox*>(); QList<QDoubleSpinBox *>::iterator it; for (it = widgetListDoubleSpinBox.begin(); it != widgetListDoubleSpinBox.end(); ++it) { QString name = (*it)->objectName(); //qDebug() << "QDoubleSpinBox:" << (*it)->objectName() << " Type:" << (*it)->metaObject()->className() << endl; QString className = (*it)->metaObject()->className(); if (name.length() > 1 && (className == QString("QDoubleSpinBox") || className == QString("MyDoubleSpinBox"))) { QDoubleSpinBox *spinbox = *it; QString type, parameterName; GetNameAndType(name, ¶meterName, &type); if (className == QString("MyDoubleSpinBox")) { MyDoubleSpinBox *mydoublespinbox = (MyDoubleSpinBox*) *it; mydoublespinbox->AssignParameterContainer(par); mydoublespinbox->AssingParameterName(parameterName); } if (type == QString("spinbox") || type == QString("spinboxd")) { if (mode == read) { double value = spinbox->value(); par->Set(parameterName, value); } else if (mode == write) { double value = par->Get<double>(parameterName); spinbox->setValue(value); } } else if (type == QString("spinbox3") || type == QString("spinboxd3")) { char lastChar = (parameterName.at(parameterName.length() - 1)).toLatin1(); QString nameVect = parameterName.left(parameterName.length() - 2); if (mode == read) { double value = spinbox->value(); CVector3 vect = par->Get<CVector3>(nameVect); switch (lastChar) { case 'x': vect.x = value; break; case 'y': vect.y = value; break; case 'z': vect.z = value; break; default: qWarning() << "cInterface::SynchronizeInterfaceWindow(): " << type << " " << nameVect << " has wrong axis name (is " << lastChar << ")" << endl; break; } par->Set(nameVect, vect); } else if (mode == write) { CVector3 vect = par->Get<CVector3>(nameVect); double value = 0; switch (lastChar) { case 'x': value = vect.x; break; case 'y': value = vect.y; break; case 'z': value = vect.z; break; default: qWarning() << "cInterface::SynchronizeInterfaceWindow(): " << type << " " << nameVect << " has wrong axis name (is " << lastChar << ")" << endl; break; } spinbox->setValue(value); } } else if (type == QString("spinbox4") || type == QString("spinboxd4")) { char lastChar = (parameterName.at(parameterName.length() - 1)).toLatin1(); QString nameVect = parameterName.left(parameterName.length() - 2); if (mode == read) { double value = spinbox->value(); CVector4 vect = par->Get<CVector4>(nameVect); switch (lastChar) { case 'x': vect.x = value; break; case 'y': vect.y = value; break; case 'z': vect.z = value; break; case 'w': vect.w = value; break; default: qWarning() << "cInterface::SynchronizeInterfaceWindow(): " << type << " " << nameVect << " has wrong axis name (is " << lastChar << ")" << endl; break; } par->Set(nameVect, vect); } else if (mode == write) { CVector4 vect = par->Get<CVector4>(nameVect); double value = 0; switch (lastChar) { case 'x': value = vect.x; break; case 'y': value = vect.y; break; case 'z': value = vect.z; break; case 'w': value = vect.w; break; default: qWarning() << "cInterface::SynchronizeInterfaceWindow(): " << type << " " << nameVect << " has wrong axis name (is " << lastChar << ")" << endl; break; } spinbox->setValue(value); } } } } } WriteLog("cInterface::SynchronizeInterface: QSpinBox", 3); //------------ integer spin-box -------------- { QList<QSpinBox *> widgetListDoubleSpinBox = window->findChildren<QSpinBox*>(); QList<QSpinBox *>::iterator it; for (it = widgetListDoubleSpinBox.begin(); it != widgetListDoubleSpinBox.end(); ++it) { QString name = (*it)->objectName(); //qDebug() << "QDoubleSpinBox:" << (*it)->objectName() << " Type:" << (*it)->metaObject()->className() << endl; QString className = (*it)->metaObject()->className(); if (name.length() > 1 && (className == QString("QSpinBox") || className == QString("MySpinBox"))) { QSpinBox *spinbox = *it; QString type, parameterName; GetNameAndType(name, ¶meterName, &type); if (className == QString("MySpinBox")) { MySpinBox *myspinbox = (MySpinBox*) *it; myspinbox->AssignParameterContainer(par); myspinbox->AssingParameterName(parameterName); } if (type == QString("spinboxInt")) { if (mode == read) { int value = spinbox->value(); par->Set(parameterName, value); } else if (mode == write) { int value = par->Get<int>(parameterName); spinbox->setValue(value); } } } } } WriteLog("cInterface::SynchronizeInterface: QCheckBox", 3); //checkboxes { QList<QCheckBox *> widgetListDoubleSpinBox = window->findChildren<QCheckBox*>(); QList<QCheckBox *>::iterator it; for (it = widgetListDoubleSpinBox.begin(); it != widgetListDoubleSpinBox.end(); ++it) { QString name = (*it)->objectName(); //qDebug() << "QCheckBox:" << (*it)->objectName() << " Type:" << (*it)->metaObject()->className() << endl; QString className = (*it)->metaObject()->className(); if (name.length() > 1 && (className == QString("QCheckBox") || className == QString("MyCheckBox"))) { QCheckBox *checkbox = *it; QString type, parameterName; GetNameAndType(name, ¶meterName, &type); if (className == QString("MyCheckBox")) { MyCheckBox *mycheckbox = (MyCheckBox*) *it; mycheckbox->AssignParameterContainer(par); mycheckbox->AssingParameterName(parameterName); } if (type == QString("checkBox")) { if (mode == read) { bool value = checkbox->isChecked(); par->Set(parameterName, value); } else if (mode == write) { bool value = par->Get<bool>(parameterName); checkbox->setChecked(value); } } } } } WriteLog("cInterface::SynchronizeInterface: QGroupBox", 3); //groupsBox with checkbox { QList<QGroupBox *> widgetListDoubleSpinBox = window->findChildren<QGroupBox*>(); QList<QGroupBox *>::iterator it; for (it = widgetListDoubleSpinBox.begin(); it != widgetListDoubleSpinBox.end(); ++it) { QString name = (*it)->objectName(); //qDebug() << "QGroupBox:" << (*it)->objectName() << " Type:" << (*it)->metaObject()->className() << endl; QString className = (*it)->metaObject()->className(); if (name.length() > 1 && (className == QString("QGroupBox") || className == QString("MyGroupBox"))) { QGroupBox *groupbox = *it; QString type, parameterName; GetNameAndType(name, ¶meterName, &type); if (className == QString("MyGroupBox")) { MyGroupBox *mygroupbox = (MyGroupBox*) *it; mygroupbox->AssignParameterContainer(par); mygroupbox->AssingParameterName(parameterName); } if (type == QString("groupCheck")) { if (mode == read) { bool value = groupbox->isChecked(); par->Set(parameterName, value); } else if (mode == write) { bool value = par->Get<bool>(parameterName); groupbox->setChecked(value); } } } } } WriteLog("cInterface::SynchronizeInterface: FileSelectWidget", 3); //---------- file select widgets ----------- { QList<FileSelectWidget *> widgetListPushButton = window->findChildren<FileSelectWidget*>(); QList<FileSelectWidget *>::iterator it; for (it = widgetListPushButton.begin(); it != widgetListPushButton.end(); ++it) { QString name = (*it)->objectName(); // QString className = (*it)->metaObject()->className(); if (name.length() > 1 && (*it)->metaObject()->className() == QString("FileSelectWidget")) { QString type, parameterName; GetNameAndType(name, ¶meterName, &type); FileSelectWidget *fileSelectWidget = *it; fileSelectWidget->AssignParameterContainer(par); fileSelectWidget->AssingParameterName(parameterName); if (mode == read) { par->Set(parameterName, fileSelectWidget->GetPath()); } else if (mode == write) { fileSelectWidget->SetPath(par->Get<QString>(parameterName)); } } } } WriteLog("cInterface::SynchronizeInterface: MyColorButton", 3); //---------- color buttons ----------- { QList<MyColorButton *> widgetListPushButton = window->findChildren<MyColorButton*>(); QList<MyColorButton *>::iterator it; for (it = widgetListPushButton.begin(); it != widgetListPushButton.end(); ++it) { QString name = (*it)->objectName(); // QString className = (*it)->metaObject()->className(); if (name.length() > 1 && (*it)->metaObject()->className() == QString("MyColorButton")) { QString type, parameterName; GetNameAndType(name, ¶meterName, &type); MyColorButton *colorButton = *it; colorButton->AssignParameterContainer(par); colorButton->AssingParameterName(parameterName); if (mode == read) { par->Set(parameterName, colorButton->GetColor()); } else if (mode == write) { colorButton->setText(""); colorButton->SetColor(par->Get<sRGB>(parameterName)); } } } } WriteLog("cInterface::SynchronizeInterface: ColorPaletteWidget", 3); //---------- colorpalette ----------- { QList<ColorPaletteWidget *> widgetListColorPalette = window->findChildren<ColorPaletteWidget*>(); QList<ColorPaletteWidget *>::iterator it; for (it = widgetListColorPalette.begin(); it != widgetListColorPalette.end(); ++it) { QString name = (*it)->objectName(); //qDebug() << "ColorPalette:" << (*it)->objectName() << " Type:" << (*it)->metaObject()->className() << endl; if (name.length() > 1 && (*it)->metaObject()->className() == QString("ColorPaletteWidget")) { ColorPaletteWidget *colorPaletteWidget = *it; QString type, parameterName; GetNameAndType(name, ¶meterName, &type); colorPaletteWidget->AssignParameterContainer(par); colorPaletteWidget->AssingParameterName(parameterName); if (type == QString("colorpalette")) { if (mode == read) { cColorPalette palette = colorPaletteWidget->GetPalette(); par->Set(parameterName, palette); } else if (mode == write) { cColorPalette palette = par->Get<cColorPalette>(parameterName); colorPaletteWidget->SetPalette(palette); } } } } } WriteLog("cInterface::SynchronizeInterface: QComboBox", 3); //combo boxes { QList<QComboBox *> widgetListPushButton = window->findChildren<QComboBox*>(); QList<QComboBox *>::iterator it; for (it = widgetListPushButton.begin(); it != widgetListPushButton.end(); ++it) { QString name = (*it)->objectName(); //qDebug() << "QComboBox:" << (*it)->objectName() << " Type:" << (*it)->metaObject()->className() << endl; if (name.length() > 1 && (*it)->metaObject()->className() == QString("QComboBox")) { QComboBox *comboBox = *it; QString type, parameterName; GetNameAndType(name, ¶meterName, &type); if (type == QString("comboBox")) { if (mode == read) { int selection = comboBox->currentIndex(); if (parameterName.left(7) == QString("formula")) { selection = fractalList[comboBox->itemData(selection).toInt()].internalID; } par->Set(parameterName, selection); } else if (mode == write) { int selection = par->Get<int>(parameterName); if (parameterName.left(7) == QString("formula")) { for (int i = 0; i < fractalList.size(); i++) { if (fractalList[i].internalID == selection) { selection = comboBox->findData(i); break; } } } comboBox->setCurrentIndex(selection); } } } } } WriteLog("cInterface::SynchronizeInterface: cMaterialSelector", 3); //---------- material selector ----------- { QList<cMaterialSelector *> widgetListMaterialSelector = window->findChildren<cMaterialSelector*>(); QList<cMaterialSelector *>::iterator it; for (it = widgetListMaterialSelector.begin(); it != widgetListMaterialSelector.end(); ++it) { QString name = (*it)->objectName(); // QString className = (*it)->metaObject()->className(); if (name.length() > 1 && (*it)->metaObject()->className() == QString("cMaterialSelector")) { QString type, parameterName; GetNameAndType(name, ¶meterName, &type); cMaterialSelector *materialSelector = *it; materialSelector->AssignParameterContainer(par); materialSelector->AssingParameterName(parameterName); if (type == QString("materialselector")) { if (mode == read) { par->Set(parameterName, materialSelector->GetMaterialIndex()); } else if (mode == write) { materialSelector->SetMaterialIndex(par->Get<int>(parameterName)); } } } } } WriteLog("cInterface::SynchronizeInterface: Done", 3); }
QList<QPair<QLabel*, QWidget*> > QgsVectorLayerSaveAsDialog::createControls( const QMap<QString, QgsVectorFileWriter::Option*>& options ) { QList<QPair<QLabel*, QWidget*> > controls; QMap<QString, QgsVectorFileWriter::Option*>::ConstIterator it; for ( it = options.constBegin(); it != options.constEnd(); ++it ) { QgsVectorFileWriter::Option *option = it.value(); QLabel *label = new QLabel( it.key() ); QWidget *control = 0; switch ( option->type ) { case QgsVectorFileWriter::Int: { QgsVectorFileWriter::IntOption* opt = dynamic_cast<QgsVectorFileWriter::IntOption*>( option ); QSpinBox* sb = new QSpinBox(); sb->setObjectName( it.key() ); sb->setValue( opt->defaultValue ); control = sb; break; } case QgsVectorFileWriter::Set: { QgsVectorFileWriter::SetOption* opt = dynamic_cast<QgsVectorFileWriter::SetOption*>( option ); QComboBox* cb = new QComboBox(); cb->setObjectName( it.key() ); Q_FOREACH ( const QString& val, opt->values ) { cb->addItem( val, val ); } if ( opt->allowNone ) cb->addItem( tr( "<Default>" ), QVariant( QVariant::String ) ); int idx = cb->findText( opt->defaultValue ); if ( idx == -1 ) idx = cb->findData( QVariant( QVariant::String ) ); cb->setCurrentIndex( idx ); control = cb; break; } case QgsVectorFileWriter::String: { QgsVectorFileWriter::StringOption* opt = dynamic_cast<QgsVectorFileWriter::StringOption*>( option ); QLineEdit* le = new QLineEdit( opt->defaultValue ); le->setObjectName( it.key() ); control = le; break; } case QgsVectorFileWriter::Hidden: control = 0; break; } if ( control ) { // Pack the tooltip in some html element, so it gets linebreaks. label->setToolTip( QString( "<p>%1</p>" ).arg( option->docString ) ); control->setToolTip( QString( "<p>%1</p>" ).arg( option->docString ) ); controls << QPair<QLabel*, QWidget*>( label, control ); } } return controls; }
BinCalcWidget::BinCalcWidget(QWidget *parent) : QWidget(parent) , m_value( 0 ) { setAutoFillBackground( true ); setPalette( Qt::green ); QLabel *label = new QLabel; label->setAutoFillBackground( true ); label->setPalette( Qt::yellow ); label->setAlignment( Qt::AlignRight ); QLineEdit *lineEdit = new QLineEdit; lineEdit->setReadOnly( true ); lineEdit->setAlignment( Qt::AlignRight ); // QPushButton *button0 = new QPushButton( "0", this ); // QPushButton *button1 = new QPushButton( "1", this ); QPushButton *button0 = new QPushButton( "0" ); QPushButton *button1 = new QPushButton( "1" ); QPushButton *buttonAdd = new QPushButton( "+" ); QPushButton *buttonSub = new QPushButton( "-" ); QPushButton *buttonMul = new QPushButton( "*" ); QPushButton *buttonDiv = new QPushButton( "/" ); QPushButton *buttonEqual = new QPushButton( "=" ); QPushButton *buttonClear = new QPushButton( "C" ); // button1->move(100, 50); // button0->show(); // button1->show(); QHBoxLayout *layout = new QHBoxLayout; layout->addWidget( button0 ); layout->addWidget( button1 ); QHBoxLayout *operatorLayout = new QHBoxLayout; operatorLayout->addWidget( buttonAdd ); operatorLayout->addWidget( buttonSub ); operatorLayout->addWidget( buttonMul ); operatorLayout->addWidget( buttonDiv ); QHBoxLayout *commandLayout = new QHBoxLayout; commandLayout->addWidget( buttonEqual ); commandLayout->addWidget( buttonClear ); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget( label ); mainLayout->addWidget( lineEdit ); mainLayout->addLayout( layout ); mainLayout->addLayout( operatorLayout ); mainLayout->addLayout( commandLayout ); setLayout( mainLayout ); connect( button0, SIGNAL(clicked(bool)), this, SLOT(numberButtonClicked()) ); connect( button1, SIGNAL(clicked(bool)), this, SLOT(numberButtonClicked()) ); connect( buttonAdd, SIGNAL(clicked(bool)), this, SLOT(operatorButtonClicked()) ); connect( buttonSub, SIGNAL(clicked(bool)), this, SLOT(operatorButtonClicked()) ); connect( buttonMul, SIGNAL(clicked(bool)), this, SLOT(operatorButtonClicked()) ); connect( buttonDiv, SIGNAL(clicked(bool)), this, SLOT(operatorButtonClicked()) ); connect( buttonEqual, SIGNAL(clicked(bool)), this, SLOT(equalButtonClicked()) ); connect( buttonClear, SIGNAL(clicked(bool)), this, SLOT(clearButtonClicked()) ); }
/** Filter the Keyboard events of QLineEdit composing the widget. */ bool FrenchSocialNumber::eventFilter(QObject *o, QEvent *e) { if (e->type()!=QEvent::KeyPress && e->type()!=QEvent::KeyRelease) return false; QKeyEvent *kevent = static_cast<QKeyEvent*>(e); if (!kevent) return false; QLineEdit *l = static_cast<QLineEdit*>(o); if (!l) return false; int currentId = m_Edits.indexOf(l); if (currentId==-1) return false; int nextTab = -1; // only key release events if (kevent->type()==QKeyEvent::KeyPress) { // qWarning() << "KeyPress" << kevent;//;->text() << kevent->key(); switch (kevent->key()) { case Qt::Key_0: case Qt::Key_1: case Qt::Key_2: case Qt::Key_3: case Qt::Key_4: case Qt::Key_5: case Qt::Key_6: case Qt::Key_7: case Qt::Key_8: case Qt::Key_9: case Qt::Key_A: case Qt::Key_B: // no management of auto-repeat e->ignore(); return true; case Qt::Key_Left: // Manage autoRepeat keys if (l->cursorPosition()==0) setCursorPosition(currentId, -1); break; case Qt::Key_Right: // Ok if (l->cursorPosition()==m_NbChars.at(currentId)) { nextTab = currentId+1; if (nextTab >= m_Edits.count()) return true; setCursorPosition(nextTab, 0); return true; } break; case Qt::Key_Backspace: { if (kevent->isAutoRepeat()) { int pos = l->cursorPosition(); removeChar(currentId, pos); --pos; if (pos==0) --pos; setCursorPosition(currentId, pos); } e->ignore(); return true; break; } case Qt::Key_Delete: if (kevent->isAutoRepeat()) { int pos = l->cursorPosition(); ++pos; removeChar(currentId, pos); setCursorPosition(currentId, pos-1); } e->ignore(); return true; default: return false; } } else if (kevent->type()==QKeyEvent::KeyRelease) { // qWarning() << "KeyReleased" << kevent->text() << kevent->key(); switch (kevent->key()) { case Qt::Key_0: case Qt::Key_1: case Qt::Key_2: case Qt::Key_3: case Qt::Key_4: case Qt::Key_5: case Qt::Key_6: case Qt::Key_7: case Qt::Key_8: case Qt::Key_9: { addChar(kevent->text(), currentId, l->cursorPosition()); return true; break; } case Qt::Key_A: case Qt::Key_B: { // only departement 2ndchar if (currentId==3 && l->cursorPosition()==1) { addChar(kevent->text(), currentId, l->cursorPosition()); return true; } break; } case Qt::Key_Home: nextTab = 0; break; case Qt::Key_End: nextTab = m_Edits.count()-2; break; case Qt::Key_Left: // if (l->cursorPosition()==0) { // setCursorPosition(currentId, -1); return true; // } break; case Qt::Key_Right: return true; break; case Qt::Key_Delete: { // remove char at int pos = l->cursorPosition(); ++pos; removeChar(currentId, pos); setCursorPosition(currentId, pos-1); return true; } case Qt::Key_Backspace: { // remove char at int pos = l->cursorPosition(); removeChar(currentId, pos); --pos; if (pos==0) --pos; setCursorPosition(currentId, pos); return true; } default: return false; } } return false; }
phoneWindow::phoneWindow(QWidget *parent, ASkinner *skinner, Phonon::AudioOutput *output) { QLabel *phoneLabel = new QLabel(this); phoneLabel->setText("SonyEricsson K510"); phoneLabel->move(10, 10); phoneLabel->setFixedSize(200, 30); phoneLabel->setFont(QFont("Calibri", 16)); phoneButtons[0][0] = new QPushButton("1", this); phoneButtons[0][0]->setFixedSize(80, 80); phoneButtons[0][0]->move(10, 50); phoneButtons[1][0] = new QPushButton("2", this); phoneButtons[1][0]->setFixedSize(80, 80); phoneButtons[1][0]->move(100, 50); phoneButtons[2][0] = new QPushButton("3", this); phoneButtons[2][0]->setFixedSize(80, 80); phoneButtons[2][0]->move(190, 50); phoneButtons[0][1] = new QPushButton("4", this); phoneButtons[0][1]->setFixedSize(80, 80); phoneButtons[0][1]->move(10, 140); phoneButtons[1][1] = new QPushButton("5", this); phoneButtons[1][1]->setFixedSize(80, 80); phoneButtons[1][1]->move(100, 140); phoneButtons[2][1] = new QPushButton("6", this); phoneButtons[2][1]->setFixedSize(80, 80); phoneButtons[2][1]->move(190, 140); phoneButtons[0][2] = new QPushButton("7", this); phoneButtons[0][2]->setFixedSize(80, 80); phoneButtons[0][2]->move(10, 230); phoneButtons[1][2] = new QPushButton("8", this); phoneButtons[1][2]->setFixedSize(80, 80); phoneButtons[1][2]->move(100, 230); phoneButtons[2][2] = new QPushButton("9", this); phoneButtons[2][2]->setFixedSize(80, 80); phoneButtons[2][2]->move(190, 230); phoneButtons[0][3] = new QPushButton("*", this); phoneButtons[0][3]->setFixedSize(80, 80); phoneButtons[0][3]->move(10, 320); phoneButtons[1][3] = new QPushButton("0", this); phoneButtons[1][3]->setFixedSize(80, 80); phoneButtons[1][3]->move(100, 320); phoneButtons[2][3] = new QPushButton("#", this); phoneButtons[2][3]->setFixedSize(80, 80); phoneButtons[2][3]->move(190, 320); QLineEdit *phoneNumber = new QLineEdit(this); phoneNumber->resize(350, 50); phoneNumber->move(300, 25); phoneNumber->setFont(QFont("Calibri", 20)); phoneNumber->setReadOnly(true); phoneNumber->setText("+74232316158"); ALyxListWidget *contactsList = new ALyxListWidget(this); contactsList->move(300, 100); contactsList->setFixedSize(350, 320); ALyxListWidgetItem *item = new ALyxListWidgetItem(contactsList, "Contact 1\n+79024809956"); contactsList->addItem(item); }
QString JabberSearch::condition(QWidget *w) { QString res; if (m_bXData && (w == NULL)) res += "x:data"; if (w == NULL) w = this; QObjectList *l = w->queryList("QLineEdit"); QObjectListIt it( *l ); QObject *obj; while ((obj = it.current()) != 0 ){ QLineEdit *edit = static_cast<QLineEdit*>(obj); if (!edit->text().isEmpty()){ if (!res.isEmpty()) res += ';'; res += edit->name(); res += '='; res += quoteChars(edit->text(), ";"); } ++it; } delete l; l = w->queryList("QComboBox"); QObjectListIt it1( *l ); while ((obj = it1.current()) != 0 ){ CComboBox *box = static_cast<CComboBox*>(obj); if (box->currentText().isEmpty()){ ++it1; continue; } if (!res.isEmpty()) res += ';'; res += box->name(); res += '='; res += quoteChars(box->value(), ";"); ++it1; } delete l; l = w->queryList("QCheckBox"); QObjectListIt it2( *l ); while ((obj = it2.current()) != 0 ){ QCheckBox *box = static_cast<QCheckBox*>(obj); if (!res.isEmpty()) res += ';'; res += box->name(); res += box->isChecked() ? "=1" : "=0"; ++it2; } delete l; l = w->queryList("QMultiLineEdit"); QObjectListIt it3( *l ); while ((obj = it3.current()) != 0 ){ QMultiLineEdit *edit = static_cast<QMultiLineEdit*>(obj); if (!edit->text().isEmpty()){ if (!res.isEmpty()) res += ';'; res += edit->name(); res += '='; res += quoteChars(edit->text(), ";"); } ++it3; } delete l; if (!m_key.isEmpty() && (w == NULL)){ if (!res.isEmpty()) res += ';'; res += "key="; res += quoteChars(m_key, ";"); } return res; }
QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value ) { if ( !vl ) return 0; QWidget *myWidget = 0; 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; 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 ( data.mAllowNull ) map.insert( nullValue, tr( "(no selection)" ) ); 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 ) { 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; 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 ); } 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 ( myWidget ) { myWidget->setDisabled( editType == QgsVectorLayer::Immutable ); } } 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; } setValue( myWidget, vl, idx, value ); return myWidget; }
OLD_MAIN(QWidget* pParent = nullptr) : QMainWindow(pParent) { Q_INIT_RESOURCE(Resources); // Settings persistence ReadSettings(); // Appearance LUT PlayerApperances appearances; // Build player table model from file PlayerTableModel* playerTableModel = new PlayerTableModel(this); playerTableModel->LoadHittingProjections(appearances); playerTableModel->LoadPitchingProjections(appearances); playerTableModel->CalculateHittingScores(); playerTableModel->CalculatePitchingScores(); playerTableModel->InitializeTargetValues(); // Draft delegate DraftDelegate* draftDelegate = new DraftDelegate(playerTableModel); LinkDelegate* linkDelegate = new LinkDelegate(this); TagDelegate* tagDelegate = new TagDelegate(this); // Hitter sort-model PlayerSortFilterProxyModel* hitterSortFilterProxyModel = new PlayerSortFilterProxyModel(Player::Hitter); hitterSortFilterProxyModel->setSourceModel(playerTableModel); hitterSortFilterProxyModel->setSortRole(PlayerTableModel::RawDataRole); // Hitter table view QTableView* hitterTableView = MakeTableView(hitterSortFilterProxyModel, true, PlayerTableModel::COLUMN_Z); hitterTableView->setItemDelegateForColumn(FindColumn(hitterSortFilterProxyModel, PlayerTableModel::COLUMN_DRAFT_BUTTON), draftDelegate); hitterTableView->setItemDelegateForColumn(FindColumn(hitterSortFilterProxyModel, PlayerTableModel::COLUMN_ID_LINK), linkDelegate); hitterTableView->setItemDelegateForColumn(FindColumn(hitterSortFilterProxyModel, PlayerTableModel::COLUMN_FLAG), tagDelegate); hitterTableView->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked); // Context menu QMenu* contextMenu = new QMenu(); contextMenu->addAction("&Remove Player"); // Apply to hitter table view hitterTableView->setContextMenuPolicy(Qt::CustomContextMenu); connect(hitterTableView, &QWidget::customContextMenuRequested, [=](const QPoint& pos) { QPoint globalPos = hitterTableView->mapToGlobal(pos); QAction* selectedItem = contextMenu->exec(globalPos); if (selectedItem) { auto proxyIndex = hitterTableView->indexAt(pos); auto srcIndex = hitterSortFilterProxyModel->mapToSource(proxyIndex); playerTableModel->RemovePlayer(srcIndex.row()); } }); // Pitcher sort-model PlayerSortFilterProxyModel* pitcherSortFilterProxyModel = new PlayerSortFilterProxyModel(Player::Pitcher); pitcherSortFilterProxyModel->setSourceModel(playerTableModel); pitcherSortFilterProxyModel->setSortRole(PlayerTableModel::RawDataRole); // Pitcher table view QTableView* pitcherTableView = MakeTableView(pitcherSortFilterProxyModel, true, PlayerTableModel::COLUMN_Z); pitcherTableView->setItemDelegateForColumn(FindColumn(pitcherSortFilterProxyModel, PlayerTableModel::COLUMN_DRAFT_BUTTON), draftDelegate); pitcherTableView->setItemDelegateForColumn(FindColumn(pitcherSortFilterProxyModel, PlayerTableModel::COLUMN_ID_LINK), linkDelegate); pitcherTableView->setItemDelegateForColumn(FindColumn(pitcherSortFilterProxyModel, PlayerTableModel::COLUMN_FLAG), tagDelegate); pitcherTableView->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked); // Top/Bottom splitter QSplitter* topBottomSplitter = new QSplitter(Qt::Vertical); topBottomSplitter->setContentsMargins(5, 5, 5, 5); // Hitter/Pitcher tab View enum PlayerTableTabs { Hitters, Pitchers, Unknown }; QTabWidget* hitterPitcherTabs = new QTabWidget(this); hitterPitcherTabs->insertTab(PlayerTableTabs::Hitters, hitterTableView, "Hitters"); hitterPitcherTabs->insertTab(PlayerTableTabs::Pitchers, pitcherTableView, "Pitchers"); topBottomSplitter->addWidget(hitterPitcherTabs); // Tab lookup helper auto CaterogyToTab = [](uint32_t catergory) { switch (catergory) { case Player::Hitter: return PlayerTableTabs::Hitters; case Player::Pitcher: return PlayerTableTabs::Pitchers; default: return PlayerTableTabs::Unknown; } }; // Drafted filter action QAction* filterDrafted = new QAction(this); connect(filterDrafted, &QAction::toggled, hitterSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterDrafted); connect(filterDrafted, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterDrafted); filterDrafted->setText(tr("Drafted")); filterDrafted->setToolTip("Toggle Drafted Players"); filterDrafted->setCheckable(true); filterDrafted->toggle(); QAction* filterReplacement = new QAction(this); connect(filterReplacement, &QAction::toggled, hitterSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterReplacement); connect(filterReplacement, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterReplacement); filterReplacement->setText(tr("($1)")); filterReplacement->setToolTip("Toggle replacements players with value under $1"); filterReplacement->setCheckable(true); filterReplacement->toggle(); // NL filter action QAction* filterNL = new QAction(this); connect(filterNL, &QAction::toggled, hitterSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterNL); connect(filterNL, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterNL); filterNL->setText(tr("NL")); filterNL->setToolTip("Toggle National Leauge"); filterNL->setCheckable(true); filterNL->toggle(); // AL filter action QAction* filterAL = new QAction(this); connect(filterAL, &QAction::toggled, hitterSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterAL); connect(filterAL, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterAL); filterAL->setText(tr("AL")); filterAL->setToolTip("Toggle American Leauge"); filterAL->setCheckable(true); filterAL->toggle(); // FA filter action QAction* filterFA = new QAction(this); connect(filterFA, &QAction::toggled, hitterSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterFA); connect(filterFA, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterFA); filterFA->setText(tr("FA")); filterFA->setToolTip("Toggle Free Agents"); filterFA->setCheckable(true); filterAL->toggle(); filterAL->toggle(); // General filter group QActionGroup* generalFilters = new QActionGroup(this); generalFilters->addAction(filterAL); generalFilters->addAction(filterNL); generalFilters->addAction(filterFA); generalFilters->setExclusive(false); // Starter filter action QAction* filterStarter = new QAction(this); connect(filterStarter, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterSP); filterStarter->setText(tr("SP")); filterStarter->setToolTip("Toggle Starting Pitchers"); filterStarter->setCheckable(true); filterStarter->toggle(); // Relief filter action QAction* filterRelief = new QAction(this); connect(filterRelief, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterRP); filterRelief->setText(tr("RP")); filterRelief->setToolTip("Toggle Relief Pitchers"); filterRelief->setCheckable(true); filterRelief->toggle(); // Pitching filter group QActionGroup* pitchingFilters = new QActionGroup(this); pitchingFilters->addAction(filterStarter); pitchingFilters->addAction(filterRelief); pitchingFilters->setExclusive(false); // Hitting filter group QActionGroup* hittingFilters = new QActionGroup(this); hittingFilters->setExclusive(false); // Filter helper auto MakeHitterFilter = [=](QString text, QString toolTip, const auto& onFilterFn) -> QAction* { QAction* action = new QAction(this); connect(action, &QAction::toggled, hitterSortFilterProxyModel, onFilterFn); action->setText(text); action->setToolTip(toolTip); action->setCheckable(true); action->toggle(); hittingFilters->addAction(action); return action; }; // Hitter filters QAction* filterC = MakeHitterFilter("C", "Filter Catchers", &PlayerSortFilterProxyModel::OnFilterC); QAction* filter1B = MakeHitterFilter("1B", "Filter 1B", &PlayerSortFilterProxyModel::OnFilter1B); QAction* filter2B = MakeHitterFilter("2B", "Filter 2B", &PlayerSortFilterProxyModel::OnFilter2B); QAction* filterSS = MakeHitterFilter("SS", "Filter SS", &PlayerSortFilterProxyModel::OnFilterSS); QAction* filter3B = MakeHitterFilter("3B", "Filter 3B", &PlayerSortFilterProxyModel::OnFilter3B); QAction* filterOF = MakeHitterFilter("OF", "Filter Outfielders", &PlayerSortFilterProxyModel::OnFilterOF); QAction* filterCI = MakeHitterFilter("CI", "Filter Corner Infielders", &PlayerSortFilterProxyModel::OnFilterCI); QAction* filterMI = MakeHitterFilter("MI", "Filter Middle Infielders", &PlayerSortFilterProxyModel::OnFilterMI); QAction* filterDH = MakeHitterFilter("DH", "Filter Designated Hitters", &PlayerSortFilterProxyModel::OnFilterDH); QAction* filterU = MakeHitterFilter("U", "Filter Utility", &PlayerSortFilterProxyModel::OnFilterU); // Menu spacer QWidget* spacer = new QWidget(this); spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // Completion Widget QCompleter* completer = new QCompleter(this); completer->setModel(playerTableModel); completer->setCompletionColumn(PlayerTableModel::COLUMN_NAME); completer->setFilterMode(Qt::MatchContains); completer->setCaseSensitivity(Qt::CaseInsensitive); // Select auto HighlightPlayerInTable = [=](const QModelIndex& srcIdx) { // Lookup catergory auto catergoryIdx = srcIdx.model()->index(srcIdx.row(), PlayerTableModel::COLUMN_CATERGORY); auto catergory = srcIdx.model()->data(catergoryIdx).toUInt(); // Change to tab hitterPitcherTabs->setCurrentIndex(CaterogyToTab(catergory)); // Select row if (catergory == Player::Catergory::Hitter) { auto proxyModel = dynamic_cast<QSortFilterProxyModel*>(hitterTableView->model()); auto proxyIdx = proxyModel->mapFromSource(srcIdx); hitterTableView->selectRow(proxyIdx.row()); hitterTableView->setFocus(); } else if (catergory == Player::Catergory::Pitcher) { auto proxyModel = dynamic_cast<QSortFilterProxyModel*>(pitcherTableView->model()); auto proxyIdx = proxyModel->mapFromSource(srcIdx); pitcherTableView->selectRow(proxyIdx.row()); pitcherTableView->setFocus(); } }; // Select the target connect(completer, static_cast<void (QCompleter::*)(const QModelIndex&)>(&QCompleter::activated), [=](const QModelIndex& index) { // Get player index QAbstractProxyModel* proxyModel = dynamic_cast<QAbstractProxyModel*>(completer->completionModel()); auto srcIdx = proxyModel->mapToSource(index); // Highlight this player HighlightPlayerInTable(srcIdx); }); // Search widget QLineEdit* playerSearch = new QLineEdit(this); playerSearch->setCompleter(completer); // Main toolbar QToolBar* toolbar = new QToolBar("Toolbar"); toolbar->addWidget(new QLabel(" Status: ", this)); toolbar->addActions(QList<QAction*>{filterDrafted, filterReplacement}); toolbar->addSeparator(); toolbar->addWidget(new QLabel(" Leagues: ", this)); toolbar->addActions(QList<QAction*>{filterAL, filterNL, filterFA}); toolbar->addSeparator(); toolbar->addWidget(new QLabel(" Positions: ", this)); toolbar->addActions(QList<QAction*>{filterStarter, filterRelief}); toolbar->addActions(QList<QAction*>{filterC, filter1B, filter2B, filterSS, filter3B, filterOF, filterCI, filterMI, filterDH, filterU}); toolbar->addWidget(spacer); toolbar->addWidget(new QLabel("Player Search: ", this)); toolbar->addWidget(playerSearch); toolbar->setFloatable(false); toolbar->setMovable(false); QMainWindow::addToolBar(toolbar); // Helper to adjust filters auto ToggleFilterGroups = [=](int index) { switch (index) { case uint32_t(PlayerTableTabs::Hitters): pitchingFilters->setVisible(false); hittingFilters->setVisible(true); break; case uint32_t(PlayerTableTabs::Pitchers): pitchingFilters->setVisible(true); hittingFilters->setVisible(false); break; default: break; } }; // Set default filter group ToggleFilterGroups(hitterPitcherTabs->currentIndex()); //--------------------------------------------------------------------- // Bottom Section //--------------------------------------------------------------------- // Owner widget QHBoxLayout* ownersLayout = new QHBoxLayout(this); ownersLayout->setSizeConstraint(QLayout::SetNoConstraint); // Owner models std::vector<OwnerSortFilterProxyModel*> vecOwnerSortFilterProxyModels; // Owner labels QList<QLabel*>* pVecOwnerLabels; pVecOwnerLabels = new QList<QLabel*>(); pVecOwnerLabels->append(new QLabel("--")); for (auto i = 1u; i <= DraftSettings::Get().OwnerCount; i++) { pVecOwnerLabels->append(new QLabel(DraftSettings::Get().OwnerNames[i])); } // Update label helper auto UpdateOwnerLabels = [=]() { for (auto i = 1u; i <= DraftSettings::Get().OwnerCount; i++) { pVecOwnerLabels->at(i)->setText(DraftSettings::Get().OwnerNames[i]); } }; // Initialize UpdateOwnerLabels(); // Loop owners for (uint32_t ownerId = 1; ownerId <= DraftSettings::Get().OwnerCount; ownerId++) { // V-Layout per owner QVBoxLayout* perOwnerLayout = new QVBoxLayout(this); ownersLayout->addLayout(perOwnerLayout); perOwnerLayout->setSizeConstraint(QLayout::SetNoConstraint); // Proxy model for this owner OwnerSortFilterProxyModel* ownerSortFilterProxyModel = new OwnerSortFilterProxyModel(ownerId, playerTableModel, this); vecOwnerSortFilterProxyModels.push_back(ownerSortFilterProxyModel); // Owner name label pVecOwnerLabels->at(ownerId)->setAlignment(Qt::AlignCenter); perOwnerLayout->addWidget(pVecOwnerLabels->at(ownerId)); // Per-owner roster table view const uint32_t tableWidth = 225; QTableView* ownerRosterTableView = MakeTableView(ownerSortFilterProxyModel, true, 0); ownerRosterTableView->setMinimumSize(tableWidth, 65); ownerRosterTableView->setMaximumSize(tableWidth, 4096); ownerRosterTableView->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); perOwnerLayout->addWidget(ownerRosterTableView); // XXX: This should be a form layout... QGridLayout* ownerSummaryGridLayout = new QGridLayout(this); ownerSummaryGridLayout->setSpacing(0); ownerSummaryGridLayout->addWidget(MakeLabel("Budget: "), 0, 0); ownerSummaryGridLayout->addWidget(MakeLabel("# Hitters: "), 1, 0); ownerSummaryGridLayout->addWidget(MakeLabel("# Pitchers: "), 2, 0); ownerSummaryGridLayout->addWidget(MakeLabel("Max Bid: "), 3, 0); QLabel* budgetLabel = MakeLabel(); QLabel* numHittersLabel = MakeLabel(); QLabel* numPitchersLabel = MakeLabel(); QLabel* maxBidLabel = MakeLabel(); // Helper auto UpdateLabels = [=]() { budgetLabel->setText(QString("$%1").arg(ownerSortFilterProxyModel->GetRemainingBudget())); numHittersLabel->setText(QString("%1 / %2").arg(ownerSortFilterProxyModel->Count(Player::Hitter)).arg(DraftSettings::Get().HitterCount)); numPitchersLabel->setText(QString("%1 / %2").arg(ownerSortFilterProxyModel->Count(Player::Pitcher)).arg(DraftSettings::Get().PitcherCount)); maxBidLabel->setText(QString("$%1").arg(ownerSortFilterProxyModel->GetMaxBid())); }; // Update labels when a draft event happens connect(playerTableModel, &PlayerTableModel::DraftedEnd, [=]() { UpdateLabels(); }); UpdateLabels(); ownerSummaryGridLayout->addWidget(budgetLabel, 0, 1); ownerSummaryGridLayout->addWidget(numHittersLabel, 1, 1); ownerSummaryGridLayout->addWidget(numPitchersLabel, 2, 1); ownerSummaryGridLayout->addWidget(maxBidLabel, 3, 1); QSpacerItem* spacer = new QSpacerItem(1, 1, QSizePolicy::Preferred, QSizePolicy::Preferred); ownerSummaryGridLayout->addItem(spacer, 0, 2); ownerSummaryGridLayout->addItem(spacer, 1, 2); ownerSummaryGridLayout->addItem(spacer, 2, 2); ownerSummaryGridLayout->addItem(spacer, 3, 2); perOwnerLayout->addLayout(ownerSummaryGridLayout); perOwnerLayout->addSpacerItem(spacer); } // Owner widget QWidget* scrollAreaWidgetContents = new QWidget(this); scrollAreaWidgetContents->setLayout(ownersLayout); scrollAreaWidgetContents->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); // Owner scroll area QScrollArea* ownerScrollArea = new QScrollArea(this); ownerScrollArea->setWidget(scrollAreaWidgetContents); ownerScrollArea->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); ownerScrollArea->setBackgroundRole(QPalette::Light); ownerScrollArea->setFrameShape(QFrame::NoFrame); ownerScrollArea->setWidgetResizable(true); // Target value widget QWidget* targetValueWidget = new QWidget(this); QFormLayout* targetValueLayout = new QFormLayout(this); targetValueWidget->setLayout(targetValueLayout); auto values = { PlayerTableModel::COLUMN_AVG, PlayerTableModel::COLUMN_HR, PlayerTableModel::COLUMN_R, PlayerTableModel::COLUMN_RBI, PlayerTableModel::COLUMN_SB, PlayerTableModel::COLUMN_SO, PlayerTableModel::COLUMN_ERA, PlayerTableModel::COLUMN_WHIP, PlayerTableModel::COLUMN_W, PlayerTableModel::COLUMN_SV, }; for (auto value : values) { auto name = playerTableModel->headerData(value, Qt::Horizontal, Qt::DisplayRole).toString(); auto target = QString::number(playerTableModel->GetTargetValue(value), 'f', 3); targetValueLayout->addRow(name, new QLabel(target)); } // Player scatter plot PlayerScatterPlotChart* chartView = new PlayerScatterPlotChart(playerTableModel, hitterSortFilterProxyModel, this); connect(hitterSortFilterProxyModel, &QSortFilterProxyModel::layoutChanged, chartView, &PlayerScatterPlotChart::Update); connect(pitcherSortFilterProxyModel, &QSortFilterProxyModel::layoutChanged, chartView, &PlayerScatterPlotChart::Update); connect(playerTableModel, &QAbstractItemModel::dataChanged, chartView, &PlayerScatterPlotChart::Update); // Summary view SummaryWidget* summary = new SummaryWidget(playerTableModel, vecOwnerSortFilterProxyModels, this); // Bottom tabs enum BottomSectionTabs { Rosters, Summary, Targets, ChartView, Log }; QTabWidget* bottomTabs = new QTabWidget(this); topBottomSplitter->addWidget(bottomTabs); bottomTabs->insertTab(BottomSectionTabs::Rosters, ownerScrollArea, "Rosters"); bottomTabs->insertTab(BottomSectionTabs::Summary, summary, "Summary"); bottomTabs->insertTab(BottomSectionTabs::Targets, targetValueWidget, "Targets"); bottomTabs->insertTab(BottomSectionTabs::ChartView, chartView, "Scatter Chart"); bottomTabs->insertTab(BottomSectionTabs::Log, GlobalLogger::Get(), "Log"); // Make top section 3x the size of the bottom topBottomSplitter->setStretchFactor(0, 3); topBottomSplitter->setStretchFactor(1, 1); //---------------------------------------------------------------------- // Connections //---------------------------------------------------------------------- // Connect tab filters connect(hitterPitcherTabs, &QTabWidget::currentChanged, this, [=](int index) { // Update filters ToggleFilterGroups(index); // Update chart view switch (index) { case PlayerTableTabs::Hitters: chartView->SetProxyModel(hitterSortFilterProxyModel); break; case PlayerTableTabs::Pitchers: chartView->SetProxyModel(pitcherSortFilterProxyModel); break; default: break; } }); // Connect chart click connect(chartView, &PlayerScatterPlotChart::PlayerClicked, this, [=](const QModelIndex& index) { HighlightPlayerInTable(index); }); // Connect summary model connect(playerTableModel, &PlayerTableModel::DraftedEnd, summary, &SummaryWidget::OnDraftedEnd); //---------------------------------------------------------------------- // Main //---------------------------------------------------------------------- // Set as main window QMainWindow::setCentralWidget(topBottomSplitter); // Create main menu bar QMenuBar* mainMenuBar = new QMenuBar(); QMainWindow::setMenuBar(mainMenuBar); // Main Menu > File menu QMenu* fileMenu = mainMenuBar->addMenu("&File"); // File dialog helper auto GetFileDialog = [&](QFileDialog::AcceptMode mode) -> QFileDialog* { QFileDialog* dialog = new QFileDialog(this); dialog->setWindowModality(Qt::WindowModal); dialog->setAcceptMode(mode); dialog->setNameFilter("CSV files (*.csv)"); return dialog; }; // Ask for the save location auto SetSaveAsFile = [=]() { QStringList files; auto dialog = GetFileDialog(QFileDialog::AcceptSave); if (dialog->exec()) { files = dialog->selectedFiles(); } else { return false; } m_currentFile = files.at(0); return true; }; // Update title bar auto UpdateApplicationName = [this]() { auto name = QString("fbb -- %1").arg(QFileInfo(m_currentFile).fileName()); QCoreApplication::setApplicationName(name); setWindowTitle(name); }; // Main Menu > File menu > Save action QAction* saveResultsAction = new QAction("&Save Results", this); connect(saveResultsAction, &QAction::triggered, [=](bool checked) { if (m_currentFile.isEmpty()) { SetSaveAsFile(); } GlobalLogger::AppendMessage(QString("Saving file: %1...").arg(m_currentFile)); UpdateApplicationName(); return playerTableModel->SaveDraftStatus(m_currentFile); }); fileMenu->addAction(saveResultsAction); // Main Menu > File menu > Save As action QAction* saveResultsAsAction = new QAction("Save Results &As...", this); connect(saveResultsAsAction, &QAction::triggered, [=](bool checked) { SetSaveAsFile(); GlobalLogger::AppendMessage(QString("Saving file: %1...").arg(m_currentFile)); UpdateApplicationName(); return playerTableModel->SaveDraftStatus(m_currentFile); }); fileMenu->addAction(saveResultsAsAction); // Main Menu > File menu > Load action QAction* loadResultsAction = new QAction("&Load Results...", this); connect(loadResultsAction, &QAction::triggered, [=](bool checked) { auto dialog = GetFileDialog(QFileDialog::AcceptOpen); QStringList files; if (dialog->exec()) { files = dialog->selectedFiles(); } else { return false; } m_currentFile = files.at(0); GlobalLogger::AppendMessage(QString("Loading file: %1...").arg(m_currentFile)); UpdateApplicationName(); return playerTableModel->LoadDraftStatus(m_currentFile); }); fileMenu->addAction(loadResultsAction); // Main Menu > File menu QMenu* settingsMenu = mainMenuBar->addMenu("&Settings"); // Main Menu > Settings menu > Options action QAction* settingsAction = new QAction("&Settings...", this); connect(settingsAction, &QAction::triggered, [=](bool checked) { DraftSettingsDialog draftSettingsDialog; if (draftSettingsDialog.exec()) { UpdateOwnerLabels(); } }); settingsMenu->addAction(settingsAction); // Main Menu > Settings menu > Options action QAction* demoDataAction = new QAction("&DemoData...", this); connect(demoDataAction, &QAction::triggered, [=](bool checked) { playerTableModel->DraftRandom(); }); settingsMenu->addAction(demoDataAction); // show me QMainWindow::show(); }
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; }
void PropertiesEditorItem::slotPropertyValueChanged() { if (mProperty.type() == QVariant::BitArray) { } else if (mProperty.type() == QVariant::Bitmap) { } else if (mProperty.type() == QVariant::Bool) { QCheckBox *checkBox = qobject_cast<QCheckBox*>(mWidget.data()); checkBox->setChecked(mProperty.read(mObject.data()).toBool()); } else if (mProperty.type() == QVariant::Brush) { } else if (mProperty.type() == QVariant::ByteArray) { } else if (mProperty.type() == QVariant::Char) { } else if (mProperty.type() == QVariant::Color) { } else if (mProperty.type() == QVariant::Cursor) { } else if (mProperty.type() == QVariant::Date) { } else if (mProperty.type() == QVariant::DateTime) { } else if (mProperty.type() == QVariant::Double) { QDoubleSpinBox *spinBox = qobject_cast<QDoubleSpinBox*>(mWidget.data()); spinBox->setValue(mProperty.read(mObject.data()).toDouble()); } else if (mProperty.type() == QVariant::EasingCurve) { QPushButton *button = qobject_cast<QPushButton*>(mWidget.data()); QEasingCurve curve = mProperty.read(mObject.data()).toEasingCurve(); button->setText(curve.staticMetaObject.enumerator(0).valueToKey(curve.type())); } else if (mProperty.type() == QVariant::Font) { QFontComboBox *comboBox = qobject_cast<QFontComboBox*>(mWidget.data()); comboBox->setCurrentFont(mProperty.read(mObject.data()).value<QFont>()); } else if (mProperty.type() == QVariant::Hash) { } else if (mProperty.type() == QVariant::Icon) { } else if (mProperty.type() == QVariant::Image) { } else if (mProperty.type() == QVariant::Int) { QSpinBox *spinBox = qobject_cast<QSpinBox*>(mWidget.data()); spinBox->setValue(mProperty.read(mObject.data()).toInt()); } else if (mProperty.type() == QVariant::KeySequence) { } else if (mProperty.type() == QVariant::Line) { } else if (mProperty.type() == QVariant::LineF) { } else if (mProperty.type() == QVariant::List) { } else if (mProperty.type() == QVariant::Locale) { } else if (mProperty.type() == QVariant::LongLong) { QDoubleSpinBox *spinBox = qobject_cast<QDoubleSpinBox*>(mWidget.data()); spinBox->setValue(mProperty.read(mObject.data()).toLongLong()); } else if (mProperty.type() == QVariant::Map) { } else if (mProperty.type() == QVariant::Matrix) { } else if (mProperty.type() == QVariant::Matrix4x4) { } else if (mProperty.type() == QVariant::Palette) { } else if (mProperty.type() == QVariant::Pen) { } else if (mProperty.type() == QVariant::Pixmap) { } else if (mProperty.type() == QVariant::Point) { } else if (mProperty.type() == QVariant::PointF) { } else if (mProperty.type() == QVariant::Polygon) { } else if (mProperty.type() == QVariant::Quaternion) { } else if (mProperty.type() == QVariant::Rect) { } else if (mProperty.type() == QVariant::RectF) { } else if (mProperty.type() == QVariant::RegExp) { } else if (mProperty.type() == QVariant::Region) { } else if (mProperty.type() == QVariant::Size) { } else if (mProperty.type() == QVariant::SizeF) { } else if (mProperty.type() == QVariant::SizePolicy) { } else if (mProperty.type() == QVariant::String) { QLineEdit *lineEdit = qobject_cast<QLineEdit*>(mWidget.data()); lineEdit->setText(mProperty.read(mObject.data()).toString()); } else if (mProperty.type() == QVariant::StringList) { } else if (mProperty.type() == QVariant::TextFormat) { } else if (mProperty.type() == QVariant::TextLength) { } else if (mProperty.type() == QVariant::Time) { } else if (mProperty.type() == QVariant::Transform) { } else if (mProperty.type() == QVariant::UInt) { QSpinBox *spinBox = qobject_cast<QSpinBox*>(mWidget.data()); spinBox->setValue(mProperty.read(mObject.data()).toUInt()); } else if (mProperty.type() == QVariant::ULongLong) { QDoubleSpinBox *spinBox = qobject_cast<QDoubleSpinBox*>(mWidget.data()); spinBox->setValue(mProperty.read(mObject.data()).toULongLong()); } else if (mProperty.type() == QVariant::Url) { QPushButton *button = qobject_cast<QPushButton*>(mWidget.data()); QUrl url = mProperty.read(mObject.data()).toUrl(); setButtonUrl(button, url); } else if (mProperty.type() == QVariant::UserType) { } else if (mProperty.type() == QVariant::Vector2D) { } else if (mProperty.type() == QVariant::Vector3D) { } else if (mProperty.type() == QVariant::Vector4D) { } }
bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value ) { if ( !editor ) return false; QgsVectorLayer::EditType editType = vl->editType( idx ); const QgsField &field = vl->pendingFields()[idx]; QVariant::Type myFieldType = field.type(); QSettings settings; QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString(); switch ( editType ) { case QgsVectorLayer::Classification: case QgsVectorLayer::UniqueValues: case QgsVectorLayer::Enumeration: case QgsVectorLayer::ValueMap: case QgsVectorLayer::ValueRelation: { QVariant v = value; QComboBox *cb = qobject_cast<QComboBox *>( editor ); if ( !cb ) return false; if ( v.isNull() ) { v = nullValue; } int idx = cb->findData( v ); if ( idx < 0 ) return false; cb->setCurrentIndex( idx ); } break; case QgsVectorLayer::DialRange: case QgsVectorLayer::SliderRange: case QgsVectorLayer::EditRange: { if ( myFieldType == QVariant::Int ) { if ( editType == QgsVectorLayer::EditRange ) { QSpinBox *sb = qobject_cast<QSpinBox *>( editor ); if ( !sb ) return false; sb->setValue( value.toInt() ); } else { QAbstractSlider *sl = qobject_cast<QAbstractSlider *>( editor ); if ( !sl ) return false; sl->setValue( value.toInt() ); } break; } else if ( myFieldType == QVariant::Double ) { QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox *>( editor ); if ( !dsb ) return false; dsb->setValue( value.toDouble() ); } } case QgsVectorLayer::CheckBox: { QCheckBox *cb = qobject_cast<QCheckBox *>( editor ); if ( cb ) { QPair<QString, QString> states = vl->checkedState( idx ); cb->setChecked( value == states.first ); break; } } // fall-through case QgsVectorLayer::LineEdit: case QgsVectorLayer::UniqueValuesEditable: case QgsVectorLayer::Immutable: case QgsVectorLayer::UuidGenerator: default: { QLineEdit *le = qobject_cast<QLineEdit *>( editor ); QTextEdit *te = qobject_cast<QTextEdit *>( editor ); QPlainTextEdit *pte = qobject_cast<QPlainTextEdit *>( editor ); if ( !le && !te && !pte ) return false; QString text; if ( value.isNull() ) { if ( myFieldType == QVariant::Int || myFieldType == QVariant::Double || myFieldType == QVariant::LongLong ) text = ""; else if ( editType == QgsVectorLayer::UuidGenerator ) text = QUuid::createUuid().toString(); else text = nullValue; } else { text = value.toString(); } if ( le ) le->setText( text ); if ( te ) te->setHtml( text ); if ( pte ) pte->setPlainText( text ); } break; case QgsVectorLayer::FileName: case QgsVectorLayer::Calendar: { QLineEdit* le = qobject_cast<QLineEdit*>( editor ); if ( !le ) { le = editor->findChild<QLineEdit *>(); } if ( !le ) { return false; } le->setText( value.toString() ); } break; } return true; }
void ScriptParametersDialog::accept() { int rowCount = ui->parameterTable->rowCount(); QScriptEngine scriptEngine; mScript->removeAllParameters(); for(int row = 0; row < rowCount; ++row) { QWidget *widget = ui->parameterTable->cellWidget(row, 0); if(!widget) continue; QLineEdit *nameLineEdit = qobject_cast<QLineEdit *>(widget); widget = ui->parameterTable->cellWidget(row, 1); if(!widget) continue; if(nameLineEdit->text().isEmpty()) continue; QRegExp nameRegExp("[a-z_][a-z0-9_]*", Qt::CaseInsensitive); if(!nameRegExp.exactMatch(nameLineEdit->text())) { QMessageBox::warning(this, tr("Script parameter error"), tr("Incorrect parameter name \"%1\".") .arg(nameLineEdit->text())); nameLineEdit->setFocus(); return; } bool isCode = false; QString value; switch(mParameterTypes.at(row)) { case ActionTools::ScriptParameter::Text: { ActionTools::CodeLineEdit *valueWidget = qobject_cast<ActionTools::CodeLineEdit *>(widget); isCode = valueWidget->isCode(); value = valueWidget->text(); } break; case ActionTools::ScriptParameter::Number: { ActionTools::CodeSpinBox *valueWidget = qobject_cast<ActionTools::CodeSpinBox *>(widget); isCode = valueWidget->isCode(); value = valueWidget->text(); } break; case ActionTools::ScriptParameter::Window: { ActionTools::WindowEdit *valueWidget = qobject_cast<ActionTools::WindowEdit *>(widget); isCode = valueWidget->isCode(); value = valueWidget->text(); } break; case ActionTools::ScriptParameter::File: { ActionTools::FileEdit *valueWidget = qobject_cast<ActionTools::FileEdit *>(widget); isCode = valueWidget->isCode(); value = valueWidget->text(); } break; case ActionTools::ScriptParameter::Line: { ActionTools::LineComboBox *valueWidget = qobject_cast<ActionTools::LineComboBox *>(widget); isCode = valueWidget->isCode(); value = valueWidget->codeLineEdit()->text(); } break; } if(isCode) { QScriptSyntaxCheckResult result = scriptEngine.checkSyntax(value); if(result.state() != QScriptSyntaxCheckResult::Valid) { QMessageBox::warning(this, tr("Script parameter error"), tr("The script parameter named \"%1\" contains an error: \"%2\", please correct it.") .arg(nameLineEdit->text()) .arg(result.errorMessage())); widget->setFocus(); return; } } mScript->addParameter(ActionTools::ScriptParameter(nameLineEdit->text(), value, isCode, mParameterTypes.at(row))); } QDialog::accept(); }
void MyPhoneLineEditDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QString value = index.model()->data(index,Qt::EditRole).toString(); QLineEdit *lineedit = static_cast<QLineEdit*>(editor); lineedit->setText(value); }
/** Filter the Keyboard events of QLineEdit composing the widget. */ bool AustrianSocialNumberEdit::eventFilter(QObject *obj, QEvent *e) { if (e->type()!=QEvent::KeyPress && e->type()!=QEvent::KeyRelease) return false; QKeyEvent *kevent = static_cast<QKeyEvent*>(e); if (!kevent) return false; QLineEdit *lineEdit = static_cast<QLineEdit*>(obj); if (!lineEdit) return false; int currentId = m_Edits.indexOf(lineEdit); if (currentId==-1) return false; int nextTab = -1; // only key release events if (kevent->type()==QKeyEvent::KeyPress) { // qWarning() << "KeyPress" << kevent;//;->text() << kevent->key(); switch (kevent->key()) { case Qt::Key_0: case Qt::Key_1: case Qt::Key_2: case Qt::Key_3: case Qt::Key_4: case Qt::Key_5: case Qt::Key_6: case Qt::Key_7: case Qt::Key_8: case Qt::Key_9: return false; if(lineEdit->cursorPosition() == lineEdit->maxLength()-1) { focusNextChild(); return false; } case Qt::Key_Right: // Ok if (lineEdit->cursorPosition()==lineEdit->maxLength() // if we are at the end of the edit && currentId != m_Edits.count()-1) { // and it's not the last edit in the Widget focusNextChild(); } return true; case Qt::Key_Left: // Manage autoRepeat keys if (lineEdit->cursorPosition()==0 // if we are at the beginning of the edit && currentId != 0) { // and it's not the first edit in the widget focusPreviousChild(); // -> go one edit left } return true; case Qt::Key_Backspace: { if (lineEdit->cursorPosition() == 0 // if we are at the beginning of the edit && currentId != 0) { // and it's not the first edit in the widget focusPreviousChild(); return false; // process Backspace as usual // if (kevent->isAutoRepeat()) { // int pos = lineEdit->cursorPosition(); // removeChar(currentId, pos); // --pos; // if (pos==0) --pos; // setCursorPosition(currentId, pos); } // e->ignore(); return false; // break; } case Qt::Key_Delete: if (kevent->isAutoRepeat()) { int pos = lineEdit->cursorPosition(); ++pos; removeChar(currentId, pos); setCursorPosition(currentId, pos-1); } e->ignore(); return true; default: return false; } } // else if (kevent->type()==QKeyEvent::KeyRelease) { // // qWarning() << "KeyReleased" << kevent->text() << kevent->key(); // switch (kevent->key()) { // case Qt::Key_0: // case Qt::Key_1: // case Qt::Key_2: // case Qt::Key_3: // case Qt::Key_4: // case Qt::Key_5: // case Qt::Key_6: // case Qt::Key_7: // case Qt::Key_8: // case Qt::Key_9: // { // addChar(kevent->text(), currentId, lineEdit->cursorPosition()); // return true; // break; // } // case Qt::Key_Home: // nextTab = 0; // break; // case Qt::Key_End: // nextTab = m_Edits.count()-2; // break; // case Qt::Key_Left: //// if (l->cursorPosition()==0) { //// setCursorPosition(currentId, -1); // return true; //// } // break; // case Qt::Key_Right: // return true; // break; // case Qt::Key_Delete: // { // // remove char at // int pos = lineEdit->cursorPosition(); // ++pos; // removeChar(currentId, pos); // setCursorPosition(currentId, pos-1); // return true; // } // case Qt::Key_Backspace: // { // // remove char at // int pos = lineEdit->cursorPosition(); // removeChar(currentId, pos); // --pos; // if (pos==0) --pos; // setCursorPosition(currentId, pos); // return true; // } // default: return false; // } // } return false; }
/* Handle Ctrl+Cursor etc better than the Qt widget, which always jumps to the next whitespace. This code additionally jumps to the next [/#?:], which makes more sense for URLs. The list of chars that will stop the cursor are '/', '.', '?', '#', ':'. */ void KLSHistoryCombo::selectWord(QKeyEvent *e) { QLineEdit* edit = lineEdit(); QString text = edit->text(); int pos = edit->cursorPosition(); int pos_old = pos; int count = 0; // TODO: make these a parameter when in kdelibs/kdeui... QValueList<QChar> chars; chars << QChar('/') << QChar('.') << QChar('?') << QChar('#') << QChar(':'); bool allow_space_break = true; if( e->key() == Key_Left || e->key() == Key_Backspace ) { do { pos--; count++; if( allow_space_break && text[pos].isSpace() && count > 1 ) break; } while( pos >= 0 && (chars.findIndex(text[pos]) == -1 || count <= 1) ); if( e->state() & ShiftButton ) { edit->cursorForward(true, 1-count); } else if( e->key() == Key_Backspace ) { edit->cursorForward(false, 1-count); QString text = edit->text(); int pos_to_right = edit->text().length() - pos_old; QString cut = text.left(edit->cursorPosition()) + text.right(pos_to_right); edit->setText(cut); edit->setCursorPosition(pos_old-count+1); } else { edit->cursorForward(false, 1-count); } } else if( e->key() == Key_Right || e->key() == Key_Delete ) { do { pos++; count++; if( allow_space_break && text[pos].isSpace() ) break; } while( pos < (int) text.length() && chars.findIndex(text[pos]) == -1 ); if( e->state() & ShiftButton ) { edit->cursorForward(true, count+1); } else if( e->key() == Key_Delete ) { edit->cursorForward(false, -count-1); QString text = edit->text(); int pos_to_right = text.length() - pos - 1; QString cut = text.left(pos_old) + (pos_to_right > 0 ? text.right(pos_to_right) : QString() ); edit->setText(cut); edit->setCursorPosition(pos_old); } else { edit->cursorForward(false, count+1); } } }
void RenderSettingsDialog::update() { int index = ui->integratorBox->currentIndex(); Properties integratorProps, samplerProps; bool needsUpdate = false; if (sender() == ui->samplerBox) { m_samplerNode->putProperties(samplerProps); needsUpdate = true; } if (sender() == ui->integratorBox) { m_integratorNode->putProperties(integratorProps); needsUpdate = true; } if (sender() == ui->rFilterBox || sender() == ui->icBox || sender() == ui->aiBox) { needsUpdate = true; } m_integratorNode = m_model->updateClass(m_integratorNode, ui->integratorBox->itemData(index).toList().at(0).toString(), ui->integratorBox->itemText(index)); index = ui->samplerBox->currentIndex(); m_samplerNode = m_model->updateClass(m_samplerNode, ui->samplerBox->itemData(index).toList().at(0).toString(), ui->samplerBox->itemText(index)); index = ui->rFilterBox->currentIndex(); m_rFilterNode = m_model->updateClass(m_rFilterNode, ui->rFilterBox->itemData(index).toList().at(0).toString(), ui->rFilterBox->itemText(index)); if (ui->icBox->isChecked()) { m_icNode = m_model->updateClass(m_icNode, "IrradianceCacheIntegrator", tr("Irradiance Cache")); } else { m_icNode = m_model->updateClass(m_icNode, "", ""); } if (ui->aiBox->isChecked()) { m_aiNode = m_model->updateClass(m_aiNode, "AdaptiveIntegrator", tr("Adaptive Integration")); } else { m_aiNode = m_model->updateClass(m_aiNode, "", ""); } if (sender() == ui->integratorBox) { for (int i=0; i<m_integratorNode->childCount(); ++i) { TreeItem *treeItem = m_integratorNode->child(i); if (integratorProps.hasProperty(treeItem->getName().toStdString())) m_integratorNode->setProperty(treeItem->getName().toStdString(), integratorProps); } } if (sender() == ui->samplerBox) { for (int i=0; i<m_samplerNode->childCount(); ++i) { TreeItem *treeItem = m_samplerNode->child(i); if (samplerProps.hasProperty(treeItem->getName().toStdString())) m_samplerNode->setProperty(treeItem->getName().toStdString(), samplerProps); } } if (needsUpdate) { int row = 0; /* Make comboboxes etc editable by default */ for (int i = 0; i < m_model->rowCount(); ++i) { QModelIndex index = m_model->index(i, 0); for (int j = 0; j < m_model->rowCount(index); ++j) { QModelIndex idx = m_model->index(j, 1, index); ui->treeView->openPersistentEditor(idx); QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(ui->treeView->indexWidget(idx)); if (spinBox) { QLineEdit *edit = spinBox->findChild<QLineEdit*>(); if (row % 2 == 0) edit->setStyleSheet("background-color: palette(alternate-base);"); edit->deselect(); } row++; } } } ui->treeView->expandAll(); dataChanged(); }
void NetworkManager::authentication(const QUrl &url, QAuthenticator *auth, QWidget *parent) { QDialog* dialog = new QDialog(parent); dialog->setWindowTitle(tr("Authorisation required")); QFormLayout* formLa = new QFormLayout(dialog); QLabel* label = new QLabel(dialog); QLabel* userLab = new QLabel(dialog); QLabel* passLab = new QLabel(dialog); userLab->setText(tr("Username: "******"Password: "******"Save username and password for this site")); QDialogButtonBox* box = new QDialogButtonBox(dialog); box->addButton(QDialogButtonBox::Ok); box->addButton(QDialogButtonBox::Cancel); connect(box, SIGNAL(rejected()), dialog, SLOT(reject())); connect(box, SIGNAL(accepted()), dialog, SLOT(accept())); label->setText(tr("A username and password are being requested by %1. " "The site says: \"%2\"").arg(url.host(), auth->realm().toHtmlEscaped())); formLa->addRow(label); formLa->addRow(userLab, user); formLa->addRow(passLab, pass); formLa->addRow(save); formLa->addWidget(box); AutoFill* fill = mApp->autoFill(); QString storedUser; QString storedPassword; bool shouldUpdateEntry = false; if (fill->isStored(url)) { const QVector<PasswordEntry> &data = fill->getFormData(url); if (!data.isEmpty()) { save->setChecked(true); shouldUpdateEntry = true; storedUser = data.at(0).username; storedPassword = data.at(0).password; user->setText(storedUser); pass->setText(storedPassword); } } // Do not save when private browsing is enabled if (mApp->isPrivate()) { save->setVisible(false); } if (dialog->exec() != QDialog::Accepted) { delete dialog; return; } auth->setUser(user->text()); auth->setPassword(pass->text()); if (save->isChecked()) { if (shouldUpdateEntry) { if (storedUser != user->text() || storedPassword != pass->text()) { fill->updateEntry(url, user->text(), pass->text()); } } else { fill->addEntry(url, user->text(), pass->text()); } } delete dialog; }
void CIPEditDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const { QString value = index.data().toString(); QLineEdit * lineEdit = static_cast<QLineEdit *>(editor); lineEdit->setText(value); }
void CameraSettingsWidget::init (Tribots::IIDC* cam1, bool memChan, bool head) { lockedCamera=true; lockedDisplay=false; camera = cam1; if (!camera) return; features = new TribotsTools::CameraSettingsWidget::FeatureInfo [11]; // z.Z. werden maximal 11 verwendet // das Widget aufbauen unsigned int y0=0; // die aktuelle y0-Position des naechsten Frames const unsigned int pwidth= 350; // die Breite der Frames QFrame* frame = new QFrame; frame->setFrameShape (QFrame::NoFrame); frame->setFrameShadow (QFrame::Plain); // das Feld mit Kamerabezeichnung und Modus QFrame* iframe = new QFrame (frame); iframe->setFrameShape (QFrame::NoFrame); iframe->setFrameShadow (QFrame::Plain); if (head) { iframe->setGeometry (0, y0, pwidth, 60); y0+=60; QLineEdit* edit = new QLineEdit (iframe); edit->setGeometry (5,5,200,20); edit->setReadOnly (true); edit->setText (camera->getCameraType().c_str()); edit = new QLineEdit (iframe); edit->setGeometry (215,5,130,20); edit->setReadOnly (true); edit->setText (camera->getCameraUID().c_str()); edit = new QLineEdit (iframe); edit->setGeometry (5,35,340,20); edit->setReadOnly (true); edit->setText (camera->getCameraMode().c_str()); } // die Featurefelder IIDC::CameraFeature feats [] = { IIDC::whiteBalance, IIDC::shutter, IIDC::gain, IIDC::brightness, IIDC::exposure, IIDC::gamma, IIDC::sharpness, IIDC::hue, IIDC::saturation, IIDC::filter }; QString featstring [] = { "WhiteBalance", "Shutter", "Gain", "Brightness", "Exposure", "Gamma", "Sharpness", "Hue", "Saturation", "Filter" }; num_features=0; for (unsigned int fn = 0; fn<10; fn++) { unsigned int fn_available = camera->availableFeatureModes (feats[fn]); if (fn_available & IIDC::featureUnavailable) { continue; } iframe = new QFrame (frame); iframe->setFrameShape (QFrame::NoFrame); iframe->setFrameShadow (QFrame::Plain); QLabel* label = new QLabel (iframe); label->setText (featstring[fn]); label->setGeometry (5, 5, 80, 20); IDComboBox* comboBox = new IDComboBox (iframe, num_features); comboBox->setGeometry (90,5,60,20); if (fn_available & IIDC::featureOff) comboBox->addItem ("Off"); if (fn_available & IIDC::featureMan) comboBox->addItem ("Man"); if (fn_available & IIDC::featureAuto) comboBox->addItem ("Auto"); IDSlider* slider = new IDSlider (iframe, num_features); slider->setGeometry (160, 5, 120, 20); unsigned int minv, maxv; camera->getFeatureMinMaxValue (minv, maxv, feats[fn]); slider->setMinimum (minv); slider->setMaximum (maxv); IDSpinBox* spinBox = new IDSpinBox (iframe, num_features); spinBox->setGeometry (290, 5, 57, 22); spinBox->setMinimum (minv); spinBox->setMaximum (maxv); if (feats[fn]==IIDC::whiteBalance) { iframe->setGeometry (0, y0, pwidth, 60); y0+=60; IDSlider* slider2 = new IDSlider (iframe, num_features+1); slider2->setGeometry (160, 35, 120, 20); slider2->setMinimum (minv); slider2->setMaximum (maxv); IDSpinBox* spinBox2 = new IDSpinBox (iframe, num_features+1); spinBox2->setGeometry (290, 35, 57, 22); spinBox2->setMinimum (minv); spinBox2->setMaximum (maxv); features[num_features].feature = feats[fn]; features[num_features].spinBox = spinBox; features[num_features].slider = slider; features[num_features].comboBox = comboBox; features[num_features].uv = true; features[num_features+1].feature = feats[fn]; features[num_features+1].spinBox = spinBox2; features[num_features+1].slider = slider2; features[num_features+1].comboBox = comboBox; features[num_features+1].uv = false; num_features+=2; connect (comboBox,SIGNAL(comboBoxChanged (unsigned int, const QString&)), this, SLOT(comboBoxChanged (unsigned int, const QString&))); connect (spinBox,SIGNAL(spinBoxChanged (unsigned int, unsigned int)), this, SLOT(spinBoxChanged (unsigned int, unsigned int))); connect (slider,SIGNAL(sliderChanged (unsigned int, unsigned int)), this, SLOT(sliderChanged (unsigned int, unsigned int))); connect (spinBox2,SIGNAL(spinBoxChanged (unsigned int, unsigned int)), this, SLOT(spinBoxChanged (unsigned int, unsigned int))); connect (slider2,SIGNAL(sliderChanged (unsigned int, unsigned int)), this, SLOT(sliderChanged (unsigned int, unsigned int))); updateFeatureMode (num_features-2); updateFeatureValue (num_features-2); updateFeatureValue (num_features-1); } else {