[Development] Moving QStandardItemModel to QtGui
Olivier Goffart
olivier at woboq.com
Wed Jun 27 11:48:20 CEST 2012
On Tuesday 26 June 2012 18:12:14 Stephen Kelly wrote:
> Hi there,
>
> I know it is late, but it was recently brought to my attention that
> QStandardItemModel could be moved from QtWidgets to QtGui, since QIcon was
> moved to QtGui.
>
> It seems that people doing model-view like to use QStandardItemModel, and
> forcing the use of the widgets module for that is unfortunate.
>
> Any objections to me moving that to src/gui/itemmodels?
>
> Thanks,
How about QtCore?
Yes, there are mention of QBrush, QFont, QIcon... but:
In the .cpp file, they are only used by reference, so do not need to include
them.
In the .h file, it is used in inline code for some setter and getter.
The setters just need QVariant. QVariant::fromValue does not need to know
about the type, it just needs the qMetaTypeId (we have it, it is a builtin
type) and the QTypeInfo (we could register thos types). So we are fine.
For the getters: since they are not called from the .cpp we could do some
template magic
template<typename T = QIcon>
inline T icon() const {
static_assert(std::same_type<QIcon, T>::value, "wrong template arg");
return qvariant_cast<T>(data(Qt::DecorationRole));
}
Since there is a default argument, you can call the function as if it was not
a template function, and because it is a template function, it is only
compiled at instentiation time, where QIcon must be included.
And that's it: we could move it in QtCore if we want.
That said, it is probably fine in QtGui
--
Olivier
Woboq - Qt services and support - http://woboq.com
More information about the Development
mailing list