Projet

Général

Profil

Révision 71c02254 original.cpp

Voir les différences:

original.cpp
24 24
#include "original.h"
25 25
#include "ui_original.h"
26 26

  
27

  
28
//---------------------------------------------------------------------------------
29
bool viewsSortProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
30
{
31
    if(this->filterRegExp().isEmpty()) return true;
32

  
33
    QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
34
    myModel* fileModel = qobject_cast<myModel*>(sourceModel());
35

  
36
    if(fileModel->fileInfo(index0).isHidden()) return false;
37
    else return true;
38
}
39

  
40

  
41
//---------------------------------------------------------------------------------
42
bool viewsSortProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
43
{
44
    myModel* fsModel = dynamic_cast<myModel*>(sourceModel());
45

  
46
    if(left.column() == 1)          //size
47
    {
48
        if(fsModel->size(left) > fsModel->size(right)) return true;
49
        else return false;
50
    }
51
    else
52
    if(left.column() == 3)          //date
53
    {
54
        if(fsModel->fileInfo(left).lastModified() > fsModel->fileInfo(right).lastModified()) return true;
55
        else return false;
56
    }
57

  
58
    return QSortFilterProxyModel::lessThan(left,right);
59
}
60

  
61
//---------------------------------------------------------------------------------
62
QStringList myCompleter::splitPath(const QString& path) const
63
{
64
    QStringList parts = path.split("/");
65
    parts[0] = "/";
66

  
67
    return parts;
68
}
69

  
70
//---------------------------------------------------------------------------------
71
QString myCompleter::pathFromIndex(const QModelIndex& index) const
72
{
73
    if(!index.isValid()) return "";
74

  
75
    QModelIndex idx = index;
76
    QStringList list;
77
    do
78
    {
79
        QString t = model()->data(idx, Qt::EditRole).toString();
80
        list.prepend(t);
81
        QModelIndex parent = idx.parent();
82
        idx = parent.sibling(parent.row(), index.column());
83
    }
84
    while (idx.isValid());
85

  
86
    list[0].clear() ; // the join below will provide the separator
87

  
88
    return list.join("/");
89
}
90

  
91
//---------------------------------------------------------------------------
92
QString formatSize(qint64 num)
93
{
94
    QString total;
95
    const qint64 kb = 1024;
96
    const qint64 mb = 1024 * kb;
97
    const qint64 gb = 1024 * mb;
98
    const qint64 tb = 1024 * gb;
99

  
100
    if (num >= tb) total = QString("%1TB").arg(QString::number(qreal(num) / tb, 'f', 2));
101
    else if(num >= gb) total = QString("%1GB").arg(QString::number(qreal(num) / gb, 'f', 2));
102
    else if(num >= mb) total = QString("%1MB").arg(QString::number(qreal(num) / mb, 'f', 1));
103
    else if(num >= kb) total = QString("%1KB").arg(QString::number(qreal(num) / kb,'f', 1));
104
    else total = QString("%1 bytes").arg(num);
105

  
106
    return total;
107
}
108

  
109
// =========================================================================================================================
110

  
111

  
27 112
original::original(QWidget *parent) :
28 113
    QMainWindow(parent),
29 114
    ui(new Ui::original)
......
165 250
        ui->statusBar->showMessage(trUtf8("Fichier en cours: %1 [hq] [mq] [lq] [meta] ... terminé").arg(list.at(i).fileName()),3000);
166 251
    }
167 252
}
253

  
254
void original::on_action_Nouvel_album_triggered()
255
{
256
    QTreeWidgetItem *i = new QTreeWidgetItem(ui->treeWidget);
257
    i->setText(0, trUtf8("Nouvel album"));
258
}
259

  
260
//---------------------------------------------------------------------------
261
void original::thumbUpdate(QModelIndex index)
262
{
263
    qDebug() << "original::thumbUpdate";
264
    ui->lvResult->update(m_modelView->mapFromSource(index));
265
}
266

  
267
void original::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column)
268
{
269
    QStringList items;
270
    m_modelList = new myModel();
271
    m_modelList->setRootPath("/tmp/");
272

  
273
    m_modelList->populateItem("/tmp/t/20120529-lea_plongee_cala_montjoi-000.jpg");
274
    m_modelList->populateItem("/tmp/t/20120529-lea_plongee_cala_montjoi-001.jpg");
275
    m_modelList->populateItem("/tmp/t/20120529-lea_plongee_cala_montjoi-002.jpg");
276
    m_modelList->populateItem("/tmp/t/20120529-lea_plongee_cala_montjoi-003.jpg");
277
    items.append("/tmp/t/20120529-lea_plongee_cala_montjoi-000.jpg");
278
    items.append("/tmp/t/20120529-lea_plongee_cala_montjoi-001.jpg");
279
    items.append("/tmp/t/20120529-lea_plongee_cala_montjoi-002.jpg");
280
    items.append("/tmp/t/20120529-lea_plongee_cala_montjoi-003.jpg");
281
    QtConcurrent::run(m_modelList,&myModel::loadThumbsQSL,items);
282

  
283
    m_modelView = new viewsSortProxyModel();
284
    m_modelView->setSourceModel(m_modelList);
285
    m_modelView->setSortCaseSensitivity(Qt::CaseInsensitive);
286
    ui->lvResult->setModel(m_modelView);
287

  
288
    connect(m_modelList,SIGNAL(thumbUpdate(QModelIndex)),this,SLOT(thumbUpdate(QModelIndex)));
289

  
290
}

Formats disponibles : Unified diff

Redmine Appliance - Powered by TurnKey Linux