[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kbibtex/kbibtex/0.6] src/program: Statistics widget correctly updated selection changes
From: Thomas Fischer <fischer () unix-ag ! uni-kl ! de>
Date: 2016-11-26 21:53:36
Message-ID: E1cAkue-0006dL-Iq () code ! kde ! org
[Download RAW message or body]
Git commit 1e51607166d770350b1ed77b247283cbe0b7a83e by Thomas Fischer.
Committed on 24/11/2016 at 21:04.
Pushed by thomasfischer into branch 'kbibtex/0.6'.
Statistics widget correctly updated selection changes
Updating the statistics widget correctly on selection changes
or when the current file is changed.
M +18 -23 src/program/docklets/statistics.cpp
M +5 -5 src/program/docklets/statistics.h
M +2 -5 src/program/mainwindow.cpp
https://commits.kde.org/kbibtex/1e51607166d770350b1ed77b247283cbe0b7a83e
diff --git a/src/program/docklets/statistics.cpp \
b/src/program/docklets/statistics.cpp index 8d74b30..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,30 +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(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 ded8b54..092b670 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 443abf1..178e8e7 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); @@ -401,10 +401,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