Qt 클래스를 사용하여 특정 데이터 모델을 사용하는 C++ 응용 프로그램을 작성하고 있습니다. 이를 위해 나는 QAbstractItemModel
에서 상속 :Qt에서 QModelIndex의 직계 자식 색인을 정렬하는 방법
// the following is a class that represents the actual data used in my application
class EventFragment
{
....
private:
qint32 address;
QString memo;
QDateTime dateCreated;
QVector<EventFragment*> _children;
....
};
// the following is the model representation that used by my application to display the actual details to the user
class EventModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit EventModel (QObject *parent = 0);
....
private:
// the following is the root item within the model - I use a tree-like presentation to show my data
EventFragment* _rootFragment;
};
를 내 응용 프로그램에서 필터/정렬 옵션을 필요로 어떤 시점에서 내가 또한 정렬을 달성하기 위해 QSortFilterProxyModel
class EventProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit EventProxyModel (QObject *parent = 0);
...
public:
// I had to add my custom implementation in the 'lessThan' method to achieve a
// more complex sort logic (not just comparing the actual values but using
// additional conditions to compare the two indexes)
virtual bool lessThan (const QModelIndex & left, const QModelIndex & right) const;
...
};
에서 상속하는 클래스를 생성, 나는 기본 QSortFilterProxyModel::sort()
메서드를 사용했습니다 (프록시 모델 클래스에서 다시 구현하지 않았습니다). 그리고 시간이 지나면 작동하는 것 같았습니다.
어떤 점에서는 실제 QSortFilterProxyModel::sort()
메서드가 전체 모델을 정렬하고 특정 인덱스의 직접적인 자식 만 정렬하는 것이 필요하다는 것을 알았습니다.
EventModel
클래스의 sort()
메서드를 다시 구현하려고했지만 잠시 후 QSortFilterProxyModel::sort()
은 전혀 언급하지 않는다는 것을 깨달았습니다. 반면에 인덱스를 안전하게 재구성하여 모델을 표시하는 뷰가 충돌하지 않도록하는 방법을 모르겠습니다.
는 난 단지 특정 QModelIndex
의 직계 자식을 정렬하는 방법이 있어야합니다 생각하지만, 나는 아직 그것을 발견하지 않았습니다.
제 사례에 대한 가능한 해결책 또는 그것을 수행하는 방법에 대한 지침을 보여주는 자습서/예가 있습니까?
감사