Skip to content

Commit

Permalink
Some work on using the "new" signal/slot syntax (#1592).
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Apr 3, 2018
1 parent 16ccb42 commit 6452f48
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 240 deletions.
4 changes: 2 additions & 2 deletions src/plugins/miscellaneous/Core/src/busywidget.cpp
Expand Up @@ -68,8 +68,8 @@ BusyWidget::BusyWidget(QWidget *pParent, double pProgress) :

setFps(10);

connect(mTimer, SIGNAL(timeout()),
this, SLOT(rotate()));
connect(mTimer, &QTimer::timeout,
this, &BusyWidget::rotate);

// Make ourselves visible and start our timer, if needed

Expand Down
133 changes: 80 additions & 53 deletions src/plugins/miscellaneous/Core/src/centralwidget.cpp
Expand Up @@ -232,41 +232,41 @@ CentralWidget::CentralWidget(QWidget *pParent) :

FileManager *fileManagerInstance = FileManager::instance();

connect(fileManagerInstance, SIGNAL(fileCreated(const QString &, const QString &)),
this, SLOT(fileCreated(const QString &, const QString &)));
connect(fileManagerInstance, SIGNAL(fileDuplicated(const QString &)),
this, SLOT(fileDuplicated(const QString &)));
connect(fileManagerInstance, &FileManager::fileCreated,
this, &CentralWidget::fileCreated);
connect(fileManagerInstance, &FileManager::fileDuplicated,
this, &CentralWidget::fileDuplicated);

// Some connections to handle changes to a file

connect(fileManagerInstance, SIGNAL(filePermissionsChanged(const QString &)),
this, SLOT(filePermissionsChanged(const QString &)));
connect(fileManagerInstance, SIGNAL(fileModified(const QString &)),
this, SLOT(fileModified(const QString &)));
connect(fileManagerInstance, &FileManager::filePermissionsChanged,
this, &CentralWidget::filePermissionsChanged);
connect(fileManagerInstance, &FileManager::fileModified,
this, &CentralWidget::fileModified);

// Some connections to handle our files tab bar

connect(mFileTabs, SIGNAL(currentChanged(int)),
this, SLOT(updateGui()));
connect(mFileTabs, SIGNAL(tabMoved(int, int)),
this, SLOT(moveFile(int, int)));
connect(mFileTabs, SIGNAL(tabCloseRequested(int)),
this, SLOT(closeFile(int)));
connect(mFileTabs, &TabBarWidget::currentChanged,
this, &CentralWidget::updateGui);
connect(mFileTabs, &TabBarWidget::tabMoved,
this, &CentralWidget::moveFile);
connect(mFileTabs, &TabBarWidget::tabCloseRequested,
this, &CentralWidget::closeFile);

// A connection to handle our modes tab bar

connect(mModeTabs, SIGNAL(currentChanged(int)),
this, SLOT(updateGui()));
connect(mModeTabs, SIGNAL(currentChanged(int)),
this, SLOT(updateFileTabIcons()));
connect(mModeTabs, &TabBarWidget::currentChanged,
this, &CentralWidget::updateGui);
connect(mModeTabs, &TabBarWidget::currentChanged,
this, &CentralWidget::updateFileTabIcons);

// Some connections to handle our mode views tab bar

foreach (CentralWidgetMode *mode, mModes) {
connect(mode->viewTabs(), SIGNAL(currentChanged(int)),
this, SLOT(updateGui()));
connect(mode->viewTabs(), SIGNAL(currentChanged(int)),
this, SLOT(updateFileTabIcons()));
connect(mode->viewTabs(), &TabBarWidget::currentChanged,
this, &CentralWidget::updateGui);
connect(mode->viewTabs(), &TabBarWidget::currentChanged,
this, &CentralWidget::updateFileTabIcons);
}

// Create our remote file dialog
Expand Down Expand Up @@ -298,13 +298,13 @@ CentralWidget::CentralWidget(QWidget *pParent) :

// Some connections to handle our remote file dialog

connect(mRemoteFileDialogUrlValue, SIGNAL(textChanged(const QString &)),
this, SLOT(openRemoteFileChanged()));
connect(mRemoteFileDialogUrlValue, &QLineEdit::textChanged,
this, &CentralWidget::openRemoteFileChanged);

connect(mRemoteFileDialogButtonBox, SIGNAL(accepted()),
this, SLOT(doOpenRemoteFile()));
connect(mRemoteFileDialogButtonBox, SIGNAL(rejected()),
this, SLOT(cancelOpenRemoteFile()));
connect(mRemoteFileDialogButtonBox, &QDialogButtonBox::accepted,
this, &CentralWidget::doOpenRemoteFile);
connect(mRemoteFileDialogButtonBox, &QDialogButtonBox::rejected,
this, &CentralWidget::cancelOpenRemoteFile);
}

//==============================================================================
Expand All @@ -322,7 +322,7 @@ CentralWidget::~CentralWidget()
// been called before to decide what needs to be done with modified
// files...

closeAllFiles(true);
doCloseAllFiles(true);

// Delete our various modes

Expand Down Expand Up @@ -356,24 +356,24 @@ void CentralWidget::loadSettings(QSettings *pSettings)

FileManager *fileManagerInstance = FileManager::instance();

connect(fileManagerInstance, SIGNAL(fileChanged(const QString &, bool, bool)),
this, SLOT(fileChanged(const QString &, bool, bool)));
connect(fileManagerInstance, SIGNAL(fileDeleted(const QString &)),
this, SLOT(fileDeleted(const QString &)));
connect(fileManagerInstance, &FileManager::fileChanged,
this, &CentralWidget::fileChanged);
connect(fileManagerInstance, &FileManager::fileDeleted,
this, &CentralWidget::fileDeleted);

// Some connections to handle an internal change in the state of a file
// Note: we do it here for the same reason as above (see the note for the
// connections to handle an external change in the state of a file)...

connect(fileManagerInstance, SIGNAL(fileModified(const QString &)),
this, SLOT(updateModifiedSettings()));
connect(fileManagerInstance, SIGNAL(fileReloaded(const QString &)),
this, SLOT(fileReloaded(const QString &)));
connect(fileManagerInstance, SIGNAL(fileRenamed(const QString &, const QString &)),
this, SLOT(fileRenamed(const QString &, const QString &)));
connect(fileManagerInstance, &FileManager::fileModified,
this, &CentralWidget::updateModifiedSettings);
connect(fileManagerInstance, &FileManager::fileReloaded,
this, &CentralWidget::fileReloaded);
connect(fileManagerInstance, &FileManager::fileRenamed,
this, &CentralWidget::fileRenamed);

connect(fileManagerInstance, SIGNAL(fileSaved(const QString &)),
this, SLOT(fileSaved(const QString &)));
connect(fileManagerInstance, &FileManager::fileSaved,
this, &CentralWidget::fileSaved);

// Let the user know of a few default things about ourselves by emitting a
// few signals
Expand Down Expand Up @@ -940,7 +940,7 @@ void CentralWidget::openRemoteFile()

//==============================================================================

void CentralWidget::reloadFile(int pIndex, bool pForce)
void CentralWidget::doReloadFile(int pIndex, bool pForce)
{
// Ask our file manager to reload the file, but only if it isn't new and if
// the user wants (in case the file has been modified)
Expand Down Expand Up @@ -1009,6 +1009,15 @@ void CentralWidget::reloadFile(int pIndex, bool pForce)

//==============================================================================

void CentralWidget::reloadFile()
{
// Reload the current file

doReloadFile();
}

//==============================================================================

void CentralWidget::duplicateFile()
{
// Make sure that the file is neither new nor modified
Expand Down Expand Up @@ -1267,7 +1276,7 @@ bool CentralWidget::canCloseFile(int pIndex)

//==============================================================================

bool CentralWidget::closeFile(int pIndex, bool pForceClosing)
bool CentralWidget::doCloseFile(int pIndex, bool pForceClosing)
{
// Make sure that we are not updating the GUI

Expand Down Expand Up @@ -1351,7 +1360,16 @@ bool CentralWidget::closeFile(int pIndex, bool pForceClosing)

//==============================================================================

void CentralWidget::closeAllFiles(bool pForceClosing)
bool CentralWidget::closeFile()
{
// Close the current file

return doCloseFile();
}

//==============================================================================

void CentralWidget::doCloseAllFiles(bool pForceClosing)
{
// Check whether we can close all the files

Expand All @@ -1360,12 +1378,21 @@ void CentralWidget::closeAllFiles(bool pForceClosing)

// Close all the files

while (closeFile(-2, pForceClosing))
while (doCloseFile(-2, pForceClosing))
;
}

//==============================================================================

void CentralWidget::closeAllFiles()
{
// Close all the files

doCloseAllFiles();
}

//==============================================================================

void CentralWidget::moveFile(int pFromIndex, int pToIndex)
{
// Update our list of file names to reflect the fact that a tab has been
Expand Down Expand Up @@ -1614,15 +1641,15 @@ void CentralWidget::setTabBarCurrentIndex(TabBarWidget *pTabBar, int pIndex)
// needed

if (mState == UpdatingGui) {
disconnect(pTabBar, SIGNAL(currentChanged(int)),
this, SLOT(updateGui()));
disconnect(pTabBar, &TabBarWidget::currentChanged,
this, &CentralWidget::updateGui);
}

pTabBar->setCurrentIndex(pIndex);

if (mState == UpdatingGui) {
connect(pTabBar, SIGNAL(currentChanged(int)),
this, SLOT(updateGui()));
connect(pTabBar, &TabBarWidget::currentChanged,
this, &CentralWidget::updateGui);
}
}

Expand Down Expand Up @@ -1789,8 +1816,8 @@ void CentralWidget::updateGui()
ViewWidget *newViewWidget = dynamic_cast<ViewWidget *>(newView);

if (newViewWidget) {
connect(newViewWidget, SIGNAL(updateFileTabIcon(const QString &, const QString &, const QIcon &)),
this, SLOT(updateFileTabIcon(const QString &, const QString &, const QIcon &)),
connect(newViewWidget, &ViewWidget::updateFileTabIcon,
this, &CentralWidget::updateFileTabIcon,
Qt::UniqueConnection);

updateStatusBarWidgets(newViewWidget->statusBarWidgets());
Expand Down Expand Up @@ -1944,7 +1971,7 @@ void CentralWidget::fileChanged(const QString &pFileName, bool pFileChanged,

for (int i = 0, iMax = mFileNames.count(); i < iMax; ++i) {
if (!mFileNames[i].compare(pFileName)) {
reloadFile(i, true);
doReloadFile(i, true);

break;
}
Expand Down Expand Up @@ -1979,7 +2006,7 @@ void CentralWidget::fileDeleted(const QString &pFileName)
if (!mFileNames[i].compare(pFileName)) {
// We have found the file to close

closeFile(i, true);
doCloseFile(i, true);

break;
}
Expand Down
41 changes: 24 additions & 17 deletions src/plugins/miscellaneous/Core/src/centralwidget.h
Expand Up @@ -191,6 +191,11 @@ class CentralWidget : public Widget

void setTabBarCurrentIndex(TabBarWidget *pTabBar, int pIndex);

void doReloadFile(int pIndex = -1, bool pForce = false);

bool doCloseFile(int pIndex = -1, bool pForceClosing = false);
void doCloseAllFiles(bool pForceClosing = false);

signals:
void guiUpdated(OpenCOR::Plugin *pViewPlugin, const QString &pFileName);

Expand All @@ -203,22 +208,34 @@ class CentralWidget : public Widget
void atLeastOneFile(bool pAtLeastOneFile);
void atLeastTwoFiles(bool pAtLeastTwoFiles);

private slots:
void updateGui();

public slots:
void openFile();

void openRemoteFileChanged();
void doOpenRemoteFile();
void cancelOpenRemoteFile();
void openRemoteFile();

void reloadFile(int pIndex = -1, bool pForce = false);
void reloadFile();

void duplicateFile();

void toggleLockedFile();

void saveFile();
void saveFileAs();
void saveAllFiles();

void previousFile();
void nextFile();

bool closeFile();
void closeAllFiles();

private slots:
void updateGui();

void openRemoteFileChanged();
void doOpenRemoteFile();
void cancelOpenRemoteFile();

void fileChanged(const QString &pFileName, bool pFileChanged,
bool pDependenciesChanged);
void fileDeleted(const QString &pFileName);
Expand All @@ -236,16 +253,6 @@ private slots:

void fileSaved(const QString &pFileName);

void saveFile();
void saveFileAs();
void saveAllFiles();

void previousFile();
void nextFile();

bool closeFile(int pIndex = -1, bool pForceClosing = false);
void closeAllFiles(bool pForceClosing = false);

void moveFile(int pFromIndex, int pToIndex);

void updateFileTabIcon(const QString &pViewName, const QString &pFileName,
Expand Down
24 changes: 12 additions & 12 deletions src/plugins/miscellaneous/Core/src/collapsiblewidget.cpp
Expand Up @@ -142,10 +142,10 @@ CollapsibleHeaderWidget::CollapsibleHeaderWidget(bool pCollapsible,
// Connections to toggle our collapsed state

if (pCollapsible) {
connect(mButton, SIGNAL(clicked(bool)),
this, SLOT(toggleCollapsedState()));
connect(mTitle, SIGNAL(doubleClicked()),
this, SLOT(toggleCollapsedState()));
connect(mButton, &QToolButton::clicked,
this, &CollapsibleHeaderWidget::toggleCollapsedState);
connect(mTitle, &CollapsibleHeaderTitleWidget::doubleClicked,
this, &CollapsibleHeaderWidget::toggleCollapsedState);
}
}

Expand Down Expand Up @@ -242,11 +242,11 @@ void CollapsibleHeaderWidget::setMenu(QMenu *pMenu)
mMenuMenu = pMenu;

if (pMenu) {
connect(mMenu, SIGNAL(clicked(bool)),
this, SLOT(showMenu()));
connect(mMenu, &QToolButton::clicked,
this, &CollapsibleHeaderWidget::showMenu);
} else {
disconnect(mMenu, SIGNAL(clicked(bool)),
this, SLOT(showMenu()));
disconnect(mMenu, &QToolButton::clicked,
this, &CollapsibleHeaderWidget::showMenu);
}
}
}
Expand Down Expand Up @@ -399,11 +399,11 @@ CollapsibleHeaderWidget * CollapsibleWidget::addWidget(QWidget *pWidget,
// new collapsible state

if (pCollapsible) {
connect(header, SIGNAL(widgetVisible(bool)),
pWidget, SLOT(setVisible(bool)));
connect(header, &CollapsibleHeaderWidget::widgetVisible,
pWidget, &QWidget::setVisible);

connect(header, SIGNAL(widgetVisible(bool)),
this, SLOT(emitCollapsed()));
connect(header, &CollapsibleHeaderWidget::widgetVisible,
this, &CollapsibleWidget::emitCollapsed);
}

return header;
Expand Down

0 comments on commit 6452f48

Please sign in to comment.