Skip to content

Commit

Permalink
Merge pull request #13816 from cr7pt0gr4ph7/ready-for-merge/sidebar-d…
Browse files Browse the repository at this point in the history
…nd/cleanup

Code cleanup in SidebarModel and WLibrarySidebar
  • Loading branch information
JoergAtGithub authored Nov 2, 2024
2 parents edae0ca + 54b7aa0 commit f7620a0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
46 changes: 35 additions & 11 deletions src/library/sidebarmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ namespace {
/// been chosen as a compromise between usability and responsiveness.
constexpr int kPressedUntilClickedTimeoutMillis = 300;

/// Enables additional debugging output.
constexpr bool kDebug = false;

} // anonymous namespace

SidebarModel::SidebarModel(
Expand Down Expand Up @@ -101,8 +104,11 @@ void SidebarModel::activateDefaultSelection() {

QModelIndex SidebarModel::index(int row, int column,
const QModelIndex& parent) const {
// qDebug() << "SidebarModel::index row=" << row
// << "column=" << column << "parent=" << parent.getData();
if constexpr (kDebug) {
qDebug() << "SidebarModel::index row=" << row
<< "column=" << column << "parent=" << parent;
}

if (parent.isValid()) {
/* If we have selected the root of a library feature at position 'row'
* its internal pointer is the current sidebar object model
Expand Down Expand Up @@ -137,7 +143,9 @@ QModelIndex SidebarModel::index(int row, int column,
}

QModelIndex SidebarModel::getFeatureRootIndex(LibraryFeature* pFeature) {
// qDebug() << "SidebarModel::getFeatureRootIndex for" << pFeature->title().toString();
if constexpr (kDebug) {
qDebug() << "SidebarModel::getFeatureRootIndex for" << pFeature->title().toString();
}
QModelIndex ind;
for (int i = 0; i < m_sFeatures.size(); ++i) {
if (m_sFeatures[i] == pFeature) {
Expand Down Expand Up @@ -167,7 +175,9 @@ void SidebarModel::paste(const QModelIndex& index) {
}

QModelIndex SidebarModel::parent(const QModelIndex& index) const {
//qDebug() << "SidebarModel::parent index=" << index.getData();
if constexpr (kDebug) {
qDebug() << "SidebarModel::parent index=" << index;
}
if (index.isValid()) {
// If we have selected the root of a library feature
// its internal pointer is the current sidebar object model
Expand Down Expand Up @@ -207,7 +217,9 @@ QModelIndex SidebarModel::parent(const QModelIndex& index) const {
}

int SidebarModel::rowCount(const QModelIndex& parent) const {
//qDebug() << "SidebarModel::rowCount parent=" << parent.getData();
if constexpr (kDebug) {
qDebug() << "SidebarModel::rowCount parent=" << parent;
}
if (parent.isValid()) {
if (parent.internalPointer() == this) {
return m_sFeatures[parent.row()]->sidebarModel()->rowCount();
Expand All @@ -225,7 +237,9 @@ int SidebarModel::rowCount(const QModelIndex& parent) const {

int SidebarModel::columnCount(const QModelIndex& parent) const {
Q_UNUSED(parent);
//qDebug() << "SidebarModel::columnCount parent=" << parent;
if constexpr (kDebug) {
qDebug() << "SidebarModel::columnCount parent=" << parent;
}
// TODO(rryan) will we ever have columns? I don't think so.
return 1;
}
Expand All @@ -247,8 +261,14 @@ bool SidebarModel::hasChildren(const QModelIndex& parent) const {
}

QVariant SidebarModel::data(const QModelIndex& index, int role) const {
// qDebug("SidebarModel::data row=%d column=%d pointer=%8x, role=%d",
// index.row(), index.column(), index.internalPointer(), role);
if constexpr (kDebug) {
qDebug("SidebarModel::data() row=%d column=%d pointer=%p, role=%d",
index.row(),
index.column(),
index.internalPointer(),
role);
}

if (!index.isValid()) {
return QVariant();
}
Expand Down Expand Up @@ -418,7 +438,9 @@ void SidebarModel::deleteItem(const QModelIndex& index) {
}

bool SidebarModel::dropAccept(const QModelIndex& index, const QList<QUrl>& urls, QObject* pSource) {
//qDebug() << "SidebarModel::dropAccept() index=" << index << url;
if constexpr (kDebug) {
qDebug() << "SidebarModel::dropAccept() index=" << index << urls;
}
bool result = false;
if (index.isValid()) {
if (index.internalPointer() == this) {
Expand All @@ -441,8 +463,10 @@ bool SidebarModel::hasTrackTable(const QModelIndex& index) const {
return false;
}

bool SidebarModel::dragMoveAccept(const QModelIndex& index, const QUrl& url) {
//qDebug() << "SidebarModel::dragMoveAccept() index=" << index << url;
bool SidebarModel::dragMoveAccept(const QModelIndex& index, const QUrl& url) const {
if constexpr (kDebug) {
qDebug() << "SidebarModel::dragMoveAccept() index=" << index << url;
}
bool result = false;

if (index.isValid()) {
Expand Down
2 changes: 1 addition & 1 deletion src/library/sidebarmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SidebarModel : public QAbstractItemModel {
QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const override;
bool dropAccept(const QModelIndex& index, const QList<QUrl>& urls, QObject* pSource);
bool dragMoveAccept(const QModelIndex& index, const QUrl& url);
bool dragMoveAccept(const QModelIndex& index, const QUrl& url) const;
bool hasChildren(const QModelIndex& parent = QModelIndex()) const override;
bool hasTrackTable(const QModelIndex& index) const;
QModelIndex translateChildIndex(const QModelIndex& index) {
Expand Down
14 changes: 8 additions & 6 deletions src/widget/wlibrarysidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void WLibrarySidebar::contextMenuEvent(QContextMenuEvent *event) {
//}
}

// Drag enter event, happens when a dragged item enters the track sources view
/// Drag enter event, happens when a dragged item enters the track sources view
void WLibrarySidebar::dragEnterEvent(QDragEnterEvent * event) {
qDebug() << "WLibrarySidebar::dragEnterEvent" << event->mimeData()->formats();
if (event->mimeData()->hasUrls()) {
Expand All @@ -62,7 +62,7 @@ void WLibrarySidebar::dragEnterEvent(QDragEnterEvent * event) {
//QTreeView::dragEnterEvent(event);
}

// Drag move event, happens when a dragged item hovers over the track sources view...
/// Drag move event, happens when a dragged item hovers over the track sources view...
void WLibrarySidebar::dragMoveEvent(QDragMoveEvent * event) {
//qDebug() << "dragMoveEvent" << event->mimeData()->formats();
// Start a timer to auto-expand sections the user hovers on.
Expand Down Expand Up @@ -102,10 +102,12 @@ void WLibrarySidebar::dragMoveEvent(QDragMoveEvent * event) {
if (sidebarModel->dragMoveAccept(destIndex, url)) {
// We only need one URL to be valid for us
// to accept the whole drag...
// consider we have a long list of valid files, checking all will
// take a lot of time that stales Mixxx and this makes the drop feature useless
// Eg. you may have tried to drag two MP3's and an EXE, the drop is accepted here,
// but the EXE is sorted out later after dropping
// Consider that we might have a long list of files,
// checking all will take a lot of time that stalls
// Mixxx and this makes the drop feature useless.
// E.g. you may have tried to drag two MP3's and an EXE,
// the drop is accepted here, but the EXE is filtered
// out later after dropping
accepted = true;
break;
}
Expand Down

0 comments on commit f7620a0

Please sign in to comment.