96 lines
2.6 KiB
C++
Executable File
96 lines
2.6 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Proxy Model for hiding empty tracks and sorting tracks by name plus having the "Markers" track always at the top
|
|
* $Id: $
|
|
* $HeadURL: $
|
|
* $Author: $
|
|
*
|
|
* Created by Mike Lennart Wille, SLTE, 2022-06-22
|
|
*/
|
|
|
|
#include "tln_timeline_proxy_model.h"
|
|
#include "tln_timeline_model.h"
|
|
|
|
|
|
namespace Timeline
|
|
{
|
|
TimelineProxyModel::TimelineProxyModel()
|
|
: QSortFilterProxyModel()
|
|
{
|
|
//setDynamicSortFilter(true);
|
|
setRecursiveFilteringEnabled(true); // if child gets items for the first time then also show the parent so that the child becomes visible ;)
|
|
}
|
|
|
|
|
|
void TimelineProxyModel::toggleShowAllRows()
|
|
{
|
|
m_forceShowAllRows = !m_forceShowAllRows;
|
|
invalidateFilter();
|
|
}
|
|
|
|
|
|
bool TimelineProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
|
{
|
|
if (m_forceShowAllRows)
|
|
return true;
|
|
|
|
auto index = sourceModel()->index(source_row, 1, source_parent);
|
|
auto index2 = sourceModel()->index(source_row, 0, source_parent);
|
|
|
|
if (index.data(Qt::UserRole).toInt() == 666) // always show markers
|
|
{
|
|
return true;
|
|
}
|
|
|
|
int trackId = index.data().toInt();
|
|
|
|
// TODO: correct solution instead of accessing the TimelineModel directly and depending on it??
|
|
if (m_modelCachedPointer == nullptr)
|
|
m_modelCachedPointer = qobject_cast<TimelineModel *>(sourceModel());
|
|
|
|
try
|
|
{
|
|
const Track &t = m_modelCachedPointer->track(trackId);
|
|
return t.hasItems();
|
|
}
|
|
catch (...)
|
|
{
|
|
Q_ASSERT(false);
|
|
return true; // bail
|
|
}
|
|
}
|
|
|
|
|
|
bool TimelineProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
|
|
{
|
|
//qWarning() << "lessThan";
|
|
|
|
// Qt doc: "Returns true if [..] source_left is less than [..] source_right, otherwise returns false."
|
|
// NOTE: only eItems is supported
|
|
|
|
//qWarning() << "lessThan marker source_left" << source_left.data(Qt::UserRole).toInt() << " "<< source_left.data(Qt::DisplayRole).toString();
|
|
//qWarning() << "lessThan marker source_right" << source_right.data(Qt::UserRole).toInt() << " "<< source_right.data(Qt::DisplayRole).toString();
|
|
|
|
// markers
|
|
if (source_left.data(Qt::UserRole).toInt() == 1)
|
|
{
|
|
return true;
|
|
}
|
|
if (source_right.data(Qt::UserRole).toInt() == 1)
|
|
{
|
|
return false;
|
|
}
|
|
//Number compare
|
|
bool okL = false;
|
|
bool okR = false;
|
|
int intL = source_left.data().toInt(&okL);
|
|
int intR = source_right.data().toInt(&okR);
|
|
if (okL && okR)
|
|
return intL < intR;
|
|
//String Compare
|
|
return QString::compare(source_left.data().toString(), source_right.data().toString()) < 0;
|
|
|
|
//return QSortFilterProxyModel::lessThan(source_left, source_right);
|
|
}
|
|
} // namespace Timeline
|