-
-
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 1 commit
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 |
---|---|---|
|
@@ -468,6 +468,42 @@ CrateTrackSelectResult CrateStorage::selectTrackCratesSorted(TrackId trackId) co | |
} | ||
} | ||
|
||
CrateSummarySelectResult CrateStorage::selectCratesWithTrackCount(const QList<TrackId>& trackIds) const { | ||
|
||
// unfortunatelly we can't bind a QList to a SqlQuery therefor we have to construct a String first | ||
// see: https://stackoverflow.com/questions/3220357/qt-how-to-bind-a-qlist-to-a-qsqlquery-with-a-where-in-clause | ||
// Using bindValue did not work, only constructing the SQL string befor. | ||
// As TrackId is a int, we are safe here | ||
QStringList idstrings; | ||
foreach(TrackId id, 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 standard C++11 |
||
idstrings << id.toString(); | ||
} | ||
QString numberlist = idstrings.join(","); | ||
QString ids = QString("%1").arg(numberlist); | ||
|
||
FwdSqlQuery query(m_database, QString( | ||
"SELECT *, (" | ||
" SELECT COUNT(*) FROM %1 WHERE %2.%3 = %1.%4 and %1.%5 in (%9)" | ||
" ) AS %6, 0 as %7 FROM %2 ORDER BY %8").arg( | ||
CRATE_TRACKS_TABLE, | ||
CRATE_TABLE, | ||
CRATETABLE_ID, | ||
CRATETRACKSTABLE_CRATEID, | ||
CRATETRACKSTABLE_TRACKID, | ||
CRATESUMMARY_TRACK_COUNT, | ||
CRATESUMMARY_TRACK_DURATION, | ||
CRATETABLE_NAME, | ||
ids)); | ||
|
||
if (query.execPrepared()) { | ||
return CrateSummarySelectResult(std::move(query)); | ||
} else { | ||
return CrateSummarySelectResult(); | ||
} | ||
|
||
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. extra blank line |
||
} | ||
|
||
|
||
|
||
CrateTrackSelectResult CrateStorage::selectTracksSortedByCrateNameLike(const QString& crateNameLike) const { | ||
FwdSqlQuery query(m_database, QString( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
#include <QUrl> | ||
#include <QDrag> | ||
#include <QShortcut> | ||
#include <QWidgetAction> | ||
#include <QCheckBox> | ||
|
||
#include "widget/wtracktableview.h" | ||
|
||
|
@@ -26,6 +28,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 +72,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 +96,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 +831,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); | ||
} | ||
|
@@ -1466,22 +1493,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.
nitpick: extra blank line here