Huge code cleanup.

This patch starts the cleanup that will take a few iterations to finish.
The current profile code uses QStateMachine, and it's much too verbose
for something we can do with less than a third of its lines of code.

I also added on the beginning of the redesign of the profile code for
planner, edit and a few other things that are going to be ported to
the new profile in the future, but not currently - I just lack the time
to make that work for the next release.

This commit basically:
 - moves all 'new' calls to the initializer-list
 - create a new 'setupItem' private method to concentrate the calls
   that any item will do

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-02-07 14:14:36 -02:00 committed by Dirk Hohndel
parent 361f8ede76
commit 6de9b329d1
2 changed files with 28 additions and 63 deletions

View file

@ -36,15 +36,15 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
timeAxis(new TimeAxis()), timeAxis(new TimeAxis()),
depthController(new DiveRectItem()), depthController(new DiveRectItem()),
timeController(new DiveRectItem()), timeController(new DiveRectItem()),
diveProfileItem(NULL), diveProfileItem(new DiveProfileItem()),
cylinderPressureAxis(new DiveCartesianAxis()), cylinderPressureAxis(new DiveCartesianAxis()),
temperatureItem(NULL), temperatureItem(new DiveTemperatureItem()),
gasPressureItem(NULL), gasPressureItem(new DiveGasPressureItem()),
cartesianPlane(new DiveCartesianPlane()), cartesianPlane(new DiveCartesianPlane()),
meanDepth(new MeanDepthLine()), meanDepth(new MeanDepthLine()),
diveComputerText(new DiveTextItem()), diveComputerText(new DiveTextItem()),
diveCeiling(NULL), diveCeiling(new DiveCalculatedCeiling()),
reportedCeiling(NULL) reportedCeiling(new DiveReportedCeiling())
{ {
setScene(new QGraphicsScene()); setScene(new QGraphicsScene());
scene()->setSceneRect(0, 0, 100, 100); scene()->setSceneRect(0, 0, 100, 100);
@ -124,76 +124,26 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
scene()->addItem(item); scene()->addItem(item);
} }
reportedCeiling = new DiveReportedCeiling(); setupItem(reportedCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1);
reportedCeiling->setHorizontalAxis(timeAxis); setupItem(diveCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1);
reportedCeiling->setVerticalAxis(profileYAxis);
reportedCeiling->setModel(dataModel);
reportedCeiling->setVerticalDataColumn(DivePlotDataModel::CEILING);
reportedCeiling->setHorizontalDataColumn(DivePlotDataModel::TIME);
reportedCeiling->setZValue(1);
scene()->addItem(reportedCeiling);
diveCeiling = new DiveCalculatedCeiling();
diveCeiling->setHorizontalAxis(timeAxis);
diveCeiling->setVerticalAxis(profileYAxis);
diveCeiling->setModel(dataModel);
diveCeiling->setVerticalDataColumn(DivePlotDataModel::CEILING);
diveCeiling->setHorizontalDataColumn(DivePlotDataModel::TIME);
diveCeiling->setZValue(1);
scene()->addItem(diveCeiling);
for(int i = 0; i < 16; i++){ for(int i = 0; i < 16; i++){
DiveCalculatedTissue *tissueItem = new DiveCalculatedTissue(); DiveCalculatedTissue *tissueItem = new DiveCalculatedTissue();
tissueItem->setHorizontalAxis(timeAxis); setupItem(tissueItem, timeAxis, profileYAxis, dataModel, DivePlotDataModel::TISSUE_1 + i, DivePlotDataModel::TIME, 1+i);
tissueItem->setVerticalAxis(profileYAxis);
tissueItem->setModel(dataModel);
tissueItem->setVerticalDataColumn(DivePlotDataModel::TISSUE_1 + i);
tissueItem->setHorizontalDataColumn(DivePlotDataModel::TIME);
tissueItem->setZValue(1);
allTissues.append(tissueItem); allTissues.append(tissueItem);
scene()->addItem(tissueItem);
} }
gasPressureItem = new DiveGasPressureItem(); setupItem(gasPressureItem, timeAxis, cylinderPressureAxis, dataModel, DivePlotDataModel::TEMPERATURE, DivePlotDataModel::TIME, 1);
gasPressureItem->setHorizontalAxis(timeAxis); setupItem(temperatureItem, timeAxis, temperatureAxis, dataModel, DivePlotDataModel::TEMPERATURE, DivePlotDataModel::TIME, 1);
gasPressureItem->setVerticalAxis(cylinderPressureAxis); setupItem(diveProfileItem, timeAxis, profileYAxis, dataModel, DivePlotDataModel::DEPTH, DivePlotDataModel::TIME, 0);
gasPressureItem->setModel(dataModel);
gasPressureItem->setVerticalDataColumn(DivePlotDataModel::TEMPERATURE);
gasPressureItem->setHorizontalDataColumn(DivePlotDataModel::TIME);
gasPressureItem->setZValue(1);
scene()->addItem(gasPressureItem);
temperatureItem = new DiveTemperatureItem();
temperatureItem->setHorizontalAxis(timeAxis);
temperatureItem->setVerticalAxis(temperatureAxis);
temperatureItem->setModel(dataModel);
temperatureItem->setVerticalDataColumn(DivePlotDataModel::TEMPERATURE);
temperatureItem->setHorizontalDataColumn(DivePlotDataModel::TIME);
temperatureItem->setZValue(1);
scene()->addItem(temperatureItem);
diveProfileItem = new DiveProfileItem();
diveProfileItem->setHorizontalAxis(timeAxis);
diveProfileItem->setVerticalAxis(profileYAxis);
diveProfileItem->setModel(dataModel);
diveProfileItem->setVerticalDataColumn(DivePlotDataModel::DEPTH);
diveProfileItem->setHorizontalDataColumn(DivePlotDataModel::TIME);
diveProfileItem->setZValue(0);
scene()->addItem(diveProfileItem);
#define CREATE_PP_GAS( ITEM, VERTICAL_COLUMN, COLOR, COLOR_ALERT, THRESHOULD_SETTINGS, VISIBILITY_SETTINGS ) \ #define CREATE_PP_GAS( ITEM, VERTICAL_COLUMN, COLOR, COLOR_ALERT, THRESHOULD_SETTINGS, VISIBILITY_SETTINGS ) \
ITEM = new PartialPressureGasItem(); \ ITEM = new PartialPressureGasItem(); \
ITEM->setHorizontalAxis(timeAxis); \ setupItem(ITEM, timeAxis, gasYAxis, dataModel, DivePlotDataModel::VERTICAL_COLUMN, DivePlotDataModel::TIME, 0); \
ITEM->setVerticalAxis(gasYAxis); \
ITEM->setModel(dataModel); \
ITEM->setVerticalDataColumn(DivePlotDataModel::VERTICAL_COLUMN); \
ITEM->setHorizontalDataColumn(DivePlotDataModel::TIME); \
ITEM->setZValue(0); \
ITEM->setThreshouldSettingsKey(THRESHOULD_SETTINGS); \ ITEM->setThreshouldSettingsKey(THRESHOULD_SETTINGS); \
ITEM->setVisibilitySettingsKey(VISIBILITY_SETTINGS); \ ITEM->setVisibilitySettingsKey(VISIBILITY_SETTINGS); \
ITEM->setColors(getColor(COLOR), getColor(COLOR_ALERT)); \ ITEM->setColors(getColor(COLOR), getColor(COLOR_ALERT)); \
ITEM->preferencesChanged(); \ ITEM->preferencesChanged();
scene()->addItem(ITEM);
CREATE_PP_GAS( pn2GasItem, PN2, PN2, PN2_ALERT, "pn2threshold", "pn2graph"); CREATE_PP_GAS( pn2GasItem, PN2, PN2, PN2_ALERT, "pn2threshold", "pn2graph");
CREATE_PP_GAS( pheGasItem, PHE, PHE, PHE_ALERT, "phethreshold", "phegraph"); CREATE_PP_GAS( pheGasItem, PHE, PHE, PHE_ALERT, "phethreshold", "phegraph");
@ -300,6 +250,17 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
mainWindow()->tabWidget()->addTab(diveDepthTableView, "Depth Model"); mainWindow()->tabWidget()->addTab(diveDepthTableView, "Depth Model");
#endif #endif
} }
void ProfileWidget2::setupItem(AbstractProfilePolygonItem* item, DiveCartesianAxis* hAxis, DiveCartesianAxis* vAxis, DivePlotDataModel* model, int vData, int hData, int zValue)
{
item->setHorizontalAxis(hAxis);
item->setVerticalAxis(vAxis);
item->setModel(model);
item->setVerticalDataColumn(vData);
item->setHorizontalDataColumn(hData);
item->setZValue(zValue);
scene()->addItem(item);
}
// Currently just one dive, but the plan is to enable All of the selected dives. // Currently just one dive, but the plan is to enable All of the selected dives.
void ProfileWidget2::plotDives(QList<dive*> dives) void ProfileWidget2::plotDives(QList<dive*> dives)
@ -310,7 +271,9 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
if (!d) if (!d)
return; return;
if ((*stateMachine->configuration().begin())->objectName() != "Profile State") {
emit startProfileState(); emit startProfileState();
}
// Here we need to probe for the limits of the dive. // Here we need to probe for the limits of the dive.
// There's already a function that does exactly that, // There's already a function that does exactly that,

View file

@ -40,6 +40,7 @@ struct DiveReportedCeiling;
struct DiveCalculatedTissue; struct DiveCalculatedTissue;
struct PartialPressureGasItem; struct PartialPressureGasItem;
struct PartialGasPressureAxis; struct PartialGasPressureAxis;
struct AbstractProfilePolygonItem;
class ProfileWidget2 : public QGraphicsView { class ProfileWidget2 : public QGraphicsView {
Q_OBJECT Q_OBJECT
@ -52,6 +53,7 @@ public:
ProfileWidget2(QWidget *parent); ProfileWidget2(QWidget *parent);
void plotDives(QList<dive*> dives); void plotDives(QList<dive*> dives);
virtual bool eventFilter(QObject*, QEvent*); virtual bool eventFilter(QObject*, QEvent*);
void setupItem( AbstractProfilePolygonItem *item, DiveCartesianAxis *hAxis, DiveCartesianAxis *vAxis, DivePlotDataModel *model, int vData, int hData, int zValue);
public slots: // Necessary to call from QAction's signals. public slots: // Necessary to call from QAction's signals.
void settingsChanged(); void settingsChanged();