#2384 multi case import. Context menu for on/off/toggle files

This commit is contained in:
Bjørn Erik Jensen 2018-01-24 12:35:47 +01:00
parent 8b4a1f05bc
commit d646af8514
2 changed files with 76 additions and 2 deletions

View File

@ -42,6 +42,7 @@
#include <QGroupBox>
#include <QListWidget>
#include <QAbstractItemView>
#include <QMenu>
#include <vector>
#include <time.h>
@ -95,6 +96,7 @@ RicFileHierarchyDialog::RicFileHierarchyDialog(QWidget* parent)
connect(m_rootDir, SIGNAL(textChanged(const QString&)), this, SLOT(slotFilterChanged(const QString&)));
connect(m_pathFilter, SIGNAL(textChanged(const QString&)), this, SLOT(slotFilterChanged(const QString&)));
connect(m_fileFilter, SIGNAL(textChanged(const QString&)), this, SLOT(slotFilterChanged(const QString&)));
connect(m_fileList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(slotFileListCustomMenuRequested(const QPoint&)));
connect(m_findOrCancelButton, SIGNAL(clicked()), this, SLOT(slotFindOrCancelButtonClicked()));
connect(m_buttons, SIGNAL(accepted()), this, SLOT(slotDialogOkClicked()));
@ -109,8 +111,9 @@ RicFileHierarchyDialog::RicFileHierarchyDialog(QWidget* parent)
m_effectiveFilter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_fileListLabel->setText("Files found");
m_fileListLabel->setVisible(false);
m_fileList->setSelectionMode(QAbstractItemView::NoSelection);
m_fileList->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_fileList->setVisible(false);
m_fileList->setContextMenuPolicy(Qt::CustomContextMenu);
m_browseButton->setText("...");
m_browseButton->setFixedWidth(25);
m_findOrCancelButton->setText(FIND_BUTTON_FIND_TEXT);
@ -419,7 +422,7 @@ void RicFileHierarchyDialog::updateEffectiveFilter()
// Remove duplicate separators
int len;
do
do
{
len = native.size();
native.replace(separator + separator, separator);
@ -445,6 +448,73 @@ void RicFileHierarchyDialog::slotFilterChanged(const QString& text)
updateEffectiveFilter();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicFileHierarchyDialog::slotFileListCustomMenuRequested(const QPoint& point)
{
QMenu menu;
QPoint globalPoint = point;
QAction* action;
action = new QAction("On", this);
connect(action, SIGNAL(triggered()), SLOT(slotTurnOnFileListItems()));
menu.addAction(action);
action = new QAction("Off", this);
connect(action, SIGNAL(triggered()), SLOT(slotTurnOffFileListItems()));
menu.addAction(action);
action = new QAction("Toggle", this);
connect(action, SIGNAL(triggered()), SLOT(slotToggleFileListItems()));
menu.addAction(action);
globalPoint = m_fileList->mapToGlobal(point);
menu.exec(globalPoint);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicFileHierarchyDialog::slotToggleFileListItems()
{
for (auto& item : m_fileList->selectedItems())
{
if ((item->flags() & Qt::ItemIsUserCheckable) != 0)
{
item->setCheckState(item->checkState() == Qt::Checked ? Qt::Unchecked : Qt::Checked);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicFileHierarchyDialog::slotTurnOffFileListItems()
{
for (auto& item : m_fileList->selectedItems())
{
if ((item->flags() & Qt::ItemIsUserCheckable) != 0)
{
item->setCheckState(Qt::Unchecked);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicFileHierarchyDialog::slotTurnOnFileListItems()
{
for (auto& item : m_fileList->selectedItems())
{
if ((item->flags() & Qt::ItemIsUserCheckable) != 0)
{
item->setCheckState(Qt::Checked);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -82,6 +82,10 @@ private:
private slots:
void slotFilterChanged(const QString& text);
void slotFileListCustomMenuRequested(const QPoint& point);
void slotToggleFileListItems();
void slotTurnOffFileListItems();
void slotTurnOnFileListItems();
void slotFindOrCancelButtonClicked();
void slotDialogOkClicked();
void slotDialogCancelClicked();