Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
modmedLog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MODMED
modmedLog
Commits
82fe1d88
Commit
82fe1d88
authored
Dec 06, 2019
by
EXT Arnaud Clère
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed error handling aborting QModelWriter
parent
012c6a96
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
25 deletions
+35
-25
tests/QBind/QJson_impl.h
tests/QBind/QJson_impl.h
+6
-0
tests/QBind/QModel_impl.h
tests/QBind/QModel_impl.h
+21
-19
tests/QBind/QValue.h
tests/QBind/QValue.h
+7
-6
tests/QBind/main.cpp
tests/QBind/main.cpp
+1
-0
No files found.
tests/QBind/QJson_impl.h
View file @
82fe1d88
...
...
@@ -156,6 +156,12 @@ public:
QJsonWriter
(
QIODevice
*
io
)
:
io
(
io
)
{
Q_ASSERT
(
io
||
ba
);
}
QJsonWriter
(
QByteArray
*
ba
)
:
ba
(
ba
)
{
Q_ASSERT
(
io
||
ba
);
}
~
QJsonWriter
()
{
while
(
!
levels
.
isEmpty
())
write
(
levels
.
takeLast
().
end
);
}
void
reset
(
QByteArray
*
other
)
{
levels
.
clear
();
io
=
nullptr
;
ba
=
other
;
Q_ASSERT
(
ba
);
}
// Shortcuts
/**/
QValue
value
(
)
{
return
QValueStatus
(
this
).
value
();
}
...
...
tests/QBind/QModel_impl.h
View file @
82fe1d88
...
...
@@ -156,19 +156,6 @@ protected:
virtual
bool
tryBind
(
QByteArray
&
r
)
{
return
tryBind
(
QByteArray
(
r
));
}
virtual
bool
tryBind
(
QVariant
&
r
)
{
return
tryBind
(
QVariant
(
r
));
}
bool
handleError
(
QIdentifierLiteral
e
,
QString
context
=
QString
())
{
if
(
errorHandler
)
{
QString
path
;
for
(
auto
current
=
parent
;
parent
.
isValid
();
current
=
current
.
parent
())
{
path
.
prepend
(
QString
(
'/'
).
append
(
current
.
row
()).
append
(
','
).
append
(
current
.
column
()));
}
return
errorHandler
(
e
,
path
.
append
(
context
));
}
else
{
return
false
;
}
}
virtual
QAbstractValue
*
itemBind
()
=
0
;
//! Checks whether current dimension \c d is R or C, inverting R and C dimensions if !rowFirst
...
...
@@ -178,7 +165,9 @@ protected:
QModelIndex
current
()
{
int
rows
=
m
->
rowCount
(
parent
);
if
(
rows
<=
row
)
m
->
insertRows
(
rows
,
1
+
row
-
rows
,
parent
);
int
cols
=
m
->
columnCount
(
parent
);
if
(
cols
<=
col
)
m
->
insertColumns
(
cols
,
1
+
col
-
cols
,
parent
);
auto
idx
=
m
->
index
(
row
,
col
,
parent
);
Q_ASSERT
(
hidden
()
||
m
->
checkIndex
(
idx
));
return
idx
;
auto
idx
=
m
->
index
(
row
,
col
,
parent
);
Q_ASSERT
(
hidden
()
||
m
->
checkIndex
(
idx
));
return
idx
;
}
//! Returns whether current data must be hidden because a current or parent column or row was filtered out
bool
hidden
()
noexcept
{
...
...
@@ -220,8 +209,6 @@ protected:
QList
<
QByteArray
>
columnNames
;
bool
metaColumnNames
=
false
;
QVector
<
int
>
sizes
;
QValueErrorHandler
errorHandler
=
nullptr
;
};
// --------------------------------------------------------------------------
...
...
@@ -405,8 +392,10 @@ protected:
// TODO QDate*, QTime
// TODO QPixmap if metadata suggests a QMimeData image ?
void
resetItemData
()
{
ba
.
clear
();
w
=
std
::
move
(
TItemWriter
(
&
ba
));
}
QAbstractValue
*
itemBind
()
{
return
static_cast
<
QAbstractValue
*>
(
&
w
);
}
virtual
bool
handleError
(
QIdentifierLiteral
e
,
QString
context
=
QString
())
{
return
errorHandler
?
errorHandler
(
e
,
context
)
:
true
;
}
void
resetItemData
()
{
ba
.
clear
();
w
.
reset
(
&
ba
);
}
QAbstractValue
*
itemBind
()
{
return
static_cast
<
QAbstractValue
*>
(
&
w
);
}
QByteArray
ba
;
TItemWriter
w
;
...
...
@@ -423,7 +412,7 @@ public:
QModelReader
(
QAbstractItemModel
*
m
,
bool
rowFirst
=
true
)
:
QModelBind
(
m
,
rowFirst
),
r
(
&
io
)
{
io
.
open
(
QIODevice
::
ReadOnly
);
}
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)
protected:
virtual
bool
tryOut
()
{
if
(
I
<=
d
)
{
...
...
@@ -630,6 +619,19 @@ protected:
QAbstractValue
*
itemBind
()
{
return
static_cast
<
QAbstractValue
*>
(
&
r
);
}
void
setItemData
(
QUtf8Data
u
)
{
io
.
buffer
()
=
u
.
utf8
();
io
.
seek
(
0
);
r
.
reset
(
&
io
);
}
bool
handleError
(
QIdentifierLiteral
e
,
QString
context
=
QString
())
{
if
(
errorHandler
)
{
QString
path
;
for
(
auto
current
=
parent
;
parent
.
isValid
();
current
=
current
.
parent
())
{
path
.
prepend
(
QString
(
'/'
).
append
(
current
.
row
()).
append
(
','
).
append
(
current
.
column
()));
}
return
errorHandler
(
e
,
path
.
append
(
context
));
}
else
{
return
false
;
}
}
QBuffer
io
;
TItemReader
r
;
};
tests/QBind/QValue.h
View file @
82fe1d88
...
...
@@ -225,8 +225,10 @@ struct QAbstractValue {
//! \warning meta() is ignored by default and subject to various interpretation, so users should define or adopt existing meta data standards like XSD for sake of interoperability
virtual
void
_meta
(
QIdentifierLiteral
&
,
QAsciiData
&
)
{}
virtual
QValueErrorHandler
setErrorHandler
(
QValueErrorHandler
newHandler
=
nullptr
)
{
Q_UNUSED
(
newHandler
)
return
nullptr
;
}
virtual
bool
handleError
(
QIdentifierLiteral
name
,
QString
context
=
QString
())
{
Q_UNUSED
(
name
)
Q_UNUSED
(
context
)
return
false
;
}
virtual
QValueErrorHandler
setErrorHandler
(
QValueErrorHandler
newHandler
=
nullptr
)
{
auto
previousHandler
=
errorHandler
;
errorHandler
=
newHandler
;
return
previousHandler
;
}
virtual
bool
handleError
(
QIdentifierLiteral
e
,
QString
context
=
QString
())
=
0
;
protected:
QValueErrorHandler
errorHandler
=
nullptr
;
};
// //////////////////////////////////////////////////////////////////////////
...
...
@@ -642,6 +644,8 @@ struct QAbstractValueWriter : public QAbstractValue
virtual
bool
tryBind
(
const
QVariant
&
r
)
{
QVariant
copy
(
r
);
return
tryBind
(
std
::
move
(
copy
));
}
virtual
bool
tryAny
()
{
return
tryNull
();
}
virtual
bool
handleError
(
QIdentifierLiteral
e
,
QString
context
=
QString
())
{
return
errorHandler
?
errorHandler
(
e
,
context
)
:
true
;
}
};
//! Base QAbstractValue implementations with QValueMode::Read
...
...
@@ -745,8 +749,7 @@ struct QAbstractValueReader : public QAbstractValue
return
bound
||
handleError
(
qBindUnexpectedValue
);
}
QValueErrorHandler
setErrorHandler
(
QValueErrorHandler
newHandler
=
nullptr
)
{
auto
previousHandler
=
errorHandler
;
errorHandler
=
newHandler
;
return
previousHandler
;
}
bool
handleError
(
QIdentifierLiteral
e
,
QString
context
=
QString
())
{
return
errorHandler
?
errorHandler
(
e
,
context
)
:
false
;
}
virtual
bool
handleError
(
QIdentifierLiteral
e
,
QString
context
=
QString
())
{
return
errorHandler
?
errorHandler
(
e
,
context
)
:
false
;
}
protected:
bool
toByteArray
(
QByteArray
&
b
,
QUtf8Data
s
)
{
const
QByteArray
&
bytes
=
s
.
utf8
();
...
...
@@ -769,8 +772,6 @@ protected:
}
v
=
QVariant
(
b
);
}
QValueErrorHandler
errorHandler
=
nullptr
;
};
// //////////////////////////////////////////////////////////////////////////
...
...
tests/QBind/main.cpp
View file @
82fe1d88
...
...
@@ -1147,6 +1147,7 @@ void doGuiExample() {
QStringList
errors
;
auto
handler
=
[
&
errors
](
QIdentifierLiteral
name
,
QString
context
){
errors
.
append
(
context
.
append
(
name
.
latin1
()));
return
true
;
};
auto
ignore
=
[](
QIdentifierLiteral
,
QString
){
return
true
;
};
// Various possibilities to customize bind
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment