aboutsummaryrefslogtreecommitdiff
path: root/lumina-fm
diff options
context:
space:
mode:
authorCarlos Bohórquez <carlos@kernelmap.com>2015-09-09 22:42:09 +0200
committerCarlos Bohórquez <carlos@kernelmap.com>2015-09-09 22:42:09 +0200
commitb30859996093f7dac37b9a077aff78493305a270 (patch)
tree1d1349c2fe82ce7f155698722ba2d1525d4f834c /lumina-fm
parentUpdate the dependencies/project to include the Qt5-Concurrent build module (n... (diff)
downloadlumina-b30859996093f7dac37b9a077aff78493305a270.tar.gz
lumina-b30859996093f7dac37b9a077aff78493305a270.tar.bz2
lumina-b30859996093f7dac37b9a077aff78493305a270.zip
Solves issue 11233
A new class has been created for manage the files displayed in QTreeWidget. This class inherits from QTreeWidgetItem and only redefines the operator< function. Now it's possible order by size and dates.
Diffstat (limited to 'lumina-fm')
-rw-r--r--lumina-fm/widgets/DirWidget.cpp9
-rw-r--r--lumina-fm/widgets/DirWidget.h66
2 files changed, 70 insertions, 5 deletions
diff --git a/lumina-fm/widgets/DirWidget.cpp b/lumina-fm/widgets/DirWidget.cpp
index ed1f4544..22879c1b 100644
--- a/lumina-fm/widgets/DirWidget.cpp
+++ b/lumina-fm/widgets/DirWidget.cpp
@@ -111,7 +111,7 @@ void DirWidget::setShowThumbnails(bool show){
void DirWidget::setDetails(QList<DETAILTYPES> list){
listDetails = list;
//Need to re-create the header item as well
- QTreeWidgetItem *it = new QTreeWidgetItem();
+ CQTreeWidgetItem *it = new CQTreeWidgetItem();
int nmcol = -1; int typecol = -1;
for(int t=0; t<listDetails.length(); t++){
switch(listDetails[t]){
@@ -283,15 +283,16 @@ void DirWidget::LoadDir(QString dir, QList<LFileInfo> list){
watcher->addPath(list[i].absoluteFilePath());
if(showDetails){
//Now create all the individual items for the details tree
- QTreeWidgetItem *it;
+ CQTreeWidgetItem *it;
bool addnew = false;
//See if an item already exists for this file
QList<QTreeWidgetItem*> items = treeWidget->findItems(list[i].fileName(),Qt::MatchExactly,0); //NOTE: This requires column 0 to be the name
if(items.isEmpty()){
- it = new QTreeWidgetItem();
+ it = new CQTreeWidgetItem();
addnew = true;
}else{
- it = items.first();
+ // Safe downcasting because CQTreeWidgetItem only redefines the virtual function bool opearot<. Not new methos added.
+ it = static_cast<CQTreeWidgetItem *> (items.first());
}
//Now update the entry contents
it->setWhatsThis(0, QString(canmodify ? "cut": "copy")+"::::"+list[i].absoluteFilePath());
diff --git a/lumina-fm/widgets/DirWidget.h b/lumina-fm/widgets/DirWidget.h
index 2c971fd8..514b3e7f 100644
--- a/lumina-fm/widgets/DirWidget.h
+++ b/lumina-fm/widgets/DirWidget.h
@@ -22,6 +22,10 @@
#define ZSNAPDIR QString("/.zfs/snapshot/")
+#ifndef DEBUG
+#define DEBUG 0
+#endif
+
namespace Ui{
class DirWidget;
};
@@ -154,4 +158,64 @@ protected:
void mouseReleaseEvent(QMouseEvent *);
};
-#endif \ No newline at end of file
+
+/*
+ * Virtual class for managing the sort of folders/files items. The problem with base class is that it only manages texts fields and
+ * we have dates and sizes.
+ *
+ * On this class, we overwrite the function operator<.
+ */
+
+class CQTreeWidgetItem : public QTreeWidgetItem {
+public:
+ CQTreeWidgetItem(int type = Type) : QTreeWidgetItem(type) {}
+ CQTreeWidgetItem(const QStringList & strings, int type = Type) : QTreeWidgetItem(strings, type) {}
+ CQTreeWidgetItem(QTreeWidget * parent, int type = Type) : QTreeWidgetItem(parent, type) {}
+ CQTreeWidgetItem(QTreeWidget * parent, const QStringList & strings, int type = Type) : QTreeWidgetItem(parent, strings, type) {}
+ CQTreeWidgetItem(QTreeWidget * parent, QTreeWidgetItem * preceding, int type = Type) : QTreeWidgetItem(parent, preceding, type) {}
+ CQTreeWidgetItem(QTreeWidgetItem * parent, int type = Type) : QTreeWidgetItem(parent, type) {}
+ CQTreeWidgetItem(QTreeWidgetItem * parent, const QStringList & strings, int type = Type) : QTreeWidgetItem(parent, strings, type) {}
+ CQTreeWidgetItem(QTreeWidgetItem * parent, QTreeWidgetItem * preceding, int type = Type) : QTreeWidgetItem(parent, preceding, type) {}
+ virtual ~CQTreeWidgetItem() {}
+ inline virtual bool operator<(const QTreeWidgetItem &tmp) const {
+ int column = this->treeWidget()->sortColumn();
+ // We are in date text
+ if(column == DirWidget::DATEMOD || column == DirWidget::DATECREATE) {
+ // Get the stored text and try to convert to QDateTime
+ QString text = this->text(column);
+ QString text_tmp = tmp.text(column);
+ QDateTime date_time = QDateTime::fromString(text, Qt::DefaultLocaleShortDate);
+ QDateTime date_time_tmp = QDateTime::fromString(text_tmp, Qt::DefaultLocaleShortDate);
+ // If the conversion are ok in both objects, compare them
+ if(date_time.isValid() && date_time_tmp.isValid())
+ return date_time < date_time_tmp;
+ // If some of the dates are invalid, use the base class implementation (order by string)
+ else {
+ if(DEBUG)
+ qDebug() << "Cannot convert the date. Texts arrived are " << text << " and " << text_tmp;
+ return QTreeWidgetItem::operator <(tmp);
+ }
+ }
+ // We are in size text
+ else if(column == DirWidget::SIZE) {
+ QString text = this->text(column);
+ QString text_tmp = tmp.text(column);
+ double filesize, filesize_tmp;
+ // On folders, text is empty so we check for that
+ // In case we are in folders, we put -1 for differentiate of regular files with 0 bytes.
+ // Doing so, all folders we'll be together instead of mixing with files with 0 bytes.
+ if(text.isEmpty())
+ filesize = -1;
+ else
+ filesize = LUtils::DisplaySizeToBytes(text);
+ if(text_tmp.isEmpty())
+ filesize_tmp = -1;
+ else
+ filesize_tmp = LUtils::DisplaySizeToBytes(text_tmp);
+ return filesize < filesize_tmp;
+ }
+ // In other cases, we trust base class implementation
+ return QTreeWidgetItem::operator<(tmp);
+ }
+};
+#endif
bgstack15