1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-01 17:15:34 +00:00

Fixed row-selection/check feature

This commit is contained in:
graffy76 2013-08-18 08:54:51 -05:00
parent a9db983233
commit 66e50343ad
4 changed files with 35 additions and 34 deletions

View file

@ -7,6 +7,9 @@
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QDebug> #include <QDebug>
#include <QMenu>
#include <QContextMenuEvent>
FileOrderList::ContentSelector::ContentSelector(QWidget *parent) : FileOrderList::ContentSelector::ContentSelector(QWidget *parent) :
QWidget(parent) QWidget(parent)
{ {
@ -26,7 +29,7 @@ void FileOrderList::ContentSelector::buildModelsAndViews()
pluginView->setModel(mPluginsProxyModel); pluginView->setModel(mPluginsProxyModel);
connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews())); connect(mDataFilesModel, SIGNAL(layoutChanged()), this, SLOT(updateViews()));
//connect(pluginView, SIGNAL()) connect(pluginView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotPluginTableItemClicked(const QModelIndex &)));
connect(masterView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentMasterIndexChanged(int))); connect(masterView, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentMasterIndexChanged(int)));
connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int))); connect(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int)));
} }
@ -88,7 +91,6 @@ void FileOrderList::ContentSelector::slotCurrentProfileIndexChanged(int index)
void FileOrderList::ContentSelector::slotCurrentMasterIndexChanged(int index) void FileOrderList::ContentSelector::slotCurrentMasterIndexChanged(int index)
{ {
qDebug() << "index Changed: " << index;
QObject *object = QObject::sender(); QObject *object = QObject::sender();
// Not a signal-slot call // Not a signal-slot call
@ -97,3 +99,8 @@ void FileOrderList::ContentSelector::slotCurrentMasterIndexChanged(int index)
setCheckState(mMasterProxyModel->index(index, 0), mMasterProxyModel); setCheckState(mMasterProxyModel->index(index, 0), mMasterProxyModel);
} }
void FileOrderList::ContentSelector::slotPluginTableItemClicked(const QModelIndex &index)
{
setCheckState(index, mPluginsProxyModel);
}

View file

@ -30,8 +30,10 @@ namespace FileOrderList
void addFiles(const QString &path); void addFiles(const QString &path);
void setEncoding(const QString &encoding); void setEncoding(const QString &encoding);
void setPluginCheckState();
void setCheckState(QModelIndex index, QSortFilterProxyModel *model); void setCheckState(QModelIndex index, QSortFilterProxyModel *model);
QStringList checkedItemsPaths(); QStringList checkedItemsPaths();
void on_checkAction_triggered();
signals: signals:
void profileChanged(int index); void profileChanged(int index);
@ -40,6 +42,7 @@ namespace FileOrderList
void updateViews(); void updateViews();
void slotCurrentProfileIndexChanged(int index); void slotCurrentProfileIndexChanged(int index);
void slotCurrentMasterIndexChanged(int index); void slotCurrentMasterIndexChanged(int index);
void slotPluginTableItemClicked(const QModelIndex &index);
}; };
} }

View file

@ -30,7 +30,19 @@ void DataFilesModel::setEncoding(const QString &encoding)
void DataFilesModel::setCheckState(const QModelIndex &index, Qt::CheckState state) void DataFilesModel::setCheckState(const QModelIndex &index, Qt::CheckState state)
{ {
setData(index, state, Qt::CheckStateRole); if (!index.isValid())
return;
QString name = item(index.row())->fileName();
mCheckStates[name] = state;
// Force a redraw of the view since unchecking one item can affect another
QModelIndex firstIndex = indexFromItem(mFiles.first());
QModelIndex lastIndex = indexFromItem(mFiles.last());
emit dataChanged(firstIndex, lastIndex);
emit checkedItemsChanged(checkedItems());
} }
Qt::CheckState DataFilesModel::checkState(const QModelIndex &index) Qt::CheckState DataFilesModel::checkState(const QModelIndex &index)
@ -210,19 +222,6 @@ bool DataFilesModel::setData(const QModelIndex &index, const QVariant &value, in
if (!index.isValid()) if (!index.isValid())
return false; return false;
if (role == Qt::CheckStateRole) {
QString name = item(index.row())->fileName();
mCheckStates[name] = static_cast<Qt::CheckState>(value.toInt());
// Force a redraw of the view since unchecking one item can affect another
QModelIndex firstIndex = indexFromItem(mFiles.first());
QModelIndex lastIndex = indexFromItem(mFiles.last());
emit dataChanged(firstIndex, lastIndex);
emit checkedItemsChanged(checkedItems());
return true;
}
return false; return false;
} }

View file

@ -10,6 +10,9 @@
<height>304</height> <height>304</height>
</rect> </rect>
</property> </property>
<property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<layout class="QHBoxLayout" name="filterLayout"> <layout class="QHBoxLayout" name="filterLayout">
@ -26,6 +29,9 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QTableView" name="pluginView"> <widget class="QTableView" name="pluginView">
<property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum>
</property>
<property name="editTriggers"> <property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set> <set>QAbstractItemView::NoEditTriggers</set>
</property> </property>
@ -138,6 +144,9 @@
</property> </property>
</action> </action>
<action name="checkAction"> <action name="checkAction">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text"> <property name="text">
<string>Check Selection</string> <string>Check Selection</string>
</property> </property>
@ -156,22 +165,5 @@
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections> <connections/>
<connection>
<sender>pluginView</sender>
<signal>clicked(QModelIndex)</signal>
<receiver>checkAction</receiver>
<slot>toggle()</slot>
<hints>
<hint type="sourcelabel">
<x>258</x>
<y>151</y>
</hint>
<hint type="destinationlabel">
<x>-1</x>
<y>-1</y>
</hint>
</hints>
</connection>
</connections>
</ui> </ui>