#include "global.h" #include "cntfilesystemmodel.h" #include #include #include "hp_mditexteditor.h" #define FILE_NUM 9 #define FILE_TYPE 5 //Todo fix for all file types const QString contentFileSystemModel::filetype_list[FILE_NUM][2]={{"hpprgm",":/icons/apps_16x16.png"}, {"CAS Vars",":/icons/casFolder_16x16.png"}, {"Complex",":/icons/complex_16x16.png"}, {"hplist",":/icons/list_16x16.png"}, {"Matrices",":/icons/table_16x16.png"}, {"Notes",":/icons/note_16x16.png"}, {"hpprgm",":/icons/program_16x16.png"}, {"Real",":/icons/real_16x16.png"}, {"Variables",":/icons/varFolder_16x16.png"} }; const hp_DataType contentFileSystemModel::func_type[FILE_TYPE]={ HP_PROG, HP_LIST, HP_MATRIX, HP_NOTE, HP_MAIN}; const QString contentFileSystemModel::file_type[FILE_TYPE]={"hpprgm", "hplist", "hpmat", "hpnote", ""}; contentFileSystemModel::contentFileSystemModel(QObject * parent) :QFileSystemModel(parent) { } //Get and pass on the data to be dragged QMimeData* contentFileSystemModel::mimeData(const QModelIndexList &indexes) const { QMimeData *mimeDataPtr = new QMimeData(); QByteArray mydata; qDebug()<<"contentFileSystemModel::mimeData"; mimeDataPtr->setData("application/x-qstandarditemmodeldatalist",mydata); /* Store row id list */ QList rowIdList; int rowId; foreach (QModelIndex index, indexes) { if (index.isValid()) { rowId = index.row(); if (!rowIdList.contains(rowId)) { rowIdList << rowId; } } } return mimeDataPtr; } //Set drop actions supported Qt::DropActions contentFileSystemModel::supportedDropActions() const { return Qt::CopyAction | Qt::MoveAction| Qt::TargetMoveAction; } //Not sure that this is neccesary. Item should control this Qt::ItemFlags contentFileSystemModel::flags(const QModelIndex &index) const { Qt::ItemFlags defaultFlags = QFileSystemModel::flags(index); if (index.isValid()) return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags; else return Qt::ItemIsDropEnabled | defaultFlags; } //Allow drop in location bool contentFileSystemModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const { return true; } //Process the drop action bool contentFileSystemModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { qDebug()<<"contentFileSystemModel::DropMineData"; if (action == Qt::IgnoreAction) { return true; } if (column > 1) { return false; } int position; if (row != -1) { position = row; } else if (parent.isValid()) { position = parent.row(); } else { position = rowCount(QModelIndex()); } // QByteArray encodedData = data->data("application/text.list"); // QDataStream stream(&encodedData, QIODevice::ReadOnly); /* Retrieve row id */ QList rowIdList; // while (!stream.atEnd()) { // QString text; // stream >> text; // rowIdList << text.toInt(); // } /* Insert rows (one by one) */ // foreach(int rowId, rowIdList) { // insertRow(position, parent, rowId); // } return true; } QVariant contentFileSystemModel::data( const QModelIndex &index, int role ) const { if( role == Qt::DecorationRole ) { QString name = index.data().toString(); QFileInfo info = contentFileSystemModel::fileInfo(index); //QFileInfo info(name); if((info.isFile()&&(name==info.fileName()))) { int i; for (i=0;iparseData(in); } break; default: ; } if (hptextedit==nullptr) hptextedit = new hp_mdiTextEdit(mdiwin,filedata, data); if (hptextedit!=nullptr) hptextedit ->show(); file.close(); } qDebug()<<"ClickAction "<