From fbdc10f0b0cde5b9699679b13d0e48fa3c90a181 Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Mon, 4 Apr 2011 18:32:38 +0200 Subject: [PATCH] Removed some leftover files and more testing --- apps/launcher/CMakeLists.txt | 6 -- apps/launcher/datafilesdialog.cpp | 125 +++++++++++++++++++++++- apps/launcher/datafilesdialog.h | 7 +- apps/launcher/datafilesmodel.cpp | 155 ------------------------------ apps/launcher/datafilesmodel.h | 35 ------- 5 files changed, 128 insertions(+), 200 deletions(-) delete mode 100644 apps/launcher/datafilesmodel.cpp delete mode 100644 apps/launcher/datafilesmodel.h diff --git a/apps/launcher/CMakeLists.txt b/apps/launcher/CMakeLists.txt index fe29375d96..bb0af03b8a 100644 --- a/apps/launcher/CMakeLists.txt +++ b/apps/launcher/CMakeLists.txt @@ -1,14 +1,10 @@ set(LAUNCHER datafilesdialog.cpp - datafilesmodel.cpp - datafilesitem.cpp lineedit.cpp main.cpp maindialog.cpp settingsdialog.cpp datafilesdialog.h - datafilesmodel.h - datafilesitem.h lineedit.h maindialog.h settingsdialog.h @@ -16,8 +12,6 @@ set(LAUNCHER SET(MOC_HDRS datafilesdialog.h - datafilesmodel.h - datafilesitem.h lineedit.h maindialog.h settingsdialog.h diff --git a/apps/launcher/datafilesdialog.cpp b/apps/launcher/datafilesdialog.cpp index f00cfdfe8f..9b9733dedf 100644 --- a/apps/launcher/datafilesdialog.cpp +++ b/apps/launcher/datafilesdialog.cpp @@ -2,6 +2,7 @@ #include #include "datafilesdialog.h" +//#include "pluginitemmodel.h" //#include "datafilesmodel.h" //#include "datafilesitem.h" @@ -14,6 +15,28 @@ DataFilesDialog::DataFilesDialog() mastertable = new QTableView(this); plugintable = new QTableView(this); + /* listtest + QTableWidget *pluginlist = new QTableWidget(this); + + pluginlist->horizontalHeader()->setStretchLastSection(true); + pluginlist->insertColumn(0); + + for (unsigned int i=0; i<6; ++i) { + pluginlist->insertRow(i); + QTableWidgetItem *item = new QTableWidgetItem(QString("Plugin %0").arg(i)); + item->setFlags(item->flags() & ~(Qt::ItemIsDropEnabled)); + pluginlist->setItem(i, 0, item); + } + + pluginlist->insertRow(6); + pluginlist->setSelectionMode(QAbstractItemView::SingleSelection); // single item can be draged or droped + pluginlist->setDragEnabled(true); + pluginlist->setDragDropMode(QAbstractItemView::InternalMove); + pluginlist->viewport()->setAcceptDrops(true); + + pluginlist->setDropIndicatorShown(true); + */ + splitter->setOrientation(Qt::Vertical); splitter->addWidget(tree); splitter->addWidget(mastertable); @@ -63,6 +86,7 @@ DataFilesDialog::DataFilesDialog() // Add the masters to mastersmodel foreach (const QString ¤tmaster, masters) { QStandardItem *item = new QStandardItem(currentmaster); + item->setFlags(item->flags() & ~(Qt::ItemIsDropEnabled)); QList foundmasters = mastersmodel->findItems(currentmaster); @@ -74,7 +98,9 @@ DataFilesDialog::DataFilesDialog() // Add the masters to datafilesmodel QStandardItem *item = new QStandardItem(masters.join(",")); + item->setFlags(item->flags() & ~(Qt::ItemIsDropEnabled)); QStandardItem *child = new QStandardItem(currentfile); + child->setFlags(child->flags() & ~(Qt::ItemIsDropEnabled)); QList masteritems = datafilesmodel->findItems(masters.join(",")); @@ -84,6 +110,7 @@ DataFilesDialog::DataFilesDialog() datafilesmodel->appendRow(item); } else { foreach (QStandardItem *currentitem, masteritems) { + currentitem->setFlags(currentitem->flags() & ~(Qt::ItemIsDropEnabled)); currentitem->appendRow(child); } } @@ -106,7 +133,12 @@ DataFilesDialog::DataFilesDialog() pluginsmodel = new QStandardItemModel(0, 1); + pluginsmodel->setSupportedDragActions(Qt::MoveAction); + pluginsmodel->invisibleRootItem()->setFlags(Qt::ItemIsDropEnabled); + + masterselectmodel = new QItemSelectionModel(mastersmodel); + pluginselectmodel = new QItemSelectionModel(pluginsmodel); tree->setModel(datafilesmodel); tree->header()->hide(); @@ -121,14 +153,26 @@ DataFilesDialog::DataFilesDialog() mastertable->horizontalHeader()->hide(); plugintable->setModel(pluginsmodel); + plugintable->setSelectionModel(pluginselectmodel); plugintable->setSelectionBehavior(QAbstractItemView::SelectRows); - plugintable->setSelectionMode(QAbstractItemView::MultiSelection); + plugintable->setSelectionMode(QAbstractItemView::SingleSelection); plugintable->setEditTriggers(QAbstractItemView::NoEditTriggers); plugintable->horizontalHeader()->setStretchLastSection(true); plugintable->horizontalHeader()->hide(); + + plugintable->setDragEnabled(true); + plugintable->setDragDropMode(QAbstractItemView::InternalMove); + plugintable->setDropIndicatorShown(true); + plugintable->setDragDropOverwriteMode(false); + plugintable->viewport()->setAcceptDrops(true); + + plugintable->setContextMenuPolicy(Qt::CustomContextMenu); + connect(masterselectmodel, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(masterSelectionChanged(const QItemSelection&, const QItemSelection&))); - + connect(plugintable, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenu(const QPoint&))); + connect(plugintable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckstate(QModelIndex))); + // Adjust the dialog width setMinimumWidth(500); } @@ -150,6 +194,8 @@ void DataFilesDialog::appendPlugins(const QModelIndex &masterindex) { // Plugin not yet in the pluginsmodel, add it QStandardItem *item = new QStandardItem(QVariant(datafilesmodel->data(childindex)).toString()); + item->setFlags(item->flags() & ~(Qt::ItemIsDropEnabled)); + item->setCheckable(true); pluginsmodel->appendRow(item); } } @@ -238,6 +284,78 @@ void DataFilesDialog::masterSelectionChanged(const QItemSelection &selected, con } } +void DataFilesDialog::showContextMenu(const QPoint &point) +{ + qDebug() << "Show me the money!"; + + + + QAction *action1 = new QAction(QIcon::fromTheme("arrow-up-double"), tr("Move to Top"), this); + QAction *action2 = new QAction(QIcon::fromTheme("arrow-down-double"), tr("Move to Bottom"), this); + QAction *action3 = new QAction(QIcon::fromTheme("arrow-up"), tr("Move Up"), this); + QAction *action4 = new QAction(QIcon::fromTheme("arrow-down"), tr("Move Down"), this); + QAction *action5 = new QAction(this); + + QModelIndex index = plugintable->indexAt(point); + + if (index.isValid()) { // Should be valid! + const QStandardItem *item = pluginsmodel->itemFromIndex(index); + + if (item->checkState() == Qt::Checked) { + action5->setText("Uncheck Item"); + } else if (item->checkState() == Qt::Unchecked) { + action5->setText("Check Item"); + } + } + + connect(action5, SIGNAL(triggered()), this, SLOT(actionCheckstate())); + + QMenu menu(this); + menu.addAction(action1); + menu.addAction(action2); + menu.addSeparator(); + menu.addAction(action3); + menu.addAction(action4); + menu.addSeparator(); + menu.addAction(action5); + + menu.exec(plugintable->viewport()->mapToGlobal(point)); + +} + +void DataFilesDialog::actionCheckstate() +{ + qDebug() << "actionCheckstate"; + + const QModelIndexList selectedindexes = pluginselectmodel->selectedIndexes(); + + // Should only be one index selected + foreach (const QModelIndex ¤tindex, selectedindexes) { + setCheckstate(currentindex); + } + +} + +void DataFilesDialog::setCheckstate(QModelIndex index) +{ + // No check if index is valid: doubleclicked() always returns + // a valid index when emitted + + //index = QModelIndex(sortModel->mapToSource(index)); // Get a valid index + index = index.sibling(index.row(), 0); // reset index to first column + // because that's where te checkbox is; makes it possible to doubleclick whole row + + if (!index.isValid()) + return; + + if (pluginsmodel->data(index, Qt::CheckStateRole) == Qt::Checked) { + // Selected row is checked, uncheck it + pluginsmodel->setData(index, Qt::Unchecked, Qt::CheckStateRole); + } else { + pluginsmodel->setData(index, Qt::Checked, Qt::CheckStateRole); + } +} + void DataFilesDialog::readConfig() { /* QString filename; @@ -406,4 +524,5 @@ void DataFilesDialog::restoreDefaults() // dataFilesModel->setData(); * / } -*/ \ No newline at end of file +*/ + diff --git a/apps/launcher/datafilesdialog.h b/apps/launcher/datafilesdialog.h index 69e57083e8..9a718f3f53 100644 --- a/apps/launcher/datafilesdialog.h +++ b/apps/launcher/datafilesdialog.h @@ -16,6 +16,7 @@ class QSortFilterProxyModel; #include #include +class PluginItemModel; class QTreeView; class QTableView; class QStandardItemModel; @@ -48,6 +49,7 @@ private: QStandardItemModel *pluginsmodel; QItemSelectionModel *masterselectmodel; + QItemSelectionModel *pluginselectmodel; QTreeView *tree; @@ -63,11 +65,14 @@ public slots: void restoreDefaults(); void readConfig(); void writeConfig(); + void showContextMenu(const QPoint &point); + + void actionCheckstate(); //void setupView(); void masterSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); //void setFilter(); - //void setCheckstate(QModelIndex index); + void setCheckstate(QModelIndex index); // void doubleClicked(QModelIndex index); }; diff --git a/apps/launcher/datafilesmodel.cpp b/apps/launcher/datafilesmodel.cpp deleted file mode 100644 index 0eb68ab4c6..0000000000 --- a/apps/launcher/datafilesmodel.cpp +++ /dev/null @@ -1,155 +0,0 @@ -#include - -#include "datafilesitem.h" -#include "datafilesmodel.h" - -//DataFilesModel::DataFilesModel(const QString &data, QObject *parent) -DataFilesModel::DataFilesModel(QObject *parent) - : QAbstractItemModel(parent) -{ - QList rootData; - rootData << " "; - //rootItem = new DataFilesItem(rootData); - rootItem = new DataFilesItem(rootData); - //setupModelData(data.split(QString("\n")), rootItem); -} - -DataFilesModel::~DataFilesModel() -{ - delete rootItem; -} - -int DataFilesModel::columnCount(const QModelIndex &parent) const -{ - if (parent.isValid()) - return static_cast(parent.internalPointer())->columnCount(); - else - return rootItem->columnCount(); -} - -QVariant DataFilesModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - if (role != Qt::DisplayRole) - return QVariant(); - - DataFilesItem *item = static_cast(index.internalPointer()); - - return item->data(index.column()); -} - -Qt::ItemFlags DataFilesModel::flags(const QModelIndex &index) const -{ - if (!index.isValid()) - return 0; - - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; -} - -QVariant DataFilesModel::headerData(int section, Qt::Orientation orientation, - int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) - return rootItem->data(section); - - return QVariant(); -} - -QModelIndex DataFilesModel::index(int row, int column, const QModelIndex &parent) - const -{ - if (!hasIndex(row, column, parent)) - return QModelIndex(); - - DataFilesItem *parentItem; - - if (!parent.isValid()) - parentItem = rootItem; - else - parentItem = static_cast(parent.internalPointer()); - - DataFilesItem *childItem = parentItem->child(row); - if (childItem) - return createIndex(row, column, childItem); - else - return QModelIndex(); -} - -QModelIndex DataFilesModel::parent(const QModelIndex &index) const -{ - if (!index.isValid()) - return QModelIndex(); - - DataFilesItem *childItem = static_cast(index.internalPointer()); - DataFilesItem *parentItem = childItem->parent(); - - if (parentItem == rootItem) - return QModelIndex(); - - return createIndex(parentItem->row(), 0, parentItem); -} - -int DataFilesModel::rowCount(const QModelIndex &parent) const -{ - DataFilesItem *parentItem; - if (parent.column() > 0) - return 0; - - if (!parent.isValid()) - parentItem = rootItem; - else - parentItem = static_cast(parent.internalPointer()); - - return parentItem->childCount(); -} - -/*void DataFilesModel::setupModelData(const QStringList &lines, DataFilesItem *parent) -{ - QList parents; - QList indentations; - parents << parent; - indentations << 0; - - int number = 0; - - while (number < lines.count()) { - int position = 0; - while (position < lines[number].length()) { - if (lines[number].mid(position, 1) != " ") - break; - position++; - } - - QString lineData = lines[number].mid(position).trimmed(); - - if (!lineData.isEmpty()) { - // Read the column data from the rest of the line. - QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts); - QList columnData; - for (int column = 0; column < columnStrings.count(); ++column) - columnData << columnStrings[column]; - - if (position > indentations.last()) { - // The last child of the current parent is now the new parent - // unless the current parent has no children. - - if (parents.last()->childCount() > 0) { - parents << parents.last()->child(parents.last()->childCount()-1); - indentations << position; - } - } else { - while (position < indentations.last() && parents.count() > 0) { - parents.pop_back(); - indentations.pop_back(); - } - } - - // Append a new item to the current parent's list of children. - parents.last()->appendChild(new DataFilesItem(columnData, parents.last())); - } - - number++; - } -}*/ \ No newline at end of file diff --git a/apps/launcher/datafilesmodel.h b/apps/launcher/datafilesmodel.h deleted file mode 100644 index bf2184dcdb..0000000000 --- a/apps/launcher/datafilesmodel.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef DATAFILESMODEL_H -#define DATAFILESMODEL_H - -#include -#include -#include - -class DataFilesItem; - -class DataFilesModel : public QAbstractItemModel -{ - Q_OBJECT - -public: - //DataFilesModel(const QString &data, QObject *parent = 0); - DataFilesModel(QObject *parent = 0); - ~DataFilesModel(); - - QVariant data(const QModelIndex &index, int role) const; - Qt::ItemFlags flags(const QModelIndex &index) const; - QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const; - QModelIndex parent(const QModelIndex &index) const; - int rowCount(const QModelIndex &parent = QModelIndex()) const; - int columnCount(const QModelIndex &parent = QModelIndex()) const; - -private: - //void setupModelData(const QStringList &lines, TreeItem *parent); - - DataFilesItem *rootItem; -}; - -#endif \ No newline at end of file