void QueryBuilder::addReturnFunctionValue( int function, int table, int value) { if ( !m_values.isEmpty() && m_values != "DISTINCT " ) m_values += ","; m_values += functionName( function ) + "("; m_values += tableName( table ) + "."; m_values += valueName( value )+ ")"; m_values += " AS "; m_values += functionName( function )+tableName( table )+valueName( value ); m_linkTables |= table; m_returnValues++; }
void QueryBuilder::sortByFunction( int function, int table, int value, bool descending ) { // This function should be used with the equivalent addReturnFunctionValue (with the same function on same values) // since it uses the "func(table.value) AS functablevalue" definition. //shall we sort case-sensitively? (not for integer columns!) bool b = true; if ( value & valID || value & valTrack || value & valScore || value & valLength || value & valBitrate || value & valSamplerate || value & valPlayCounter || value & valAccessDate || value & valCreateDate || value & valPercentage || table & tabYear ) b = false; if ( !m_sort.isEmpty() ) m_sort += ","; //m_sort += functionName( function ) + "("; if ( b ) m_sort += "LOWER( "; if ( table & tabYear ) m_sort += "("; QString columnName = functionName( function )+tableName( table )+valueName( value ); m_sort += columnName; if ( table & tabYear ) m_sort += "+0)"; if ( b ) m_sort += " ) "; //m_sort += " ) "; if ( descending ) m_sort += " DESC "; m_linkTables |= table; }
void QueryBuilder::addMatch( int tables, int value, const QString& match ) { if ( !match.isEmpty() ) { m_where += "AND ( true "; m_where += QString( "OR %1.%2 LIKE '" ).arg( tableName( tables ) ).arg( valueName( value ) ) + escapeString( match ) + "' "; if ( ( value & valName ) && match == i18n( "Unknown" ) ) m_where += QString( "OR %1.%2 = '' " ).arg( tableName( tables ) ).arg( valueName( value ) ); m_where += " ) "; } m_linkTables |= tables; }
void QueryBuilder::groupBy( int table, int value ) { if ( !m_group.isEmpty() ) m_group += ","; m_group += tableName( table ) + "."; m_group += valueName( value ); m_linkTables |= table; }
void QueryBuilder::exclusiveFilter( int tableMatching, int tableNotMatching, int value ) { m_join += " LEFT JOIN "; m_join += tableName( tableNotMatching ); m_join += " ON "; m_join += tableName( tableMatching ) + "."; m_join += valueName( value ); m_join+= " = "; m_join += tableName( tableNotMatching ) + "."; m_join += valueName( value ); m_where += " AND "; m_where += tableName( tableNotMatching ) + "."; m_where += valueName( value ); m_where += " IS null "; }
QList<SerialPortId> enumerateSerialPorts(int) { DWORD index=0; SP_DEVINFO_DATA info; GUID guid = GUID_DEVCLASS_PORTS; HDEVINFO infoset = SetupDiGetClassDevs(&guid, 0, 0, DIGCF_PRESENT); QString valueName(16384, 0); QList<SerialPortId> list; for (index=0;;index++) { ZeroMemory(&info, sizeof(SP_DEVINFO_DATA)); info.cbSize = sizeof(SP_DEVINFO_DATA); if (!SetupDiEnumDeviceInfo(infoset, index, &info)) break; QString friendlyName; QString portName; DWORD size=0; SetupDiGetDeviceRegistryProperty(infoset, &info, SPDRP_FRIENDLYNAME, 0, 0, 0, &size); QByteArray ba(size, 0); if(SetupDiGetDeviceRegistryProperty(infoset, &info, SPDRP_FRIENDLYNAME, 0, (BYTE*)(ba.data()), size, 0)) { friendlyName = QString((const QChar*)(ba.constData()), ba.size() / 2 - 1); } HKEY key = SetupDiOpenDevRegKey(infoset, &info, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ); if(key != INVALID_HANDLE_VALUE) { //RegGetValue not supported on XP, SHRegGetValue not supported by mingw, so use the old method of enumerating all the values for (DWORD dwi=0;;dwi++) { DWORD vsize = valueName.size(); if (ERROR_SUCCESS == RegEnumValue(key, dwi, (WCHAR*)(valueName.data()), &vsize, 0, 0, 0, &size)) { if (valueName.startsWith("PortName")) { QByteArray ba(size, 0); vsize = valueName.size(); if(ERROR_SUCCESS == RegEnumValue(key, dwi, (WCHAR*)(valueName.data()), &vsize, 0, 0, (BYTE*)(ba.data()), &size)) { portName = QString((const QChar*)(ba.constData()), ba.size() / 2 - 1); } } } else { break; } } RegCloseKey(key); } SerialPortId id; id.portName = portName; id.friendlyName = friendlyName; list.append(id); } SetupDiDestroyDeviceInfoList(infoset); return list; }
String CSSPrimitiveValue::getStringValue() const { switch (m_primitiveUnitType) { case CSS_STRING: case CSS_ATTR: case CSS_URI: return m_value.string; case CSS_VALUE_ID: return valueName(m_value.valueID); case CSS_PROPERTY_ID: return propertyName(m_value.propertyID); default: break; } return String(); }
String CSSPrimitiveValue::getStringValue() const { switch (type()) { case UnitType::CustomIdentifier: case UnitType::String: case UnitType::Attribute: case UnitType::URI: return m_value.string; case UnitType::ValueID: return valueName(m_value.valueID); case UnitType::PropertyID: return propertyName(m_value.propertyID); default: break; } return String(); }
void QueryBuilder::addReturnValue( int table, int value ) { if ( !m_values.isEmpty() && m_values != "DISTINCT " ) m_values += ","; if ( table & tabStats && value & valScore ) m_values += "round("; if ( value == valDummy ) m_values += "''"; else { m_values += tableName( table ) + "."; m_values += valueName( value ); } if ( table & tabStats && value & valScore ) m_values += " + 0.4 )"; m_linkTables |= table; m_returnValues++; }
String CSSPrimitiveValue::getStringValue(ExceptionCode& ec) const { ec = 0; switch (m_primitiveUnitType) { case CSS_STRING: case CSS_ATTR: case CSS_URI: return m_value.string; case CSS_VALUE_ID: return valueName(m_value.valueID); case CSS_PROPERTY_ID: return propertyName(m_value.propertyID); default: ec = INVALID_ACCESS_ERR; break; } return String(); }
void QueryBuilder::sortBy( int table, int value, bool descending ) { //shall we sort case-sensitively? (not for integer columns!) bool b = true; if ( value & valID || value & valTrack || value & valScore || value & valLength || value & valBitrate || value & valSamplerate || value & valPlayCounter || value & valAccessDate || value & valCreateDate || value & valPercentage || table & tabYear ) b = false; if ( !m_sort.isEmpty() ) m_sort += ","; if ( b ) m_sort += "LOWER( "; if ( table & tabYear ) m_sort += "("; m_sort += tableName( table ) + "."; m_sort += valueName( value ); if ( table & tabYear ) m_sort += "+0)"; if ( b ) m_sort += " ) "; if ( descending ) m_sort += " DESC "; m_linkTables |= table; }
String CSSPrimitiveValue::customCSSText() const { if (m_hasCachedCSSText) { ASSERT(cssTextCache().contains(this)); return cssTextCache().get(this); } String text; switch (type()) { case UnitType::Unknown: // FIXME break; case UnitType::Integer: text = String::format("%d", getIntValue()); break; case UnitType::Number: case UnitType::Percentage: case UnitType::Ems: case UnitType::Exs: case UnitType::Rems: case UnitType::Chs: case UnitType::Pixels: case UnitType::Centimeters: case UnitType::DotsPerPixel: case UnitType::DotsPerInch: case UnitType::DotsPerCentimeter: case UnitType::Millimeters: case UnitType::Inches: case UnitType::Points: case UnitType::Picas: case UnitType::Degrees: case UnitType::Radians: case UnitType::Gradians: case UnitType::Milliseconds: case UnitType::Seconds: case UnitType::Hertz: case UnitType::Kilohertz: case UnitType::Turns: case UnitType::Fraction: case UnitType::ViewportWidth: case UnitType::ViewportHeight: case UnitType::ViewportMin: case UnitType::ViewportMax: text = formatNumber(m_value.num, unitTypeToString(type())); break; case UnitType::CustomIdentifier: text = quoteCSSStringIfNeeded(m_value.string); break; case UnitType::String: { text = serializeString(m_value.string); break; } case UnitType::URI: text = "url(" + quoteCSSURLIfNeeded(m_value.string) + ")"; break; case UnitType::ValueID: text = valueName(m_value.valueID); break; case UnitType::PropertyID: text = propertyName(m_value.propertyID); break; case UnitType::Attribute: { StringBuilder result; result.reserveCapacity(6 + m_value.string->length()); result.appendLiteral("attr("); result.append(m_value.string); result.append(')'); text = result.toString(); break; } case UnitType::Counter: { StringBuilder result; String separator = m_value.counter->separator(); if (separator.isEmpty()) result.appendLiteral("counter("); else result.appendLiteral("counters("); result.append(m_value.counter->identifier()); if (!separator.isEmpty()) { result.appendLiteral(", "); result.append(serializeString(separator)); } String listStyle = m_value.counter->listStyle(); bool isDefaultListStyle = m_value.counter->listStyleIdent() == CSSValueDecimal; if (!listStyle.isEmpty() && !isDefaultListStyle) { result.appendLiteral(", "); result.append(listStyle); } result.append(')'); text = result.toString(); break; } case UnitType::Rect: text = getRectValue()->cssText(); break; case UnitType::Quad: text = getQuadValue()->cssText(); break; case UnitType::RGBColor: { text = Color(m_value.rgbcolor).serializedAsCSSComponentValue(); break; } case UnitType::Pair: text = getPairValue()->cssText(); break; case UnitType::Calc: text = m_value.calc->customCSSText(); break; case UnitType::Shape: text = m_value.shape->cssText(); break; case UnitType::CalcPercentageWithNumber: case UnitType::CalcPercentageWithLength: case UnitType::QuirkyEms: ASSERT_NOT_REACHED(); break; } ASSERT(!cssTextCache().contains(this)); cssTextCache().set(this, text); m_hasCachedCSSText = true; return text; }
ALWAYS_INLINE String CSSPrimitiveValue::formatNumberForcustomCSSText() const { switch (m_primitiveUnitType) { case CSS_UNKNOWN: return String(); case CSS_NUMBER: case CSS_PARSER_INTEGER: return formatNumberValue(""); case CSS_PERCENTAGE: return formatNumberValue("%"); case CSS_EMS: return formatNumberValue("em"); case CSS_EXS: return formatNumberValue("ex"); case CSS_REMS: return formatNumberValue("rem"); case CSS_CHS: return formatNumberValue("ch"); case CSS_PX: return formatNumberValue("px"); case CSS_CM: return formatNumberValue("cm"); #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY) case CSS_DPPX: return formatNumberValue("dppx"); case CSS_DPI: return formatNumberValue("dpi"); case CSS_DPCM: return formatNumberValue("dpcm"); #endif case CSS_MM: return formatNumberValue("mm"); case CSS_IN: return formatNumberValue("in"); case CSS_PT: return formatNumberValue("pt"); case CSS_PC: return formatNumberValue("pc"); case CSS_DEG: return formatNumberValue("deg"); case CSS_RAD: return formatNumberValue("rad"); case CSS_GRAD: return formatNumberValue("grad"); case CSS_MS: return formatNumberValue("ms"); case CSS_S: return formatNumberValue("s"); case CSS_HZ: return formatNumberValue("hz"); case CSS_KHZ: return formatNumberValue("khz"); case CSS_TURN: return formatNumberValue("turn"); case CSS_FR: return formatNumberValue("fr"); case CSS_DIMENSION: // FIXME: We currently don't handle CSS_DIMENSION properly as we don't store // the actual dimension, just the numeric value as a string. case CSS_STRING: return quoteCSSStringIfNeeded(m_value.string); case CSS_URI: return "url(" + quoteCSSURLIfNeeded(m_value.string) + ')'; case CSS_VALUE_ID: return valueName(m_value.valueID); case CSS_PROPERTY_ID: return propertyName(m_value.propertyID); case CSS_ATTR: { StringBuilder result; result.reserveCapacity(6 + m_value.string->length()); result.appendLiteral("attr("); result.append(m_value.string); result.append(')'); return result.toString(); } case CSS_COUNTER_NAME: return "counter(" + String(m_value.string) + ')'; case CSS_COUNTER: { StringBuilder result; String separator = m_value.counter->separator(); if (separator.isEmpty()) result.appendLiteral("counter("); else result.appendLiteral("counters("); result.append(m_value.counter->identifier()); if (!separator.isEmpty()) { result.appendLiteral(", "); result.append(quoteCSSStringIfNeeded(separator)); } String listStyle = m_value.counter->listStyle(); if (!listStyle.isEmpty()) { result.appendLiteral(", "); result.append(listStyle); } result.append(')'); return result.toString(); } case CSS_RECT: return getRectValue()->cssText(); case CSS_QUAD: return getQuadValue()->cssText(); case CSS_RGBCOLOR: case CSS_PARSER_HEXCOLOR: { RGBA32 rgbColor = m_value.rgbcolor; if (m_primitiveUnitType == CSS_PARSER_HEXCOLOR) Color::parseHexColor(m_value.string, rgbColor); Color color(rgbColor); Vector<LChar> result; result.reserveInitialCapacity(32); bool colorHasAlpha = color.hasAlpha(); if (colorHasAlpha) result.append("rgba(", 5); else result.append("rgb(", 4); appendNumber(result, static_cast<unsigned char>(color.red())); result.append(", ", 2); appendNumber(result, static_cast<unsigned char>(color.green())); result.append(", ", 2); appendNumber(result, static_cast<unsigned char>(color.blue())); if (colorHasAlpha) { result.append(", ", 2); NumberToStringBuffer buffer; const char* alphaString = numberToFixedPrecisionString(color.alpha() / 255.0f, 6, buffer, true); result.append(alphaString, strlen(alphaString)); } result.append(')'); return String::adopt(result); } case CSS_PAIR: return getPairValue()->cssText(); #if ENABLE(DASHBOARD_SUPPORT) case CSS_DASHBOARD_REGION: { StringBuilder result; for (DashboardRegion* region = getDashboardRegionValue(); region; region = region->m_next.get()) { if (!result.isEmpty()) result.append(' '); result.appendLiteral("dashboard-region("); result.append(region->m_label); if (region->m_isCircle) result.appendLiteral(" circle"); else if (region->m_isRectangle) result.appendLiteral(" rectangle"); else break; if (region->top()->m_primitiveUnitType == CSS_VALUE_ID && region->top()->getValueID() == CSSValueInvalid) { ASSERT(region->right()->m_primitiveUnitType == CSS_VALUE_ID); ASSERT(region->bottom()->m_primitiveUnitType == CSS_VALUE_ID); ASSERT(region->left()->m_primitiveUnitType == CSS_VALUE_ID); ASSERT(region->right()->getValueID() == CSSValueInvalid); ASSERT(region->bottom()->getValueID() == CSSValueInvalid); ASSERT(region->left()->getValueID() == CSSValueInvalid); } else { result.append(' '); result.append(region->top()->cssText()); result.append(' '); result.append(region->right()->cssText()); result.append(' '); result.append(region->bottom()->cssText()); result.append(' '); result.append(region->left()->cssText()); } result.append(')'); } return result.toString(); } #endif case CSS_PARSER_OPERATOR: { char c = static_cast<char>(m_value.parserOperator); return String(&c, 1U); } case CSS_PARSER_IDENTIFIER: return quoteCSSStringIfNeeded(m_value.string); case CSS_CALC: return m_value.calc->cssText(); case CSS_SHAPE: return m_value.shape->cssText(); case CSS_VW: return formatNumberValue("vw"); case CSS_VH: return formatNumberValue("vh"); case CSS_VMIN: return formatNumberValue("vmin"); case CSS_VMAX: return formatNumberValue("vmax"); } return String(); }
bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const { if (m_primitiveUnitType != other.m_primitiveUnitType) return false; switch (m_primitiveUnitType) { case CSS_UNKNOWN: return false; case CSS_NUMBER: case CSS_PARSER_INTEGER: case CSS_PERCENTAGE: case CSS_EMS: case CSS_EXS: case CSS_REMS: case CSS_PX: case CSS_CM: #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY) case CSS_DPPX: case CSS_DPI: case CSS_DPCM: #endif case CSS_MM: case CSS_IN: case CSS_PT: case CSS_PC: case CSS_DEG: case CSS_RAD: case CSS_GRAD: case CSS_MS: case CSS_S: case CSS_HZ: case CSS_KHZ: case CSS_TURN: case CSS_VW: case CSS_VH: case CSS_VMIN: case CSS_DIMENSION: case CSS_FR: return m_value.num == other.m_value.num; case CSS_PROPERTY_ID: return propertyName(m_value.propertyID) == propertyName(other.m_value.propertyID); case CSS_VALUE_ID: return valueName(m_value.valueID) == valueName(other.m_value.valueID); case CSS_STRING: case CSS_URI: case CSS_ATTR: case CSS_COUNTER_NAME: case CSS_PARSER_IDENTIFIER: case CSS_PARSER_HEXCOLOR: return equal(m_value.string, other.m_value.string); case CSS_COUNTER: return m_value.counter && other.m_value.counter && m_value.counter->equals(*other.m_value.counter); case CSS_RECT: return m_value.rect && other.m_value.rect && m_value.rect->equals(*other.m_value.rect); case CSS_QUAD: return m_value.quad && other.m_value.quad && m_value.quad->equals(*other.m_value.quad); case CSS_RGBCOLOR: return m_value.rgbcolor == other.m_value.rgbcolor; case CSS_PAIR: return m_value.pair && other.m_value.pair && m_value.pair->equals(*other.m_value.pair); #if ENABLE(DASHBOARD_SUPPORT) case CSS_DASHBOARD_REGION: return m_value.region && other.m_value.region && m_value.region->equals(*other.m_value.region); #endif case CSS_PARSER_OPERATOR: return m_value.parserOperator == other.m_value.parserOperator; case CSS_CALC: return m_value.calc && other.m_value.calc && m_value.calc->equals(*other.m_value.calc); case CSS_SHAPE: return m_value.shape && other.m_value.shape && m_value.shape->equals(*other.m_value.shape); } return false; }
String CSSPrimitiveValue::customCSSText() const { if (m_hasCachedCSSText) { ASSERT(cssTextCache().contains(this)); return cssTextCache().get(this); } String text; switch (type()) { case UnitType::Unknown: // FIXME break; case UnitType::Integer: text = String::format("%d", getIntValue()); break; case UnitType::Number: case UnitType::Percentage: case UnitType::Ems: case UnitType::QuirkyEms: case UnitType::Exs: case UnitType::Rems: case UnitType::Chs: case UnitType::Pixels: case UnitType::Centimeters: case UnitType::DotsPerPixel: case UnitType::DotsPerInch: case UnitType::DotsPerCentimeter: case UnitType::Millimeters: case UnitType::Inches: case UnitType::Points: case UnitType::Picas: case UnitType::Degrees: case UnitType::Radians: case UnitType::Gradians: case UnitType::Milliseconds: case UnitType::Seconds: case UnitType::Hertz: case UnitType::Kilohertz: case UnitType::Turns: case UnitType::Fraction: case UnitType::ViewportWidth: case UnitType::ViewportHeight: case UnitType::ViewportMin: case UnitType::ViewportMax: text = formatNumber(m_value.num, unitTypeToString(type())); break; case UnitType::CustomIdentifier: text = quoteCSSStringIfNeeded(m_value.string); break; case UnitType::String: { text = serializeString(m_value.string); break; } case UnitType::URI: text = serializeURI(m_value.string); break; case UnitType::ValueID: text = valueName(m_value.valueID); break; case UnitType::PropertyID: text = propertyName(m_value.propertyID); break; case UnitType::RGBColor: { text = Color(m_value.rgbcolor).serializedAsCSSComponentValue(); break; } case UnitType::Calc: text = m_value.calc->customCSSText(); break; case UnitType::CalcPercentageWithNumber: case UnitType::CalcPercentageWithLength: ASSERT_NOT_REACHED(); break; } ASSERT(!cssTextCache().contains(this)); cssTextCache().set(this, text); m_hasCachedCSSText = true; return text; }
String CSSIdentifierValue::customCSSText() const { return valueName(m_valueID); }