# # # patch "src/model/InventoryProxyModel.cpp" # from [305b276fd10e5d3b20bcd9fe304027c9f5a82d29] # to [5d1c6ddf5394a061d60ad61f59adc58cefaddfa3] # # patch "src/model/InventoryProxyModel.h" # from [6e67d2896fbe64b69530829c33407785583ef608] # to [333a3d4519fc18ade293a4fcd52d5c433040271e] # ============================================================ --- src/model/InventoryProxyModel.cpp 305b276fd10e5d3b20bcd9fe304027c9f5a82d29 +++ src/model/InventoryProxyModel.cpp 5d1c6ddf5394a061d60ad61f59adc58cefaddfa3 @@ -21,20 +21,17 @@ #include "InventoryProxyModel.h" #include "InventoryItem.h" -InventoryProxyModel::InventoryProxyModel(QObject *parent, bool folderTree_) -: QSortFilterProxyModel(parent), folderTree(folderTree_), -sortColumn(0), hideIgnored(false), sortOrder(Qt::AscendingOrder) -{ -} +InventoryProxyModel::InventoryProxyModel(QObject * parent, bool isFolderTree) + : QSortFilterProxyModel(parent), folderTree(isFolderTree), + sortColumn(0), hideIgnored(false), sortOrder(Qt::AscendingOrder) +{} -InventoryProxyModel::~InventoryProxyModel(void) -{ -} +InventoryProxyModel::~InventoryProxyModel() {} -bool InventoryProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +bool InventoryProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const { - QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); - InventoryItem *item = static_cast(index.internalPointer()); + QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); + InventoryItem * item = static_cast(index.internalPointer()); // display the pseudo CdUp item only in the file list regardless of the // state of the item @@ -45,26 +42,27 @@ bool InventoryProxyModel::filterAcceptsR // way to cdUp anymore) return !folderTree && sourceParent.parent().isValid(); } - + // hide ignored files (not recursively) if (item->hasStatus(InventoryItem::Ignored) && hideIgnored) { return false; } - + bool acceptRow = true; - + // check the view options int state = item->getStatusRecursive(); bool patched = state & InventoryItem::Patched; bool added = state & InventoryItem::Added; bool dropped = state & InventoryItem::Dropped; - bool renamed = state & InventoryItem::RenamedFrom || state & InventoryItem::RenamedTo; + bool renamed = state & InventoryItem::RenamedFrom || + state & InventoryItem::RenamedTo; bool unknown = state & InventoryItem::Unknown; bool missing = state & InventoryItem::Missing; bool ignored = state & InventoryItem::Ignored; - bool changed = patched || added || dropped || renamed; - + bool changed = patched || added || dropped || renamed; + acceptRow &= viewOption != Changed || changed; acceptRow &= viewOption != Patched || patched; acceptRow &= viewOption != Added || added; @@ -73,59 +71,59 @@ bool InventoryProxyModel::filterAcceptsR acceptRow &= viewOption != Unknown || unknown; acceptRow &= viewOption != Missing || missing; acceptRow &= viewOption != Ignored || ignored; - - // check if we should only display folders + + // check if we should only display folders acceptRow &= !folderTree || item->isDirectory(); return acceptRow; } -bool InventoryProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const +bool InventoryProxyModel::lessThan(const QModelIndex & left, const QModelIndex & right) const { - // TODO: Needs some tweaking for correct sorting when clicked on different headers - // f.e. status strings are sorted differently based on their translation - InventoryItem *itemLeft = static_cast(left.internalPointer()); - InventoryItem *itemRight = static_cast(right.internalPointer()); + // TODO: Needs some tweaking for correct sorting when clicked on different headers + // f.e. status strings are sorted differently based on their translation + InventoryItem * itemLeft = static_cast(left.internalPointer()); + InventoryItem * itemRight = static_cast(right.internalPointer()); - // We shall sort by the name of the item - if (sortColumn == 0) - { + // We shall sort by the name of the item + if (sortColumn == 0) + { // place cd up items always on the first position if (itemLeft->isCdUp() || itemRight->isCdUp()) return false; - - if (itemLeft->isDirectory() && itemRight->isDirectory()) - { - return itemLeft->getFilename() < itemRight->getFilename(); - } - if (!itemLeft->isDirectory() && !itemRight->isDirectory()) - { - return itemLeft->getFilename() < itemRight->getFilename(); - } + if (itemLeft->isDirectory() && itemRight->isDirectory()) + { + return itemLeft->getFilename() < itemRight->getFilename(); + } - if (itemLeft->isDirectory() && !itemRight->isDirectory()) - { - return true; - } + if (!itemLeft->isDirectory() && !itemRight->isDirectory()) + { + return itemLeft->getFilename() < itemRight->getFilename(); + } - // last case: !itemLeft->isDirectory() && itemRight->isDirectory() - return false; - } - // we shall sort only by status - else if (sortColumn == 1) - { - return itemLeft->getStatus() < itemRight->getStatus(); - } - // anything else - else - { - return false; - } + if (itemLeft->isDirectory() && !itemRight->isDirectory()) + { + return true; + } + + // last case: !itemLeft->isDirectory() && itemRight->isDirectory() + return false; + } + // we shall sort only by status + else if (sortColumn == 1) + { + return itemLeft->getStatus() < itemRight->getStatus(); + } + // anything else + else + { + return false; + } } void InventoryProxyModel::sort(int column, Qt::SortOrder order) { sortOrder = order; - sortColumn = column; + sortColumn = column; QSortFilterProxyModel::sort(column, order); } ============================================================ --- src/model/InventoryProxyModel.h 6e67d2896fbe64b69530829c33407785583ef608 +++ src/model/InventoryProxyModel.h 333a3d4519fc18ade293a4fcd52d5c433040271e @@ -25,25 +25,24 @@ class InventoryProxyModel : public QSort class InventoryProxyModel : public QSortFilterProxyModel { - public: - enum ViewOption { All, Changed, Patched, Added, Dropped, + enum ViewOption { All, Changed, Patched, Added, Dropped, Renamed, Missing, Unknown, Ignored }; - - explicit InventoryProxyModel(QObject * parent, bool folderTree_); - ~InventoryProxyModel(void); - bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; - bool lessThan(const QModelIndex &left, const QModelIndex &right) const; - void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); - void setHideIgnoredFiles(bool hide); - void setViewOption(ViewOption opt); - + + explicit InventoryProxyModel(QObject *, bool); + ~InventoryProxyModel(); + bool filterAcceptsRow(int, const QModelIndex &) const; + bool lessThan(const QModelIndex &, const QModelIndex &) const; + void sort(int, Qt::SortOrder order = Qt::AscendingOrder); + void setHideIgnoredFiles(bool); + void setViewOption(ViewOption); + private: - bool folderTree; - int sortColumn; + bool folderTree; + int sortColumn; bool hideIgnored; ViewOption viewOption; - Qt::SortOrder sortOrder; + Qt::SortOrder sortOrder; }; #endif