refs #641, support for IOrderable in specialized views/models

* menu to order objects per drag and drop
* changed model/views to specialized model/views
This commit is contained in:
Klaus Basan
2016-04-23 02:42:36 +02:00
parent bb6eea6c72
commit 7d43af343e
18 changed files with 435 additions and 161 deletions

View File

@@ -94,7 +94,6 @@ namespace BlackGui
}
}
void CViewBaseNonTemplate::setFilterDialog(CFilterDialog *filterDialog)
{
this->setFilterWidgetImpl(filterDialog);
@@ -303,25 +302,6 @@ namespace BlackGui
QTableView::showEvent(event);
}
void CViewBaseNonTemplate::allowDragDropValueObjects(bool allowDrag, bool allowDrop)
{
// see model for implementing logic of drag
this->setAcceptDrops(allowDrop);
this->setDragEnabled(allowDrag);
this->setDropIndicatorShown(allowDrop);
CDropBase::allowDrop(allowDrop);
}
void CViewBaseNonTemplate::allowDrop(bool allow)
{
this->allowDragDropValueObjects(this->dragEnabled(), allow);
}
bool CViewBaseNonTemplate::isDropAllowed() const
{
return this->acceptDrops();
}
int CViewBaseNonTemplate::getHorizontalHeaderFontHeight() const
{
QFontMetrics m(this->getHorizontalHeaderFont());
@@ -518,10 +498,10 @@ namespace BlackGui
this->setVisible(false);
// magic trick from:
// http://stackoverflow.com/q/3433664/356726
const QRect vporig = this->viewport()->geometry();
QRect vpnew = vporig;
vpnew.setWidth(std::numeric_limits<int>::max());
this->viewport()->setGeometry(vpnew);
const QRect vpOriginal = this->viewport()->geometry();
QRect vpNew = vpOriginal;
vpNew.setWidth(std::numeric_limits<int>::max());
this->viewport()->setGeometry(vpNew);
this->m_resizeCount++;
this->resizeColumnsToContents(); // columns
@@ -531,16 +511,10 @@ namespace BlackGui
// re-stretch
this->horizontalHeader()->setStretchLastSection(true);
}
this->viewport()->setGeometry(vporig);
this->viewport()->setGeometry(vpOriginal);
this->setVisible(true);
}
void CViewBaseNonTemplate::presizeOrFullResizeToContents()
{
}
void CViewBaseNonTemplate::ps_customMenuRequested(QPoint pos)
{
QMenu menu;
@@ -601,14 +575,14 @@ namespace BlackGui
void CViewBaseNonTemplate::dragEnterEvent(QDragEnterEvent *event)
{
if (!event || !acceptDrop(event->mimeData())) { return; }
if (!event || !this->acceptDrop(event->mimeData())) { return; }
setBackgroundRole(QPalette::Highlight);
event->acceptProposedAction();
}
void CViewBaseNonTemplate::dragMoveEvent(QDragMoveEvent *event)
{
if (!event || !acceptDrop(event->mimeData())) { return; }
if (!event || !this->acceptDrop(event->mimeData())) { return; }
event->acceptProposedAction();
}
@@ -618,11 +592,6 @@ namespace BlackGui
event->accept();
}
void CViewBaseNonTemplate::dropEvent(QDropEvent *event)
{
Q_UNUSED(event);
}
template <class ModelClass, class ContainerType, class ObjectType>
CViewBase<ModelClass, ContainerType, ObjectType>::CViewBase(QWidget *parent, ModelClass *model) : CViewBaseNonTemplate(parent), m_model(model)
{
@@ -646,7 +615,7 @@ namespace BlackGui
// we have data
this->showLoadIndicator(container.size());
bool reallyResize = resize && isResizeConditionMet(container.size()); // do we really perform resizing
const bool reallyResize = resize && isResizeConditionMet(container.size()); // do we really perform resizing
bool presize = (m_resizeMode == PresizeSubset) &&
this->isEmpty() && // only when no data yet
!reallyResize; // not when we resize later
@@ -894,6 +863,47 @@ namespace BlackGui
return this->m_model->rowCount() < 1;
}
template <class ModelClass, class ContainerType, class ObjectType>
bool CViewBase<ModelClass, ContainerType, ObjectType>::isOrderable() const
{
Q_ASSERT(this->m_model);
return this->m_model->isOrderable();
}
template <class ModelClass, class ContainerType, class ObjectType>
void CViewBase<ModelClass, ContainerType, ObjectType>::allowDragDrop(bool allowDrag, bool allowDrop)
{
Q_ASSERT(this->m_model);
// see model for implementing logic of drag
this->viewport()->setAcceptDrops(allowDrop);
this->setDragEnabled(allowDrag);
this->setDropIndicatorShown(allowDrop);
this->m_model->allowDrop(allowDrop);
}
template <class ModelClass, class ContainerType, class ObjectType>
bool CViewBase<ModelClass, ContainerType, ObjectType>::isDropAllowed() const
{
Q_ASSERT(this->m_model);
return this->m_model->isDropAllowed();
}
template <class ModelClass, class ContainerType, class ObjectType>
bool CViewBase<ModelClass, ContainerType, ObjectType>::acceptDrop(const QMimeData *mimeData) const
{
Q_ASSERT(this->m_model);
const bool a = this->m_model->acceptDrop(mimeData);
return a;
}
template <class ModelClass, class ContainerType, class ObjectType>
void CViewBase<ModelClass, ContainerType, ObjectType>::setSorting(const CPropertyIndex &propertyIndex, Qt::SortOrder order)
{
Q_ASSERT(this->m_model);
this->m_model->setSorting(propertyIndex, order);
}
template <class ModelClass, class ContainerType, class ObjectType>
QJsonObject CViewBase<ModelClass, ContainerType, ObjectType>::toJson() const
{
@@ -936,6 +946,23 @@ namespace BlackGui
return derivedModel()->hasFilter();
}
template <class ModelClass, class ContainerType, class ObjectType>
void CViewBase<ModelClass, ContainerType, ObjectType>::addContainerTypesAsDropTypes(bool objectType, bool containerType)
{
if (objectType) { this->m_model->addAcceptedMetaTypeId(qMetaTypeId<ObjectType>()); }
if (containerType) { this->m_model->addAcceptedMetaTypeId(qMetaTypeId<ContainerType>()); }
}
template <class ModelClass, class ContainerType, class ObjectType>
void CViewBase<ModelClass, ContainerType, ObjectType>::initAsOrderable()
{
Q_ASSERT_X(isOrderable(), Q_FUNC_INFO, "Model not orderable");
this->allowDragDrop(true, true);
this->setDragDropMode(InternalMove);
this->setDropActions(Qt::MoveAction);
this->addContainerTypesAsDropTypes(true, true);
}
template <class ModelClass, class ContainerType, class ObjectType>
void CViewBase<ModelClass, ContainerType, ObjectType>::setSortIndicator()
{