-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use checkbox menu in crate selection. #1341
Changes from 4 commits
0a75b38
de8f406
7f2e1e7
e892e99
39d609e
6c8b9a1
341acf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
#include <QUrl> | ||
#include <QDrag> | ||
#include <QShortcut> | ||
#include <QWidgetAction> | ||
#include <QCheckBox> | ||
#include <QLinkedList> | ||
|
||
#include "widget/wtracktableview.h" | ||
|
||
|
@@ -26,6 +29,7 @@ | |
#include "util/dnd.h" | ||
#include "util/time.h" | ||
#include "util/assert.h" | ||
#include "util/parented_ptr.h" | ||
|
||
WTrackTableView::WTrackTableView(QWidget * parent, | ||
UserSettingsPointer pConfig, | ||
|
@@ -69,7 +73,7 @@ WTrackTableView::WTrackTableView(QWidget * parent, | |
m_pPlaylistMenu = new QMenu(this); | ||
m_pPlaylistMenu->setTitle(tr("Add to Playlist")); | ||
m_pCrateMenu = new QMenu(this); | ||
m_pCrateMenu->setTitle(tr("Add to Crate")); | ||
m_pCrateMenu->setTitle(tr("Crates")); | ||
m_pBPMMenu = new QMenu(this); | ||
m_pBPMMenu->setTitle(tr("BPM Options")); | ||
m_pCoverMenu = new WCoverArtMenu(this); | ||
|
@@ -93,8 +97,9 @@ WTrackTableView::WTrackTableView(QWidget * parent, | |
|
||
connect(&m_playlistMapper, SIGNAL(mapped(int)), | ||
this, SLOT(addSelectionToPlaylist(int))); | ||
connect(&m_crateMapper, SIGNAL(mapped(int)), | ||
this, SLOT(addSelectionToCrate(int))); | ||
|
||
connect(&m_crateMapper, SIGNAL(mapped(QWidget *)), | ||
this, SLOT(addRemoveSelectionInCrate(QWidget *))); | ||
|
||
m_pCOTGuiTick = new ControlProxy("[Master]", "guiTick50ms", this); | ||
m_pCOTGuiTick->connectValueChanged(SLOT(slotGuiTick50ms(double))); | ||
|
@@ -827,21 +832,44 @@ void WTrackTableView::contextMenuEvent(QContextMenuEvent* event) { | |
|
||
if (modelHasCapabilities(TrackModel::TRACKMODELCAPS_ADDTOCRATE)) { | ||
m_pCrateMenu->clear(); | ||
CrateSelectResult allCrates(m_pTrackCollection->crates().selectCrates()); | ||
Crate crate; | ||
const QList<TrackId> trackIds = getSelectedTrackIds(); | ||
|
||
CrateSummarySelectResult allCrates(m_pTrackCollection->crates().selectCratesWithTrackCount(trackIds)); | ||
|
||
CrateSummary crate; | ||
while (allCrates.populateNext(&crate)) { | ||
auto pAction = std::make_unique<QAction>(crate.getName(), m_pCrateMenu); | ||
auto pAction = make_parented<QWidgetAction>(m_pCrateMenu); | ||
auto pCheckBox = make_parented<QCheckBox>(m_pCrateMenu); | ||
|
||
pCheckBox->setText(crate.getName()); | ||
pCheckBox->setProperty("crateId", | ||
QVariant::fromValue(crate.getId())); | ||
pCheckBox->setEnabled(!crate.isLocked()); | ||
pAction->setEnabled(!crate.isLocked()); | ||
m_crateMapper.setMapping(pAction.get(), crate.getId().toInt()); | ||
connect(pAction.get(), SIGNAL(triggered()), &m_crateMapper, SLOT(map())); | ||
pAction->setDefaultWidget(pCheckBox.get()); | ||
|
||
if(crate.getTrackCount() == 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
pCheckBox->setChecked(false); | ||
} else if(crate.getTrackCount() == (uint)trackIds.length()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
pCheckBox->setChecked(true); | ||
} else { | ||
pCheckBox->setTristate(true); | ||
pCheckBox->setCheckState(Qt::PartiallyChecked); | ||
} | ||
|
||
m_crateMapper.setMapping(pAction.get(), pCheckBox.get()); | ||
m_crateMapper.setMapping(pCheckBox.get(), pCheckBox.get()); | ||
m_pCrateMenu->addAction(pAction.get()); | ||
pAction.release(); | ||
connect(pAction.get(), SIGNAL(triggered()), | ||
&m_crateMapper, SLOT(map())); | ||
connect(pCheckBox.get(), SIGNAL(stateChanged(int)), | ||
&m_crateMapper, SLOT(map())); | ||
|
||
} | ||
m_pCrateMenu->addSeparator(); | ||
QAction* newCrateAction = new QAction(tr("Create New Crate"), m_pCrateMenu); | ||
m_pCrateMenu->addAction(newCrateAction); | ||
m_crateMapper.setMapping(newCrateAction, CrateId().toInt());// invalid crate id for new crate | ||
connect(newCrateAction, SIGNAL(triggered()), &m_crateMapper, SLOT(map())); | ||
connect(newCrateAction, SIGNAL(triggered()), this, SLOT(addSelectionToNewCrate())); | ||
|
||
m_pMenu->addMenu(m_pCrateMenu); | ||
} | ||
|
@@ -1355,6 +1383,31 @@ QList<TrackId> WTrackTableView::getSelectedTrackIds() const { | |
return trackIds; | ||
} | ||
|
||
void WTrackTableView::setSelectedTracks(QList<TrackId> trackIds) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This parameter should be passed as const-ref to avoid a deep copy of the list. Unfortunately the range-based for loops do not work well with Qt containers. Declaring the loop variable as const-ref is not enough. The container itself must be const! There is already a link in our coding guidelines. We have this issue at many places and I have done this wrong until recently. Checking the code with clazy could reveal those hidden performance killers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will fix this after merge There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I already did in #1427 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
QItemSelectionModel* pSelectionModel = selectionModel(); | ||
VERIFY_OR_DEBUG_ASSERT(pSelectionModel != nullptr) { | ||
qWarning() << "No selected tracks available"; | ||
return; | ||
} | ||
|
||
TrackModel* pTrackModel = getTrackModel(); | ||
VERIFY_OR_DEBUG_ASSERT(pTrackModel != nullptr) { | ||
qWarning() << "No selected tracks available"; | ||
return; | ||
} | ||
|
||
foreach(TrackId trackId, trackIds) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use modern standard C++ instead of old Qt |
||
const QLinkedList<int> gts = pTrackModel->getTrackRows(trackId); | ||
|
||
QLinkedList<int>::const_iterator i; | ||
for (i = gts.constBegin(); i != gts.constEnd(); ++i) { | ||
pSelectionModel->select(model()->index(*i, 0), | ||
QItemSelectionModel::Select | QItemSelectionModel::Rows); | ||
} | ||
} | ||
} | ||
|
||
|
||
void WTrackTableView::sendToAutoDJ(PlaylistDAO::AutoDJSendLoc loc) { | ||
if (!modelHasCapabilities(TrackModel::TRACKMODELCAPS_ADDTOAUTODJ)) { | ||
return; | ||
|
@@ -1466,22 +1519,55 @@ void WTrackTableView::addSelectionToPlaylist(int iPlaylistId) { | |
playlistDao.appendTracksToPlaylist(trackIds, iPlaylistId); | ||
} | ||
|
||
void WTrackTableView::addSelectionToCrate(int iCrateId) { | ||
void WTrackTableView::addRemoveSelectionInCrate(QWidget* pWidget) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function name is ambiguous. Does it add or does it remove? |
||
auto pCheckBox = qobject_cast<QCheckBox*>(pWidget); | ||
VERIFY_OR_DEBUG_ASSERT(pCheckBox) { | ||
qWarning() << "crateId is not ef CrateId type"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "not ef"? Did you mean "not of"? |
||
return; | ||
} | ||
CrateId crateId = pCheckBox->property("crateId").value<CrateId>(); | ||
|
||
const QList<TrackId> trackIds = getSelectedTrackIds(); | ||
|
||
if (trackIds.isEmpty()) { | ||
qWarning() << "No tracks selected for crate"; | ||
return; | ||
} | ||
|
||
CrateId crateId(iCrateId); | ||
if (!crateId.isValid()) { // i.e. a new crate is suppose to be created | ||
crateId = CrateFeatureHelper( | ||
m_pTrackCollection, m_pConfig).createEmptyCrate(); | ||
// we need to disable tristate again as the mixed state will now be gone and can't be brought back | ||
pCheckBox->setTristate(false); | ||
if(!pCheckBox->isChecked()) { | ||
if (crateId.isValid()) { | ||
m_pTrackCollection->removeCrateTracks(crateId, trackIds); | ||
} | ||
} else { | ||
if (!crateId.isValid()) { // i.e. a new crate is suppose to be created | ||
crateId = CrateFeatureHelper( | ||
m_pTrackCollection, m_pConfig).createEmptyCrate(); | ||
} | ||
if (crateId.isValid()) { | ||
m_pTrackCollection->unhideTracks(trackIds); | ||
m_pTrackCollection->addCrateTracks(crateId, trackIds); | ||
} | ||
} | ||
} | ||
|
||
void WTrackTableView::addSelectionToNewCrate() { | ||
const QList<TrackId> trackIds = getSelectedTrackIds(); | ||
|
||
if (trackIds.isEmpty()) { | ||
qWarning() << "No tracks selected for crate"; | ||
return; | ||
} | ||
|
||
CrateId crateId = CrateFeatureHelper( | ||
m_pTrackCollection, m_pConfig).createEmptyCrate(); | ||
|
||
if (crateId.isValid()) { | ||
m_pTrackCollection->unhideTracks(trackIds); | ||
m_pTrackCollection->addCrateTracks(crateId, trackIds); | ||
} | ||
|
||
} | ||
|
||
void WTrackTableView::doSortByColumn(int headerSection) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const auto& trackId
to prevent unnecessary copy