From 46efa2def1212dcb2610c545a78c8ab81bb22bbf Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 29 Sep 2018 16:29:21 +0200 Subject: Add main attribute to the filelist. Use QHash random seed hack in all places where QDomDocument is being used. --- src/filelist.cc | 76 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 19 deletions(-) (limited to 'src/filelist.cc') diff --git a/src/filelist.cc b/src/filelist.cc index 990ae4c..7b2ec2b 100644 --- a/src/filelist.cc +++ b/src/filelist.cc @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -58,15 +59,22 @@ public: QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override { - // Name: + // Main channel: if(index.column() == 2) + { + auto w = new QCheckBox(parent); + return w; + } + + // Name: + if(index.column() == 3) { auto w = new QLineEdit(parent); return w; } // Channel Map ID: - if(index.column() == 3) + if(index.column() == 4) { auto w = new QComboBox(parent); w->addItem(tr(""), -1); @@ -84,8 +92,16 @@ public: void setEditorData(QWidget *editor, const QModelIndex &index) const override { - // Name: + // Main channel: if(index.column() == 2) + { + auto w = static_cast(editor); + auto b = index.data(Qt::EditRole).toBool(); + w->setCheckState(b ? Qt::Checked : Qt::Unchecked); + } + + // Name: + if(index.column() == 3) { auto w = static_cast(editor); auto s = index.data(Qt::EditRole).toString(); @@ -93,7 +109,7 @@ public: } // Channel Map ID: - if(index.column() == 3) + if(index.column() == 4) { auto w = static_cast(editor); auto i = w->findData(index.data(Qt::EditRole).toInt()); @@ -103,15 +119,24 @@ public: void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override - { // Name: + { + // Main channel: if(index.column() == 2) + { + model->setData(index, + static_cast(editor)->checkState() == Qt::Checked, + Qt::EditRole); + } + + // Name: + if(index.column() == 3) { model->setData(index, static_cast(editor)->text(), Qt::EditRole); } // Channel Map ID: - if(index.column() == 3) + if(index.column() == 4) { model->setData(index, static_cast(editor)->currentData(), Qt::EditRole); @@ -189,7 +214,7 @@ public: int columnCount(const QModelIndex &parent = QModelIndex()) const override { - return 4; + return 5; } QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override @@ -223,9 +248,11 @@ public: { switch(index.column()) { + case 0: return QVariant(); // Master case 1: return audiofile.getFile(); - case 2: return audiofile.getName(); - case 3: + case 2: return audiofile.getMainChannel() ? "x" : " "; + case 3: return audiofile.getName(); + case 4: { auto channelMapId = audiofile.getChannelMapId(); if(channelMapId == -1) @@ -241,9 +268,11 @@ public: { switch(index.column()) { + case 0: return QVariant(); // Master case 1: return audiofile.getFile(); - case 2: return audiofile.getName(); - case 3: return audiofile.getChannelMapId(); + case 2: return audiofile.getMainChannel(); + case 3: return audiofile.getName(); + case 4: return audiofile.getChannelMapId(); default: return QVariant(); } } @@ -262,8 +291,9 @@ public: { case 0: return tr("M"); case 1: return tr("Filename"); - case 2: return tr("Name"); - case 3: return tr("Kit Channel"); + case 2: return tr("m"); + case 3: return tr("Name"); + case 4: return tr("Kit Channel"); default: return QVariant(); } } @@ -283,10 +313,12 @@ public: case 0: // Master return QAbstractItemModel::flags(index); case 1: // File - return QAbstractItemModel::flags(index); // only column 1 is editable - case 2: // Name + return QAbstractItemModel::flags(index); + case 2: // Main channel + return Qt::ItemIsEditable | QAbstractItemModel::flags(index); + case 3: // Name return Qt::ItemIsEditable | QAbstractItemModel::flags(index); - case 3: // Channel map id + case 4: // Channel map id return Qt::ItemIsEditable | QAbstractItemModel::flags(index); } } @@ -296,7 +328,8 @@ public: { auto audiofile_ids = instrument.getAudioFileList(); - if(index.row() > audiofile_ids.size() || index.column() > 2) + if(index.row() > audiofile_ids.size() || + index.column() > (columnCount() - 1)) { return false; } @@ -310,10 +343,13 @@ public: break; case 1: // File break; - case 2: // Name + case 2: // Main Channel + audiofile.setMainChannel(value.toBool()); + break; + case 3: // Name audiofile.setName(value.toString()); break; - case 3: // Channel map id + case 4: // Channel map id audiofile.setChannelMapId(value.toInt()); break; default: break; @@ -345,6 +381,7 @@ FileList::FileList(Instrument& instrument) this, SLOT(onCustomContextMenu(const QPoint &))); setRootIsDecorated(false); header()->resizeSection(0, 24); + header()->resizeSection(2, 24); connect(this, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(selectionChanged(const QModelIndex&))); @@ -380,6 +417,7 @@ void FileList::addFiles() audiofile.setName(name); audiofile.setFile(file); audiofile.setChannelMapId(-1); + audiofile.setMainChannel(false); i++; } -- cgit v1.2.3