summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widget/wlibrarytableview.cpp17
-rw-r--r--src/widget/wlibrarytableview.h17
-rw-r--r--src/widget/wtracktableview.cpp18
3 files changed, 49 insertions, 3 deletions
diff --git a/src/widget/wlibrarytableview.cpp b/src/widget/wlibrarytableview.cpp
index 7c121703b5..86bed34e1d 100644
--- a/src/widget/wlibrarytableview.cpp
+++ b/src/widget/wlibrarytableview.cpp
@@ -18,6 +18,8 @@ WLibraryTableView::WLibraryTableView(QWidget* parent,
m_pConfig(pConfig),
m_vScrollBarPosKey(vScrollBarPosKey) {
+ qWarning() << "vScrollBarPosKey=" << vScrollBarPosKey;
+
// Setup properties for table
// Editing starts when clicking on an already selected item.
@@ -73,6 +75,7 @@ void WLibraryTableView::saveVScrollBarPos() {
//Save the scrollbar's position so we can return here after
//a search is cleared.
m_iSavedVScrollBarPos = verticalScrollBar()->value();
+
}
@@ -112,6 +115,20 @@ void WLibraryTableView::moveSelection(int delta) {
}
}
+void WLibraryTableView::saveVScrollBarPos(const QString key){
+ m_vScrollBarPosValues[key] = verticalScrollBar()->value();
+}
+
+void WLibraryTableView::restoreVScrollBarPos(const QString key){
+ updateGeometries();
+ if (m_vScrollBarPosValues.contains(key)){
+ verticalScrollBar()->setValue(m_vScrollBarPosValues[key]);
+ }else{
+ m_vScrollBarPosValues[key] = 0;
+ verticalScrollBar()->setValue(0);
+ }
+}
+
void WLibraryTableView::setTrackTableFont(const QFont& font) {
setFont(font);
setTrackTableRowHeight(verticalHeader()->defaultSectionSize());
diff --git a/src/widget/wlibrarytableview.h b/src/widget/wlibrarytableview.h
index b810bdee65..a08a956d91 100644
--- a/src/widget/wlibrarytableview.h
+++ b/src/widget/wlibrarytableview.h
@@ -24,6 +24,19 @@ class WLibraryTableView : public QTableView, public virtual LibraryView {
~WLibraryTableView() override;
void moveSelection(int delta) override;
+ /**
+ * @brief saveVScrollBarPos function saves current position of scrollbar
+ * using string key - can be any value but should invariant for model
+ * @param key unique for trackmodel
+ */
+ void saveVScrollBarPos(const QString key);
+ /**
+ * @brief restoreVScrollBarPos function finds scrollbar value associated with model
+ * by given key and restores it
+ * @param key unique for trackmodel
+ */
+ void restoreVScrollBarPos(const QString key);
+
signals:
void loadTrack(TrackPointer pTrack);
void loadTrackToPlayer(TrackPointer pTrack, QString group,
@@ -33,7 +46,7 @@ class WLibraryTableView : public QTableView, public virtual LibraryView {
void scrollValueChanged(int);
public slots:
- void saveVScrollBarPos();
+ void saveVScrollBarPos(); // these slosts remain for compatibility
void restoreVScrollBarPos();
void setTrackTableFont(const QFont& font);
void setTrackTableRowHeight(int rowHeight);
@@ -42,6 +55,8 @@ class WLibraryTableView : public QTableView, public virtual LibraryView {
void loadVScrollBarPosState();
void saveVScrollBarPosState();
+ QMap<QString, int> m_vScrollBarPosValues;
+
UserSettingsPointer m_pConfig;
ConfigKey m_vScrollBarPosKey;
// The position of the vertical scrollbar slider, eg. before a search is
diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp
index a6451d3a29..c0102b3e3e 100644
--- a/src/widget/wtracktableview.cpp
+++ b/src/widget/wtracktableview.cpp
@@ -28,10 +28,11 @@
WTrackTableView::WTrackTableView(QWidget * parent,
UserSettingsPointer pConfig,
- TrackCollection* pTrackCollection, bool sorting)
+ TrackCollection* pTrackCollection,
+ const QString scrollBarKey, bool sorting)
: WLibraryTableView(parent, pConfig,
ConfigKey(LIBRARY_CONFIGVALUE,
- WTRACKTABLEVIEW_VSCROLLBARPOS_KEY)),
+ scrollBarKey)),
m_pConfig(pConfig),
m_pTrackCollection(pTrackCollection),
m_sorting(sorting),
@@ -43,6 +44,7 @@ WTrackTableView::WTrackTableView(QWidget * parent,
m_selectionChangedSinceLastGuiTick(true),
m_loadCachedOnly(false) {
+ qWarning() << "WTrackTableView called";
connect(&m_loadTrackMapper, SIGNAL(mapped(QString)),
this, SLOT(loadSelectionToGroup(QString)));
@@ -199,6 +201,8 @@ void WTrackTableView::slotGuiTick50ms(double /*unused*/) {
void WTrackTableView::loadTrackModel(QAbstractItemModel *model) {
//qDebug() << "WTrackTableView::loadTrackModel()" << model;
+ qWarning() << "loadTrackModel:" << reinterpret_cast<unsigned long>(model);
+
TrackModel* trackModel = dynamic_cast<TrackModel*>(model);
DEBUG_ASSERT_AND_HANDLE(model) {
@@ -217,6 +221,13 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel *model) {
// a select() if the table is dirty.
doSortByColumn(horizontalHeader()->sortIndicatorSection());
return;
+ }else{
+ saveVScrollBarPos(QString::number(reinterpret_cast<unsigned long>(getTrackModel())));
+ //saving current vertical bar position
+ //using adress of track model as key
+ restoreVScrollBarPos(QString::number(reinterpret_cast<unsigned long>(trackModel)));
+ // restoring scrollBar position using model pointer as key
+ // scrollbar positions with respect to different models are backed by map
}
// The "coverLocation" and "hash" column numbers are required very often
@@ -357,6 +368,7 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel *model) {
// target though, so my hax above may not be completely unjustified.
setVisible(true);
+ //restoreVScrollBarPos();
}
void WTrackTableView::createActions() {
@@ -563,6 +575,7 @@ void WTrackTableView::slotOpenInFileBrowser() {
}
void WTrackTableView::slotHide() {
+
QModelIndexList indices = selectionModel()->selectedRows();
if (indices.size() > 0) {
TrackModel* trackModel = getTrackModel();
@@ -1009,6 +1022,7 @@ void WTrackTableView::onSearchCleared() {
}
void WTrackTableView::onShow() {
+ restoreVScrollBarPos();
}
void WTrackTableView::mouseMoveEvent(QMouseEvent* pEvent) {