Public Types | Public Slots | Public Member Functions

FileSelectionModel Class Reference

Simply an container model for the selected files used by the FileUploadWizard. More...

#include <fileselectionmodel.h>

Inheritance diagram for FileSelectionModel:
Inheritance graph
[legend]
Collaboration diagram for FileSelectionModel:
Collaboration graph
[legend]

List of all members.

Public Types

enum  FileRoles { FileName = Qt::UserRole + 400, FilePath, FileModDate }

Public Slots

void deleteFiles (const QModelIndexList &indexes)
void addFiles (QWidget *parent=0)
void addToFailedUploadList (const QModelIndex &index)

Public Member Functions

 FileSelectionModel (QObject *parent=0)
int rowCount (const QModelIndex &parent=QModelIndex()) const
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
Qt::ItemFlags flags (const QModelIndex &index) const
FilesUploadedModeluploadedFilesModel ()

Detailed Description

Simply an container model for the selected files used by the FileUploadWizard.


Member Enumeration Documentation

Enumerator:
FileName 
FilePath 
FileModDate 

                  {
        FileName = Qt::UserRole + 400,
        FilePath,
        FileModDate
    };


Constructor & Destructor Documentation

FileSelectionModel::FileSelectionModel ( QObject parent = 0  ) 

                                                                : QAbstractListModel(parent)
{
#ifdef DEBUG_PRELOADFILES // Check to see if flag is defined
    fileList << "U:/projects/smartlet/logger/samples/gesloten kas_skw30sgk_2009_04_02_09_57_01.dat"
            << "U:/projects/smartlet/logger/samples/CR1000_tomnl10s.dat"
            << "U:/projects/smartlet/logger/Smartkas/USB/Smartkas Hoogstraten 2009/Data (dat.bestanden)/Meerle gesloten kas_pchGK30s_2009_07_29_12_09_57.dat";
#endif // DEBUG_PRELOADFILES
    uploadedFileModel = new FilesUploadedModel(this);
};


Member Function Documentation

void FileSelectionModel::addFiles ( QWidget parent = 0  )  [slot]

{
    QAbstractListModel::beginResetModel();
    QStringList fileNames = QFileDialog::getOpenFileNames(parent, "Select files to upload to the database", "U:/projects/smartlet/logger/samples");
    fileList << fileNames;
    fileList.removeDuplicates();
    QAbstractListModel::endResetModel();
}

void FileSelectionModel::addToFailedUploadList ( const QModelIndex index  )  [slot]

{
    failedToUploadFileList.append(index.data(FileSelectionModel::FilePath).toString());
}

QVariant FileSelectionModel::data ( const QModelIndex index,
int  role = Qt::DisplayRole 
) const

{
    QFileInfo info(fileList.at(index.row()));
    if (role==FileSelectionModel::FileName  || role==Qt::DisplayRole) return QVariant::fromValue(info.fileName());
    if (role==FileSelectionModel::FilePath || role==Qt::ToolTipRole) return QVariant::fromValue(info.filePath());
    if (role==FileSelectionModel::FileModDate) return QVariant::fromValue(info.lastModified());
    if (role==Qt::BackgroundRole){
        if (failedToUploadFileList.contains(info.filePath())) return QVariant::fromValue(QBrush(Qt::red));
        QMap<int, QString> fileUniqueId; //combination of filename and modificationDate
        fileUniqueId.insert(1, info.fileName());
        fileUniqueId.insert(2, info.lastModified().toString(Qt::ISODate));
        if (uploadedFileModel->contains(fileUniqueId)) return QVariant::fromValue(QBrush(Qt::yellow));
        else return QVariant();
    }
    else return QVariant();
}

void FileSelectionModel::deleteFiles ( const QModelIndexList &  indexes  )  [slot]

{
    QAbstractListModel::beginResetModel();
    QModelIndexList sortedIndexes = indexes;
    qSort(sortedIndexes.begin(), sortedIndexes.end(), isGreaterThan);
    if (indexes.isEmpty()) return;
    for (int i = 0; i < sortedIndexes.size(); i++){
        fileList.removeAt(sortedIndexes[i].row());
    }
    QAbstractListModel::endResetModel();
}

Qt::ItemFlags FileSelectionModel::flags ( const QModelIndex index  )  const

{
    return QAbstractListModel::flags(index);// | Qt::ItemIsEditable;
}

int FileSelectionModel::rowCount ( const QModelIndex parent = QModelIndex()  )  const

{
    return fileList.count();
}

FilesUploadedModel * FileSelectionModel::uploadedFilesModel (  ) 

{
    return uploadedFileModel;
}


The documentation for this class was generated from the following files: