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

List:       kde-commits
Subject:    [kbibtex/kbibtex/0.7] src/program: Statistics widget correctly updated selection changes
From:       Thomas Fischer <fischer () unix-ag ! uni-kl ! de>
Date:       2016-11-19 22:12:24
Message-ID: E1c8Ds0-0001ai-NH () code ! kde ! org
[Download RAW message or body]

Git commit 3aec038b8355a489a9cc18aa24a29c077c447f83 by Thomas Fischer.
Committed on 19/11/2016 at 21:20.
Pushed by thomasfischer into branch 'kbibtex/0.7'.

Statistics widget correctly updated selection changes

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

Forward-porting commit 9534e9c08652 from branch kbibtex/0.6

M  +18   -25   src/program/docklets/statistics.cpp
M  +5    -5    src/program/docklets/statistics.h
M  +2    -5    src/program/mainwindow.cpp

http://commits.kde.org/kbibtex/3aec038b8355a489a9cc18aa24a29c077c447f83

diff --git a/src/program/docklets/statistics.cpp \
b/src/program/docklets/statistics.cpp index 983b6ad..c44108e 100644
--- a/src/program/docklets/statistics.cpp
+++ b/src/program/docklets/statistics.cpp
@@ -26,9 +26,11 @@
 
 #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 +39,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 +83,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 +128,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 @@ -140,10 +147,11 @@ public:
     }
 };
 
-Statistics::Statistics(QWidget *parent)
+Statistics::Statistics(OpenFileInfoManager *ofim, QWidget *parent)
         : QWidget(parent), d(new StatisticsPrivate(this))
 {
-    update();
+    d->update();
+    connect(ofim, SIGNAL(currentChanged(OpenFileInfo*,KService::Ptr)), this, \
SLOT(update()));  }
 
 Statistics::~Statistics()
@@ -151,32 +159,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, SIGNAL(destroyed()), this, \
                SLOT(selectionModelDestroyed()));
-        disconnect(d->selectionModel, \
                SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, \
                SLOT(update()));
-    }
-
-    if (selectionModel != NULL && selectionModel != d->selectionModel) {
-        connect(selectionModel, SIGNAL(destroyed()), this, \
                SLOT(selectionModelDestroyed()));
-        connect(selectionModel, \
                SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, \
                SLOT(update()));
-    }
-
-    d->file = file;
-    d->selectionModel = selectionModel;
-
-    update();
+    if (d->fileView != NULL)
+        disconnect(d->fileView, SIGNAL(selectedElementsChanged()), this, \
SLOT(update())); +    d->fileView = fileView;
+    if (d->fileView != NULL)
+        connect(d->fileView, SIGNAL(selectedElementsChanged()), this, \
SLOT(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 b81af49..aa5e972 100644
--- a/src/program/docklets/statistics.h
+++ b/src/program/docklets/statistics.h
@@ -22,22 +22,22 @@
 
 class QItemSelectionModel;
 
-class Element;
-class File;
+class FileView;
+
+class OpenFileInfoManager;
 
 class Statistics : public QWidget
 {
     Q_OBJECT
 
 public:
-    explicit Statistics(QWidget *parent);
+    explicit Statistics(OpenFileInfoManager *ofim, QWidget *parent);
     ~Statistics();
 
-    void setFile(const File *, const QItemSelectionModel *);
+    void setFileView(FileView *);
 
 private slots:
     void update();
-    void selectionModelDestroyed();
 
 private:
     class StatisticsPrivate;
diff --git a/src/program/mainwindow.cpp b/src/program/mainwindow.cpp
index 446d9a5..0839ece 100644
--- a/src/program/mainwindow.cpp
+++ b/src/program/mainwindow.cpp
@@ -158,7 +158,7 @@ KBibTeXMainWindow::KBibTeXMainWindow()
     d->dockStatistics = new QDockWidget(i18n("Statistics"), this);
     d->dockStatistics->setAllowedAreas(Qt::BottomDockWidgetArea | \
Qt::TopDockWidgetArea | Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);  \
                addDockWidget(Qt::LeftDockWidgetArea, d->dockStatistics);
-    d->statistics = new Statistics(d->dockStatistics);
+    d->statistics = new Statistics(d->mdiWidget->getOpenFileInfoManager(), \
d->dockStatistics);  d->dockStatistics->setWidget(d->statistics);
     d->dockStatistics->setObjectName("dockStatistics");
     d->dockStatistics->setFeatures(QDockWidget::DockWidgetClosable | \
QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); @@ -402,10 +402,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