/** * Normalizes the value of a XML processing instruction **/ void XMLUtils::normalizePIValue(nsAString& piValue) { nsAutoString origValue(piValue); PRUint32 origLength = origValue.Length(); PRUint32 conversionLoop = 0; PRUnichar prevCh = 0; piValue.Truncate(); while (conversionLoop < origLength) { PRUnichar ch = origValue.CharAt(conversionLoop); switch (ch) { case '>': { if (prevCh == '?') { piValue.Append(PRUnichar(' ')); } break; } default: { break; } } piValue.Append(ch); prevCh = ch; ++conversionLoop; } }
/* Method to fetch (as string) the first value of a given * variable list. * * In this context, a variable list is the same as a variable but * it is composed of several parts (words), separated by spaces. * * @param variableList Variable list name. * @param section Section the variable list belongs to. * * \warning This method will MODIFY the original content of * 'variableList'. */ string ConfDataReader::fetchListValue( string variableList, string section, string defaultVal ) throw(ConfigurationException) { try { // Let's make sure that section and variable names are uppercase section = StringUtils::upperCase(section); variableList = StringUtils::upperCase(variableList); // Store the original value of 'variableList' string origValue( getValue(variableList, section) ); // Get the first word in 'originalValue' string firstValue( StringUtils::stripFirstWord(origValue) ); // Modify the originalValue value confData[section][variableList].value = StringUtils::strip(origValue); // Return the first value string value = StringUtils::strip(firstValue); return ( (value=="") ? string(defaultVal) : value ); } catch (ConfigurationException& e) { GPSTK_RETHROW(e); } } // End of method 'ConfDataReader::fetchListValue()'
bool RunsTableModel::postRow(int row_no, bool throw_exc) { bool is_single_user = sqlConnection().driverName().endsWith(QLatin1String("SQLITE"), Qt::CaseInsensitive); if(is_single_user) return Super::postRow(row_no, throw_exc); int col_stime = columnIndex("startTimeMs"); QF_ASSERT(col_stime >= 0, "Bad startTimeMs column!", return false); if(isDirty(row_no, col_stime)) { int id = value(row_no, "runs.id").toInt(); int orig_msec = origValue(row_no, col_stime).toInt(); int db_msec = 0; qf::core::sql::Transaction transaction(sqlConnection()); QString qs = "SELECT id, startTimeMs FROM runs WHERE id=" QF_IARG(id) " FOR UPDATE"; qf::core::sql::Query q(transaction.connection()); q.exec(qs, qf::core::Exception::Throw); if(q.next()) { db_msec = q.value("startTimeMs").toInt(); } if(orig_msec == db_msec) { bool ret = Super::postRow(row_no, throw_exc); transaction.commit(); return ret; } else { QString err_msg = tr("Mid-air collision setting start time, reload table and try it again."); revertRow(row_no); if(throw_exc) QF_EXCEPTION(err_msg); return false; } } return Super::postRow(row_no, throw_exc); }
int KexiComboBoxBase::rowToHighlightForLookupTable() const { if (!popup()) return -1;//err KexiDB::LookupFieldSchema *lookupFieldSchema = this->lookupFieldSchema(); if (!lookupFieldSchema) return -1; if (lookupFieldSchema->boundColumn() == -1) return -1; //err bool ok; const int rowUid = origValue().toInt(); //! @todo for now we're assuming the id is INTEGER KexiTableViewData *tvData = popup()->tableView()->data(); const int boundColumn = lookupFieldSchema->boundColumn(); int row = -1; for (KexiTableViewData::Iterator it(tvData->constBegin()); it != tvData->constEnd(); ++it) { row++; KexiDB::RecordData* record = *it; if (record->at(boundColumn).toInt(&ok) == rowUid && ok) return row; if (!ok) break; } //item not found: highlight 1st row, if available return -1; }
QVariant KexiComboBoxBase::value() { KexiTableViewData *relData = column() ? column()->relatedData() : 0; KexiDB::LookupFieldSchema *lookupFieldSchema = 0; if (relData) { if (m_internalEditorValueChanged) { //we've user-entered text: look for id //TODO: make error if matching text not found? int rowToHighlight; return valueForString(m_userEnteredValue.toString(), &rowToHighlight, 1, 0, true/*allowNulls*/); } else { //use 'related table data' model KexiDB::RecordData *record = popup() ? popup()->tableView()->selectedItem() : 0; return record ? record->at(0) : origValue(); } } else if ((lookupFieldSchema = this->lookupFieldSchema())) { if (lookupFieldSchema->boundColumn() == -1) return origValue(); KexiDB::RecordData *record = popup() ? popup()->tableView()->selectedItem() : 0; if (/*!record &&*/ m_internalEditorValueChanged && !m_userEnteredValue.toString().isEmpty()) { // //try to select a row using the user-entered text if (!popup()) { QVariant prevUserEnteredValue = m_userEnteredValue; createPopup(false); m_userEnteredValue = prevUserEnteredValue; } record = selectItemForEnteredValueInLookupTable(m_userEnteredValue); } return record ? record->at(lookupFieldSchema->boundColumn()) : QVariant(); } else if (popup()) { //use 'enum hints' model const int row = popup()->tableView()->currentRow(); if (row >= 0) return QVariant(row); } if (valueFromInternalEditor().toString().isEmpty()) return QVariant(); /*! \todo don't return just 1st row, but use autocompletion feature and: show message box if entered text does not match! */ return origValue(); //unchanged }
void KexiComboBoxBase::setValueInternal(const QVariant& add_, bool removeOld) { Q_UNUSED(removeOld); m_mouseBtnPressedWhenPopupVisible = false; m_updatePopupSelectionOnShow = true; QString add(add_.toString()); if (add.isEmpty()) { KexiTableViewData *relData = column() ? column()->relatedData() : 0; QVariant valueToSet; bool hasValueToSet = true; int rowToHighlight = -1; KexiDB::LookupFieldSchema *lookupFieldSchema = this->lookupFieldSchema(); if (lookupFieldSchema) { //use 'lookup field' model //! @todo support more RowSourceType's, not only table if (lookupFieldSchema->boundColumn() == -1) //! @todo errmsg return; if (m_setVisibleValueOnSetValueInternal) { //only for table views if (!popup()) createPopup(false/*!show*/); } if (popup()) { const int rowToHighlight = rowToHighlightForLookupTable(); popup()->tableView()->setHighlightedRecord(rowToHighlight); const int visibleColumn = lookupFieldSchema->visibleColumn(popup()->tableView()->data()->columnsCount()); if (m_setVisibleValueOnSetValueInternal && -1 != visibleColumn) { //only for table views KexiDB::RecordData *record = popup()->tableView()->highlightedItem(); if (record) valueToSet = record->at(visibleColumn); } else { hasValueToSet = false; } } } else if (relData) { //use 'related table data' model valueToSet = valueForString(origValue().toString(), &rowToHighlight, 0, 1); } else { //use 'enum hints' model const int row = origValue().toInt(); valueToSet = field()->enumHint(row).trimmed(); } if (hasValueToSet) setValueOrTextInInternalEditor(valueToSet); /*impl.*/moveCursorToEndInInternalEditor(); /*impl.*/selectAllInInternalEditor(); if (popup()) { if (origValue().isNull()) { popup()->tableView()->clearSelection(); popup()->tableView()->setHighlightedRecord(0); } else { if (relData) { if (rowToHighlight != -1) popup()->tableView()->setHighlightedRecord(rowToHighlight); } else if (!lookupFieldSchema) { //popup()->tableView()->selectRow(origValue().toInt()); popup()->tableView()->setHighlightedRecord(origValue().toInt()); } } } } else { //todo: autocompl.? if (popup()) popup()->tableView()->clearSelection(); /*impl.*/setValueInInternalEditor(add); //not setLineEditText(), because 'add' is entered by user! //setLineEditText( add ); /*impl.*/moveCursorToEndInInternalEditor(); } }
void KexiComboBoxBase::createPopup(bool show) { //kDebug() << show << field() << popup() << m_updatePopupSelectionOnShow; if (!field()) return; m_insideCreatePopup = true; QWidget* thisWidget = dynamic_cast<QWidget*>(this); QWidget *widgetToFocus = internalEditor() ? internalEditor() : thisWidget; if (m_reinstantiatePopupOnShow) { QWidget *oldPopup = popup(); setPopup(0); delete oldPopup; } if (!popup()) { setPopup(column() ? new KexiComboBoxPopup(thisWidget, *column()) : new KexiComboBoxPopup(thisWidget, *field())); QObject::connect(popup(), SIGNAL(rowAccepted(KexiDB::RecordData*,int)), thisWidget, SLOT(slotRowAccepted(KexiDB::RecordData*,int))); QObject::connect(popup()->tableView(), SIGNAL(itemSelected(KexiDB::RecordData*)), thisWidget, SLOT(slotItemSelected(KexiDB::RecordData*))); popup()->setFocusProxy(widgetToFocus); popup()->tableView()->setFocusProxy(widgetToFocus); popup()->installEventFilter(thisWidget); if (origValue().isNull()) popup()->tableView()->clearSelection(); else { popup()->tableView()->selectRow(0); popup()->tableView()->setHighlightedRecord(0); } } if (show && internalEditor() && !internalEditor()->isVisible()) /*emit*/editRequested(); QPoint posMappedToGlobal = mapFromParentToGlobal(thisWidget->pos()); if (posMappedToGlobal != QPoint(-1, -1)) { //! todo alter the position to fit the popup within screen boundaries popup()->hide(); popup()->move(posMappedToGlobal + QPoint(0, thisWidget->height())); //kDebug() << "pos:" << posMappedToGlobal + QPoint(0, thisWidget->height()); //to avoid flickering: first resize to 0-height, then show and resize back to prev. height const int w = popupWidthHint(); popup()->resize(w, 0); if (show) { popup()->show(); //kDebug(44010) << "SHOW!!!"; } popup()->updateSize(w); if (m_updatePopupSelectionOnShow) { int rowToHighlight = -1; KexiDB::LookupFieldSchema *lookupFieldSchema = this->lookupFieldSchema(); KexiTableViewData *relData = column() ? column()->relatedData() : 0; if (lookupFieldSchema) { rowToHighlight = rowToHighlightForLookupTable(); } else if (relData) { (void)valueForString(origValue().toString(), &rowToHighlight, 0, 1); } else //enum hint rowToHighlight = origValue().toInt(); /*-->*/ m_moveCursorToEndInInternalEditor_enabled = show; m_selectAllInInternalEditor_enabled = show; m_setValueInInternalEditor_enabled = show; if (rowToHighlight == -1) { rowToHighlight = qMax(popup()->tableView()->highlightedRecord(), 0); setValueInInternalEditor(QVariant()); } popup()->tableView()->selectRow(rowToHighlight); popup()->tableView()->setHighlightedRecord(rowToHighlight); if (rowToHighlight < popup()->tableView()->rowsPerPage()) popup()->tableView()->ensureCellVisible(0, -1); /*-->*/ m_moveCursorToEndInInternalEditor_enabled = true; m_selectAllInInternalEditor_enabled = true; m_setValueInInternalEditor_enabled = true; } } if (show) { moveCursorToEndInInternalEditor(); selectAllInInternalEditor(); widgetToFocus->setFocus(); popup()->show(); popup()->raise(); popup()->repaint(); } m_insideCreatePopup = false; }