Skip to content

Commit

Permalink
Improve WidgetInterface API (#9)
Browse files Browse the repository at this point in the history
* started adding base class API for widgetInterface (on mouse events, slice change, etc.)
added basic fix/hack to copy plugins to bundle on osx

* major refactoring:
- added signals and slots to base widget class
- replaced pt_clicked by mouse_clicked (moved/released)
- simplified connection/disconnection of slots in Mainwindow
- added todos
- biggest worry is currently: on_tissuenr_changed -> what is meaning of index passed to callback, how is it used (offset -1 all over the code makes things really confusing)

* use override keyword in widgetinterface derived classes

* more cleanup of WidgetInterface and derived classes

* use git mv to rename files to fix capitalization

* rename some classes, change pointer/reference alignment

* fix several cases where slicenr_change api was not yet updated
instead of calling cleanup for specific widgets, base class now has cleanup API, and Mainwindow calls it in generic block

* renamed folder (and project) Plugin to Interface (iSegInterface respectively)

* rename XAddon.* to XPlugin.*
  • Loading branch information
dyollb authored and sanderegg committed Apr 10, 2018
1 parent bb0a14a commit dc17764
Show file tree
Hide file tree
Showing 117 changed files with 4,257 additions and 5,187 deletions.
9 changes: 6 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AllowShortFunctionsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlignEscapedNewlines: Right
AlignAfterOpenBracket: Align
AlignAfterOpenBracket: DontAlign
AlwaysBreakAfterReturnType: None
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
Expand All @@ -23,7 +23,9 @@ BraceWrapping:
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
BreakBeforeInheritanceComma: false
BreakBeforeInheritanceComma: true
BreakConstructorInitializers: BeforeColon
PointerAlignment: Left
CompactNamespaces: true
Cpp11BracedListStyle: true
FixNamespaceComments: true
Expand All @@ -32,7 +34,7 @@ SortIncludes: true
IndentCaseLabels: false
IndentPPDirectives: AfterHash
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: false
KeepEmptyLinesAtTheStartOfBlocks: true
NamespaceIndentation: None
ReflowComments: false
IndentWidth: 2
Expand All @@ -47,3 +49,4 @@ SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesInAngles: false
MaxEmptyLinesToKeep: 1
ColumnLimit: 0
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ INCLUDE_DIRECTORIES(
)

ADD_SUBDIRECTORY(Thirdparty)
ADD_SUBDIRECTORY(Interface)
ADD_SUBDIRECTORY(Core)
ADD_SUBDIRECTORY(Plugin)
ADD_SUBDIRECTORY(iSeg)
ADD_SUBDIRECTORY(Plugins)

Expand Down
3 changes: 2 additions & 1 deletion Core/BranchItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

#include "iSegCore.h"

#include "Point.h"
#include "Vec3.h"

#include "Interface/Point.h"

#include <list>
#include <sstream>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion Core/Contour.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "iSegCore.h"

#include "Point.h"
#include "Interface/Point.h"

#include <iostream>
#include <vector>
Expand Down
3 changes: 2 additions & 1 deletion Core/FeatureExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include "iSegCore.h"

#include "Pair.h"
#include "Point.h"

#include "Interface/Point.h"

namespace iseg {

Expand Down
3 changes: 2 additions & 1 deletion Core/ImageForestingTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
*/
#pragma once

#include "Interface/Point.h"

#include "Core/IndexPriorityQueue.h"
#include "Core/Point.h"

#include <algorithm>
#include <functional>
Expand Down
2 changes: 2 additions & 0 deletions Core/LoadPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ bool LoadPlugin(const std::string& plugin_file_path)

bool LoadPlugins(const std::string& directory_path)
{
std::cerr << "LoadPlugins: " << directory_path << std::endl;

bool ok = true;
try
{
Expand Down
3 changes: 2 additions & 1 deletion Core/Mark.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

#include "iSegCore.h"

#include "Point.h"
#include "Interface/Point.h"

#include <string>

namespace iseg {
Expand Down
6 changes: 4 additions & 2 deletions Core/Outline.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
*/
#pragma once

#include "iSegCore.h"

#include "Pair.h"
#include "Point.h"
#include "Types.h"
#include "iSegCore.h"

#include "Interface/Point.h"

#include <map>
#include <set>
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions Core/UndoElem.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

#include "iSegCore.h"

#include "DataSelection.h"
#include "Mark.h"
#include "Point.h"
#include "Types.h"

#include "Interface/Point.h"
#include "Interface/DataSelection.h"

#include <vector>

namespace iseg {
Expand Down
1 change: 0 additions & 1 deletion Core/VTIreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,6 @@ bool VTIwriter::writeVolumeAll(const char* filename, float** slicesbmp,
<< endl;
return false;
}
//BL? input->Update();

int info = input->GetPointData()->SetActiveScalars("Source");
for (int k = 0; k < nrslices; k++)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Core/addLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "iSegCore.h"

#include "Point.h"
#include "Interface/Point.h"

#include <vector>

Expand Down
7 changes: 3 additions & 4 deletions Plugin/CMakeLists.txt → Interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ USE_ITK()
SET(SOURCES
Plugin.cpp
Plugin.h
PluginApi.h
InterfaceApi.h
SlicesHandlerInterface.h
WidgetInterface.h
WidgetInterface.cpp
)

QT4_WRAP_CPP(MOCSrcs WidgetInterface.h)
ADD_LIBRARY(Plugin SHARED ${SOURCES} ${MOCSrcs})
TARGET_LINK_LIBRARIES(Plugin ${MY_EXTERNAL_LINK_LIBRARIES} )
VS_SET_PROPERTY(Plugin "Plugins")
ADD_LIBRARY(iSegInterface SHARED ${SOURCES} ${MOCSrcs})
TARGET_LINK_LIBRARIES(iSegInterface ${MY_EXTERNAL_LINK_LIBRARIES} )
File renamed without changes.
8 changes: 4 additions & 4 deletions Plugin/PluginApi.h → Interface/InterfaceApi.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#pragma once

#if defined(WIN32)
# ifdef Plugin_EXPORTS
# define ISEG_PLUGIN_API __declspec(dllexport)
# ifdef iSegInterface_EXPORTS
# define ISEG_INTERFACE_API __declspec(dllexport)
# else
# define ISEG_PLUGIN_API __declspec(dllimport)
# define ISEG_INTERFACE_API __declspec(dllimport)
# endif
#else
# define ISEG_PLUGIN_API
# define ISEG_INTERFACE_API
#endif
File renamed without changes.
11 changes: 6 additions & 5 deletions Plugin/Plugin.h → Interface/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
#pragma once

#include "PluginApi.h"
#include "InterfaceApi.h"

#include "SlicesHandlerInterface.h"
#include "WidgetInterface.h"
Expand All @@ -23,7 +23,7 @@ class SliceHandlerInterface;

namespace iseg { namespace plugin {

class ISEG_PLUGIN_API Plugin
class ISEG_INTERFACE_API Plugin
{
public:
Plugin();
Expand All @@ -36,16 +36,17 @@ class ISEG_PLUGIN_API Plugin

virtual std::string description() const = 0;

virtual WidgetInterface* create_widget(QWidget* parent, const char* name,
Qt::WindowFlags wFlags) const = 0;
virtual WidgetInterface* create_widget(QWidget* parent,
const char* name, Qt::WindowFlags wFlags) const = 0;

private:
SliceHandlerInterface* _slice_handler;
};

class ISEG_PLUGIN_API PluginRegistry
class ISEG_INTERFACE_API PluginRegistry
{
public:
static std::vector<Plugin*> registered_plugins();
};

}} // namespace iseg::plugin
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
#pragma once

#include "PluginApi.h"
#include "InterfaceApi.h"

#include <itkImage.h> // BL TODO get rid of this
#include <itkSliceContiguousImage.h>
Expand All @@ -20,7 +20,7 @@ class SliceHandlerInterface
{
public:
typedef unsigned short tissue_type;
typedef float pixel_type;
typedef float pixel_type;

virtual unsigned short return_startslice() = 0;
virtual unsigned short return_endslice() = 0;
Expand Down
7 changes: 7 additions & 0 deletions Plugin/WidgetInterface.cpp → Interface/WidgetInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@
namespace iseg {

bool WidgetInterface::hideparams = false;

WidgetInterface::WidgetInterface(QWidget* parent, const char* name, Qt::WindowFlags wFlags)
: QWidget(parent, name, wFlags)
{
m_cursor = new QCursor(Qt::CrossCursor);
}

} // namespace iseg
70 changes: 70 additions & 0 deletions Interface/WidgetInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2018 The Foundation for Research on Information Technologies in Society (IT'IS).
*
* This file is part of iSEG
* (see https://github.com/ITISFoundation/osparc-iseg).
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once

#include "InterfaceApi.h"

#include "DataSelection.h"
#include "Point.h"

#include <qcursor.h>
#include <qdir.h>
#include <qicon.h>
#include <qwidget.h>

namespace iseg {

class ISEG_INTERFACE_API WidgetInterface : public QWidget
{
Q_OBJECT
public:
WidgetInterface(QWidget* parent, const char* name, Qt::WindowFlags wFlags);
virtual void init() {}
virtual void newloaded() {}
virtual void cleanup() {}
virtual FILE* SaveParams(FILE* fp, int version) { return fp; };
virtual FILE* LoadParams(FILE* fp, int version) { return fp; };
virtual void hideparams_changed() {}
static void set_hideparams(bool hide) { hideparams = hide; }
static bool get_hideparams() { return hideparams; }
virtual std::string GetName() { return std::string(""); }
virtual QIcon GetIcon(QDir picdir) = 0;

virtual void on_tissuenr_changed(int i) {}
virtual void on_slicenr_changed() {}

virtual void on_mouse_clicked(Point p) {}
virtual void on_mouse_released(Point p) {}
virtual void on_mouse_moved(Point p) {}

QCursor* get_cursor() { return m_cursor; }

signals:
void begin_datachange(iseg::DataSelection& dataSelection,
QWidget* sender = NULL, bool beginUndo = true);
void end_datachange(QWidget* sender = NULL,
iseg::EndUndoAction undoAction = iseg::EndUndo);

private slots:
void tissuenr_changed(int i) { on_tissuenr_changed(i); }
void slicenr_changed() { on_slicenr_changed(); }

// \todo duplicate slots (and connections) and pass argument source_or_target to callbacks
void mouse_clicked(Point p) { on_mouse_clicked(p); }
void mouse_released(Point p) { on_mouse_released(p); }
void mouse_moved(Point p) { on_mouse_moved(p); }

protected:
QCursor* m_cursor;

static bool hideparams;
};

} // namespace iseg
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ IF(ISEG_BUILD_TESTING)
test_iSegImageAdaptor.cpp
)

ADD_LIBRARY(TestSuite_Plugin ${SOURCES} ${HEADERS})
TARGET_LINK_LIBRARIES(TestSuite_Plugin
Plugin
ADD_LIBRARY(TestSuite_iSegInterface ${SOURCES} ${HEADERS})
TARGET_LINK_LIBRARIES(TestSuite_iSegInterface
iSegInterface
${MY_EXTERNAL_LINK_LIBRARIES}
)
VS_SET_PROPERTY(TestSuite_Plugin "TestSuite")
VS_SET_PROPERTY(TestSuite_iSegInterface "TestSuite")
ENDIF()
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#define BOOST_TEST_MODULE Plugin
#define BOOST_TEST_MODULE Interface
#define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp>

#include "../PluginApi.h"
#include "../InterfaceApi.h"
File renamed without changes.
Loading

0 comments on commit dc17764

Please sign in to comment.