commit 340d747fff92fc98907a0285ce22b6c500276505
Author: Guillaume Munch <[email protected]>
Date: Sat Mar 18 15:08:20 2017 +0100
Clean up
Only keep one dynamic-cast. This fixes coverity warnings.
---
src/frontends/qt4/GuiView.cpp | 1 -
src/frontends/qt4/GuiWorkArea.cpp | 41 +++++++++++++++++++------------------
src/frontends/qt4/GuiWorkArea.h | 22 ++++++++++++++-----
3 files changed, 37 insertions(+), 27 deletions(-)
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index fe2646a..625a424 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -3735,7 +3735,6 @@ void GuiView::dispatch(FuncRequest const & cmd,
DispatchResult & dr)
if (!doc_buffer->isClean()) {
docstring const file =
makeDisplayPath(doc_buffer->absFileName(), 20);
- doc_buffer->notifiesExternalModification();
docstring text =
doc_buffer->notifiesExternalModification() ?
_("Any changes will be lost. "
"Are you sure you want to load the
version on disk "
diff --git a/src/frontends/qt4/GuiWorkArea.cpp
b/src/frontends/qt4/GuiWorkArea.cpp
index 67d9494..b87bb48 100644
--- a/src/frontends/qt4/GuiWorkArea.cpp
+++ b/src/frontends/qt4/GuiWorkArea.cpp
@@ -1683,35 +1683,41 @@ void TabWorkArea::showBar(bool show)
}
-GuiWorkArea * TabWorkArea::currentWorkArea()
+GuiWorkAreaContainer * TabWorkArea::widget(int index) const
{
- if (count() == 0)
- return 0;
-
- GuiWorkAreaContainer * wac =
- dynamic_cast<GuiWorkAreaContainer *>(currentWidget());
+ QWidget * w = QTabWidget::widget(index);
+ if (!w)
+ return nullptr;
+ GuiWorkAreaContainer * wac = dynamic_cast<GuiWorkAreaContainer *>(w);
LATTEST(wac);
- GuiWorkArea * wa = wac->workArea();
- LATTEST(wa);
- return wa;
+ return wac;
+}
+
+
+GuiWorkAreaContainer * TabWorkArea::currentWidget() const
+{
+ return widget(currentIndex());
}
-GuiWorkArea const * TabWorkArea::workArea(int index) const
+GuiWorkArea * TabWorkArea::workArea(int index) const
{
- return (dynamic_cast<GuiWorkAreaContainer
*>(widget(index)))->workArea();
+ GuiWorkAreaContainer * w = widget(index);
+ if (!w)
+ return nullptr;
+ return w->workArea();
}
-GuiWorkArea * TabWorkArea::workArea(int index)
+GuiWorkArea * TabWorkArea::currentWorkArea() const
{
- return (dynamic_cast<GuiWorkAreaContainer
*>(widget(index)))->workArea();
+ return workArea(currentIndex());
}
-GuiWorkArea * TabWorkArea::workArea(Buffer & buffer)
+GuiWorkArea * TabWorkArea::workArea(Buffer & buffer) const
{
- // FIXME: this method doesn't work if we have more than work area
+ // FIXME: this method doesn't work if we have more than one work area
// showing the same buffer.
for (int i = 0; i != count(); ++i) {
GuiWorkArea * wa = workArea(i);
@@ -2220,9 +2226,6 @@ GuiWorkAreaContainer::GuiWorkAreaContainer(GuiWorkArea *
wa, QWidget * parent)
void GuiWorkAreaContainer::updateDisplay()
{
- if (!wa_)
- notificationFrame->hide();
-
Buffer const & buf = wa_->bufferView().buffer();
notificationFrame->setHidden(!buf.notifiesExternalModification());
QString const label = QString("<b>The file \"%1\" changed on disk.</b>")
@@ -2233,8 +2236,6 @@ void GuiWorkAreaContainer::updateDisplay()
void GuiWorkAreaContainer::dispatch(FuncRequest f) const
{
- if (!wa_)
- return;
lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH,
wa_->bufferView().buffer().absFileName()));
lyx::dispatch(f);
diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h
index aa407e1..b22d2a5 100644
--- a/src/frontends/qt4/GuiWorkArea.h
+++ b/src/frontends/qt4/GuiWorkArea.h
@@ -193,6 +193,8 @@ private:
}; // EmbeddedWorkArea
+class GuiWorkAreaContainer;
+
/// A tabbed set of GuiWorkAreas.
class TabWorkArea : public QTabWidget
{
@@ -200,6 +202,10 @@ class TabWorkArea : public QTabWidget
public:
TabWorkArea(QWidget * parent = 0);
+ /// hide QTabWidget methods
+ GuiWorkAreaContainer * currentWidget() const;
+ GuiWorkAreaContainer * widget(int index) const;
+
///
void setFullScreen(bool full_screen);
void showBar(bool show);
@@ -207,10 +213,9 @@ public:
bool setCurrentWorkArea(GuiWorkArea *);
GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
bool removeWorkArea(GuiWorkArea *);
- GuiWorkArea * currentWorkArea();
- GuiWorkArea * workArea(Buffer & buffer);
- GuiWorkArea const * workArea(int index) const;
- GuiWorkArea * workArea(int index);
+ GuiWorkArea * currentWorkArea() const;
+ GuiWorkArea * workArea(Buffer & buffer) const;
+ GuiWorkArea * workArea(int index) const;
void paintEvent(QPaintEvent *);
Q_SIGNALS:
@@ -230,7 +235,7 @@ public Q_SLOTS:
void moveTab(int fromIndex, int toIndex);
///
void updateTabTexts();
-
+
private Q_SLOTS:
///
void on_currentTabChanged(int index);
@@ -245,6 +250,9 @@ private Q_SLOTS:
int indexOfWorkArea(GuiWorkArea * w) const;
private:
+ using QTabWidget::addTab;
+ using QTabWidget::insertTab;
+
/// true if position is a tab (rather than the blank space in tab bar)
bool posIsTab(QPoint position);
@@ -286,6 +294,7 @@ Q_SIGNALS:
class GuiWorkAreaContainer : public QWidget, public Ui::WorkAreaUi
{
Q_OBJECT
+ // non-null
GuiWorkArea * const wa_;
void dispatch(FuncRequest f) const;
@@ -298,8 +307,9 @@ protected:
void mouseDoubleClickEvent(QMouseEvent * event); //override
public:
- ///
+ /// wa != 0
GuiWorkAreaContainer(GuiWorkArea * wa, QWidget * parent = 0);
+ /// non-null
GuiWorkArea * workArea() const { return wa_; }
};