[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kbibtex] src/program: Statistics widget correctly updated selection changes
From:       Thomas Fischer <fischer () unix-ag ! uni-kl ! de>
Date:       2016-11-26 21:53:09
Message-ID: E1cAkuD-0006O8-TZ () code ! kde ! org
[Download RAW message or body]

Git commit 8b5a5404f611616c6eea6973981fcc5fc05d9556 by Thomas Fischer.
Committed on 26/11/2016 at 21:37.
Pushed by thomasfischer into branch 'master'.

Statistics widget correctly updated selection changes

Updating the statistics widget correctly on selection changes or when
the current file is changed.

Manually forward-porting commit 9534e9c08652 from branch kbibtex/0.6

M  +17   -25   src/program/docklets/statistics.cpp
M  +2    -6    src/program/docklets/statistics.h
M  +1    -4    src/program/mainwindow.cpp

https://commits.kde.org/kbibtex/8b5a5404f611616c6eea6973981fcc5fc05d9556

diff --git a/src/program/docklets/statistics.cpp \
b/src/program/docklets/statistics.cpp index 12f3a85..74b3e68 100644
--- a/src/program/docklets/statistics.cpp
+++ b/src/program/docklets/statistics.cpp
@@ -24,11 +24,12 @@
 
 #include <KLocalizedString>
 
-#include "element.h"
 #include "file.h"
+#include "fileview.h"
 #include "entry.h"
 #include "macro.h"
 #include "comment.h"
+#include "openfileinfo.h"
 
 class Statistics::StatisticsPrivate
 {
@@ -37,11 +38,12 @@ private:
     QLabel *labelNumberOfElements, *labelNumberOfEntries, \
*labelNumberOfJournalArticles, *labelNumberOfConferencePublications, \
*labelNumberOfBooks, *labelNumberOfOtherEntries, *labelNumberOfComments, \
*labelNumberOfMacros;  
 public:
+    FileView *fileView;
     const File *file;
     const QItemSelectionModel *selectionModel;
 
     StatisticsPrivate(Statistics *parent)
-        : /* UNUSED p(parent),*/ file(NULL), selectionModel(NULL) {
+        : /* UNUSED p(parent),*/ fileView(NULL), file(NULL), selectionModel(NULL) {
         QFormLayout *layout = new QFormLayout(parent);
 
         labelNumberOfElements = new QLabel(parent);
@@ -80,6 +82,9 @@ public:
     }
 
     void update() {
+        file = fileView != NULL && fileView->fileModel() != NULL ? \
fileView->fileModel()->bibliographyFile() : NULL; +        selectionModel = fileView \
!= NULL ? fileView->selectionModel() : NULL; +
         if (file != NULL) {
             int numElements, numEntries, numJournalArticles, \
                numConferencePublications, numBooks, numComments, numMacros;
             countElementTypes(numElements, numEntries, numJournalArticles, \
numConferencePublications, numBooks, numComments, numMacros); @@ -122,6 +127,7 @@ \
public:  
     void countElementTypes(int &numElements, int &numEntries, int \
&numJournalArticles, int &numConferencePublications, int &numBooks, int &numComments, \
                int &numMacros) {
         numElements = numEntries = numJournalArticles = numConferencePublications = \
numBooks = numComments = numMacros = 0; +        Q_ASSERT_X(file != NULL, \
"Statistics::StatisticsPrivate::countElementTypes(..)", "Function was called with \
file==NULL");  
         if (selectionModel != NULL && selectionModel->selectedRows().count() > 1) {
             /// Use selected items for statistics if selection contains at least two \
elements @@ -143,7 +149,8 @@ public:
 Statistics::Statistics(QWidget *parent)
         : QWidget(parent), d(new StatisticsPrivate(this))
 {
-    update();
+    d->update();
+    connect(OpenFileInfoManager::instance(), &OpenFileInfoManager::currentChanged, \
this, &Statistics::update);  }
 
 Statistics::~Statistics()
@@ -151,32 +158,17 @@ Statistics::~Statistics()
     delete d;
 }
 
-void Statistics::setFile(const File *file, const QItemSelectionModel \
*selectionModel) +void Statistics::setFileView(FileView *fileView)
 {
-    /// unregister from update notifications of selection models no longer used
-    if (d->selectionModel != NULL && selectionModel != d->selectionModel) {
-        disconnect(d->selectionModel, &QItemSelectionModel::destroyed, this, \
                &Statistics::selectionModelDestroyed);
-        disconnect(d->selectionModel, &QItemSelectionModel::selectionChanged, this, \
                &Statistics::update);
-    }
-
-    if (selectionModel != NULL && selectionModel != d->selectionModel) {
-        connect(selectionModel, &QItemSelectionModel::destroyed, this, \
                &Statistics::selectionModelDestroyed);
-        connect(selectionModel, &QItemSelectionModel::selectionChanged, this, \
                &Statistics::update);
-    }
-
-    d->file = file;
-    d->selectionModel = selectionModel;
-
-    update();
+    if (d->fileView != NULL)
+        disconnect(d->fileView, &FileView::selectedElementsChanged, this, \
&Statistics::update); +    d->fileView = fileView;
+    if (d->fileView != NULL)
+        connect(d->fileView, &FileView::selectedElementsChanged, this, \
&Statistics::update); +    d->update();
 }
 
 void Statistics::update()
 {
     d->update();
 }
-
-void Statistics::selectionModelDestroyed() {
-    d->file = NULL;
-    d->selectionModel = NULL;
-    update();
-}
diff --git a/src/program/docklets/statistics.h b/src/program/docklets/statistics.h
index 92afa4f..936d6a4 100644
--- a/src/program/docklets/statistics.h
+++ b/src/program/docklets/statistics.h
@@ -22,8 +22,7 @@
 
 class QItemSelectionModel;
 
-class Element;
-class File;
+class FileView;
 
 class Statistics : public QWidget
 {
@@ -33,14 +32,11 @@ public:
     explicit Statistics(QWidget *parent);
     ~Statistics();
 
-    void setFile(const File *, const QItemSelectionModel *);
+    void setFileView(FileView *);
 
 public slots:
     void update();
 
-private slots:
-    void selectionModelDestroyed();
-
 private:
     class StatisticsPrivate;
     StatisticsPrivate *d;
diff --git a/src/program/mainwindow.cpp b/src/program/mainwindow.cpp
index ca13c32..b8301e5 100644
--- a/src/program/mainwindow.cpp
+++ b/src/program/mainwindow.cpp
@@ -417,10 +417,7 @@ void KBibTeXMainWindow::documentSwitched(FileView *oldFileView, \
FileView *newFil  d->documentPreview->setElement(QSharedPointer<Element>(), NULL);
     d->valueList->setFileView(newFileView);
     d->fileSettings->setFileView(newFileView);
-    if (newFileView != NULL && newFileView->fileModel() != NULL)
-        d->statistics->setFile(newFileView->fileModel()->bibliographyFile(), \
                newFileView->selectionModel());
-    else
-        d->statistics->setFile(NULL, NULL);
+    d->statistics->setFileView(newFileView);
     d->referencePreview->setFileView(newFileView);
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic