Commit 05b5f4ad authored by Jarosław Staniek's avatar Jarosław Staniek

Add support for user data storage and remember column widths in table

Core
*Add support for user data storage
FEATURE:305074

Table View
*Remember column widths in tabular data view
FEATURE:230994

REVIEW:106132
DIGEST:Kexi gets support for user data storage and remembers column widths of table views.
parent 17490357
......@@ -70,8 +70,7 @@ Field::Field(QuerySchema *querySchema, BaseExpr* expr)
Field::Field(const QString& name, Type ctype,
uint cconst, uint options, uint maxLength, uint precision,
QVariant defaultValue, const QString& caption, const QString& description,
uint width)
QVariant defaultValue, const QString& caption, const QString& description)
: m_parent(0)
, m_name(name.toLower())
, m_precision(precision)
......@@ -81,7 +80,6 @@ Field::Field(const QString& name, Type ctype,
, m_order(-1)
, m_caption(caption)
, m_desc(description)
, m_width(width)
, m_expr(0)
, m_customProperties(0)
, m_type(ctype)
......@@ -127,7 +125,6 @@ void Field::init()
m_options = NoOptions;
m_defaultValue = QVariant(QString());
m_order = -1;
m_width = 0;
m_expr = 0;
m_customProperties = 0;
setMaxLength(0); // do not move this line up!
......
......@@ -164,8 +164,7 @@ public:
uint maxLength = 0, uint precision = 0,
QVariant defaultValue = QVariant(),
const QString& caption = QString(),
const QString& description = QString(),
uint width = 0);
const QString& description = QString());
/*! Copy constructor. */
Field(const Field& f);
......@@ -495,12 +494,6 @@ public:
return m_desc;
}
/*! \return width of this field (usually in pixels or points)
0 (the default) means there is no hint for the width. */
inline uint width() const {
return m_width;
}
//! if the type has the unsigned attribute
inline bool isUnsigned() const {
return m_options & Unsigned;
......@@ -622,12 +615,6 @@ public:
m_desc = description;
}
/*! Sets visible width for this field to \a w
(usually in pixels or points). 0 means there is no hint for the width. */
void setWidth(uint w) {
m_width = w;
}
/*! There can be added asterisks (QueryAsterisk objects)
to query schemas' field list. QueryAsterisk subclasses Field class,
and to check if the given object (pointed by Field*)
......@@ -729,7 +716,6 @@ protected:
int m_order;
QString m_caption;
QString m_desc;
uint m_width;
QVector<QString> m_hints;
KexiDB::BaseExpr *m_expr;
......
/* This file is part of the KDE project
Copyright (C) 2004-2012 Jarosław Staniek <staniek@kde.org>
Contains code from KConfigGroupPrivate from kconfiggroup.cpp (kdelibs 4)
Copyright (c) 2006 Thomas Braxton <brax108@cox.net>
Copyright (c) 1999 Preston Brown <pbrown@kde.org>
Copyright (c) 1997-1999 Matthias Kalle Dalheimer <kalle@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
......@@ -749,10 +754,6 @@ bool KexiDB::setFieldProperties(Field& field, const QHash<QByteArray, QVariant>&
return false;
if ((it = values.find("defaultValue")) != values.constEnd())
field.setDefaultValue(*it);
if ((it = values.find("width")) != values.constEnd())
field.setWidth((*it).isNull() ? 0/*default*/ : (*it).toUInt(&ok));
if (!ok)
return false;
if ((it = values.find("visibleDecimalPlaces")) != values.constEnd()
&& KexiDB::supportsVisibleDecimalPlacesProperty(field.type()))
field.setVisibleDecimalPlaces((*it).isNull() ? -1/*default*/ : (*it).toInt(&ok));
......@@ -888,8 +889,6 @@ bool KexiDB::setFieldProperty(Field& field, const QByteArray& propertyName, cons
field.setDefaultValue(value);
return true;
}
if ("width" == propertyName)
GET_INT(setWidth);
// last chance that never fails: custom field property
field.setCustomProperty(propertyName, value);
......@@ -1186,10 +1185,94 @@ QByteArray KexiDB::pgsqlByteaToByteArray(const char* data, int length)
return array;
}
QList<int> KexiDB::stringListToIntList(const QStringList &list, bool *ok)
{
QList<int> result;
foreach (const QString &item, list) {
int val = item.toInt(ok);
if (ok && !*ok) {
return QList<int>();
}
result.append(val);
}
if (ok) {
*ok = true;
}
return result;
}
// Based on KConfigGroupPrivate::serializeList() from kconfiggroup.cpp (kdelibs 4)
QString KexiDB::serializeList(const QStringList &list)
{
QString value = "";
if (!list.isEmpty()) {
QStringList::ConstIterator it = list.constBegin();
const QStringList::ConstIterator end = list.constEnd();
value = QString(*it).replace('\\', "\\\\").replace(',', "\\,");
while (++it != end) {
// In the loop, so it is not done when there is only one element.
// Doing it repeatedly is a pretty cheap operation.
value.reserve(4096);
value += ',';
value += QString(*it).replace('\\', "\\\\").replace(',', "\\,");
}
// To be able to distinguish an empty list from a list with one empty element.
if (value.isEmpty())
value = "\\0";
}
return value;
}
// Based on KConfigGroupPrivate::deserializeList() from kconfiggroup.cpp (kdelibs 4)
QStringList KexiDB::deserializeList(const QString &data)
{
if (data.isEmpty())
return QStringList();
if (data == QLatin1String("\\0"))
return QStringList(QString());
QStringList value;
QString val;
val.reserve(data.size());
bool quoted = false;
for (int p = 0; p < data.length(); p++) {
if (quoted) {
val += data[p];
quoted = false;
} else if (data[p].unicode() == '\\') {
quoted = true;
} else if (data[p].unicode() == ',') {
val.squeeze(); // release any unused memory
value.append(val);
val.clear();
val.reserve(data.size() - p);
} else {
val += data[p];
}
}
value.append(val);
return value;
}
QList<int> KexiDB::deserializeIntList(const QString &data, bool *ok)
{
return KexiDB::stringListToIntList(
KexiDB::deserializeList(data), ok);
}
QString KexiDB::variantToString(const QVariant& v)
{
if (v.type() == QVariant::ByteArray)
if (v.type() == QVariant::ByteArray) {
return KexiDB::escapeBLOB(v.toByteArray(), KexiDB::BLOBEscapeHex);
}
else if (v.type() == QVariant::StringList) {
return serializeList(v.toStringList());
}
return v.toString();
}
......@@ -1218,6 +1301,10 @@ QVariant KexiDB::stringToVariant(const QString& s, QVariant::Type type, bool &ok
ok = true;
return ba;
}
if (type == QVariant::StringList) {
ok = true;
return deserializeList(s);
}
QVariant result(s);
if (!result.convert(type)) {
ok = false;
......
/* This file is part of the KDE project
Copyright (C) 2004-2010 Jarosław Staniek <staniek@kde.org>
Copyright (C) 2004-2012 Jarosław Staniek <staniek@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -72,6 +72,18 @@ inline CALLIGRADB_EXPORT bool deleteRow(Connection &conn, const QString &tableNa
+ " AND " + keyname2 + "=" + conn.driver()->valueToSQL(keytype2, keyval2));
}
/*! Delete record with three generic criterias. */
inline CALLIGRADB_EXPORT bool deleteRow(Connection &conn, const QString &tableName,
const QString &keyname1, Field::Type keytype1, const QVariant& keyval1,
const QString &keyname2, Field::Type keytype2, const QVariant& keyval2,
const QString &keyname3, Field::Type keytype3, const QVariant& keyval3)
{
return conn.executeSQL("DELETE FROM " + tableName + " WHERE "
+ keyname1 + "=" + conn.driver()->valueToSQL(keytype1, keyval1)
+ " AND " + keyname2 + "=" + conn.driver()->valueToSQL(keytype2, keyval2)
+ " AND " + keyname3 + "=" + conn.driver()->valueToSQL(keytype3, keyval3));
}
inline CALLIGRADB_EXPORT bool replaceRow(Connection &conn, TableSchema *table,
const QString &keyname, const QString &keyval, const QString &valname, QVariant val, int ftype)
{
......@@ -415,6 +427,29 @@ CALLIGRADB_EXPORT QString escapeBLOB(const QByteArray& array, BLOBEscapingType t
This function is used by PostgreSQL KexiDB and migration drivers. */
CALLIGRADB_EXPORT QByteArray pgsqlByteaToByteArray(const char* data, int length);
/*! \return int list converted from string list.
If \a ok is not 0, *ok is set to result of the conversion.
*/
CALLIGRADB_EXPORT QList<int> stringListToIntList(const QStringList &list, bool *ok);
/*! \return string converted from list \a list.
Separators are ',' characters, "," and "\\" are escaped.
@see deserializeList()
*/
CALLIGRADB_EXPORT QString serializeList(const QStringList &list);
/*! \return string list converted from \a data which was built using serializeList().
Separators are ',' characters, escaping is assumed as "\\,".
*/
CALLIGRADB_EXPORT QStringList deserializeList(const QString &data);
/*! \return int list converted from \a data which was built using serializeList().
Separators are ',' characters, escaping is assumed as "\\,".
If \a ok is not 0, *ok is set to result of the conversion.
@see KexiDB::stringListToIntList()
*/
CALLIGRADB_EXPORT QList<int> deserializeIntList(const QString &data, bool *ok);
/*! \return string value serialized from a variant value \a v.
This functions works like QVariant::toString() except the case when \a v is of type ByteArray.
In this case KexiDB::escapeBLOB(v.toByteArray(), KexiDB::BLOBEscapeHex) is used.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment