Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit fd881f91 authored by EXT Arnaud Clère's avatar EXT Arnaud Clère
Browse files

Removed generic part from QModel

parent 7f694c3b
...@@ -53,13 +53,11 @@ ...@@ -53,13 +53,11 @@
// ////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////
// Q*Model support // Q*Model support
class QModelBind : public QAbstractValue class QModelBind
{ {
Q_DISABLE_COPY(QModelBind) Q_DISABLE_COPY(QModelBind)
public: public:
QModelBind(QAbstractItemModel* m, bool rowFirst=true) : m(m), rowFirst(rowFirst) { Q_ASSERT(m); } QModelBind(QAbstractItemModel* m, bool rowFirst=true) : m(m), rowFirst(rowFirst) { Q_ASSERT(m); }
QValue value() { return QCur(this).value(); }
protected: protected:
enum : int { enum : int {
T=0, //!< initial state T=0, //!< initial state
...@@ -102,61 +100,7 @@ protected: ...@@ -102,61 +100,7 @@ protected:
} }
} }
virtual bool tryAny() { return true; } virtual QAbstractValue* itemBind() = 0;
using QAbstractValue::tryBind; // full overload set so that following overloads calls work (instead of calling themselves and overflowing the call stack)
virtual bool tryBind(const QUtf8Data& r) { QUtf8Data copy(r); return tryBind(std::move(copy)); }
virtual bool tryBind(const QString& r) { QString copy(r); return tryBind(std::move(copy)); }
virtual bool tryBind(const bool& r) { bool copy(r); return tryBind(std::move(copy)); }
virtual bool tryBind(const qint8& r) { qint8 copy(r); return tryBind(std::move(copy)); }
virtual bool tryBind(const quint8& r) { quint8 copy(r); return tryBind(std::move(copy)); }
virtual bool tryBind(const qint16& r) { qint16 copy(r); return tryBind(std::move(copy)); }
virtual bool tryBind(const quint16& r) { quint16 copy(r); return tryBind(std::move(copy)); }
virtual bool tryBind(const qint32& r) { qint32 copy(r); return tryBind(std::move(copy)); }
virtual bool tryBind(const quint32& r) { quint32 copy(r); return tryBind(std::move(copy)); }
virtual bool tryBind(const qint64& r) { qint64 copy(r); return tryBind(std::move(copy)); }
virtual bool tryBind(const quint64& r) { quint64 copy(r); return tryBind(std::move(copy)); }
virtual bool tryBind(const float& r) { float copy(r); return tryBind(std::move(copy)); }
virtual bool tryBind(const double& r) { double copy(r); return tryBind(std::move(copy)); }
virtual bool tryBind(const QByteArray& r) { QByteArray copy(r); return tryBind(std::move(copy)); }
virtual bool tryBind(const QVariant& r) { QVariant copy(r); return tryBind(std::move(copy)); }
virtual bool tryBind( const char* u) { return tryBind(QString::fromUtf8 (u )); } // required to match better than QString overloads
virtual bool tryBind( QUtf8DataView u) { return tryBind(QString::fromUtf8 (u.data(), u.size())); }
virtual bool tryBind( QAsciiDataView a) { return tryBind(QString::fromLatin1(a.data(), a.size())); }
virtual bool tryBind( QLatin1String l) { return tryBind(QString(l) ); }
virtual bool tryBind( QStringView s) { return tryBind(s.toString() ); }
virtual bool tryBind( QUtf8Data&& s) { return tryBind(QString::fromUtf8 (s.utf8(), s.size())); }
virtual bool tryBind( QByteArray&& s) { return tryBind(QString(s.size()*2+2+1, Qt::Uninitialized).append("0x").append(s.toHex())); }
virtual bool tryBind( qint8&& n) { return tryBind( qint64(n)); }
virtual bool tryBind( quint8&& n) { return tryBind( quint64(n)); }
virtual bool tryBind( qint16&& n) { return tryBind( qint64(n)); }
virtual bool tryBind( quint16&& n) { return tryBind( quint64(n)); }
virtual bool tryBind( qint32&& n) { return tryBind( qint64(n)); }
virtual bool tryBind( quint32&& n) { return tryBind( quint64(n)); }
virtual bool tryBind( qint8& n) { return tryBind( qint64(n)); }
virtual bool tryBind( quint8& n) { return tryBind( quint64(n)); }
virtual bool tryBind( qint16& n) { return tryBind( qint64(n)); }
virtual bool tryBind( quint16& n) { return tryBind( quint64(n)); }
virtual bool tryBind( qint32& n) { return tryBind( qint64(n)); }
virtual bool tryBind( quint32& n) { return tryBind( quint64(n)); }
virtual bool tryBind( QUtf8Data& r) { return tryBind( QUtf8Data(r)); }
virtual bool tryBind( QString& r) { return tryBind( QString(r)); }
virtual bool tryBind( bool& r) { return tryBind( bool(r)); }
virtual bool tryBind( qint64& r) { return tryBind( qint64(r)); }
virtual bool tryBind( quint64& r) { return tryBind( quint64(r)); }
virtual bool tryBind( float& r) { return tryBind( float(r)); }
virtual bool tryBind( double& r) { return tryBind( double(r)); }
virtual bool tryBind( QByteArray& r) { return tryBind(QByteArray(r)); }
virtual bool tryBind( QVariant& r) { return tryBind( QVariant(r)); }
virtual QAbstractValue* itemBind() = 0;
//! Checks whether current dimension \c d is R or C, inverting R and C dimensions if !rowFirst //! Checks whether current dimension \c d is R or C, inverting R and C dimensions if !rowFirst
bool is(int rc) { Q_ASSERT(rc==R || rc==C); return rowFirst ? d==rc : d==(rc==R ? C : R); } bool is(int rc) { Q_ASSERT(rc==R || rc==C); return rowFirst ? d==rc : d==(rc==R ? C : R); }
...@@ -214,15 +158,18 @@ protected: ...@@ -214,15 +158,18 @@ protected:
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
template <class TItemWriter=QJsonWriter> template <class TItemWriter=QJsonWriter>
class QModelWriter : public QModelBind class QModelWriter : public QModelBind, public QAbstractValueWriter
{ {
Q_DISABLE_COPY(QModelWriter) Q_DISABLE_COPY(QModelWriter)
public: public:
QModelWriter(QAbstractItemModel* m, bool rowFirst=true) : QModelBind(m, rowFirst), w(&ba) {} QModelWriter(QAbstractItemModel* m, bool rowFirst=true) : QModelBind(m, rowFirst), w(&ba) {}
virtual QValueMode mode() const noexcept { return QValueMode::Write; } virtual QValueMode mode() const noexcept { return QValueMode::Write; }
virtual bool isValid() const noexcept { return true; } //!< Write status ignored by default (no need to test intermediate status to choose between trySequence(), etc. virtual bool isValid() const noexcept { return true; } //!< Write status ignored by default (no need to test intermediate status to choose between trySequence(), etc.
virtual QValue value() { return QCur(this).value(); }
protected: protected:
virtual void _meta(QIdentifierLiteral& n, QAsciiData& meta) { return QModelBind::_meta(n, meta); }
virtual bool tryOut() { virtual bool tryOut() {
d--; d--;
if (I<=(d+1)) { if (I<=(d+1)) {
...@@ -378,6 +325,8 @@ protected: ...@@ -378,6 +325,8 @@ protected:
using QAbstractValue::tryBind; // full overload set so that following overloads calls work (instead of calling themselves and overflowing the call stack) using QAbstractValue::tryBind; // full overload set so that following overloads calls work (instead of calling themselves and overflowing the call stack)
virtual bool tryBind(QUtf8DataView u) { return tryBind(QString::fromUtf8 (u.data(), u.size())); }
virtual bool tryAny ( ) { return hidden() ? true : I<=d ? itemBind()->tryAny() : write(QVariant()); } virtual bool tryAny ( ) { return hidden() ? true : I<=d ? itemBind()->tryAny() : write(QVariant()); }
virtual bool tryNull( ) { return hidden() ? true : I<=d ? itemBind()->tryNull() : write(QVariant::fromValue(nullptr)); } virtual bool tryNull( ) { return hidden() ? true : I<=d ? itemBind()->tryNull() : write(QVariant::fromValue(nullptr)); }
virtual bool tryBind( QString&& u) { return hidden() ? true : I<=d ? itemBind()->tryBind(std::move(u)) : write(u ); } virtual bool tryBind( QString&& u) { return hidden() ? true : I<=d ? itemBind()->tryBind(std::move(u)) : write(u ); }
...@@ -385,9 +334,9 @@ protected: ...@@ -385,9 +334,9 @@ protected:
virtual bool tryBind( float&& f) { return hidden() ? true : I<=d ? itemBind()->tryBind(std::move(f)) : write(f ); } virtual bool tryBind( float&& f) { return hidden() ? true : I<=d ? itemBind()->tryBind(std::move(f)) : write(f ); }
virtual bool tryBind( double&& f) { return hidden() ? true : I<=d ? itemBind()->tryBind(std::move(f)) : write(f ); } virtual bool tryBind( double&& f) { return hidden() ? true : I<=d ? itemBind()->tryBind(std::move(f)) : write(f ); }
virtual bool tryBind( quint64&& i) { return hidden() ? true : I<=d ? itemBind()->tryBind(std::move(i)) : i<=quint64(std::numeric_limits<unsigned int>::max()) ? write(static_cast<unsigned int>(i)) : virtual bool tryBind( quint64&& i) { return hidden() ? true : I<=d ? itemBind()->tryBind(std::move(i)) : i<=quint64(std::numeric_limits<unsigned int>::max()) ? write(static_cast<unsigned int>(i)) :
write(i ); } // with QSpinBox delegate write(i ); } // with QSpinBox delegate
virtual bool tryBind( qint64&& i) { return hidden() ? true : I<=d ? itemBind()->tryBind(std::move(i)) : i<= qint64(std::numeric_limits< int>::max()) ? write(static_cast< int>(i)) : virtual bool tryBind( qint64&& i) { return hidden() ? true : I<=d ? itemBind()->tryBind(std::move(i)) : i<= qint64(std::numeric_limits< int>::max()) ? write(static_cast< int>(i)) :
write(i ); } write(i ); }
virtual bool tryBind( QVariant&& t) { return hidden() ? true : I<=d ? itemBind()->tryBind( QVariant(t)) : write(t ); } virtual bool tryBind( QVariant&& t) { return hidden() ? true : I<=d ? itemBind()->tryBind( QVariant(t)) : write(t ); }
// TODO QDate*, QTime // TODO QDate*, QTime
// TODO QPixmap if metadata suggests a QMimeData image ? // TODO QPixmap if metadata suggests a QMimeData image ?
...@@ -402,15 +351,18 @@ protected: ...@@ -402,15 +351,18 @@ protected:
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
template <class TItemReader=QJsonReader> template <class TItemReader=QJsonReader>
class QModelReader : public QModelBind class QModelReader : public QModelBind, public QAbstractValueReader
{ {
Q_DISABLE_COPY(QModelReader) Q_DISABLE_COPY(QModelReader)
public: public:
QModelReader(QAbstractItemModel* m, bool rowFirst=true) : QModelBind(m, rowFirst), r(&io) { io.open(QIODevice::ReadOnly); } QModelReader(QAbstractItemModel* m, bool rowFirst=true) : QModelBind(m, rowFirst), r(&io) { io.open(QIODevice::ReadOnly); }
virtual QValueMode mode() const noexcept { return QValueMode::Read; } virtual QValueMode mode() const noexcept { return QValueMode::Read; }
virtual bool isValid() const noexcept { return true; } //!< Read status ignored by default (QAbstractItemModel is not sequential) virtual bool isValid() const noexcept { return true; } //!< Read status ignored by default (QAbstractItemModel is not sequential)
virtual QValue value() { return QCur(this).value(); }
protected: protected:
virtual void _meta(QIdentifierLiteral& n, QAsciiData& meta) { return QModelBind::_meta(n, meta); }
virtual bool tryOut() { virtual bool tryOut() {
if (I<=d) { if (I<=d) {
d--; d--;
...@@ -596,13 +548,6 @@ protected: ...@@ -596,13 +548,6 @@ protected:
// TODO QDate*, QTime // TODO QDate*, QTime
// TODO QPixmap if metadata suggests a QMimeData image ? // TODO QPixmap if metadata suggests a QMimeData image ?
virtual bool tryBind( qint8& n) { qint64 l; if (!tryBind(l)) return false; if (l<std::numeric_limits< qint8>::min() || std::numeric_limits< qint8>::max()<l) { isErrorFiltered(qBindExpectedSmallerNumber); return false; } n= qint8(l); return true; }
virtual bool tryBind( quint8& n) { quint64 l; if (!tryBind(l)) return false; if ( std::numeric_limits< quint8>::max()<l) { isErrorFiltered(qBindExpectedSmallerNumber); return false; } n= quint8(l); return true; }
virtual bool tryBind( qint16& n) { qint64 l; if (!tryBind(l)) return false; if (l<std::numeric_limits< qint16>::min() || std::numeric_limits< qint16>::max()<l) { isErrorFiltered(qBindExpectedSmallerNumber); return false; } n= qint16(l); return true; }
virtual bool tryBind( quint16& n) { quint64 l; if (!tryBind(l)) return false; if ( std::numeric_limits<quint16>::max()<l) { isErrorFiltered(qBindExpectedSmallerNumber); return false; } n=quint16(l); return true; }
virtual bool tryBind( qint32& n) { qint64 l; if (!tryBind(l)) return false; if (l<std::numeric_limits< qint32>::min() || std::numeric_limits< qint32>::max()<l) { isErrorFiltered(qBindExpectedSmallerNumber); return false; } n= qint32(l); return true; }
virtual bool tryBind( quint32& n) { quint64 l; if (!tryBind(l)) return false; if ( std::numeric_limits<quint32>::max()<l) { isErrorFiltered(qBindExpectedSmallerNumber); return false; } n=quint32(l); return true; }
virtual bool tryBind( QUtf8Data& r) { if (hidden()) return true; if (I<=d) return itemBind()->tryBind(r); QVariant v=read(); if (v.type()!=QVariant ::String ) return false; r=QUtf8Data(v.toString().toUtf8()); return true; } virtual bool tryBind( QUtf8Data& r) { if (hidden()) return true; if (I<=d) return itemBind()->tryBind(r); QVariant v=read(); if (v.type()!=QVariant ::String ) return false; r=QUtf8Data(v.toString().toUtf8()); return true; }
virtual bool tryBind( QString& r) { if (hidden()) return true; if (I<=d) return itemBind()->tryBind(r); QVariant v=read(); if (v.type()!=QVariant ::String ) return false; r= v.toString () ; return true; } virtual bool tryBind( QString& r) { if (hidden()) return true; if (I<=d) return itemBind()->tryBind(r); QVariant v=read(); if (v.type()!=QVariant ::String ) return false; r= v.toString () ; return true; }
virtual bool tryBind( bool& r) { if (hidden()) return true; if (I<=d) return itemBind()->tryBind(r); QVariant v=read(); if (v.type()!=QVariant ::Bool ) return false; r= v.toBool () ; return true; } virtual bool tryBind( bool& r) { if (hidden()) return true; if (I<=d) return itemBind()->tryBind(r); QVariant v=read(); if (v.type()!=QVariant ::Bool ) return false; r= v.toBool () ; return true; }
......
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