mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 07:53:53 +00:00
Fixed row-selection/check feature
This commit is contained in:
parent
a9db983233
commit
66e50343ad
4 changed files with 35 additions and 34 deletions
|
@ -7,6 +7,9 @@
|
|||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMenu>
|
||||
#include <QContextMenuEvent>
|
||||
|
||||
FileOrderList::ContentSelector::ContentSelector(QWidget *parent) :
|
||||
QWidget(parent)
|
||||
{
|
||||
|
@ -26,7 +29,7 @@ void FileOrderList::ContentSelector::buildModelsAndViews()
|
|||
pluginView->setModel(mPluginsProxyModel);
|
||||
|
||||
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(profilesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int)));
|
||||
}
|
||||
|
@ -88,7 +91,6 @@ void FileOrderList::ContentSelector::slotCurrentProfileIndexChanged(int index)
|
|||
|
||||
void FileOrderList::ContentSelector::slotCurrentMasterIndexChanged(int index)
|
||||
{
|
||||
qDebug() << "index Changed: " << index;
|
||||
QObject *object = QObject::sender();
|
||||
|
||||
// Not a signal-slot call
|
||||
|
@ -97,3 +99,8 @@ void FileOrderList::ContentSelector::slotCurrentMasterIndexChanged(int index)
|
|||
|
||||
setCheckState(mMasterProxyModel->index(index, 0), mMasterProxyModel);
|
||||
}
|
||||
|
||||
void FileOrderList::ContentSelector::slotPluginTableItemClicked(const QModelIndex &index)
|
||||
{
|
||||
setCheckState(index, mPluginsProxyModel);
|
||||
}
|
||||
|
|
|
@ -30,8 +30,10 @@ namespace FileOrderList
|
|||
|
||||
void addFiles(const QString &path);
|
||||
void setEncoding(const QString &encoding);
|
||||
void setPluginCheckState();
|
||||
void setCheckState(QModelIndex index, QSortFilterProxyModel *model);
|
||||
QStringList checkedItemsPaths();
|
||||
void on_checkAction_triggered();
|
||||
|
||||
signals:
|
||||
void profileChanged(int index);
|
||||
|
@ -40,6 +42,7 @@ namespace FileOrderList
|
|||
void updateViews();
|
||||
void slotCurrentProfileIndexChanged(int index);
|
||||
void slotCurrentMasterIndexChanged(int index);
|
||||
void slotPluginTableItemClicked(const QModelIndex &index);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,19 @@ void DataFilesModel::setEncoding(const QString &encoding)
|
|||
|
||||
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)
|
||||
|
@ -210,19 +222,6 @@ bool DataFilesModel::setData(const QModelIndex &index, const QVariant &value, in
|
|||
if (!index.isValid())
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
<height>304</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::DefaultContextMenu</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="filterLayout">
|
||||
|
@ -26,6 +29,9 @@
|
|||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTableView" name="pluginView">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::DefaultContextMenu</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
|
@ -138,6 +144,9 @@
|
|||
</property>
|
||||
</action>
|
||||
<action name="checkAction">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Check Selection</string>
|
||||
</property>
|
||||
|
@ -156,22 +165,5 @@
|
|||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<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>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
Loading…
Reference in a new issue