Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Telemetry
KUserFeedback
Commits
d6459a67
Commit
d6459a67
authored
Dec 29, 2016
by
Volker Krause
Browse files
Extract and expand aggregation element structure
This adds support for non-scalar entry properties such as size.
parent
8288829a
Changes
10
Hide whitespace changes
Inline
Side-by-side
analyzer/CMakeLists.txt
View file @
d6459a67
set
(
analyzer_lib_srcs
core/aggregation.cpp
core/aggregationelement.cpp
core/product.cpp
core/sample.cpp
core/schemaentry.cpp
...
...
analyzer/core/aggregation.cpp
View file @
d6459a67
...
...
@@ -32,12 +32,12 @@ void Aggregation::setType(Aggregation::Type t)
m_type
=
t
;
}
QVector
<
Aggregation
::
Element
>
Aggregation
::
elements
()
const
QVector
<
AggregationElement
>
Aggregation
::
elements
()
const
{
return
m_elements
;
}
void
Aggregation
::
setElements
(
const
QVector
<
Aggregation
::
Element
>&
elements
)
void
Aggregation
::
setElements
(
const
QVector
<
AggregationElement
>&
elements
)
{
m_elements
=
elements
;
}
analyzer/core/aggregation.h
View file @
d6459a67
...
...
@@ -18,8 +18,7 @@
#ifndef USERFEEDBACK_ANALYZER_AGGREGATION_H
#define USERFEEDBACK_ANALYZER_AGGREGATION_H
#include <core/schemaentry.h>
#include <core/schemaentryelement.h>
#include <core/aggregationelement.h>
#include <QTypeInfo>
...
...
@@ -45,23 +44,18 @@ public:
Type
type
()
const
;
void
setType
(
Type
t
);
struct
Element
{
SchemaEntry
entry
;
SchemaEntryElement
element
;
};
QVector
<
Element
>
elements
()
const
;
void
setElements
(
const
QVector
<
Element
>
&
elements
);
QVector
<
AggregationElement
>
elements
()
const
;
void
setElements
(
const
QVector
<
AggregationElement
>
&
elements
);
private:
Type
m_type
=
None
;
QVector
<
Element
>
m_elements
;
QVector
<
Aggregation
Element
>
m_elements
;
};
}
}
Q_DECLARE_TYPEINFO
(
UserFeedback
::
Analyzer
::
Aggregation
,
Q_MOVABLE_TYPE
);
Q_DECLARE_METATYPE
(
UserFeedback
::
Analyzer
::
Aggregation
::
Element
)
Q_DECLARE_METATYPE
(
UserFeedback
::
Analyzer
::
Aggregation
::
Type
)
#endif // USERFEEDBACK_ANALYZER_AGGREGATION_H
analyzer/core/aggregationelement.cpp
0 → 100644
View file @
d6459a67
/*
Copyright (C) 2016 Volker Krause <vkrause@kde.org>
This program 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 version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "aggregationelement.h"
using
namespace
UserFeedback
::
Analyzer
;
AggregationElement
::
AggregationElement
()
=
default
;
AggregationElement
::~
AggregationElement
()
=
default
;
SchemaEntry
AggregationElement
::
schemaEntry
()
const
{
return
m_entry
;
}
void
AggregationElement
::
setSchemaEntry
(
const
SchemaEntry
&
entry
)
{
m_entry
=
entry
;
}
SchemaEntryElement
AggregationElement
::
schemaEntryElement
()
const
{
return
m_element
;
}
void
AggregationElement
::
setSchemaEntryElement
(
const
SchemaEntryElement
&
element
)
{
m_element
=
element
;
}
AggregationElement
::
Type
AggregationElement
::
type
()
const
{
return
m_type
;
}
void
AggregationElement
::
setType
(
AggregationElement
::
Type
t
)
{
m_type
=
t
;
}
QString
AggregationElement
::
displayString
()
const
{
switch
(
m_type
)
{
case
Value
:
return
m_entry
.
name
()
+
QLatin1Char
(
'.'
)
+
m_element
.
name
();
case
Size
:
return
m_entry
.
name
()
+
QLatin1String
(
"[size]"
);
}
Q_UNREACHABLE
();
}
bool
AggregationElement
::
operator
==
(
const
AggregationElement
&
other
)
const
{
if
(
m_type
!=
other
.
m_type
)
return
false
;
switch
(
m_type
)
{
case
Value
:
return
m_element
.
name
()
==
other
.
m_element
.
name
()
&&
m_entry
.
name
()
==
other
.
m_entry
.
name
();
case
Size
:
return
m_element
.
name
()
==
other
.
m_element
.
name
();
}
Q_UNREACHABLE
();
}
analyzer/core/aggregationelement.h
0 → 100644
View file @
d6459a67
/*
Copyright (C) 2016 Volker Krause <vkrause@kde.org>
This program 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 version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef USERFEEDBACK_ANALYZER_AGGREGATIONELEMENT_H
#define USERFEEDBACK_ANALYZER_AGGREGATIONELEMENT_H
#include "schemaentry.h"
#include "schemaentryelement.h"
namespace
UserFeedback
{
namespace
Analyzer
{
class
AggregationElement
{
public:
AggregationElement
();
~
AggregationElement
();
bool
operator
==
(
const
AggregationElement
&
other
)
const
;
enum
Type
{
Value
,
Size
};
Type
type
()
const
;
void
setType
(
Type
t
);
SchemaEntry
schemaEntry
()
const
;
void
setSchemaEntry
(
const
SchemaEntry
&
entry
);
SchemaEntryElement
schemaEntryElement
()
const
;
void
setSchemaEntryElement
(
const
SchemaEntryElement
&
element
);
QString
displayString
()
const
;
private:
SchemaEntry
m_entry
;
SchemaEntryElement
m_element
;
Type
m_type
=
Value
;
};
}
}
Q_DECLARE_TYPEINFO
(
UserFeedback
::
Analyzer
::
AggregationElement
,
Q_MOVABLE_TYPE
);
Q_DECLARE_METATYPE
(
UserFeedback
::
Analyzer
::
AggregationElement
)
#endif // USERFEEDBACK_ANALYZER_AGGREGATIONELEMENT_H
analyzer/core/product.cpp
View file @
d6459a67
...
...
@@ -103,7 +103,10 @@ static Product productFromJsonObject(const QJsonObject &obj)
for
(
const
auto
&
elem
:
entry
.
elements
())
{
Aggregation
aggr
;
aggr
.
setType
(
Aggregation
::
Category
);
aggr
.
setElements
({{
entry
,
elem
}});
AggregationElement
e
;
e
.
setSchemaEntry
(
entry
);
e
.
setSchemaEntryElement
(
elem
);
aggr
.
setElements
({
e
});
aggrs
.
push_back
(
aggr
);
}
}
...
...
analyzer/model/aggregationeditormodel.cpp
View file @
d6459a67
...
...
@@ -65,7 +65,7 @@ QVariant AggregationEditorModel::data(const QModelIndex& index, int role) const
case
1
:
if
(
aggr
.
elements
().
isEmpty
())
return
tr
(
"<none>"
);
return
QString
(
aggr
.
elements
().
at
(
0
).
entry
.
name
()
+
QLatin1Char
(
'.'
)
+
aggr
.
elements
().
at
(
0
).
element
.
name
()
);
return
aggr
.
elements
().
at
(
0
).
displayString
(
);
}
}
else
if
(
role
==
Qt
::
EditRole
)
{
const
auto
aggr
=
m_product
.
aggregations
().
at
(
index
.
row
());
...
...
@@ -115,7 +115,7 @@ bool AggregationEditorModel::setData(const QModelIndex& index, const QVariant& v
aggr
.
setType
(
value
.
value
<
Aggregation
::
Type
>
());
break
;
case
1
:
aggr
.
setElements
({
value
.
value
<
Aggregation
::
Element
>
()
});
aggr
.
setElements
({
value
.
value
<
AggregationElement
>
()
});
break
;
}
m_product
.
setAggregations
(
aggrs
);
...
...
analyzer/model/aggregationelementmodel.cpp
View file @
d6459a67
...
...
@@ -33,8 +33,19 @@ void AggregationElementModel::setProduct(const Product& product)
beginResetModel
();
m_elements
.
clear
();
for
(
const
auto
&
entry
:
product
.
schema
())
{
for
(
const
auto
&
elem
:
entry
.
elements
())
m_elements
.
push_back
({
entry
,
elem
});
for
(
const
auto
&
elem
:
entry
.
elements
())
{
AggregationElement
e
;
e
.
setSchemaEntry
(
entry
);
e
.
setSchemaEntryElement
(
elem
);
e
.
setType
(
AggregationElement
::
Value
);
m_elements
.
push_back
(
e
);
}
if
(
entry
.
dataType
()
!=
SchemaEntry
::
Scalar
)
{
AggregationElement
e
;
e
.
setSchemaEntry
(
entry
);
e
.
setType
(
AggregationElement
::
Size
);
m_elements
.
push_back
(
e
);
}
}
endResetModel
();
}
...
...
@@ -53,7 +64,7 @@ QVariant AggregationElementModel::data(const QModelIndex& index, int role) const
const
auto
e
=
m_elements
.
at
(
index
.
row
());
switch
(
role
)
{
case
Qt
::
DisplayRole
:
return
QString
(
e
.
entry
.
name
()
+
QLatin1Char
(
'.'
)
+
e
.
element
.
name
()
);
case
Qt
::
DisplayRole
:
return
e
.
displayString
(
);
case
Qt
::
EditRole
:
return
QVariant
::
fromValue
(
e
);
}
...
...
@@ -62,10 +73,10 @@ QVariant AggregationElementModel::data(const QModelIndex& index, int role) const
QModelIndexList
AggregationElementModel
::
match
(
const
QModelIndex
&
start
,
int
role
,
const
QVariant
&
value
,
int
hits
,
Qt
::
MatchFlags
flags
)
const
{
if
(
role
==
Qt
::
EditRole
&&
value
.
userType
()
==
qMetaTypeId
<
Aggregation
::
Element
>
()
&&
hits
==
1
&&
start
.
row
()
==
0
)
{
const
auto
cmp
=
value
.
value
<
Aggregation
::
Element
>
();
if
(
role
==
Qt
::
EditRole
&&
value
.
userType
()
==
qMetaTypeId
<
AggregationElement
>
()
&&
hits
==
1
&&
start
.
row
()
==
0
)
{
const
auto
cmp
=
value
.
value
<
AggregationElement
>
();
for
(
int
i
=
0
;
i
<
m_elements
.
size
();
++
i
)
{
if
(
m_elements
.
at
(
i
)
.
entry
==
cmp
.
entry
&&
m_elements
.
at
(
i
).
element
==
cmp
.
element
)
if
(
m_elements
.
at
(
i
)
==
cmp
)
return
{
index
(
i
,
0
)
};
}
}
...
...
analyzer/model/aggregationelementmodel.h
View file @
d6459a67
...
...
@@ -43,7 +43,7 @@ public:
QModelIndexList
match
(
const
QModelIndex
&
start
,
int
role
,
const
QVariant
&
value
,
int
hits
,
Qt
::
MatchFlags
flags
)
const
override
;
private:
QVector
<
Aggregation
::
Element
>
m_elements
;
QVector
<
AggregationElement
>
m_elements
;
};
}
}
...
...
analyzer/schemaeditor/schemaentryitemeditorfactory.cpp
View file @
d6459a67
...
...
@@ -80,7 +80,7 @@ SchemaEntryItemEditorFactory::SchemaEntryItemEditorFactory() :
registerEditor
(
qMetaTypeId
<
SchemaEntry
::
AggregationType
>
(),
new
QStandardItemEditorCreator
<
MetaEnumComboBox
>
());
registerEditor
(
qMetaTypeId
<
SchemaEntryElement
::
Type
>
(),
new
QStandardItemEditorCreator
<
MetaEnumComboBox
>
());
registerEditor
(
qMetaTypeId
<
Aggregation
::
Type
>
(),
new
QStandardItemEditorCreator
<
MetaEnumComboBox
>
());
registerEditor
(
qMetaTypeId
<
Aggregation
::
Element
>
(),
new
AggregationElementEditorCreator
(
m_elementModel
.
get
()));
registerEditor
(
qMetaTypeId
<
AggregationElement
>
(),
new
AggregationElementEditorCreator
(
m_elementModel
.
get
()));
}
void
SchemaEntryItemEditorFactory
::
setProduct
(
const
Product
&
product
)
...
...
Write
Preview
Supports
Markdown
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