From 1783817b962496de0049e4fd37c849cc36cbe71b Mon Sep 17 00:00:00 2001 From: James Cotton Date: Tue, 13 Sep 2011 00:25:03 -0500 Subject: [PATCH 001/149] INS: First pass at altitude hold code --- flight/INS/ins.c | 2 +- flight/Modules/AltitudeHold/altitudehold.c | 158 ++++++++++++++++++ .../Modules/AltitudeHold/inc/altitudehold.h | 31 ++++ .../Modules/ManualControl/inc/manualcontrol.h | 1 + flight/Modules/ManualControl/manualcontrol.c | 52 +++++- flight/OpenPilot/Makefile | 1 + flight/OpenPilot/UAVObjects.inc | 2 + .../OpenPilotOSX.xcodeproj/project.pbxproj | 41 +++++ .../src/plugins/uavobjects/uavobjects.pro | 4 + .../altitudeholddesired.xml | 13 ++ .../altitudeholdsettings.xml | 12 ++ shared/uavobjectdefinition/flightstatus.xml | 2 +- .../manualcontrolsettings.xml | 2 +- 13 files changed, 317 insertions(+), 4 deletions(-) create mode 100644 flight/Modules/AltitudeHold/altitudehold.c create mode 100644 flight/Modules/AltitudeHold/inc/altitudehold.h create mode 100644 shared/uavobjectdefinition/altitudeholddesired.xml create mode 100644 shared/uavobjectdefinition/altitudeholdsettings.xml diff --git a/flight/INS/ins.c b/flight/INS/ins.c index 7728ea871..f87d84535 100644 --- a/flight/INS/ins.c +++ b/flight/INS/ins.c @@ -260,7 +260,7 @@ int main() time_val2 = PIOS_DELAY_GetRaw(); - print_ekf_binary(true); + //print_ekf_binary(true); switch(ahrs_algorithm) { diff --git a/flight/Modules/AltitudeHold/altitudehold.c b/flight/Modules/AltitudeHold/altitudehold.c new file mode 100644 index 000000000..47eabe72a --- /dev/null +++ b/flight/Modules/AltitudeHold/altitudehold.c @@ -0,0 +1,158 @@ +/** + ****************************************************************************** + * + * @file guidance.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief This module compared @ref PositionActuatl to @ref ActiveWaypoint + * and sets @ref AttitudeDesired. It only does this when the FlightMode field + * of @ref ManualControlCommand is Auto. + * + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/** + * Input object: ActiveWaypoint + * Input object: PositionActual + * Input object: ManualControlCommand + * Output object: AttitudeDesired + * + * This module will periodically update the value of the AttitudeDesired object. + * + * The module executes in its own thread in this example. + * + * Modules have no API, all communication to other modules is done through UAVObjects. + * However modules may use the API exposed by shared libraries. + * See the OpenPilot wiki for more details. + * http://www.openpilot.org/OpenPilot_Application_Architecture + * + */ + +#include "openpilot.h" +#include "altitudeholdsettings.h" +#include "altitudeholddesired.h" // object that will be updated by the module +#include "positionactual.h" +#include "stabilizationdesired.h" + +// Private constants +#define MAX_QUEUE_SIZE 1 +#define STACK_SIZE_BYTES 1024 +#define TASK_PRIORITY (tskIDLE_PRIORITY+2) +// Private types + +// Private variables +static xTaskHandle altitudeHoldTaskHandle; +static xQueueHandle queue; + +// Private functions +static void altitudeHoldTask(void *parameters); + +/** + * Initialise the module, called on startup + * \returns 0 on success or -1 if initialisation failed + */ +int32_t AltitudeHoldStart() +{ + // Start main task + xTaskCreate(altitudeHoldTask, (signed char *)"AltitudeHold", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &altitudeHoldTaskHandle); +// TaskMonitorAdd(TASKINFO_RUNNING_GUIDANCE, guidanceTaskHandle); + + return 0; +} + +/** + * Initialise the module, called on startup + * \returns 0 on success or -1 if initialisation failed + */ +int32_t AltitudeHoldInitialize() +{ + AltitudeHoldSettingsInitialize(); + AltitudeHoldDesiredInitialize(); + + // Create object queue + queue = xQueueCreate(MAX_QUEUE_SIZE, sizeof(UAVObjEvent)); + + // Listen for updates. + AltitudeHoldDesiredConnectQueue(queue); + + return 0; +} +MODULE_INITCALL(AltitudeHoldInitialize, AltitudeHoldStart) + +static float throttleIntegral = 0; + +/** + * Module thread, should not return. + */ +static void altitudeHoldTask(void *parameters) +{ + AltitudeHoldSettingsData altitudeHoldSettings; + AltitudeHoldDesiredData altitudeHoldDesired; + PositionActualData positionActual; + StabilizationDesiredData stabilizationDesired; + + portTickType thisTime; + portTickType lastSysTime; + UAVObjEvent ev; + + // Main task loop + lastSysTime = xTaskGetTickCount(); + while (1) { + + // Wait until the AttitudeRaw object is updated, if a timeout then go to failsafe + if ( xQueueReceive(queue, &ev, 100 / portTICK_RATE_MS) != pdTRUE ) + { + // Todo: Add alarm if it should be running + throttleIntegral = 0; + continue; + } else { + AltitudeHoldDesiredGet(&altitudeHoldDesired); + AltitudeHoldSettingsGet(&altitudeHoldSettings); + PositionActualGet(&positionActual); + StabilizationDesiredGet(&stabilizationDesired); + float dT; + + thisTime = xTaskGetTickCount(); + if(thisTime > lastSysTime) // reuse dt in case of wraparound + dT = (thisTime - lastSysTime) / portTICK_RATE_MS / 1000.0f; + lastSysTime = thisTime; + + // Flipping sign on error since altitude is "down" + float error = - (altitudeHoldDesired.Down - positionActual.Down); + throttleIntegral += error * altitudeHoldSettings.Ki * dT * 1000; + if(throttleIntegral > altitudeHoldSettings.ILimit) + throttleIntegral = altitudeHoldSettings.ILimit; + else if (throttleIntegral < 0) + throttleIntegral = 0; + stabilizationDesired.Throttle = error * altitudeHoldSettings.Kp + throttleIntegral; + if(stabilizationDesired.Throttle > 1) + stabilizationDesired.Throttle = 1; + else if (stabilizationDesired.Throttle < 0) + stabilizationDesired.Throttle = 0; + + stabilizationDesired.StabilizationMode[STABILIZATIONDESIRED_STABILIZATIONMODE_ROLL] = STABILIZATIONDESIRED_STABILIZATIONMODE_ATTITUDE; + stabilizationDesired.StabilizationMode[STABILIZATIONDESIRED_STABILIZATIONMODE_PITCH] = STABILIZATIONDESIRED_STABILIZATIONMODE_ATTITUDE; + stabilizationDesired.StabilizationMode[STABILIZATIONDESIRED_STABILIZATIONMODE_YAW] = STABILIZATIONDESIRED_STABILIZATIONMODE_AXISLOCK; + stabilizationDesired.Roll = altitudeHoldDesired.Roll; + stabilizationDesired.Pitch = altitudeHoldDesired.Pitch; + stabilizationDesired.Yaw = altitudeHoldDesired.Yaw; + StabilizationDesiredSet(&stabilizationDesired); + } + + } +} diff --git a/flight/Modules/AltitudeHold/inc/altitudehold.h b/flight/Modules/AltitudeHold/inc/altitudehold.h new file mode 100644 index 000000000..86ef46b2d --- /dev/null +++ b/flight/Modules/AltitudeHold/inc/altitudehold.h @@ -0,0 +1,31 @@ +/** + ****************************************************************************** + * + * @file examplemodperiodic.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Example module to be used as a template for actual modules. + * + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef EXAMPLEMODPERIODIC_H +#define EXAMPLEMODPERIODIC_H + +int32_t ExampleModPeriodicInitialize(); +int32_t GuidanceInitialize(void); +#endif // EXAMPLEMODPERIODIC_H diff --git a/flight/Modules/ManualControl/inc/manualcontrol.h b/flight/Modules/ManualControl/inc/manualcontrol.h index 1215ca27d..f71cdebde 100644 --- a/flight/Modules/ManualControl/inc/manualcontrol.h +++ b/flight/Modules/ManualControl/inc/manualcontrol.h @@ -39,6 +39,7 @@ typedef enum {FLIGHTMODE_UNDEFINED = 0, FLIGHTMODE_MANUAL = 1, FLIGHTMODE_STABIL (x == FLIGHTSTATUS_FLIGHTMODE_STABILIZED1) ? FLIGHTMODE_STABILIZED : \ (x == FLIGHTSTATUS_FLIGHTMODE_STABILIZED2) ? FLIGHTMODE_STABILIZED : \ (x == FLIGHTSTATUS_FLIGHTMODE_STABILIZED3) ? FLIGHTMODE_STABILIZED : \ + (x == FLIGHTSTATUS_FLIGHTMODE_ALTITUDEHOLD) ? FLIGHTMODE_GUIDANCE : \ (x == FLIGHTSTATUS_FLIGHTMODE_VELOCITYCONTROL) ? FLIGHTMODE_GUIDANCE : \ (x == FLIGHTSTATUS_FLIGHTMODE_POSITIONHOLD) ? FLIGHTMODE_GUIDANCE : FLIGHTMODE_UNDEFINED \ ) diff --git a/flight/Modules/ManualControl/manualcontrol.c b/flight/Modules/ManualControl/manualcontrol.c index e8b18fefb..90ca5a25d 100644 --- a/flight/Modules/ManualControl/manualcontrol.c +++ b/flight/Modules/ManualControl/manualcontrol.c @@ -44,6 +44,8 @@ #include "flightstatus.h" #include "accessorydesired.h" #include "receiveractivity.h" +#include "altitudeholddesired.h" +#include "positionactual.h" // Private constants #if defined(PIOS_MANUAL_STACK_SIZE) @@ -79,6 +81,7 @@ static portTickType lastSysTime; // Private functions static void updateActuatorDesired(ManualControlCommandData * cmd); static void updateStabilizationDesired(ManualControlCommandData * cmd, ManualControlSettingsData * settings); +static void altitudeHoldDesired(ManualControlCommandData * cmd); static void processFlightMode(ManualControlSettingsData * settings, float flightMode); static void processArm(ManualControlCommandData * cmd, ManualControlSettingsData * settings); static void setArmedIfChanged(uint8_t val); @@ -375,7 +378,13 @@ static void manualControlTask(void *parameters) updateStabilizationDesired(&cmd, &settings); break; case FLIGHTMODE_GUIDANCE: - // TODO: Implement + switch(flightStatus.FlightMode) { + case FLIGHTSTATUS_FLIGHTMODE_ALTITUDEHOLD: + altitudeHoldDesired(&cmd); + break; + default: + AlarmsSet(SYSTEMALARMS_ALARM_MANUALCONTROL, SYSTEMALARMS_ALARM_CRITICAL); + } break; } } @@ -588,6 +597,47 @@ static void updateStabilizationDesired(ManualControlCommandData * cmd, ManualCon StabilizationDesiredSet(&stabilization); } +// TODO: Need compile flag to exclude this from copter control +static void altitudeHoldDesired(ManualControlCommandData * cmd) +{ + const float DEADBAND_HIGH = 0.45; + const float DEADBAND_LOW = 0.55; + + static portTickType lastSysTime; + static bool zeroed = false; + portTickType thisSysTime; + float dT; + AltitudeHoldDesiredData altitudeHoldDesired; + AltitudeHoldDesiredGet(&altitudeHoldDesired); + + StabilizationSettingsData stabSettings; + StabilizationSettingsGet(&stabSettings); + + thisSysTime = xTaskGetTickCount(); + if(thisSysTime > lastSysTime) // reuse dt in case of wraparound + dT = (thisSysTime - lastSysTime) / portTICK_RATE_MS / 1000.0f; + lastSysTime = thisSysTime; + + altitudeHoldDesired.Roll = cmd->Roll * stabSettings.RollMax; + altitudeHoldDesired.Pitch = cmd->Pitch * stabSettings.PitchMax; + altitudeHoldDesired.Yaw = cmd->Yaw * stabSettings.ManualRate[STABILIZATIONSETTINGS_MANUALRATE_YAW]; + + float currentDown; + PositionActualDownGet(¤tDown); + if(dT > 1) { + // After not being in this mode for a while init at current height + altitudeHoldDesired.Down = currentDown; + zeroed = false; + } else if (cmd->Throttle > DEADBAND_HIGH && zeroed) + altitudeHoldDesired.Down += (DEADBAND_HIGH - cmd->Throttle) * dT; + else if (cmd->Throttle < DEADBAND_LOW && zeroed) + altitudeHoldDesired.Down += (DEADBAND_LOW - cmd->Throttle) * dT; + else if (cmd->Throttle >= DEADBAND_LOW && cmd->Throttle <= DEADBAND_HIGH) // Require the stick to enter the dead band before they can move height + zeroed = true; + + AltitudeHoldDesiredSet(&altitudeHoldDesired); +} + /** * Convert channel from servo pulse duration (microseconds) to scaled -1/+1 range. */ diff --git a/flight/OpenPilot/Makefile b/flight/OpenPilot/Makefile index 0da393848..8e6704e56 100644 --- a/flight/OpenPilot/Makefile +++ b/flight/OpenPilot/Makefile @@ -61,6 +61,7 @@ MODULES = Actuator Telemetry ManualControl AHRSComms Stabilization FirmwareIAP PYMODULES = FlightPlan #MODULES += Osd/OsdEtStd #MODULES += Guidance +MODULES += AltitudeHold # Paths OPSYSTEM = ./System diff --git a/flight/OpenPilot/UAVObjects.inc b/flight/OpenPilot/UAVObjects.inc index cbe2f79b0..4b45746b4 100644 --- a/flight/OpenPilot/UAVObjects.inc +++ b/flight/OpenPilot/UAVObjects.inc @@ -72,6 +72,8 @@ UAVOBJSRCFILENAMES += hwsettings UAVOBJSRCFILENAMES += receiveractivity UAVOBJSRCFILENAMES += cameradesired UAVOBJSRCFILENAMES += camerastabsettings +UAVOBJSRCFILENAMES += altitudeholdsettings +UAVOBJSRCFILENAMES += altitudeholddesired UAVOBJSRC = $(foreach UAVOBJSRCFILE,$(UAVOBJSRCFILENAMES),$(UAVOBJSYNTHDIR)/$(UAVOBJSRCFILE).c ) UAVOBJDEFINE = $(foreach UAVOBJSRCFILE,$(UAVOBJSRCFILENAMES),-DUAVOBJ_INIT_$(UAVOBJSRCFILE) ) diff --git a/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj b/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj index 16cc8cc6d..f8553b87a 100644 --- a/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj +++ b/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj @@ -279,6 +279,10 @@ 6589A9DB131DEE76006BD67C /* pios_rtc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_rtc.c; sourceTree = ""; }; 6589A9E2131DF1C7006BD67C /* pios_rtc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_rtc.h; sourceTree = ""; }; 659ED317122226B60011010E /* ahrssettings.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = ahrssettings.xml; sourceTree = ""; }; + 65A47983141F123F00AECBDD /* altitudehold.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = altitudehold.c; sourceTree = ""; }; + 65A47985141F123F00AECBDD /* altitudehold.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = altitudehold.h; sourceTree = ""; }; + 65A47987141F146F00AECBDD /* camerastab.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = camerastab.c; sourceTree = ""; }; + 65A47989141F146F00AECBDD /* camerastab.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = camerastab.h; sourceTree = ""; }; 65B35D7F121C261E003EAD18 /* bin.pro */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = bin.pro; sourceTree = ""; }; 65B35D80121C261E003EAD18 /* openpilotgcs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = openpilotgcs; sourceTree = ""; }; 65B35D81121C261E003EAD18 /* openpilotgcs.pri */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = openpilotgcs.pri; sourceTree = ""; }; @@ -3393,8 +3397,10 @@ 650D8E2012DFE16400D05CC9 /* Actuator */, 650D8E2412DFE16400D05CC9 /* AHRSComms */, 650D8E2812DFE16400D05CC9 /* Altitude */, + 65A47982141F123F00AECBDD /* AltitudeHold */, 65C35F6512F0DC2D004811C2 /* Attitude */, 650D8E2E12DFE16400D05CC9 /* Battery */, + 65A47986141F146F00AECBDD /* CameraStab */, 650D8E3212DFE16400D05CC9 /* Example */, 650D8E3B12DFE16400D05CC9 /* FirmwareIAP */, 650D8E3F12DFE16400D05CC9 /* FlightPlan */, @@ -4132,6 +4138,41 @@ path = inc; sourceTree = ""; }; + 65A47982141F123F00AECBDD /* AltitudeHold */ = { + isa = PBXGroup; + children = ( + 65A47983141F123F00AECBDD /* altitudehold.c */, + 65A47984141F123F00AECBDD /* inc */, + ); + name = AltitudeHold; + path = /Users/jcotton81/Documents/Programming/OpenPilot/flight/Modules/AltitudeHold; + sourceTree = ""; + }; + 65A47984141F123F00AECBDD /* inc */ = { + isa = PBXGroup; + children = ( + 65A47985141F123F00AECBDD /* altitudehold.h */, + ); + path = inc; + sourceTree = ""; + }; + 65A47986141F146F00AECBDD /* CameraStab */ = { + isa = PBXGroup; + children = ( + 65A47987141F146F00AECBDD /* camerastab.c */, + 65A47988141F146F00AECBDD /* inc */, + ); + path = CameraStab; + sourceTree = ""; + }; + 65A47988141F146F00AECBDD /* inc */ = { + isa = PBXGroup; + children = ( + 65A47989141F146F00AECBDD /* camerastab.h */, + ); + path = inc; + sourceTree = ""; + }; 65B35D7D121C261E003EAD18 /* ground */ = { isa = PBXGroup; children = ( diff --git a/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro b/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro index fdd57753d..6adc1c903 100644 --- a/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro +++ b/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro @@ -27,6 +27,8 @@ HEADERS += $$UAVOBJECT_SYNTHETICS/accessorydesired.h \ $$UAVOBJECT_SYNTHETICS/insstatus.h \ $$UAVOBJECT_SYNTHETICS/baroaltitude.h \ $$UAVOBJECT_SYNTHETICS/attitudeactual.h \ + $$UAVOBJECT_SYNTHETICS/altitudeholddesired.h \ + $$UAVOBJECT_SYNTHETICS/altitudeholdsettings.h \ $$UAVOBJECT_SYNTHETICS/inssettings.h \ $$UAVOBJECT_SYNTHETICS/gcstelemetrystats.h \ $$UAVOBJECT_SYNTHETICS/attituderaw.h \ @@ -78,6 +80,8 @@ SOURCES += $$UAVOBJECT_SYNTHETICS/accessorydesired.cpp \ $$UAVOBJECT_SYNTHETICS/insstatus.cpp \ $$UAVOBJECT_SYNTHETICS/baroaltitude.cpp \ $$UAVOBJECT_SYNTHETICS/attitudeactual.cpp \ + $$UAVOBJECT_SYNTHETICS/altitudeholddesired.cpp \ + $$UAVOBJECT_SYNTHETICS/altitudeholdsettings.cpp \ $$UAVOBJECT_SYNTHETICS/inssettings.cpp \ $$UAVOBJECT_SYNTHETICS/gcstelemetrystats.cpp \ $$UAVOBJECT_SYNTHETICS/attituderaw.cpp \ diff --git a/shared/uavobjectdefinition/altitudeholddesired.xml b/shared/uavobjectdefinition/altitudeholddesired.xml new file mode 100644 index 000000000..26d674669 --- /dev/null +++ b/shared/uavobjectdefinition/altitudeholddesired.xml @@ -0,0 +1,13 @@ + + + Holds the desired altitude (from manual control) as well as the desired attitude to pass through + + + + + + + + + + diff --git a/shared/uavobjectdefinition/altitudeholdsettings.xml b/shared/uavobjectdefinition/altitudeholdsettings.xml new file mode 100644 index 000000000..93807be4e --- /dev/null +++ b/shared/uavobjectdefinition/altitudeholdsettings.xml @@ -0,0 +1,12 @@ + + + Settings for the @ref AltitudeHold module + + + + + + + + + diff --git a/shared/uavobjectdefinition/flightstatus.xml b/shared/uavobjectdefinition/flightstatus.xml index 849e458d6..995f318ab 100644 --- a/shared/uavobjectdefinition/flightstatus.xml +++ b/shared/uavobjectdefinition/flightstatus.xml @@ -4,7 +4,7 @@ - + diff --git a/shared/uavobjectdefinition/manualcontrolsettings.xml b/shared/uavobjectdefinition/manualcontrolsettings.xml index ae7c9b24c..1ec1edde4 100644 --- a/shared/uavobjectdefinition/manualcontrolsettings.xml +++ b/shared/uavobjectdefinition/manualcontrolsettings.xml @@ -21,7 +21,7 @@ - + From 3b399ad44ce08f1b31d5ad197c123e750cae3962 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Tue, 13 Sep 2011 08:30:50 -0500 Subject: [PATCH 002/149] Increase gyro bias rate again --- flight/INS/insgps13state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flight/INS/insgps13state.c b/flight/INS/insgps13state.c index e2868bbd6..c4ad0a99a 100644 --- a/flight/INS/insgps13state.c +++ b/flight/INS/insgps13state.c @@ -114,7 +114,7 @@ void INSGPSInit() //pretty much just a place holder for now Q[0] = Q[1] = Q[2] = 50e-8; // gyro noise variance (rad/s)^2 Q[3] = Q[4] = Q[5] = 0.01; // accelerometer noise variance (m/s^2)^2 - Q[6] = Q[7] = Q[8] = 2e-15; // gyro bias random walk variance (rad/s^2)^2 + Q[6] = Q[7] = Q[8] = 2e-10; // gyro bias random walk variance (rad/s^2)^2 R[0] = R[1] = 0.004; // High freq GPS horizontal position noise variance (m^2) R[2] = 0.036; // High freq GPS vertical position noise variance (m^2) From 06190d1d95e0af7671664452a40b5fba39abde04 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Tue, 13 Sep 2011 10:34:56 -0500 Subject: [PATCH 003/149] Fix altitude hold dead band range --- flight/Modules/ManualControl/manualcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flight/Modules/ManualControl/manualcontrol.c b/flight/Modules/ManualControl/manualcontrol.c index 90ca5a25d..4eca4ea55 100644 --- a/flight/Modules/ManualControl/manualcontrol.c +++ b/flight/Modules/ManualControl/manualcontrol.c @@ -600,8 +600,8 @@ static void updateStabilizationDesired(ManualControlCommandData * cmd, ManualCon // TODO: Need compile flag to exclude this from copter control static void altitudeHoldDesired(ManualControlCommandData * cmd) { - const float DEADBAND_HIGH = 0.45; - const float DEADBAND_LOW = 0.55; + const float DEADBAND_HIGH = 0.55; + const float DEADBAND_LOW = 0.45; static portTickType lastSysTime; static bool zeroed = false; From 716bb8ec561f1fa9467e1a89623bd95e90bfdd8d Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Thu, 15 Dec 2011 23:49:01 +0100 Subject: [PATCH 004/149] GCS:Scope: Backward Compatibility: Set Interpolation to minimum (1) when not set in config file --- .../openpilotgcs/src/plugins/scope/scopegadgetconfiguration.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.cpp b/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.cpp index 6337be38f..3228497f3 100644 --- a/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.cpp +++ b/ground/openpilotgcs/src/plugins/scope/scopegadgetconfiguration.cpp @@ -66,6 +66,7 @@ ScopeGadgetConfiguration::ScopeGadgetConfiguration(QString classId, QSettings* q plotCurveConf->color = color; plotCurveConf->yScalePower = qSettings->value("yScalePower").toInt(); plotCurveConf->yInterpolationSamples = qSettings->value("yInterpolationSamples").toInt(); + if (!plotCurveConf->yInterpolationSamples) plotCurveConf->yInterpolationSamples = 1; // fallback for backward compatibility with earlier versions plotCurveConf->yMinimum = qSettings->value("yMinimum").toDouble(); plotCurveConf->yMaximum = qSettings->value("yMaximum").toDouble(); From d2ce7761c51fe73d2ddb3253e98756cc2b534e89 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Mon, 2 Jan 2012 17:19:14 -0600 Subject: [PATCH 005/149] Add derivative term --- flight/Modules/AltitudeHold/altitudehold.c | 26 +++++++++++++++++-- flight/Modules/Stabilization/stabilization.c | 2 +- .../altitudeholdsettings.xml | 5 ++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/flight/Modules/AltitudeHold/altitudehold.c b/flight/Modules/AltitudeHold/altitudehold.c index 47eabe72a..9b1ae1798 100644 --- a/flight/Modules/AltitudeHold/altitudehold.c +++ b/flight/Modules/AltitudeHold/altitudehold.c @@ -61,6 +61,7 @@ static xQueueHandle queue; // Private functions static void altitudeHoldTask(void *parameters); +static void SettingsUpdatedCb(UAVObjEvent * ev); /** * Initialise the module, called on startup @@ -90,6 +91,8 @@ int32_t AltitudeHoldInitialize() // Listen for updates. AltitudeHoldDesiredConnectQueue(queue); + AltitudeHoldSettingsConnectCallback(&SettingsUpdatedCb); + return 0; } MODULE_INITCALL(AltitudeHoldInitialize, AltitudeHoldStart) @@ -110,6 +113,9 @@ static void altitudeHoldTask(void *parameters) portTickType lastSysTime; UAVObjEvent ev; + // Force update of the settings + SettingsUpdatedCb(&ev); + // Main task loop lastSysTime = xTaskGetTickCount(); while (1) { @@ -121,8 +127,6 @@ static void altitudeHoldTask(void *parameters) throttleIntegral = 0; continue; } else { - AltitudeHoldDesiredGet(&altitudeHoldDesired); - AltitudeHoldSettingsGet(&altitudeHoldSettings); PositionActualGet(&positionActual); StabilizationDesiredGet(&stabilizationDesired); float dT; @@ -131,9 +135,14 @@ static void altitudeHoldTask(void *parameters) if(thisTime > lastSysTime) // reuse dt in case of wraparound dT = (thisTime - lastSysTime) / portTICK_RATE_MS / 1000.0f; lastSysTime = thisTime; + + static float altitude; + const float altitudeTau = 0.1; + // Flipping sign on error since altitude is "down" float error = - (altitudeHoldDesired.Down - positionActual.Down); + static float throttleIntegral += error * altitudeHoldSettings.Ki * dT * 1000; if(throttleIntegral > altitudeHoldSettings.ILimit) throttleIntegral = altitudeHoldSettings.ILimit; @@ -156,3 +165,16 @@ static void altitudeHoldTask(void *parameters) } } + +static void SettingsUpdatedCb(UAVObjEvent * ev) +{ + AltitudeHoldDesiredGet(&altitudeHoldDesired); + AltitudeHoldSettingsGet(&altitudeHoldSettings); + + const float fakeDt = 0.0025; + if(settings.GyroTau < 0.0001) + gyro_alpha = 0; // not trusting this to resolve to 0 + else + gyro_alpha = expf(-fakeDt / settings.GyroTau); + +} diff --git a/flight/Modules/Stabilization/stabilization.c b/flight/Modules/Stabilization/stabilization.c index 261e02303..b07513c66 100644 --- a/flight/Modules/Stabilization/stabilization.c +++ b/flight/Modules/Stabilization/stabilization.c @@ -466,7 +466,7 @@ static void SettingsUpdatedCb(UAVObjEvent * ev) if(settings.GyroTau < 0.0001) gyro_alpha = 0; // not trusting this to resolve to 0 else - gyro_alpha = exp(-fakeDt / settings.GyroTau); + gyro_alpha = expf(-fakeDt / settings.GyroTau); } diff --git a/shared/uavobjectdefinition/altitudeholdsettings.xml b/shared/uavobjectdefinition/altitudeholdsettings.xml index 93807be4e..42b13e5ab 100644 --- a/shared/uavobjectdefinition/altitudeholdsettings.xml +++ b/shared/uavobjectdefinition/altitudeholdsettings.xml @@ -1,9 +1,10 @@ Settings for the @ref AltitudeHold module - + - + + From dd26e7c80f25989deac19819c8eb5fde071a4339 Mon Sep 17 00:00:00 2001 From: sambas Date: Sun, 8 Jan 2012 12:13:51 +0200 Subject: [PATCH 006/149] qwt 6.0.1 upgrade, sadly doesn't fix QT-4.8.0 scopeplugin in windows. --- ground/openpilotgcs/src/libs/qwt/qwt.pro | 7 +- .../openpilotgcs/src/libs/qwt/qwtconfig.pri | 101 +- ground/openpilotgcs/src/libs/qwt/src/qwt.h | 6 +- .../src/libs/qwt/src/qwt_abstract_scale.cpp | 83 +- .../src/libs/qwt/src/qwt_abstract_scale.h | 34 +- .../libs/qwt/src/qwt_abstract_scale_draw.cpp | 260 +-- .../libs/qwt/src/qwt_abstract_scale_draw.h | 114 +- .../src/libs/qwt/src/qwt_abstract_slider.cpp | 257 +-- .../src/libs/qwt/src/qwt_abstract_slider.h | 185 +-- .../src/libs/qwt/src/qwt_analog_clock.cpp | 117 +- .../src/libs/qwt/src/qwt_analog_clock.h | 38 +- .../src/libs/qwt/src/qwt_arrow_button.cpp | 241 ++- .../src/libs/qwt/src/qwt_arrow_button.h | 22 +- .../src/libs/qwt/src/qwt_clipper.cpp | 748 ++++----- .../src/libs/qwt/src/qwt_clipper.h | 22 +- .../src/libs/qwt/src/qwt_color_map.cpp | 279 ++-- .../src/libs/qwt/src/qwt_color_map.h | 121 +- .../src/libs/qwt/src/qwt_column_symbol.cpp | 296 ++++ .../src/libs/qwt/src/qwt_column_symbol.h | 161 ++ .../src/libs/qwt/src/qwt_compass.cpp | 178 +- .../src/libs/qwt/src/qwt_compass.h | 48 +- .../src/libs/qwt/src/qwt_compass_rose.cpp | 245 ++- .../src/libs/qwt/src/qwt_compass_rose.h | 61 +- .../src/libs/qwt/src/qwt_compat.h | 40 + .../src/libs/qwt/src/qwt_counter.cpp | 439 +++-- .../src/libs/qwt/src/qwt_counter.h | 93 +- .../src/libs/qwt/src/qwt_curve_fitter.cpp | 311 +++- .../src/libs/qwt/src/qwt_curve_fitter.h | 108 +- .../src/libs/qwt/src/qwt_data.cpp | 384 ----- .../openpilotgcs/src/libs/qwt/src/qwt_data.h | 166 -- .../src/libs/qwt/src/qwt_dial.cpp | 865 ++++------ .../openpilotgcs/src/libs/qwt/src/qwt_dial.h | 153 +- .../src/libs/qwt/src/qwt_dial_needle.cpp | 762 ++++----- .../src/libs/qwt/src/qwt_dial_needle.h | 140 +- .../src/libs/qwt/src/qwt_double_interval.h | 284 ---- .../src/libs/qwt/src/qwt_double_range.cpp | 350 ++-- .../src/libs/qwt/src/qwt_double_range.h | 42 +- .../src/libs/qwt/src/qwt_double_rect.cpp | 605 ------- .../src/libs/qwt/src/qwt_double_rect.h | 501 ------ .../src/libs/qwt/src/qwt_dyngrid_layout.cpp | 408 ++--- .../src/libs/qwt/src/qwt_dyngrid_layout.h | 64 +- .../src/libs/qwt/src/qwt_event_pattern.cpp | 162 +- .../src/libs/qwt/src/qwt_event_pattern.h | 82 +- .../src/libs/qwt/src/qwt_global.h | 17 +- ...t_double_interval.cpp => qwt_interval.cpp} | 158 +- .../src/libs/qwt/src/qwt_interval.h | 296 ++++ .../src/libs/qwt/src/qwt_interval_data.cpp | 90 - .../src/libs/qwt/src/qwt_interval_data.h | 90 - .../src/libs/qwt/src/qwt_interval_symbol.cpp | 298 ++++ .../src/libs/qwt/src/qwt_interval_symbol.h | 86 + .../src/libs/qwt/src/qwt_knob.cpp | 594 ++++--- .../openpilotgcs/src/libs/qwt/src/qwt_knob.h | 113 +- .../src/libs/qwt/src/qwt_layout_metrics.cpp | 339 ---- .../src/libs/qwt/src/qwt_layout_metrics.h | 169 -- .../src/libs/qwt/src/qwt_legend.cpp | 487 ++---- .../src/libs/qwt/src/qwt_legend.h | 81 +- .../src/libs/qwt/src/qwt_legend_item.cpp | 643 +++----- .../src/libs/qwt/src/qwt_legend_item.h | 86 +- .../src/libs/qwt/src/qwt_legend_itemmanager.h | 22 +- .../src/libs/qwt/src/qwt_magnifier.cpp | 225 ++- .../src/libs/qwt/src/qwt_magnifier.h | 42 +- .../src/libs/qwt/src/qwt_math.cpp | 26 +- .../openpilotgcs/src/libs/qwt/src/qwt_math.h | 150 +- .../libs/qwt/src/qwt_matrix_raster_data.cpp | 270 +++ .../src/libs/qwt/src/qwt_matrix_raster_data.h | 71 + .../src/libs/qwt/src/qwt_null_paintdevice.cpp | 428 +++++ .../src/libs/qwt/src/qwt_null_paintdevice.h | 89 + .../src/libs/qwt/src/qwt_paint_buffer.cpp | 201 --- .../src/libs/qwt/src/qwt_paint_buffer.h | 65 - .../src/libs/qwt/src/qwt_painter.cpp | 1011 ++++++------ .../src/libs/qwt/src/qwt_painter.h | 196 ++- .../src/libs/qwt/src/qwt_panner.cpp | 341 ++-- .../src/libs/qwt/src/qwt_panner.h | 61 +- .../src/libs/qwt/src/qwt_picker.cpp | 933 ++++++----- .../src/libs/qwt/src/qwt_picker.h | 363 ++-- .../src/libs/qwt/src/qwt_picker_machine.cpp | 229 ++- .../src/libs/qwt/src/qwt_picker_machine.h | 117 +- .../src/libs/qwt/src/qwt_plot.cpp | 503 +++--- .../openpilotgcs/src/libs/qwt/src/qwt_plot.h | 240 ++- .../src/libs/qwt/src/qwt_plot_axis.cpp | 307 ++-- .../src/libs/qwt/src/qwt_plot_canvas.cpp | 1119 ++++++++++--- .../src/libs/qwt/src/qwt_plot_canvas.h | 127 +- .../src/libs/qwt/src/qwt_plot_curve.cpp | 1463 +++++++---------- .../src/libs/qwt/src/qwt_plot_curve.h | 378 ++--- .../src/libs/qwt/src/qwt_plot_dict.cpp | 125 +- .../src/libs/qwt/src/qwt_plot_dict.h | 25 +- .../libs/qwt/src/qwt_plot_directpainter.cpp | 313 ++++ .../src/libs/qwt/src/qwt_plot_directpainter.h | 100 ++ .../src/libs/qwt/src/qwt_plot_grid.cpp | 211 +-- .../src/libs/qwt/src/qwt_plot_grid.h | 34 +- .../src/libs/qwt/src/qwt_plot_histogram.cpp | 648 ++++++++ .../src/libs/qwt/src/qwt_plot_histogram.h | 134 ++ .../libs/qwt/src/qwt_plot_intervalcurve.cpp | 547 ++++++ .../src/libs/qwt/src/qwt_plot_intervalcurve.h | 130 ++ .../src/libs/qwt/src/qwt_plot_item.cpp | 380 ++--- .../src/libs/qwt/src/qwt_plot_item.h | 111 +- .../src/libs/qwt/src/qwt_plot_layout.cpp | 662 ++++---- .../src/libs/qwt/src/qwt_plot_layout.h | 89 +- .../src/libs/qwt/src/qwt_plot_magnifier.cpp | 57 +- .../src/libs/qwt/src/qwt_plot_magnifier.h | 10 +- .../src/libs/qwt/src/qwt_plot_marker.cpp | 432 +++-- .../src/libs/qwt/src/qwt_plot_marker.h | 79 +- .../src/libs/qwt/src/qwt_plot_panner.cpp | 78 +- .../src/libs/qwt/src/qwt_plot_panner.h | 23 +- .../src/libs/qwt/src/qwt_plot_picker.cpp | 247 ++- .../src/libs/qwt/src/qwt_plot_picker.h | 58 +- .../src/libs/qwt/src/qwt_plot_print.cpp | 530 ------ .../src/libs/qwt/src/qwt_plot_printfilter.cpp | 590 ------- .../src/libs/qwt/src/qwt_plot_printfilter.h | 83 - .../src/libs/qwt/src/qwt_plot_rasteritem.cpp | 790 +++++++-- .../src/libs/qwt/src/qwt_plot_rasteritem.h | 91 +- .../src/libs/qwt/src/qwt_plot_renderer.cpp | 833 ++++++++++ .../src/libs/qwt/src/qwt_plot_renderer.h | 154 ++ .../src/libs/qwt/src/qwt_plot_rescaler.cpp | 293 ++-- .../src/libs/qwt/src/qwt_plot_rescaler.h | 104 +- .../src/libs/qwt/src/qwt_plot_scaleitem.cpp | 227 ++- .../src/libs/qwt/src/qwt_plot_scaleitem.h | 47 +- .../src/libs/qwt/src/qwt_plot_seriesitem.cpp | 90 + .../src/libs/qwt/src/qwt_plot_seriesitem.h | 203 +++ .../libs/qwt/src/qwt_plot_spectrocurve.cpp | 300 ++++ .../src/libs/qwt/src/qwt_plot_spectrocurve.h | 76 + .../src/libs/qwt/src/qwt_plot_spectrogram.cpp | 586 +++---- .../src/libs/qwt/src/qwt_plot_spectrogram.h | 84 +- .../src/libs/qwt/src/qwt_plot_svgitem.cpp | 182 +- .../src/libs/qwt/src/qwt_plot_svgitem.h | 33 +- .../src/libs/qwt/src/qwt_plot_xml.cpp | 24 +- .../src/libs/qwt/src/qwt_plot_zoomer.cpp | 343 ++-- .../src/libs/qwt/src/qwt_plot_zoomer.h | 98 +- .../qwt/src/{qwt_array.h => qwt_point_3d.cpp} | 27 +- .../src/libs/qwt/src/qwt_point_3d.h | 189 +++ .../src/libs/qwt/src/qwt_point_polar.cpp | 114 ++ .../src/libs/qwt/src/qwt_point_polar.h | 195 +++ .../src/libs/qwt/src/qwt_polygon.h | 35 - .../src/libs/qwt/src/qwt_raster_data.cpp | 273 ++- .../src/libs/qwt/src/qwt_raster_data.h | 106 +- .../src/libs/qwt/src/qwt_round_scale_draw.cpp | 217 ++- .../src/libs/qwt/src/qwt_round_scale_draw.h | 35 +- .../src/libs/qwt/src/qwt_sampling_thread.cpp | 106 ++ .../src/libs/qwt/src/qwt_sampling_thread.h | 50 + .../src/libs/qwt/src/qwt_scale_div.cpp | 68 +- .../src/libs/qwt/src/qwt_scale_div.h | 78 +- .../src/libs/qwt/src/qwt_scale_draw.cpp | 663 ++++---- .../src/libs/qwt/src/qwt_scale_draw.h | 92 +- .../src/libs/qwt/src/qwt_scale_engine.cpp | 658 ++++---- .../src/libs/qwt/src/qwt_scale_engine.h | 163 +- .../src/libs/qwt/src/qwt_scale_map.cpp | 280 +++- .../src/libs/qwt/src/qwt_scale_map.h | 134 +- .../src/libs/qwt/src/qwt_scale_widget.cpp | 679 ++++---- .../src/libs/qwt/src/qwt_scale_widget.h | 105 +- .../src/libs/qwt/src/qwt_series_data.cpp | 586 +++++++ .../src/libs/qwt/src/qwt_series_data.h | 442 +++++ .../src/libs/qwt/src/qwt_slider.cpp | 886 +++++----- .../src/libs/qwt/src/qwt_slider.h | 118 +- .../src/libs/qwt/src/qwt_spline.cpp | 259 ++- .../src/libs/qwt/src/qwt_spline.h | 69 +- .../src/libs/qwt/src/qwt_symbol.cpp | 1064 +++++++++--- .../src/libs/qwt/src/qwt_symbol.h | 170 +- .../src/libs/qwt/src/qwt_system_clock.cpp | 364 ++++ .../src/libs/qwt/src/qwt_system_clock.h | 49 + .../src/libs/qwt/src/qwt_text.cpp | 402 ++--- .../openpilotgcs/src/libs/qwt/src/qwt_text.h | 170 +- .../src/libs/qwt/src/qwt_text_engine.cpp | 286 ++-- .../src/libs/qwt/src/qwt_text_engine.h | 90 +- .../src/libs/qwt/src/qwt_text_label.cpp | 115 +- .../src/libs/qwt/src/qwt_text_label.h | 31 +- .../src/libs/qwt/src/qwt_thermo.cpp | 1125 +++++++------ .../src/libs/qwt/src/qwt_thermo.h | 126 +- .../src/libs/qwt/src/qwt_valuelist.h | 57 - .../src/libs/qwt/src/qwt_wheel.cpp | 718 ++++---- .../openpilotgcs/src/libs/qwt/src/qwt_wheel.h | 65 +- ground/openpilotgcs/src/libs/qwt/src/src.pro | 90 +- .../src/plugins/scope/scopegadget.h | 3 +- .../src/plugins/scope/scopegadgetwidget.cpp | 21 +- .../src/plugins/scope/scopegadgetwidget.h | 2 +- 174 files changed, 23966 insertions(+), 19970 deletions(-) create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_column_symbol.cpp create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_column_symbol.h create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_compat.h delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_data.cpp delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_data.h delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_double_interval.h delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_double_rect.cpp delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_double_rect.h rename ground/openpilotgcs/src/libs/qwt/src/{qwt_double_interval.cpp => qwt_interval.cpp} (57%) create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_interval.h delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_interval_data.cpp delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_interval_data.h create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_interval_symbol.cpp create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_interval_symbol.h delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_layout_metrics.cpp delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_layout_metrics.h create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_matrix_raster_data.cpp create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_matrix_raster_data.h create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_null_paintdevice.cpp create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_null_paintdevice.h delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_paint_buffer.cpp delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_paint_buffer.h create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_plot_directpainter.cpp create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_plot_directpainter.h create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_plot_histogram.cpp create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_plot_histogram.h create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_plot_intervalcurve.cpp create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_plot_intervalcurve.h delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_plot_print.cpp delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_plot_printfilter.cpp delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_plot_printfilter.h create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_plot_renderer.cpp create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_plot_renderer.h create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_plot_seriesitem.cpp create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_plot_seriesitem.h create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_plot_spectrocurve.cpp create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_plot_spectrocurve.h rename ground/openpilotgcs/src/libs/qwt/src/{qwt_array.h => qwt_point_3d.cpp} (58%) create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_point_3d.h create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_point_polar.cpp create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_point_polar.h delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_polygon.h create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_sampling_thread.cpp create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_sampling_thread.h create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_series_data.cpp create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_series_data.h create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_system_clock.cpp create mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_system_clock.h delete mode 100644 ground/openpilotgcs/src/libs/qwt/src/qwt_valuelist.h diff --git a/ground/openpilotgcs/src/libs/qwt/qwt.pro b/ground/openpilotgcs/src/libs/qwt/qwt.pro index 1a542872d..7d056a921 100644 --- a/ground/openpilotgcs/src/libs/qwt/qwt.pro +++ b/ground/openpilotgcs/src/libs/qwt/qwt.pro @@ -1,15 +1,14 @@ -# -*- mode: sh -*- ########################### +################################################################ # Qwt Widget Library # Copyright (C) 1997 Josef Wilgen # Copyright (C) 2002 Uwe Rathmann # # This library is free software; you can redistribute it and/or # modify it under the terms of the Qwt License, Version 1.0 -############################################## +################################################################ include( qwtconfig.pri ) TEMPLATE = subdirs -SUBDIRS = src \ - +SUBDIRS = src diff --git a/ground/openpilotgcs/src/libs/qwt/qwtconfig.pri b/ground/openpilotgcs/src/libs/qwt/qwtconfig.pri index 82754c682..b9d7538ed 100644 --- a/ground/openpilotgcs/src/libs/qwt/qwtconfig.pri +++ b/ground/openpilotgcs/src/libs/qwt/qwtconfig.pri @@ -1,41 +1,96 @@ +################################################################ +# Qwt Widget Library +# Copyright (C) 1997 Josef Wilgen +# Copyright (C) 2002 Uwe Rathmann +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the Qwt License, Version 1.0 +################################################################ + +#QWT_VER_MAJ = 6 +#QWT_VER_MIN = 0 +#QWT_VER_PAT = 1 +#QWT_VERSION = $${QWT_VER_MAJ}.$${QWT_VER_MIN}.$${QWT_VER_PAT} + ###################################################################### # Install paths ###################################################################### -#VER_MAJ = 5 -#VER_MIN = 2 -#VER_PAT = 0 -#VERSION = $${VER_MAJ}.$${VER_MIN}.$${VER_PAT} +#QWT_INSTALL_PREFIX = $$[QT_INSTALL_PREFIX] + +unix { + QWT_INSTALL_PREFIX = /usr/local/qwt-$$QWT_VERSION +} + +win32 { + #QWT_INSTALL_PREFIX = C:/Qwt-$$QWT_VERSION +} + +#QWT_INSTALL_DOCS = $${QWT_INSTALL_PREFIX}/doc +#QWT_INSTALL_HEADERS = $${QWT_INSTALL_PREFIX}/include +#QWT_INSTALL_LIBS = $${QWT_INSTALL_PREFIX}/lib ###################################################################### -# qmake internal options +# Designer plugin ###################################################################### -CONFIG += qt # Also for Qtopia Core! -CONFIG += warn_on -CONFIG += thread +#QWT_INSTALL_PLUGINS = $${QWT_INSTALL_PREFIX}/plugins/designer +# QWT_INSTALL_PLUGINS = $${QT_INSTALL_PREFIX}/plugins/designer ###################################################################### -# release/debug mode -# If you want to build both DEBUG_SUFFIX and RELEASE_SUFFIX -# have to differ to avoid, that they overwrite each other. +# Features +# When building a Qwt application with qmake you might want to load +# the compiler/linker flags, that are required to build a Qwt application +# from qwt.prf. Therefore all you need to do is to add "CONFIG += qwt" +# to your project file and take care, that qwt.prf can be found by qmake. +# ( see http://doc.trolltech.com/4.7/qmake-advanced-usage.html#adding-new-configuration-features ) +# I recommend not to install the Qwt features together with the +# Qt features, because you will have to reinstall the Qwt features, +# with every Qt upgrade. ###################################################################### -VVERSION = $$[QT_VERSION] +#QWT_INSTALL_FEATURES = $${QWT_INSTALL_PREFIX}/features +# QWT_INSTALL_FEATURES = $${QT_INSTALL_PREFIX}/features + +###################################################################### +# Build the static/shared libraries. +# If QwtDll is enabled, a shared library is built, otherwise +# it will be a static library. +###################################################################### + +QWT_CONFIG += QwtDll ###################################################################### # QwtPlot enables all classes, that are needed to use the QwtPlot # widget. ###################################################################### -CONFIG += QwtPlot +QWT_CONFIG += QwtPlot ###################################################################### # QwtWidgets enables all classes, that are needed to use the all other # widgets (sliders, dials, ...), beside QwtPlot. ###################################################################### -CONFIG += QwtWidgets +QWT_CONFIG += QwtWidgets + +###################################################################### +# If you want to display svg images on the plot canvas, or +# export a plot to a SVG document +###################################################################### + +QWT_CONFIG += QwtSvg + +###################################################################### +# You can use the MathML renderer of the Qt solutions package to +# enable MathML support in Qwt. Because of license implications +# the ( modified ) code of the MML Widget solution is included and +# linked together with the QwtMathMLTextEngine into an own library. +# To use it you will have to add "CONFIG += qwtmathml" +# to your qmake project file. +###################################################################### + +QWT_CONFIG += QwtMathML ###################################################################### # If you want to build the Qwt designer plugin, @@ -43,5 +98,21 @@ CONFIG += QwtWidgets # Otherwise you have to build it from the designer directory. ###################################################################### -#CONFIG += QwtDesigner +#QWT_CONFIG += QwtDesigner +###################################################################### +# If you want to auto build the examples, enable the line below +# Otherwise you have to build them from the examples directory. +###################################################################### + +# QWT_CONFIG += QwtExamples + +###################################################################### +# When Qt has been built as framework qmake ( qtAddLibrary ) wants +# to link frameworks instead of regular libs +###################################################################### + +macx:CONFIG(qt_framework, qt_framework|qt_no_framework) { + + QWT_CONFIG += QwtFramework +} diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt.h b/ground/openpilotgcs/src/libs/qwt/src/qwt.h index 394bbb2bf..5aab34dfc 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -15,8 +15,8 @@ /*! Some constants for use within Qwt. */ -namespace Qwt +namespace Qwt { -} +}; #endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale.cpp index 14af7fe07..485d8b56b 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale.cpp @@ -2,26 +2,26 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ +#include "qwt_abstract_scale.h" #include "qwt_scale_engine.h" #include "qwt_scale_draw.h" #include "qwt_scale_div.h" #include "qwt_scale_map.h" -#include "qwt_double_interval.h" -#include "qwt_abstract_scale.h" +#include "qwt_interval.h" class QwtAbstractScale::PrivateData { public: PrivateData(): - maxMajor(5), - maxMinor(3), - stepSize(0.0), - autoScale(true) + maxMajor( 5 ), + maxMinor( 3 ), + stepSize( 0.0 ), + autoScale( true ) { scaleEngine = new QwtLinearScaleEngine; scaleDraw = new QwtScaleDraw(); @@ -46,14 +46,14 @@ public: /*! Constructor - Creates a default QwtScaleDraw and a QwtLinearScaleEngine. + Creates a default QwtScaleDraw and a QwtLinearScaleEngine. Autoscaling is enabled, and the stepSize is initialized by 0.0. */ - + QwtAbstractScale::QwtAbstractScale() { d_data = new PrivateData; - rescale(0.0, 100.0); + rescale( 0.0, 100.0 ); } //! Destructor @@ -72,12 +72,12 @@ QwtAbstractScale::~QwtAbstractScale() \param stepSize major step size \sa setAutoScale() */ -void QwtAbstractScale::setScale(double vmin, double vmax, double stepSize) +void QwtAbstractScale::setScale( double vmin, double vmax, double stepSize ) { d_data->autoScale = false; d_data->stepSize = stepSize; - rescale(vmin, vmax, stepSize); + rescale( vmin, vmax, stepSize ); } /*! @@ -89,10 +89,9 @@ void QwtAbstractScale::setScale(double vmin, double vmax, double stepSize) \param stepSize major step size \sa setAutoScale() */ -void QwtAbstractScale::setScale(const QwtDoubleInterval &interval, - double stepSize) +void QwtAbstractScale::setScale( const QwtInterval &interval, double stepSize ) { - setScale(interval.minValue(), interval.maxValue(), stepSize); + setScale( interval.minValue(), interval.maxValue(), stepSize ); } @@ -104,13 +103,13 @@ void QwtAbstractScale::setScale(const QwtDoubleInterval &interval, \param scaleDiv Scale division \sa setAutoScale() */ -void QwtAbstractScale::setScale(const QwtScaleDiv &scaleDiv) +void QwtAbstractScale::setScale( const QwtScaleDiv &scaleDiv ) { d_data->autoScale = false; - if (scaleDiv != d_data->scaleDraw->scaleDiv()) + if ( scaleDiv != d_data->scaleDraw->scaleDiv() ) { - d_data->scaleDraw->setScaleDiv(scaleDiv); + d_data->scaleDraw->setScaleDiv( scaleDiv ); scaleChange(); } } @@ -124,16 +123,16 @@ void QwtAbstractScale::setScale(const QwtScaleDiv &scaleDiv) \sa scaleChange() */ -void QwtAbstractScale::rescale(double vmin, double vmax, double stepSize) +void QwtAbstractScale::rescale( double vmin, double vmax, double stepSize ) { const QwtScaleDiv scaleDiv = d_data->scaleEngine->divideScale( - vmin, vmax, d_data->maxMajor, d_data->maxMinor, stepSize); + vmin, vmax, d_data->maxMajor, d_data->maxMinor, stepSize ); if ( scaleDiv != d_data->scaleDraw->scaleDiv() ) { d_data->scaleDraw->setTransformation( - d_data->scaleEngine->transformation()); - d_data->scaleDraw->setScaleDiv(scaleDiv); + d_data->scaleEngine->transformation() ); + d_data->scaleDraw->setScaleDiv( scaleDiv ); scaleChange(); } } @@ -141,12 +140,12 @@ void QwtAbstractScale::rescale(double vmin, double vmax, double stepSize) /*! \brief Advise the widget to control the scale range internally. - Autoscaling is on by default. + Autoscaling is on by default. \sa setScale(), autoScale() */ void QwtAbstractScale::setAutoScale() { - if (!d_data->autoScale) + if ( !d_data->autoScale ) { d_data->autoScale = true; scaleChange(); @@ -155,7 +154,7 @@ void QwtAbstractScale::setAutoScale() /*! \return \c true if autoscaling is enabled -*/ +*/ bool QwtAbstractScale::autoScale() const { return d_data->autoScale; @@ -170,9 +169,9 @@ bool QwtAbstractScale::autoScale() const \param ticks maximal number of major ticks. \sa QwtAbstractScaleDraw */ -void QwtAbstractScale::setScaleMaxMajor(int ticks) +void QwtAbstractScale::setScaleMaxMajor( int ticks ) { - if (ticks != d_data->maxMajor) + if ( ticks != d_data->maxMajor ) { d_data->maxMajor = ticks; updateScaleDraw(); @@ -188,29 +187,29 @@ void QwtAbstractScale::setScaleMaxMajor(int ticks) \param ticks \sa QwtAbstractScaleDraw */ -void QwtAbstractScale::setScaleMaxMinor(int ticks) +void QwtAbstractScale::setScaleMaxMinor( int ticks ) { - if ( ticks != d_data->maxMinor) + if ( ticks != d_data->maxMinor ) { d_data->maxMinor = ticks; updateScaleDraw(); } } -/*! - \return Max. number of minor tick intervals +/*! + \return Max. number of minor tick intervals The default value is 3. */ -int QwtAbstractScale::scaleMaxMinor() const +int QwtAbstractScale::scaleMaxMinor() const { return d_data->maxMinor; } -/*! - \return Max. number of major tick intervals +/*! + \return Max. number of major tick intervals The default value is 5. */ -int QwtAbstractScale::scaleMaxMajor() const +int QwtAbstractScale::scaleMaxMajor() const { return d_data->maxMajor; } @@ -221,23 +220,23 @@ int QwtAbstractScale::scaleMaxMajor() const scaleDraw has to be created with new and will be deleted in ~QwtAbstractScale or the next call of setAbstractScaleDraw. */ -void QwtAbstractScale::setAbstractScaleDraw(QwtAbstractScaleDraw *scaleDraw) +void QwtAbstractScale::setAbstractScaleDraw( QwtAbstractScaleDraw *scaleDraw ) { if ( scaleDraw == NULL || scaleDraw == d_data->scaleDraw ) return; if ( d_data->scaleDraw != NULL ) - scaleDraw->setScaleDiv(d_data->scaleDraw->scaleDiv()); + scaleDraw->setScaleDiv( d_data->scaleDraw->scaleDiv() ); delete d_data->scaleDraw; d_data->scaleDraw = scaleDraw; -} +} /*! \return Scale draw \sa setAbstractScaleDraw() */ -QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw() +QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw() { return d_data->scaleDraw; } @@ -253,8 +252,8 @@ const QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw() const void QwtAbstractScale::updateScaleDraw() { - rescale( d_data->scaleDraw->scaleDiv().lowerBound(), - d_data->scaleDraw->scaleDiv().upperBound(), d_data->stepSize); + rescale( d_data->scaleDraw->scaleDiv().lowerBound(), + d_data->scaleDraw->scaleDiv().upperBound(), d_data->stepSize ); } /*! @@ -266,7 +265,7 @@ void QwtAbstractScale::updateScaleDraw() scaleEngine has to be created with new and will be deleted in ~QwtAbstractScale or the next call of setScaleEngine. */ -void QwtAbstractScale::setScaleEngine(QwtScaleEngine *scaleEngine) +void QwtAbstractScale::setScaleEngine( QwtScaleEngine *scaleEngine ) { if ( scaleEngine != NULL && scaleEngine != d_data->scaleEngine ) { diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale.h index c28f4e56a..7896f61c0 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -16,13 +16,13 @@ class QwtScaleEngine; class QwtAbstractScaleDraw; class QwtScaleDiv; class QwtScaleMap; -class QwtDoubleInterval; +class QwtInterval; /*! - \brief An abstract base class for classes containing a scale + \brief An abstract base class for classes containing a scale - QwtAbstractScale is used to provide classes with a QwtScaleDraw, - and a QwtScaleDiv. The QwtScaleDiv might be set explicitely + QwtAbstractScale is used to provide classes with a QwtScaleDraw, + and a QwtScaleDiv. The QwtScaleDiv might be set explicitely or calculated by a QwtScaleEngine. */ @@ -31,30 +31,30 @@ class QWT_EXPORT QwtAbstractScale public: QwtAbstractScale(); virtual ~QwtAbstractScale(); - - void setScale(double vmin, double vmax, double step = 0.0); - void setScale(const QwtDoubleInterval &, double step = 0.0); - void setScale(const QwtScaleDiv &s); + + void setScale( double vmin, double vmax, double step = 0.0 ); + void setScale( const QwtInterval &, double step = 0.0 ); + void setScale( const QwtScaleDiv & ); void setAutoScale(); bool autoScale() const; - void setScaleMaxMajor( int ticks); + void setScaleMaxMajor( int ticks ); int scaleMaxMinor() const; - void setScaleMaxMinor( int ticks); - int scaleMaxMajor() const; + void setScaleMaxMinor( int ticks ); + int scaleMaxMajor() const; - void setScaleEngine(QwtScaleEngine *); + void setScaleEngine( QwtScaleEngine * ); const QwtScaleEngine *scaleEngine() const; QwtScaleEngine *scaleEngine(); const QwtScaleMap &scaleMap() const; - -protected: - void rescale(double vmin, double vmax, double step = 0.0); - void setAbstractScaleDraw(QwtAbstractScaleDraw *); +protected: + void rescale( double vmin, double vmax, double step = 0.0 ); + + void setAbstractScaleDraw( QwtAbstractScaleDraw * ); const QwtAbstractScaleDraw *abstractScaleDraw() const; QwtAbstractScaleDraw *abstractScaleDraw(); diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale_draw.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale_draw.cpp index 3e7b462fc..7de0051b4 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale_draw.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale_draw.cpp @@ -2,45 +2,48 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - -#include -#include -#include -#include +#include "qwt_abstract_scale_draw.h" #include "qwt_math.h" #include "qwt_text.h" #include "qwt_painter.h" #include "qwt_scale_map.h" -#include "qwt_scale_draw.h" +#include +#include +#include +#include class QwtAbstractScaleDraw::PrivateData { public: PrivateData(): - components(Backbone | Ticks | Labels), - spacing(4), - minExtent(0) + spacing( 4.0 ), + penWidth( 0 ), + minExtent( 0.0 ) { - tickLength[QwtScaleDiv::MinorTick] = 4; - tickLength[QwtScaleDiv::MediumTick] = 6; - tickLength[QwtScaleDiv::MajorTick] = 8; + components = QwtAbstractScaleDraw::Backbone + | QwtAbstractScaleDraw::Ticks + | QwtAbstractScaleDraw::Labels; + + tickLength[QwtScaleDiv::MinorTick] = 4.0; + tickLength[QwtScaleDiv::MediumTick] = 6.0; + tickLength[QwtScaleDiv::MajorTick] = 8.0; } - int components; - + ScaleComponents components; + QwtScaleMap map; QwtScaleDiv scldiv; - - int spacing; - int tickLength[QwtScaleDiv::NTickTypes]; - int minExtent; + double spacing; + double tickLength[QwtScaleDiv::NTickTypes]; + int penWidth; + + double minExtent; QMap labelCache; }; @@ -57,25 +60,13 @@ QwtAbstractScaleDraw::QwtAbstractScaleDraw() d_data = new QwtAbstractScaleDraw::PrivateData; } -//! Copy constructor -QwtAbstractScaleDraw::QwtAbstractScaleDraw(const QwtAbstractScaleDraw &other) -{ - d_data = new QwtAbstractScaleDraw::PrivateData(*other.d_data); -} - //! Destructor QwtAbstractScaleDraw::~QwtAbstractScaleDraw() { delete d_data; } -//! Assignment operator -QwtAbstractScaleDraw &QwtAbstractScaleDraw::operator=(const QwtAbstractScaleDraw &other) -{ - *d_data = *other.d_data; - return *this; -} -/*! +/*! En/Disable a component of the scale \param component Scale component @@ -84,7 +75,7 @@ QwtAbstractScaleDraw &QwtAbstractScaleDraw::operator=(const QwtAbstractScaleDraw \sa hasComponent() */ void QwtAbstractScaleDraw::enableComponent( - ScaleComponent component, bool enable) + ScaleComponent component, bool enable ) { if ( enable ) d_data->components |= component; @@ -92,23 +83,23 @@ void QwtAbstractScaleDraw::enableComponent( d_data->components &= ~component; } -/*! - Check if a component is enabled +/*! + Check if a component is enabled \sa enableComponent() */ -bool QwtAbstractScaleDraw::hasComponent(ScaleComponent component) const +bool QwtAbstractScaleDraw::hasComponent( ScaleComponent component ) const { - return (d_data->components & component); + return ( d_data->components & component ); } /*! Change the scale division \param sd New scale division */ -void QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &sd) +void QwtAbstractScaleDraw::setScaleDiv( const QwtScaleDiv &sd ) { d_data->scldiv = sd; - d_data->map.setScaleInterval(sd.lowerBound(), sd.upperBound()); + d_data->map.setScaleInterval( sd.lowerBound(), sd.upperBound() ); d_data->labelCache.clear(); } @@ -117,121 +108,129 @@ void QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &sd) \param transformation New scale transformation */ void QwtAbstractScaleDraw::setTransformation( - QwtScaleTransformation *transformation) + QwtScaleTransformation *transformation ) { - d_data->map.setTransformation(transformation); + d_data->map.setTransformation( transformation ); } //! \return Map how to translate between scale and pixel values -const QwtScaleMap &QwtAbstractScaleDraw::map() const +const QwtScaleMap &QwtAbstractScaleDraw::scaleMap() const { return d_data->map; } //! \return Map how to translate between scale and pixel values -QwtScaleMap &QwtAbstractScaleDraw::scaleMap() +QwtScaleMap &QwtAbstractScaleDraw::scaleMap() { return d_data->map; } -//! \return scale division -const QwtScaleDiv& QwtAbstractScaleDraw::scaleDiv() const -{ - return d_data->scldiv; +//! \return scale division +const QwtScaleDiv& QwtAbstractScaleDraw::scaleDiv() const +{ + return d_data->scldiv; } -#if QT_VERSION < 0x040000 /*! - \brief Draw the scale - - \param painter The painter - - \param colorGroup Color group, text color is used for the labels, - foreground color for ticks and backbone + \brief Specify the width of the scale pen + \param width Pen width + \sa penWidth() */ -void QwtAbstractScaleDraw::draw(QPainter *painter, - const QColorGroup& colorGroup) const +void QwtAbstractScaleDraw::setPenWidth( int width ) +{ + if ( width < 0 ) + width = 0; -#else + if ( width != d_data->penWidth ) + d_data->penWidth = width; +} + +/*! + \return Scale pen width + \sa setPenWidth() +*/ +int QwtAbstractScaleDraw::penWidth() const +{ + return d_data->penWidth; +} /*! \brief Draw the scale \param painter The painter - \param palette Palette, text color is used for the labels, + \param palette Palette, text color is used for the labels, foreground color for ticks and backbone */ -void QwtAbstractScaleDraw::draw(QPainter *painter, - const QPalette& palette) const -#endif +void QwtAbstractScaleDraw::draw( QPainter *painter, + const QPalette& palette ) const { - if ( hasComponent(QwtAbstractScaleDraw::Labels) ) + painter->save(); + + QPen pen = painter->pen(); + pen.setWidth( d_data->penWidth ); + pen.setCosmetic( false ); + painter->setPen( pen ); + + if ( hasComponent( QwtAbstractScaleDraw::Labels ) ) { painter->save(); + painter->setPen( palette.color( QPalette::Text ) ); // ignore pen style -#if QT_VERSION < 0x040000 - painter->setPen(colorGroup.text()); // ignore pen style -#else - painter->setPen(palette.color(QPalette::Text)); // ignore pen style -#endif + const QList &majorTicks = + d_data->scldiv.ticks( QwtScaleDiv::MajorTick ); - const QwtValueList &majorTicks = - d_data->scldiv.ticks(QwtScaleDiv::MajorTick); - - for (int i = 0; i < (int)majorTicks.count(); i++) + for ( int i = 0; i < majorTicks.count(); i++ ) { const double v = majorTicks[i]; - if ( d_data->scldiv.contains(v) ) - drawLabel(painter, majorTicks[i]); + if ( d_data->scldiv.contains( v ) ) + drawLabel( painter, majorTicks[i] ); } painter->restore(); } - if ( hasComponent(QwtAbstractScaleDraw::Ticks) ) + if ( hasComponent( QwtAbstractScaleDraw::Ticks ) ) { painter->save(); QPen pen = painter->pen(); -#if QT_VERSION < 0x040000 - pen.setColor(colorGroup.foreground()); -#else - pen.setColor(palette.color(QPalette::Foreground)); -#endif - painter->setPen(pen); + pen.setColor( palette.color( QPalette::WindowText ) ); + pen.setCapStyle( Qt::FlatCap ); - for ( int tickType = QwtScaleDiv::MinorTick; + painter->setPen( pen ); + + for ( int tickType = QwtScaleDiv::MinorTick; tickType < QwtScaleDiv::NTickTypes; tickType++ ) { - const QwtValueList &ticks = d_data->scldiv.ticks(tickType); - for (int i = 0; i < (int)ticks.count(); i++) + const QList &ticks = d_data->scldiv.ticks( tickType ); + for ( int i = 0; i < ticks.count(); i++ ) { const double v = ticks[i]; - if ( d_data->scldiv.contains(v) ) - drawTick(painter, v, d_data->tickLength[tickType]); + if ( d_data->scldiv.contains( v ) ) + drawTick( painter, v, d_data->tickLength[tickType] ); } } painter->restore(); } - if ( hasComponent(QwtAbstractScaleDraw::Backbone) ) + if ( hasComponent( QwtAbstractScaleDraw::Backbone ) ) { painter->save(); QPen pen = painter->pen(); -#if QT_VERSION < 0x040000 - pen.setColor(colorGroup.foreground()); -#else - pen.setColor(palette.color(QPalette::Foreground)); -#endif - painter->setPen(pen); + pen.setColor( palette.color( QPalette::WindowText ) ); + pen.setCapStyle( Qt::FlatCap ); - drawBackbone(painter); + painter->setPen( pen ); + + drawBackbone( painter ); painter->restore(); } + + painter->restore(); } /*! @@ -244,7 +243,7 @@ void QwtAbstractScaleDraw::draw(QPainter *painter, \sa spacing() */ -void QwtAbstractScaleDraw::setSpacing(int spacing) +void QwtAbstractScaleDraw::setSpacing( double spacing ) { if ( spacing < 0 ) spacing = 0; @@ -260,7 +259,7 @@ void QwtAbstractScaleDraw::setSpacing(int spacing) \sa setSpacing() */ -int QwtAbstractScaleDraw::spacing() const +double QwtAbstractScaleDraw::spacing() const { return d_data->spacing; } @@ -278,10 +277,10 @@ int QwtAbstractScaleDraw::spacing() const \sa extent(), minimumExtent() */ -void QwtAbstractScaleDraw::setMinimumExtent(int minExtent) +void QwtAbstractScaleDraw::setMinimumExtent( double minExtent ) { - if ( minExtent < 0 ) - minExtent = 0; + if ( minExtent < 0.0 ) + minExtent = 0.0; d_data->minExtent = minExtent; } @@ -290,34 +289,34 @@ void QwtAbstractScaleDraw::setMinimumExtent(int minExtent) Get the minimum extent \sa extent(), setMinimumExtent() */ -int QwtAbstractScaleDraw::minimumExtent() const +double QwtAbstractScaleDraw::minimumExtent() const { return d_data->minExtent; } /*! Set the length of the ticks - + \param tickType Tick type \param length New length \warning the length is limited to [0..1000] */ void QwtAbstractScaleDraw::setTickLength( - QwtScaleDiv::TickType tickType, int length) + QwtScaleDiv::TickType tickType, double length ) { - if ( tickType < QwtScaleDiv::MinorTick || + if ( tickType < QwtScaleDiv::MinorTick || tickType > QwtScaleDiv::MajorTick ) { return; } - if ( length < 0 ) - length = 0; + if ( length < 0.0 ) + length = 0.0; - const int maxTickLen = 1000; + const double maxTickLen = 1000.0; if ( length > maxTickLen ) - length = 1000; + length = maxTickLen; d_data->tickLength[tickType] = length; } @@ -325,11 +324,11 @@ void QwtAbstractScaleDraw::setTickLength( /*! Return the length of the ticks - \sa setTickLength(), majTickLength() + \sa setTickLength(), maxTickLength() */ -int QwtAbstractScaleDraw::tickLength(QwtScaleDiv::TickType tickType) const +double QwtAbstractScaleDraw::tickLength( QwtScaleDiv::TickType tickType ) const { - if ( tickType < QwtScaleDiv::MinorTick || + if ( tickType < QwtScaleDiv::MinorTick || tickType > QwtScaleDiv::MajorTick ) { return 0; @@ -339,17 +338,24 @@ int QwtAbstractScaleDraw::tickLength(QwtScaleDiv::TickType tickType) const } /*! - The same as QwtAbstractScaleDraw::tickLength(QwtScaleDiv::MajorTick). + \return Length of the longest tick + + Useful for layout calculations + \sa tickLength(), setTickLength() */ -int QwtAbstractScaleDraw::majTickLength() const +double QwtAbstractScaleDraw::maxTickLength() const { - return d_data->tickLength[QwtScaleDiv::MajorTick]; + double length = 0.0; + for ( int i = 0; i < QwtScaleDiv::NTickTypes; i++ ) + length = qMax( length, d_data->tickLength[i] ); + + return length; } /*! - \brief Convert a value into its representing label + \brief Convert a value into its representing label - The value is converted to a plain text using + The value is converted to a plain text using QLocale::system().toString(value). This method is often overloaded by applications to have individual labels. @@ -357,9 +363,9 @@ int QwtAbstractScaleDraw::majTickLength() const \param value Value \return Label string. */ -QwtText QwtAbstractScaleDraw::label(double value) const +QwtText QwtAbstractScaleDraw::label( double value ) const { - return QLocale::system().toString(value); + return QLocale().toString( value ); } /*! @@ -368,7 +374,7 @@ QwtText QwtAbstractScaleDraw::label(double value) const The conversion between value and label is called very often in the layout and painting code. Unfortunately the calculation of the label sizes might be slow (really slow - for rich text in Qt4), so it's necessary to cache the labels. + for rich text in Qt4), so it's necessary to cache the labels. \param font Font \param value Value @@ -376,21 +382,21 @@ QwtText QwtAbstractScaleDraw::label(double value) const \return Tick label */ const QwtText &QwtAbstractScaleDraw::tickLabel( - const QFont &font, double value) const + const QFont &font, double value ) const { - QMap::const_iterator it = d_data->labelCache.find(value); + QMap::const_iterator it = d_data->labelCache.find( value ); if ( it == d_data->labelCache.end() ) { - QwtText lbl = label(value); - lbl.setRenderFlags(0); - lbl.setLayoutAttribute(QwtText::MinimumLayout); + QwtText lbl = label( value ); + lbl.setRenderFlags( 0 ); + lbl.setLayoutAttribute( QwtText::MinimumLayout ); - (void)lbl.textSize(font); // initialize the internal cache + ( void )lbl.textSize( font ); // initialize the internal cache - it = d_data->labelCache.insert(value, lbl); + it = d_data->labelCache.insert( value, lbl ); } - return (*it); + return ( *it ); } /*! @@ -398,7 +404,7 @@ const QwtText &QwtAbstractScaleDraw::tickLabel( The cache is invalidated, when a new QwtScaleDiv is set. If the labels need to be changed. while the same QwtScaleDiv is set, - QwtAbstractScaleDraw::invalidateCache needs to be called manually. + invalidateCache() needs to be called manually. */ void QwtAbstractScaleDraw::invalidateCache() { diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale_draw.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale_draw.h index cadea0040..bd5150470 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale_draw.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_scale_draw.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -14,12 +14,7 @@ #include "qwt_scale_div.h" #include "qwt_text.h" - -#if QT_VERSION < 0x040000 -class QColorGroup; -#else class QPalette; -#endif class QPainter; class QFont; class QwtScaleTransformation; @@ -38,80 +33,77 @@ class QWT_EXPORT QwtAbstractScaleDraw { public: - /*! - Components of a scale - - - Backbone - - Ticks - - Labels - - \sa enableComponent(), hasComponent + /*! + Components of a scale + \sa enableComponent(), hasComponent */ - enum ScaleComponent - { - Backbone = 1, - Ticks = 2, - Labels = 4 + { + //! Backbone = the line where the ticks are located + Backbone = 0x01, + + //! Ticks + Ticks = 0x02, + + //! Labels + Labels = 0x04 }; - + + //! Scale components + typedef QFlags ScaleComponents; + QwtAbstractScaleDraw(); - QwtAbstractScaleDraw( const QwtAbstractScaleDraw & ); virtual ~QwtAbstractScaleDraw(); - QwtAbstractScaleDraw &operator=(const QwtAbstractScaleDraw &); - - void setScaleDiv(const QwtScaleDiv &s); + void setScaleDiv( const QwtScaleDiv &s ); const QwtScaleDiv& scaleDiv() const; - void setTransformation(QwtScaleTransformation *); - const QwtScaleMap &map() const; + void setTransformation( QwtScaleTransformation * ); + const QwtScaleMap &scaleMap() const; + QwtScaleMap &scaleMap(); - void enableComponent(ScaleComponent, bool enable = true); - bool hasComponent(ScaleComponent) const; + void enableComponent( ScaleComponent, bool enable = true ); + bool hasComponent( ScaleComponent ) const; - void setTickLength(QwtScaleDiv::TickType, int length); - int tickLength(QwtScaleDiv::TickType) const; - int majTickLength() const; + void setTickLength( QwtScaleDiv::TickType, double length ); + double tickLength( QwtScaleDiv::TickType ) const; + double maxTickLength() const; - void setSpacing(int margin); - int spacing() const; - -#if QT_VERSION < 0x040000 - virtual void draw(QPainter *, const QColorGroup &) const; -#else - virtual void draw(QPainter *, const QPalette &) const; -#endif + void setSpacing( double margin ); + double spacing() const; - virtual QwtText label(double) const; + void setPenWidth( int width ); + int penWidth() const; - /*! - Calculate the extent + virtual void draw( QPainter *, const QPalette & ) const; + + virtual QwtText label( double ) const; + + /*! + Calculate the extent The extent is the distcance from the baseline to the outermost pixel of the scale draw in opposite to its orientation. It is at least minimumExtent() pixels. - + \sa setMinimumExtent(), minimumExtent() */ - virtual int extent(const QPen &, const QFont &) const = 0; + virtual double extent( const QFont & ) const = 0; - void setMinimumExtent(int); - int minimumExtent() const; - - QwtScaleMap &scaleMap(); + void setMinimumExtent( double ); + double minimumExtent() const; protected: /*! Draw a tick - + \param painter Painter \param value Value of the tick \param len Lenght of the tick \sa drawBackbone(), drawLabel() - */ - virtual void drawTick(QPainter *painter, double value, int len) const = 0; + */ + virtual void drawTick( QPainter *painter, double value, double len ) const = 0; /*! Draws the baseline of the scale @@ -119,27 +111,29 @@ protected: \sa drawTick(), drawLabel() */ - virtual void drawBackbone(QPainter *painter) const = 0; + virtual void drawBackbone( QPainter *painter ) const = 0; - /*! + /*! Draws the label for a major scale tick - + \param painter Painter \param value Value - \sa drawTick, drawBackbone - */ - virtual void drawLabel(QPainter *painter, double value) const = 0; + \sa drawTick(), drawBackbone() + */ + virtual void drawLabel( QPainter *painter, double value ) const = 0; void invalidateCache(); - const QwtText &tickLabel(const QFont &, double value) const; + const QwtText &tickLabel( const QFont &, double value ) const; private: - int operator==(const QwtAbstractScaleDraw &) const; - int operator!=(const QwtAbstractScaleDraw &) const; + QwtAbstractScaleDraw( const QwtAbstractScaleDraw & ); + QwtAbstractScaleDraw &operator=( const QwtAbstractScaleDraw & ); class PrivateData; PrivateData *d_data; }; +Q_DECLARE_OPERATORS_FOR_FLAGS( QwtAbstractScaleDraw::ScaleComponents ) + #endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_slider.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_slider.cpp index 3e8f17eb8..b0c127d9e 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_slider.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_slider.cpp @@ -2,35 +2,36 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -#include -#include #include "qwt_abstract_slider.h" #include "qwt_math.h" +#include +#include -#ifndef WHEEL_DELTA -#define WHEEL_DELTA 120 +#if QT_VERSION < 0x040601 +#define qFabs(x) ::fabs(x) +#define qExp(x) ::exp(x) #endif class QwtAbstractSlider::PrivateData { public: PrivateData(): - scrollMode(ScrNone), - mouseOffset(0.0), - tracking(true), - tmrID(0), - updTime(150), - mass(0.0), - readOnly(false) + scrollMode( QwtAbstractSlider::ScrNone ), + mouseOffset( 0.0 ), + tracking( true ), + tmrID( 0 ), + updTime( 150 ), + mass( 0.0 ), + readOnly( false ) { } - int scrollMode; + QwtAbstractSlider::ScrollMode scrollMode; double mouseOffset; int direction; int tracking; @@ -45,30 +46,27 @@ public: bool readOnly; }; -/*! +/*! \brief Constructor \param orientation Orientation \param parent Parent widget */ QwtAbstractSlider::QwtAbstractSlider( - Qt::Orientation orientation, QWidget *parent): - QWidget(parent, NULL) + Qt::Orientation orientation, QWidget *parent ): + QWidget( parent, NULL ) { d_data = new QwtAbstractSlider::PrivateData; d_data->orientation = orientation; -#if QT_VERSION >= 0x040000 - using namespace Qt; -#endif - setFocusPolicy(TabFocus); + setFocusPolicy( Qt::TabFocus ); } //! Destructor QwtAbstractSlider::~QwtAbstractSlider() { - if(d_data->tmrID) - killTimer(d_data->tmrID); + if ( d_data->tmrID ) + killTimer( d_data->tmrID ); delete d_data; } @@ -82,7 +80,7 @@ QwtAbstractSlider::~QwtAbstractSlider() \param readOnly Enables in case of true \sa isReadOnly() */ -void QwtAbstractSlider::setReadOnly(bool readOnly) +void QwtAbstractSlider::setReadOnly( bool readOnly ) { d_data->readOnly = readOnly; update(); @@ -105,12 +103,12 @@ bool QwtAbstractSlider::isReadOnly() const \param o Orientation. Allowed values are Qt::Horizontal and Qt::Vertical. */ -void QwtAbstractSlider::setOrientation(Qt::Orientation o) +void QwtAbstractSlider::setOrientation( Qt::Orientation o ) { d_data->orientation = o; } -/*! +/*! \return Orientation \sa setOrientation() */ @@ -121,11 +119,11 @@ Qt::Orientation QwtAbstractSlider::orientation() const //! Stop updating if automatic scrolling is active -void QwtAbstractSlider::stopMoving() +void QwtAbstractSlider::stopMoving() { - if(d_data->tmrID) + if ( d_data->tmrID ) { - killTimer(d_data->tmrID); + killTimer( d_data->tmrID ); d_data->tmrID = 0; } } @@ -135,19 +133,19 @@ void QwtAbstractSlider::stopMoving() \param t update interval in milliseconds \sa getScrollMode() */ -void QwtAbstractSlider::setUpdateTime(int t) +void QwtAbstractSlider::setUpdateTime( int t ) { - if (t < 50) + if ( t < 50 ) t = 50; d_data->updTime = t; } -/*! +/*! Mouse press event handler \param e Mouse event */ -void QwtAbstractSlider::mousePressEvent(QMouseEvent *e) +void QwtAbstractSlider::mousePressEvent( QMouseEvent *e ) { if ( isReadOnly() ) { @@ -161,24 +159,24 @@ void QwtAbstractSlider::mousePressEvent(QMouseEvent *e) d_data->timerTick = 0; - getScrollMode(p, d_data->scrollMode, d_data->direction); + getScrollMode( p, d_data->scrollMode, d_data->direction ); stopMoving(); - - switch(d_data->scrollMode) + + switch ( d_data->scrollMode ) { case ScrPage: case ScrTimer: d_data->mouseOffset = 0; - d_data->tmrID = startTimer(qwtMax(250, 2 * d_data->updTime)); + d_data->tmrID = startTimer( qMax( 250, 2 * d_data->updTime ) ); break; - + case ScrMouse: d_data->time.start(); d_data->speed = 0; - d_data->mouseOffset = getValue(p) - value(); - emit sliderPressed(); + d_data->mouseOffset = getValue( p ) - value(); + Q_EMIT sliderPressed(); break; - + default: d_data->mouseOffset = 0; d_data->direction = 0; @@ -190,16 +188,16 @@ void QwtAbstractSlider::mousePressEvent(QMouseEvent *e) //! Emits a valueChanged() signal if necessary void QwtAbstractSlider::buttonReleased() { - if ((!d_data->tracking) || (value() != prevValue())) - emit valueChanged(value()); + if ( ( !d_data->tracking ) || ( value() != prevValue() ) ) + Q_EMIT valueChanged( value() ); } -/*! +/*! Mouse Release Event handler \param e Mouse event */ -void QwtAbstractSlider::mouseReleaseEvent(QMouseEvent *e) +void QwtAbstractSlider::mouseReleaseEvent( QMouseEvent *e ) { if ( isReadOnly() ) { @@ -210,33 +208,33 @@ void QwtAbstractSlider::mouseReleaseEvent(QMouseEvent *e) return; const double inc = step(); - - switch(d_data->scrollMode) + + switch ( d_data->scrollMode ) { case ScrMouse: { - setPosition(e->pos()); + setPosition( e->pos() ); d_data->direction = 0; d_data->mouseOffset = 0; - if (d_data->mass > 0.0) + if ( d_data->mass > 0.0 ) { const int ms = d_data->time.elapsed(); - if ((fabs(d_data->speed) > 0.0) && (ms < 50)) - d_data->tmrID = startTimer(d_data->updTime); + if ( ( qFabs( d_data->speed ) > 0.0 ) && ( ms < 50 ) ) + d_data->tmrID = startTimer( d_data->updTime ); } else { d_data->scrollMode = ScrNone; buttonReleased(); } - emit sliderReleased(); - + Q_EMIT sliderReleased(); + break; } case ScrDirect: { - setPosition(e->pos()); + setPosition( e->pos() ); d_data->direction = 0; d_data->mouseOffset = 0; d_data->scrollMode = ScrNone; @@ -247,8 +245,8 @@ void QwtAbstractSlider::mouseReleaseEvent(QMouseEvent *e) case ScrPage: { stopMoving(); - if (!d_data->timerTick) - QwtDoubleRange::incPages(d_data->direction); + if ( !d_data->timerTick ) + QwtDoubleRange::incPages( d_data->direction ); d_data->timerTick = 0; buttonReleased(); d_data->scrollMode = ScrNone; @@ -258,8 +256,8 @@ void QwtAbstractSlider::mouseReleaseEvent(QMouseEvent *e) case ScrTimer: { stopMoving(); - if (!d_data->timerTick) - QwtDoubleRange::fitValue(value() + double(d_data->direction) * inc); + if ( !d_data->timerTick ) + QwtDoubleRange::fitValue( value() + double( d_data->direction ) * inc ); d_data->timerTick = 0; buttonReleased(); d_data->scrollMode = ScrNone; @@ -279,9 +277,9 @@ void QwtAbstractSlider::mouseReleaseEvent(QMouseEvent *e) Move the slider to a specified point, adjust the value and emit signals if necessary. */ -void QwtAbstractSlider::setPosition(const QPoint &p) +void QwtAbstractSlider::setPosition( const QPoint &p ) { - QwtDoubleRange::fitValue(getValue(p) - d_data->mouseOffset); + QwtDoubleRange::fitValue( getValue( p ) - d_data->mouseOffset ); } @@ -299,16 +297,16 @@ void QwtAbstractSlider::setPosition(const QPoint &p) Tracking is enabled by default. \param enable \c true (enable) or \c false (disable) tracking. */ -void QwtAbstractSlider::setTracking(bool enable) +void QwtAbstractSlider::setTracking( bool enable ) { d_data->tracking = enable; } -/*! +/*! Mouse Move Event handler \param e Mouse event */ -void QwtAbstractSlider::mouseMoveEvent(QMouseEvent *e) +void QwtAbstractSlider::mouseMoveEvent( QMouseEvent *e ) { if ( isReadOnly() ) { @@ -319,27 +317,27 @@ void QwtAbstractSlider::mouseMoveEvent(QMouseEvent *e) if ( !isValid() ) return; - if (d_data->scrollMode == ScrMouse ) + if ( d_data->scrollMode == ScrMouse ) { - setPosition(e->pos()); - if (d_data->mass > 0.0) + setPosition( e->pos() ); + if ( d_data->mass > 0.0 ) { - double ms = double(d_data->time.elapsed()); - if (ms < 1.0) + double ms = double( d_data->time.elapsed() ); + if ( ms < 1.0 ) ms = 1.0; - d_data->speed = (exactValue() - exactPrevValue()) / ms; + d_data->speed = ( exactValue() - exactPrevValue() ) / ms; d_data->time.start(); } - if (value() != prevValue()) - emit sliderMoved(value()); + if ( value() != prevValue() ) + Q_EMIT sliderMoved( value() ); } } -/*! +/*! Wheel Event handler \param e Whell event */ -void QwtAbstractSlider::wheelEvent(QWheelEvent *e) +void QwtAbstractSlider::wheelEvent( QWheelEvent *e ) { if ( isReadOnly() ) { @@ -350,16 +348,20 @@ void QwtAbstractSlider::wheelEvent(QWheelEvent *e) if ( !isValid() ) return; - int mode = ScrNone, direction = 0; + QwtAbstractSlider::ScrollMode mode = ScrNone; + int direction = 0; // Give derived classes a chance to say ScrNone - getScrollMode(e->pos(), mode, direction); - if ( mode != ScrNone ) + getScrollMode( e->pos(), mode, direction ); + if ( mode != QwtAbstractSlider::ScrNone ) { - const int inc = e->delta() / WHEEL_DELTA; - QwtDoubleRange::incPages(inc); - if (value() != prevValue()) - emit sliderMoved(value()); + // Most mouse types work in steps of 15 degrees, in which case + // the delta value is a multiple of 120 + + const int inc = e->delta() / 120; + QwtDoubleRange::incPages( inc ); + if ( value() != prevValue() ) + Q_EMIT sliderMoved( value() ); } } @@ -374,7 +376,7 @@ void QwtAbstractSlider::wheelEvent(QWheelEvent *e) \param e Key event \sa isReadOnly() */ -void QwtAbstractSlider::keyPressEvent(QKeyEvent *e) +void QwtAbstractSlider::keyPressEvent( QKeyEvent *e ) { if ( isReadOnly() ) { @@ -386,7 +388,7 @@ void QwtAbstractSlider::keyPressEvent(QKeyEvent *e) return; int increment = 0; - switch ( e->key() ) + switch ( e->key() ) { case Qt::Key_Down: if ( orientation() == Qt::Vertical ) @@ -410,32 +412,32 @@ void QwtAbstractSlider::keyPressEvent(QKeyEvent *e) if ( increment != 0 ) { - QwtDoubleRange::incValue(increment); - if (value() != prevValue()) - emit sliderMoved(value()); + QwtDoubleRange::incValue( increment ); + if ( value() != prevValue() ) + Q_EMIT sliderMoved( value() ); } } -/*! +/*! Qt timer event \param e Timer event */ -void QwtAbstractSlider::timerEvent(QTimerEvent *) +void QwtAbstractSlider::timerEvent( QTimerEvent * ) { const double inc = step(); - switch (d_data->scrollMode) + switch ( d_data->scrollMode ) { case ScrMouse: { - if (d_data->mass > 0.0) + if ( d_data->mass > 0.0 ) { - d_data->speed *= exp( - double(d_data->updTime) * 0.001 / d_data->mass ); - const double newval = - exactValue() + d_data->speed * double(d_data->updTime); - QwtDoubleRange::fitValue(newval); + d_data->speed *= qExp( - double( d_data->updTime ) * 0.001 / d_data->mass ); + const double newval = + exactValue() + d_data->speed * double( d_data->updTime ); + QwtDoubleRange::fitValue( newval ); // stop if d_data->speed < one step per second - if (fabs(d_data->speed) < 0.001 * fabs(step())) + if ( qFabs( d_data->speed ) < 0.001 * qFabs( step() ) ) { d_data->speed = 0; stopMoving(); @@ -444,27 +446,27 @@ void QwtAbstractSlider::timerEvent(QTimerEvent *) } else - stopMoving(); + stopMoving(); break; } case ScrPage: { - QwtDoubleRange::incPages(d_data->direction); - if (!d_data->timerTick) + QwtDoubleRange::incPages( d_data->direction ); + if ( !d_data->timerTick ) { - killTimer(d_data->tmrID); - d_data->tmrID = startTimer(d_data->updTime); + killTimer( d_data->tmrID ); + d_data->tmrID = startTimer( d_data->updTime ); } break; } case ScrTimer: { - QwtDoubleRange::fitValue(value() + double(d_data->direction) * inc); - if (!d_data->timerTick) + QwtDoubleRange::fitValue( value() + double( d_data->direction ) * inc ); + if ( !d_data->timerTick ) { - killTimer(d_data->tmrID); - d_data->tmrID = startTimer(d_data->updTime); + killTimer( d_data->tmrID ); + d_data->tmrID = startTimer( d_data->updTime ); } break; } @@ -487,10 +489,10 @@ void QwtAbstractSlider::timerEvent(QTimerEvent *) The default implementation emits a valueChanged() signal if tracking is enabled. */ -void QwtAbstractSlider::valueChange() +void QwtAbstractSlider::valueChange() { - if (d_data->tracking) - emit valueChanged(value()); + if ( d_data->tracking ) + Q_EMIT valueChanged( value() ); } /*! @@ -510,14 +512,14 @@ void QwtAbstractSlider::valueChange() The maximal mass is limited to 100kg. \sa mass() */ -void QwtAbstractSlider::setMass(double val) +void QwtAbstractSlider::setMass( double val ) { - if (val < 0.001) - d_data->mass = 0.0; - else if (val > 100.0) - d_data->mass = 100.0; + if ( val < 0.001 ) + d_data->mass = 0.0; + else if ( val > 100.0 ) + d_data->mass = 100.0; else - d_data->mass = val; + d_data->mass = val; } /*! @@ -525,8 +527,8 @@ void QwtAbstractSlider::setMass(double val) \sa setMass() */ double QwtAbstractSlider::mass() const -{ - return d_data->mass; +{ + return d_data->mass; } @@ -538,11 +540,11 @@ double QwtAbstractSlider::mass() const \param val new value \sa fitValue() */ -void QwtAbstractSlider::setValue(double val) +void QwtAbstractSlider::setValue( double val ) { - if (d_data->scrollMode == ScrMouse) + if ( d_data->scrollMode == ScrMouse ) stopMoving(); - QwtDoubleRange::setValue(val); + QwtDoubleRange::setValue( val ); } @@ -553,11 +555,11 @@ void QwtAbstractSlider::setValue(double val) \param value Value \sa setValue(), incValue() */ -void QwtAbstractSlider::fitValue(double value) +void QwtAbstractSlider::fitValue( double value ) { - if (d_data->scrollMode == ScrMouse) + if ( d_data->scrollMode == ScrMouse ) stopMoving(); - QwtDoubleRange::fitValue(value); + QwtDoubleRange::fitValue( value ); } /*! @@ -565,23 +567,30 @@ void QwtAbstractSlider::fitValue(double value) \param steps number of steps \sa setValue() */ -void QwtAbstractSlider::incValue(int steps) +void QwtAbstractSlider::incValue( int steps ) { - if (d_data->scrollMode == ScrMouse) + if ( d_data->scrollMode == ScrMouse ) stopMoving(); - QwtDoubleRange::incValue(steps); + QwtDoubleRange::incValue( steps ); } -void QwtAbstractSlider::setMouseOffset(double offset) +/*! + \sa mouseOffset() +*/ +void QwtAbstractSlider::setMouseOffset( double offset ) { d_data->mouseOffset = offset; -} +} +/*! + \sa setMouseOffset() +*/ double QwtAbstractSlider::mouseOffset() const { return d_data->mouseOffset; } +//! sa ScrollMode int QwtAbstractSlider::scrollMode() const { return d_data->scrollMode; diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_slider.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_slider.h index b63d70733..ab36b53c2 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_slider.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_abstract_slider.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -10,9 +10,9 @@ #ifndef QWT_ABSTRACT_SLIDER_H #define QWT_ABSTRACT_SLIDER_H -#include #include "qwt_global.h" #include "qwt_double_range.h" +#include /*! \brief An abstract base class for slider widgets @@ -20,105 +20,112 @@ QwtAbstractSlider is a base class for slider widgets. It handles mouse events and updates the slider's value accordingly. Derived classes - only have to implement the getValue() and + only have to implement the getValue() and getScrollMode() members, and should react to a - valueChange(), which normally requires repainting. + valueChange(), which normally requires repainting. */ class QWT_EXPORT QwtAbstractSlider : public QWidget, public QwtDoubleRange { - Q_OBJECT + Q_OBJECT Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly ) Q_PROPERTY( bool valid READ isValid WRITE setValid ) Q_PROPERTY( double mass READ mass WRITE setMass ) -#ifndef Q_MOC_RUN // Qt3 moc -#define QWT_PROPERTY Q_PROPERTY - Q_PROPERTY( Orientation orientation - READ orientation WRITE setOrientation ) -#else // Qt4 moc -// MOC_SKIP_BEGIN - Q_PROPERTY( Qt::Orientation orientation - READ orientation WRITE setOrientation ) -// MOC_SKIP_END -#endif + Q_PROPERTY( Qt::Orientation orientation + READ orientation WRITE setOrientation ) public: - /*! + /*! Scroll mode \sa getScrollMode() */ - enum ScrollMode - { - ScrNone, - ScrMouse, - ScrTimer, - ScrDirect, - ScrPage + enum ScrollMode + { + //! Scrolling switched off. Don't change the value. + ScrNone, + + /*! + Change the value while the user keeps the + button pressed and moves the mouse. + */ + ScrMouse, + + /*! + Automatic scrolling. Increment the value in the specified direction + as long as the user keeps the button pressed. + */ + ScrTimer, + + ScrDirect, + + //! Automatic scrolling. Same as ScrTimer, but increment by page size. + ScrPage }; - - explicit QwtAbstractSlider(Qt::Orientation, QWidget *parent = NULL); + + explicit QwtAbstractSlider( Qt::Orientation, QWidget *parent = NULL ); virtual ~QwtAbstractSlider(); - void setUpdateTime(int t); + void setUpdateTime( int t ); void stopMoving(); - void setTracking(bool enable); - - virtual void setMass(double val); + void setTracking( bool enable ); + + virtual void setMass( double val ); virtual double mass() const; -#if QT_VERSION >= 0x040000 - virtual void setOrientation(Qt::Orientation o); + virtual void setOrientation( Qt::Orientation o ); Qt::Orientation orientation() const; -#else - virtual void setOrientation(Orientation o); - Orientation orientation() const; -#endif bool isReadOnly() const; - /* + /* Wrappers for QwtDblRange::isValid/QwtDblRange::setValid made to be available as Q_PROPERTY in the designer. */ - /*! + /*! \sa QwtDblRange::isValid() */ - bool isValid() const { return QwtDoubleRange::isValid(); } + bool isValid() const + { + return QwtDoubleRange::isValid(); + } - /*! + /*! \param valid true/false \sa QwtDblRange::isValid() */ - void setValid(bool valid) { QwtDoubleRange::setValid(valid); } + void setValid( bool valid ) + { + QwtDoubleRange::setValid( valid ); + } -public slots: - virtual void setValue(double val); - virtual void fitValue(double val); - virtual void incValue(int steps); +public Q_SLOTS: + virtual void setValue( double val ); + virtual void fitValue( double val ); + virtual void incValue( int steps ); - virtual void setReadOnly(bool); + virtual void setReadOnly( bool ); -signals: +Q_SIGNALS: /*! \brief Notify a change of value. - In the default setting - (tracking enabled), this signal will be emitted every - time the value changes ( see setTracking() ). + In the default setting + (tracking enabled), this signal will be emitted every + time the value changes ( see setTracking() ). \param value new value */ - void valueChanged(double value); + void valueChanged( double value ); /*! - This signal is emitted when the user presses the + This signal is emitted when the user presses the movable part of the slider (start ScrMouse Mode). */ void sliderPressed(); /*! - This signal is emitted when the user releases the + This signal is emitted when the user releases the movable part of the slider. */ @@ -128,57 +135,45 @@ signals: slider with the mouse. \param value new value */ - void sliderMoved(double value); - + void sliderMoved( double value ); + protected: - virtual void setPosition(const QPoint &); + virtual void setPosition( const QPoint & ); virtual void valueChange(); - virtual void timerEvent(QTimerEvent *e); - virtual void mousePressEvent(QMouseEvent *e); - virtual void mouseReleaseEvent(QMouseEvent *e); - virtual void mouseMoveEvent(QMouseEvent *e); - virtual void keyPressEvent(QKeyEvent *e); - virtual void wheelEvent(QWheelEvent *e); + virtual void timerEvent( QTimerEvent *e ); + virtual void mousePressEvent( QMouseEvent *e ); + virtual void mouseReleaseEvent( QMouseEvent *e ); + virtual void mouseMoveEvent( QMouseEvent *e ); + virtual void keyPressEvent( QKeyEvent *e ); + virtual void wheelEvent( QWheelEvent *e ); - /*! - \brief Determine the value corresponding to a specified poind + /*! + \brief Determine the value corresponding to a specified poind - This is an abstract virtual function which is called when - the user presses or releases a mouse button or moves the - mouse. It has to be implemented by the derived class. - \param p point - */ - virtual double getValue(const QPoint & p) = 0; - /*! - \brief Determine what to do when the user presses a mouse button. + This is an abstract virtual function which is called when + the user presses or releases a mouse button or moves the + mouse. It has to be implemented by the derived class. + \param p point + */ + virtual double getValue( const QPoint & p ) = 0; - This function is abstract and has to be implemented by derived classes. - It is called on a mousePress event. The derived class can determine - what should happen next in dependence of the position where the mouse - was pressed by returning scrolling mode and direction. QwtAbstractSlider - knows the following modes:
-
QwtAbstractSlider::ScrNone -
Scrolling switched off. Don't change the value. -
QwtAbstractSlider::ScrMouse -
Change the value while the user keeps the - button pressed and moves the mouse. -
QwtAbstractSlider::ScrTimer -
Automatic scrolling. Increment the value - in the specified direction as long as - the user keeps the button pressed. -
QwtAbstractSlider::ScrPage -
Automatic scrolling. Same as ScrTimer, but - increment by page size.
+ /*! + \brief Determine what to do when the user presses a mouse button. - \param p point where the mouse was pressed - \retval scrollMode The scrolling mode - \retval direction direction: 1, 0, or -1. - */ - virtual void getScrollMode( const QPoint &p, - int &scrollMode, int &direction) = 0; + This function is abstract and has to be implemented by derived classes. + It is called on a mousePress event. The derived class can determine + what should happen next in dependence of the position where the mouse + was pressed by returning scrolling mode and direction. - void setMouseOffset(double); + \param pos point where the mouse was pressed + \retval scrollMode The scrolling mode + \retval direction direction: 1, 0, or -1. + */ + virtual void getScrollMode( const QPoint &pos, + ScrollMode &scrollMode, int &direction ) const = 0; + + void setMouseOffset( double ); double mouseOffset() const; int scrollMode() const; diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_analog_clock.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_analog_clock.cpp index 9c04bafd0..042e421aa 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_analog_clock.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_analog_clock.cpp @@ -8,50 +8,34 @@ *****************************************************************************/ #include "qwt_analog_clock.h" +#include /*! Constructor \param parent Parent widget */ -QwtAnalogClock::QwtAnalogClock(QWidget *parent): - QwtDial(parent) +QwtAnalogClock::QwtAnalogClock( QWidget *parent ): + QwtDial( parent ) { initClock(); } -#if QT_VERSION < 0x040000 -/*! - Constructor - \param parent Parent widget - \param name Object name -*/ -QwtAnalogClock::QwtAnalogClock(QWidget* parent, const char *name): - QwtDial(parent, name) -{ - initClock(); -} -#endif - void QwtAnalogClock::initClock() { - setWrapping(true); - setReadOnly(true); + setWrapping( true ); + setReadOnly( true ); - setOrigin(270.0); - setRange(0.0, 60.0 * 60.0 * 12.0); // seconds - setScale(-1, 5, 60.0 * 60.0); + setOrigin( 270.0 ); + setRange( 0.0, 60.0 * 60.0 * 12.0 ); // seconds + setScale( -1, 5, 60.0 * 60.0 ); - setScaleOptions(ScaleTicks | ScaleLabel); - setScaleTicks(1, 0, 8); - scaleDraw()->setSpacing(8); + setScaleComponents( + QwtAbstractScaleDraw::Ticks | QwtAbstractScaleDraw::Labels ); + setScaleTicks( 1, 0, 8 ); + scaleDraw()->setSpacing( 8 ); - QColor knobColor = -#if QT_VERSION < 0x040000 - palette().color(QPalette::Active, QColorGroup::Text); -#else - palette().color(QPalette::Active, QPalette::Text); -#endif - knobColor = knobColor.dark(120); + QColor knobColor = palette().color( QPalette::Active, QPalette::Text ); + knobColor = knobColor.dark( 120 ); QColor handColor; int width; @@ -61,7 +45,7 @@ void QwtAnalogClock::initClock() if ( i == SecondHand ) { width = 2; - handColor = knobColor.dark(120); + handColor = knobColor.dark( 120 ); } else { @@ -70,11 +54,11 @@ void QwtAnalogClock::initClock() } QwtDialSimpleNeedle *hand = new QwtDialSimpleNeedle( - QwtDialSimpleNeedle::Arrow, true, handColor, knobColor); - hand->setWidth(width); + QwtDialSimpleNeedle::Arrow, true, handColor, knobColor ); + hand->setWidth( width ); d_hand[i] = NULL; - setHand((Hand)i, hand); + setHand( ( Hand )i, hand ); } } @@ -85,11 +69,11 @@ QwtAnalogClock::~QwtAnalogClock() delete d_hand[i]; } -/*! +/*! Nop method, use setHand instead \sa setHand() */ -void QwtAnalogClock::setNeedle(QwtDialNeedle *) +void QwtAnalogClock::setNeedle( QwtDialNeedle * ) { // no op return; @@ -101,7 +85,7 @@ void QwtAnalogClock::setNeedle(QwtDialNeedle *) \param needle Hand \sa hand() */ -void QwtAnalogClock::setHand(Hand hand, QwtDialNeedle *needle) +void QwtAnalogClock::setHand( Hand hand, QwtDialNeedle *needle ) { if ( hand >= 0 || hand < NHands ) { @@ -115,7 +99,7 @@ void QwtAnalogClock::setHand(Hand hand, QwtDialNeedle *needle) \param hd Specifies the type of hand \sa setHand() */ -QwtDialNeedle *QwtAnalogClock::hand(Hand hd) +QwtDialNeedle *QwtAnalogClock::hand( Hand hd ) { if ( hd < 0 || hd >= NHands ) return NULL; @@ -128,9 +112,9 @@ QwtDialNeedle *QwtAnalogClock::hand(Hand hd) \param hd Specifies the type of hand \sa setHand() */ -const QwtDialNeedle *QwtAnalogClock::hand(Hand hd) const +const QwtDialNeedle *QwtAnalogClock::hand( Hand hd ) const { - return ((QwtAnalogClock *)this)->hand(hd); + return const_cast( this )->hand( hd ); } /*! @@ -140,37 +124,37 @@ const QwtDialNeedle *QwtAnalogClock::hand(Hand hd) const can't handle default parameters for slots. */ void QwtAnalogClock::setCurrentTime() -{ - setTime(QTime::currentTime()); +{ + setTime( QTime::currentTime() ); } /*! - Set a time + Set a time \param time Time to display */ -void QwtAnalogClock::setTime(const QTime &time) +void QwtAnalogClock::setTime( const QTime &time ) { if ( time.isValid() ) { - setValue((time.hour() % 12) * 60.0 * 60.0 - + time.minute() * 60.0 + time.second()); + setValue( ( time.hour() % 12 ) * 60.0 * 60.0 + + time.minute() * 60.0 + time.second() ); } else - setValid(false); + setValid( false ); } -/*! +/*! Find the scale label for a given value \param value Value \return Label */ -QwtText QwtAnalogClock::scaleLabel(double value) const +QwtText QwtAnalogClock::scaleLabel( double value ) const { if ( value == 0.0 ) value = 60.0 * 60.0 * 12.0; - return QString::number(int(value / (60.0 * 60.0))); + return QString::number( int( value / ( 60.0 * 60.0 ) ) ); } /*! @@ -183,20 +167,23 @@ QwtText QwtAnalogClock::scaleLabel(double value) const \param painter Painter \param center Center of the clock \param radius Maximum length for the hands - \param direction Dummy, not used. - \param cg ColorGroup + \param dir Dummy, not used. + \param colorGroup ColorGroup \sa drawHand() */ -void QwtAnalogClock::drawNeedle(QPainter *painter, const QPoint ¢er, - int radius, double, QPalette::ColorGroup cg) const +void QwtAnalogClock::drawNeedle( QPainter *painter, const QPointF ¢er, + double radius, double dir, QPalette::ColorGroup colorGroup ) const { + Q_UNUSED( dir ); + if ( isValid() ) { - const double hours = value() / (60.0 * 60.0); - const double minutes = (value() - (int)hours * 60.0 * 60.0) / 60.0; - const double seconds = value() - (int)hours * 60.0 * 60.0 - - (int)minutes * 60.0; + const double hours = value() / ( 60.0 * 60.0 ); + const double minutes = + ( value() - qFloor(hours) * 60.0 * 60.0 ) / 60.0; + const double seconds = value() - qFloor(hours) * 60.0 * 60.0 + - qFloor(minutes) * 60.0; double angle[NHands]; angle[HourHand] = 360.0 * hours / 12.0; @@ -211,7 +198,7 @@ void QwtAnalogClock::drawNeedle(QPainter *painter, const QPoint ¢er, d -= origin(); - drawHand(painter, (Hand)hand, center, radius, d, cg); + drawHand( painter, ( Hand )hand, center, radius, d, colorGroup ); } } } @@ -226,16 +213,16 @@ void QwtAnalogClock::drawNeedle(QPainter *painter, const QPoint ¢er, \param direction Direction of the hand in degrees, counter clockwise \param cg ColorGroup */ -void QwtAnalogClock::drawHand(QPainter *painter, Hand hd, - const QPoint ¢er, int radius, double direction, - QPalette::ColorGroup cg) const +void QwtAnalogClock::drawHand( QPainter *painter, Hand hd, + const QPointF ¢er, double radius, double direction, + QPalette::ColorGroup cg ) const { - const QwtDialNeedle *needle = hand(hd); + const QwtDialNeedle *needle = hand( hd ); if ( needle ) { if ( hd == HourHand ) - radius = qRound(0.8 * radius); + radius = qRound( 0.8 * radius ); - needle->draw(painter, center, radius, direction, cg); + needle->draw( painter, center, radius, direction, cg ); } } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_analog_clock.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_analog_clock.h index c9c0adda7..67c7baf73 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_analog_clock.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_analog_clock.h @@ -10,10 +10,10 @@ #ifndef QWT_ANALOG_CLOCK_H #define QWT_ANALOG_CLOCK_H -#include #include "qwt_global.h" #include "qwt_dial.h" #include "qwt_dial_needle.h" +#include /*! \brief An analog clock @@ -47,45 +47,47 @@ class QWT_EXPORT QwtAnalogClock: public QwtDial Q_OBJECT public: - /*! + /*! Hand type \sa setHand(), hand() */ - enum Hand { + //! Needle displaying the seconds SecondHand, + + //! Needle displaying the minutes MinuteHand, + + //! Needle displaying the hours HourHand, + //! Number of needles NHands }; - explicit QwtAnalogClock(QWidget* parent = NULL); -#if QT_VERSION < 0x040000 - explicit QwtAnalogClock(QWidget* parent, const char *name); -#endif + explicit QwtAnalogClock( QWidget* parent = NULL ); virtual ~QwtAnalogClock(); - virtual void setHand(Hand, QwtDialNeedle *); - const QwtDialNeedle *hand(Hand) const; - QwtDialNeedle *hand(Hand); + virtual void setHand( Hand, QwtDialNeedle * ); + const QwtDialNeedle *hand( Hand ) const; + QwtDialNeedle *hand( Hand ); -public slots: +public Q_SLOTS: void setCurrentTime(); - void setTime(const QTime & = QTime::currentTime()); + void setTime( const QTime & = QTime::currentTime() ); protected: - virtual QwtText scaleLabel(double) const; + virtual QwtText scaleLabel( double ) const; - virtual void drawNeedle(QPainter *, const QPoint &, - int radius, double direction, QPalette::ColorGroup) const; + virtual void drawNeedle( QPainter *, const QPointF &, + double radius, double direction, QPalette::ColorGroup ) const; - virtual void drawHand(QPainter *, Hand, const QPoint &, - int radius, double direction, QPalette::ColorGroup) const; + virtual void drawHand( QPainter *, Hand, const QPointF &, + double radius, double direction, QPalette::ColorGroup ) const; private: - virtual void setNeedle(QwtDialNeedle *); + virtual void setNeedle( QwtDialNeedle * ); void initClock(); QwtDialNeedle *d_hand[NHands]; diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_arrow_button.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_arrow_button.cpp index ce7dc4816..aa5267b9a 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_arrow_button.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_arrow_button.cpp @@ -2,17 +2,18 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ +#include "qwt_arrow_button.h" +#include "qwt_math.h" #include #include +#include #include -#include "qwt_math.h" -#include "qwt_polygon.h" -#include "qwt_arrow_button.h" +#include static const int MaxNum = 3; static const int Margin = 2; @@ -25,57 +26,53 @@ public: Qt::ArrowType arrowType; }; - -#if QT_VERSION >= 0x040000 -#include -static QStyleOptionButton styleOpt(const QwtArrowButton* btn) +static QStyleOptionButton styleOpt( const QwtArrowButton* btn ) { QStyleOptionButton option; - option.init(btn); + option.init( btn ); option.features = QStyleOptionButton::None; - if (btn->isFlat()) + if ( btn->isFlat() ) option.features |= QStyleOptionButton::Flat; - if (btn->menu()) + if ( btn->menu() ) option.features |= QStyleOptionButton::HasMenu; - if (btn->autoDefault() || btn->isDefault()) + if ( btn->autoDefault() || btn->isDefault() ) option.features |= QStyleOptionButton::AutoDefaultButton; - if (btn->isDefault()) + if ( btn->isDefault() ) option.features |= QStyleOptionButton::DefaultButton; - if (btn->isDown()) + if ( btn->isDown() ) option.state |= QStyle::State_Sunken; - if (!btn->isFlat() && !btn->isDown()) + if ( !btn->isFlat() && !btn->isDown() ) option.state |= QStyle::State_Raised; return option; } -#endif /*! \param num Number of arrows \param arrowType see Qt::ArowType in the Qt docs. \param parent Parent widget */ -QwtArrowButton::QwtArrowButton(int num, - Qt::ArrowType arrowType, QWidget *parent): - QPushButton(parent) +QwtArrowButton::QwtArrowButton( int num, + Qt::ArrowType arrowType, QWidget *parent ): + QPushButton( parent ) { d_data = new PrivateData; - d_data->num = qwtLim(num, 1, MaxNum); + d_data->num = qBound( 1, num, MaxNum ); d_data->arrowType = arrowType; - setAutoRepeat(true); - setAutoDefault(false); + setAutoRepeat( true ); + setAutoDefault( false ); - switch(d_data->arrowType) + switch ( d_data->arrowType ) { case Qt::LeftArrow: case Qt::RightArrow: - setSizePolicy(QSizePolicy::Expanding, - QSizePolicy::Fixed); + setSizePolicy( QSizePolicy::Expanding, + QSizePolicy::Fixed ); break; default: - setSizePolicy(QSizePolicy::Fixed, - QSizePolicy::Expanding); + setSizePolicy( QSizePolicy::Fixed, + QSizePolicy::Expanding ); } } @@ -89,17 +86,17 @@ QwtArrowButton::~QwtArrowButton() /*! \brief The direction of the arrows */ -Qt::ArrowType QwtArrowButton::arrowType() const -{ - return d_data->arrowType; +Qt::ArrowType QwtArrowButton::arrowType() const +{ + return d_data->arrowType; } /*! \brief The number of arrows */ -int QwtArrowButton::num() const -{ - return d_data->num; +int QwtArrowButton::num() const +{ + return d_data->num; } /*! @@ -110,43 +107,33 @@ QRect QwtArrowButton::labelRect() const const int m = Margin; QRect r = rect(); - r.setRect(r.x() + m, r.y() + m, - r.width() - 2 * m, r.height() - 2 * m); + r.setRect( r.x() + m, r.y() + m, + r.width() - 2 * m, r.height() - 2 * m ); if ( isDown() ) { - int ph, pv; -#if QT_VERSION < 0x040000 - ph = style().pixelMetric( - QStyle::PM_ButtonShiftHorizontal, this); - pv = style().pixelMetric( - QStyle::PM_ButtonShiftVertical, this); - r.moveBy(ph, pv); -#else - QStyleOptionButton option = styleOpt(this); - ph = style()->pixelMetric( - QStyle::PM_ButtonShiftHorizontal, &option, this); - pv = style()->pixelMetric( - QStyle::PM_ButtonShiftVertical, &option, this); - r.translate(ph, pv); -#endif + QStyleOptionButton option = styleOpt( this ); + const int ph = style()->pixelMetric( + QStyle::PM_ButtonShiftHorizontal, &option, this ); + const int pv = style()->pixelMetric( + QStyle::PM_ButtonShiftVertical, &option, this ); + + r.translate( ph, pv ); } return r; } -#if QT_VERSION >= 0x040000 /*! Paint event handler \param event Paint event */ -void QwtArrowButton::paintEvent(QPaintEvent *event) +void QwtArrowButton::paintEvent( QPaintEvent *event ) { - QPushButton::paintEvent(event); - QPainter painter(this); - drawButtonLabel(&painter); + QPushButton::paintEvent( event ); + QPainter painter( this ); + drawButtonLabel( &painter ); } -#endif /*! \brief Draw the button label @@ -154,7 +141,7 @@ void QwtArrowButton::paintEvent(QPaintEvent *event) \param painter Painter \sa The Qt Manual on QPushButton */ -void QwtArrowButton::drawButtonLabel(QPainter *painter) +void QwtArrowButton::drawButtonLabel( QPainter *painter ) { const bool isVertical = d_data->arrowType == Qt::UpArrow || d_data->arrowType == Qt::DownArrow; @@ -163,12 +150,12 @@ void QwtArrowButton::drawButtonLabel(QPainter *painter) QSize boundingSize = labelRect().size(); if ( isVertical ) boundingSize.transpose(); - - const int w = - (boundingSize.width() - (MaxNum - 1) * Spacing) / MaxNum; - QSize arrow = arrowSize(Qt::RightArrow, - QSize(w, boundingSize.height())); + const int w = + ( boundingSize.width() - ( MaxNum - 1 ) * Spacing ) / MaxNum; + + QSize arrow = arrowSize( Qt::RightArrow, + QSize( w, boundingSize.height() ) ); if ( isVertical ) arrow.transpose(); @@ -176,25 +163,25 @@ void QwtArrowButton::drawButtonLabel(QPainter *painter) QRect contentsSize; // aligned rect where to paint all arrows if ( d_data->arrowType == Qt::LeftArrow || d_data->arrowType == Qt::RightArrow ) { - contentsSize.setWidth(d_data->num * arrow.width() - + (d_data->num - 1) * Spacing); - contentsSize.setHeight(arrow.height()); + contentsSize.setWidth( d_data->num * arrow.width() + + ( d_data->num - 1 ) * Spacing ); + contentsSize.setHeight( arrow.height() ); } else { - contentsSize.setWidth(arrow.width()); - contentsSize.setHeight(d_data->num * arrow.height() - + (d_data->num - 1) * Spacing); + contentsSize.setWidth( arrow.width() ); + contentsSize.setHeight( d_data->num * arrow.height() + + ( d_data->num - 1 ) * Spacing ); } - QRect arrowRect(contentsSize); - arrowRect.moveCenter(r.center()); - arrowRect.setSize(arrow); + QRect arrowRect( contentsSize ); + arrowRect.moveCenter( r.center() ); + arrowRect.setSize( arrow ); painter->save(); - for (int i = 0; i < d_data->num; i++) + for ( int i = 0; i < d_data->num; i++ ) { - drawArrow(painter, arrowRect, d_data->arrowType); + drawArrow( painter, arrowRect, d_data->arrowType ); int dx = 0; int dy = 0; @@ -204,29 +191,18 @@ void QwtArrowButton::drawButtonLabel(QPainter *painter) else dx = arrow.width() + Spacing; -#if QT_VERSION >= 0x040000 - arrowRect.translate(dx, dy); -#else - arrowRect.moveBy(dx, dy); -#endif + arrowRect.translate( dx, dy ); } painter->restore(); if ( hasFocus() ) { -#if QT_VERSION >= 0x040000 QStyleOptionFocusRect option; - option.init(this); - option.backgroundColor = palette().color(QPalette::Background); + option.init( this ); + option.backgroundColor = palette().color( QPalette::Window ); - style()->drawPrimitive(QStyle::PE_FrameFocusRect, - &option, painter, this); -#else - const QRect focusRect = - style().subRect(QStyle::SR_PushButtonFocusRect, this); - style().drawPrimitive(QStyle::PE_FocusRect, painter, - focusRect, colorGroup()); -#endif + style()->drawPrimitive( QStyle::PE_FrameFocusRect, + &option, painter, this ); } } @@ -237,46 +213,43 @@ void QwtArrowButton::drawButtonLabel(QPainter *painter) \param r Rectangle where to paint the arrow \param arrowType Arrow type */ -void QwtArrowButton::drawArrow(QPainter *painter, - const QRect &r, Qt::ArrowType arrowType) const +void QwtArrowButton::drawArrow( QPainter *painter, + const QRect &r, Qt::ArrowType arrowType ) const { - QwtPolygon pa(3); + QPolygon pa( 3 ); - switch(arrowType) + switch ( arrowType ) { case Qt::UpArrow: - pa.setPoint(0, r.bottomLeft()); - pa.setPoint(1, r.bottomRight()); - pa.setPoint(2, r.center().x(), r.top()); + pa.setPoint( 0, r.bottomLeft() ); + pa.setPoint( 1, r.bottomRight() ); + pa.setPoint( 2, r.center().x(), r.top() ); break; case Qt::DownArrow: - pa.setPoint(0, r.topLeft()); - pa.setPoint(1, r.topRight()); - pa.setPoint(2, r.center().x(), r.bottom()); + pa.setPoint( 0, r.topLeft() ); + pa.setPoint( 1, r.topRight() ); + pa.setPoint( 2, r.center().x(), r.bottom() ); break; case Qt::RightArrow: - pa.setPoint(0, r.topLeft()); - pa.setPoint(1, r.bottomLeft()); - pa.setPoint(2, r.right(), r.center().y()); + pa.setPoint( 0, r.topLeft() ); + pa.setPoint( 1, r.bottomLeft() ); + pa.setPoint( 2, r.right(), r.center().y() ); break; case Qt::LeftArrow: - pa.setPoint(0, r.topRight()); - pa.setPoint(1, r.bottomRight()); - pa.setPoint(2, r.left(), r.center().y()); + pa.setPoint( 0, r.topRight() ); + pa.setPoint( 1, r.bottomRight() ); + pa.setPoint( 2, r.left(), r.center().y() ); break; default: break; } painter->save(); -#if QT_VERSION < 0x040000 - painter->setPen(colorGroup().buttonText()); - painter->setBrush(colorGroup().brush(QColorGroup::ButtonText)); -#else - painter->setPen(palette().color(QPalette::ButtonText)); - painter->setBrush(palette().brush(QPalette::ButtonText)); -#endif - painter->drawPolygon(pa); + + painter->setPen( palette().color( QPalette::ButtonText ) ); + painter->setBrush( palette().brush( QPalette::ButtonText ) ); + painter->drawPolygon( pa ); + painter->restore(); } @@ -285,7 +258,8 @@ void QwtArrowButton::drawArrow(QPainter *painter, */ QSize QwtArrowButton::sizeHint() const { - return minimumSizeHint(); + const QSize hint = minimumSizeHint(); + return hint.expandedTo( QApplication::globalStrut() ); } /*! @@ -293,30 +267,21 @@ QSize QwtArrowButton::sizeHint() const */ QSize QwtArrowButton::minimumSizeHint() const { - const QSize asz = arrowSize(Qt::RightArrow, QSize()); + const QSize asz = arrowSize( Qt::RightArrow, QSize() ); QSize sz( - 2 * Margin + (MaxNum - 1) * Spacing + MaxNum * asz.width(), + 2 * Margin + ( MaxNum - 1 ) * Spacing + MaxNum * asz.width(), 2 * Margin + asz.height() ); if ( d_data->arrowType == Qt::UpArrow || d_data->arrowType == Qt::DownArrow ) sz.transpose(); -#if QT_VERSION >= 0x040000 QStyleOption styleOption; - styleOption.init(this); + styleOption.init( this ); - const QSize hsz = style()->sizeFromContents(QStyle::CT_PushButton, - &styleOption, sz, this); -#if QT_VERSION < 0x040300 - if ( hsz.width() != 80 ) // avoid a bug in the Cleanlooks style -#endif - sz = hsz; - -#else - sz = style().sizeFromContents(QStyle::CT_PushButton, this, sz); -#endif + sz = style()->sizeFromContents( QStyle::CT_PushButton, + &styleOption, sz, this ); return sz; } @@ -328,16 +293,16 @@ QSize QwtArrowButton::minimumSizeHint() const \param boundingSize Bounding size \return Size of the arrow */ -QSize QwtArrowButton::arrowSize(Qt::ArrowType arrowType, - const QSize &boundingSize) const +QSize QwtArrowButton::arrowSize( Qt::ArrowType arrowType, + const QSize &boundingSize ) const { QSize bs = boundingSize; if ( arrowType == Qt::UpArrow || arrowType == Qt::DownArrow ) bs.transpose(); - + const int MinLen = 2; const QSize sz = bs.expandedTo( - QSize(MinLen, 2 * MinLen - 1)); // minimum + QSize( MinLen, 2 * MinLen - 1 ) ); // minimum int w = sz.width(); int h = 2 * w - 1; @@ -345,10 +310,10 @@ QSize QwtArrowButton::arrowSize(Qt::ArrowType arrowType, if ( h > sz.height() ) { h = sz.height(); - w = (h + 1) / 2; + w = ( h + 1 ) / 2; } - QSize arrSize(w, h); + QSize arrSize( w, h ); if ( arrowType == Qt::UpArrow || arrowType == Qt::DownArrow ) arrSize.transpose(); @@ -358,10 +323,10 @@ QSize QwtArrowButton::arrowSize(Qt::ArrowType arrowType, /*! \brief autoRepeat for the space keys */ -void QwtArrowButton::keyPressEvent(QKeyEvent *e) +void QwtArrowButton::keyPressEvent( QKeyEvent *event ) { - if ( e->isAutoRepeat() && e->key() == Qt::Key_Space ) - emit clicked(); + if ( event->isAutoRepeat() && event->key() == Qt::Key_Space ) + Q_EMIT clicked(); - QPushButton::keyPressEvent(e); + QPushButton::keyPressEvent( event ); } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_arrow_button.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_arrow_button.h index 860b71996..b3285daa5 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_arrow_button.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_arrow_button.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -10,8 +10,8 @@ #ifndef QWT_ARROW_BUTTON_H #define QWT_ARROW_BUTTON_H -#include #include "qwt_global.h" +#include /*! \brief Arrow Button @@ -23,7 +23,7 @@ class QWT_EXPORT QwtArrowButton : public QPushButton { public: - explicit QwtArrowButton (int num, Qt::ArrowType, QWidget *parent = NULL); + explicit QwtArrowButton ( int num, Qt::ArrowType, QWidget *parent = NULL ); virtual ~QwtArrowButton(); Qt::ArrowType arrowType() const; @@ -33,18 +33,16 @@ public: virtual QSize minimumSizeHint() const; protected: -#if QT_VERSION >= 0x040000 - virtual void paintEvent(QPaintEvent *event); -#endif + virtual void paintEvent( QPaintEvent *event ); - virtual void drawButtonLabel(QPainter *p); - virtual void drawArrow(QPainter *, - const QRect &, Qt::ArrowType) const; + virtual void drawButtonLabel( QPainter *p ); + virtual void drawArrow( QPainter *, + const QRect &, Qt::ArrowType ) const; virtual QRect labelRect() const; - virtual QSize arrowSize(Qt::ArrowType, - const QSize &boundingSize) const; + virtual QSize arrowSize( Qt::ArrowType, + const QSize &boundingSize ) const; - virtual void keyPressEvent(QKeyEvent *); + virtual void keyPressEvent( QKeyEvent * ); private: class PrivateData; diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_clipper.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_clipper.cpp index 40ad34c25..d43c47fa9 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_clipper.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_clipper.cpp @@ -2,404 +2,368 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -#include -#include "qwt_math.h" #include "qwt_clipper.h" +#include "qwt_point_polar.h" +#include -static inline QwtDoubleRect boundingRect(const QwtPolygonF &polygon) -{ -#if QT_VERSION < 0x040000 - if (polygon.isEmpty()) - return QwtDoubleRect(0, 0, 0, 0); - - register const QwtDoublePoint *pd = polygon.data(); - - double minx, maxx, miny, maxy; - minx = maxx = pd->x(); - miny = maxy = pd->y(); - pd++; - - for (uint i = 1; i < polygon.size(); i++, pd++) - { - if (pd->x() < minx) - minx = pd->x(); - else if (pd->x() > maxx) - maxx = pd->x(); - if (pd->y() < miny) - miny = pd->y(); - else if (pd->y() > maxy) - maxy = pd->y(); - } - return QwtDoubleRect(minx, miny, maxx - minx, maxy - miny); -#else - return polygon.boundingRect(); -#endif -} - -enum Edge -{ - Left, - Top, - Right, - Bottom, - NEdges -}; - -class QwtPolygonClipper: public QRect -{ -public: - QwtPolygonClipper(const QRect &r); - - QwtPolygon clipPolygon(const QwtPolygon &) const; - -private: - void clipEdge(Edge, const QwtPolygon &, QwtPolygon &) const; - bool insideEdge(const QPoint &, Edge edge) const; - QPoint intersectEdge(const QPoint &p1, - const QPoint &p2, Edge edge) const; - - void addPoint(QwtPolygon &, uint pos, const QPoint &point) const; -}; - -class QwtPolygonClipperF: public QwtDoubleRect -{ -public: - QwtPolygonClipperF(const QwtDoubleRect &r); - QwtPolygonF clipPolygon(const QwtPolygonF &) const; - -private: - void clipEdge(Edge, const QwtPolygonF &, QwtPolygonF &) const; - bool insideEdge(const QwtDoublePoint &, Edge edge) const; - QwtDoublePoint intersectEdge(const QwtDoublePoint &p1, - const QwtDoublePoint &p2, Edge edge) const; - - void addPoint(QwtPolygonF &, uint pos, const QwtDoublePoint &point) const; -}; - -#if QT_VERSION >= 0x040000 -class QwtCircleClipper: public QwtDoubleRect -{ -public: - QwtCircleClipper(const QwtDoubleRect &r); - QwtArray clipCircle( - const QwtDoublePoint &, double radius) const; - -private: - QList cuttingPoints( - Edge, const QwtDoublePoint &pos, double radius) const; - double toAngle(const QwtDoublePoint &, const QwtDoublePoint &) const; -}; +#if QT_VERSION < 0x040601 +#define qAtan(x) ::atan(x) #endif -QwtPolygonClipper::QwtPolygonClipper(const QRect &r): - QRect(r) +namespace QwtClip { + // some templates used for inlining + template class LeftEdge; + template class RightEdge; + template class TopEdge; + template class BottomEdge; + + template class PointBuffer; } -inline void QwtPolygonClipper::addPoint( - QwtPolygon &pa, uint pos, const QPoint &point) const +template +class QwtClip::LeftEdge { - if ( uint(pa.size()) <= pos ) - pa.resize(pos + 5); - - pa.setPoint(pos, point); -} - -//! Sutherland-Hodgman polygon clipping -QwtPolygon QwtPolygonClipper::clipPolygon(const QwtPolygon &pa) const -{ - if ( contains( pa.boundingRect() ) ) - return pa; - - QwtPolygon cpa(pa.size()); - - clipEdge((Edge)0, pa, cpa); - - for ( uint edge = 1; edge < NEdges; edge++ ) +public: + inline LeftEdge( Value x1, Value, Value, Value ): + d_x1( x1 ) { - const QwtPolygon rpa = cpa; -#if QT_VERSION < 0x040000 - cpa.detach(); + } + + inline bool isInside( const Point &p ) const + { + return p.x() >= d_x1; + } + + inline Point intersection( const Point &p1, const Point &p2 ) const + { + double dy = ( p1.y() - p2.y() ) / double( p1.x() - p2.x() ); + return Point( d_x1, ( Value ) ( p2.y() + ( d_x1 - p2.x() ) * dy ) ); + } +private: + const Value d_x1; +}; + +template +class QwtClip::RightEdge +{ +public: + inline RightEdge( Value, Value x2, Value, Value ): + d_x2( x2 ) + { + } + + inline bool isInside( const Point &p ) const + { + return p.x() <= d_x2; + } + + inline Point intersection( const Point &p1, const Point &p2 ) const + { + double dy = ( p1.y() - p2.y() ) / double( p1.x() - p2.x() ); + return Point( d_x2, ( Value ) ( p2.y() + ( d_x2 - p2.x() ) * dy ) ); + } + +private: + const Value d_x2; +}; + +template +class QwtClip::TopEdge +{ +public: + inline TopEdge( Value, Value, Value y1, Value ): + d_y1( y1 ) + { + } + + inline bool isInside( const Point &p ) const + { + return p.y() >= d_y1; + } + + inline Point intersection( const Point &p1, const Point &p2 ) const + { + double dx = ( p1.x() - p2.x() ) / double( p1.y() - p2.y() ); + return Point( ( Value )( p2.x() + ( d_y1 - p2.y() ) * dx ), d_y1 ); + } + +private: + const Value d_y1; +}; + +template +class QwtClip::BottomEdge +{ +public: + inline BottomEdge( Value, Value, Value, Value y2 ): + d_y2( y2 ) + { + } + + inline bool isInside( const Point &p ) const + { + return p.y() <= d_y2; + } + + inline Point intersection( const Point &p1, const Point &p2 ) const + { + double dx = ( p1.x() - p2.x() ) / double( p1.y() - p2.y() ); + return Point( ( Value )( p2.x() + ( d_y2 - p2.y() ) * dx ), d_y2 ); + } + +private: + const Value d_y2; +}; + +template +class QwtClip::PointBuffer +{ +public: + PointBuffer( int capacity = 0 ): + m_capacity( 0 ), + m_size( 0 ), + m_buffer( NULL ) + { + if ( capacity > 0 ) + reserve( capacity ); + } + + ~PointBuffer() + { + if ( m_buffer ) + qFree( m_buffer ); + } + + inline void setPoints( int numPoints, const Point *points ) + { + reserve( numPoints ); + + m_size = numPoints; + qMemCopy( m_buffer, points, m_size * sizeof( Point ) ); + } + + inline void reset() + { + m_size = 0; + } + + inline int size() const + { + return m_size; + } + + inline Point *data() const + { + return m_buffer; + } + + inline Point &operator[]( int i ) + { + return m_buffer[i]; + } + + inline const Point &operator[]( int i ) const + { + return m_buffer[i]; + } + + inline void add( const Point &point ) + { + if ( m_capacity <= m_size ) + reserve( m_size + 1 ); + + m_buffer[m_size++] = point; + } + +private: + inline void reserve( int size ) + { + if ( m_capacity == 0 ) + m_capacity = 1; + + while ( m_capacity < size ) + m_capacity *= 2; + + m_buffer = ( Point * ) qRealloc( + m_buffer, m_capacity * sizeof( Point ) ); + } + + int m_capacity; + int m_size; + Point *m_buffer; +}; + +using namespace QwtClip; + +template +class QwtPolygonClipper +{ +public: + QwtPolygonClipper( const Rect &clipRect ): + d_clipRect( clipRect ) + { + } + + Polygon clipPolygon( const Polygon &polygon, bool closePolygon ) const + { +#if 0 + if ( d_clipRect.contains( polygon.boundingRect() ) ) + return polygon; #endif - clipEdge((Edge)edge, rpa, cpa); + + PointBuffer points1; + PointBuffer points2( qMin( 256, polygon.size() ) ); + + points1.setPoints( polygon.size(), polygon.data() ); + + clipEdge< LeftEdge >( closePolygon, points1, points2 ); + clipEdge< RightEdge >( closePolygon, points2, points1 ); + clipEdge< TopEdge >( closePolygon, points1, points2 ); + clipEdge< BottomEdge >( closePolygon, points2, points1 ); + + Polygon p; + p.resize( points1.size() ); + qMemCopy( p.data(), points1.data(), points1.size() * sizeof( Point ) ); + + return p; } - return cpa; -} - -bool QwtPolygonClipper::insideEdge(const QPoint &p, Edge edge) const -{ - switch(edge) +private: + template + inline void clipEdge( bool closePolygon, + PointBuffer &points, PointBuffer &clippedPoints ) const { - case Left: - return p.x() > left(); - case Top: - return p.y() > top(); - case Right: - return p.x() < right(); - case Bottom: - return p.y() < bottom(); - default: - break; - } + clippedPoints.reset(); - return false; -} - -QPoint QwtPolygonClipper::intersectEdge(const QPoint &p1, - const QPoint &p2, Edge edge ) const -{ - int x=0, y=0; - double m = 0; - - const double dy = p2.y() - p1.y(); - const double dx = p2.x() - p1.x(); - - switch ( edge ) - { - case Left: - x = left(); - m = double(qwtAbs(p1.x() - x)) / qwtAbs(dx); - y = p1.y() + int(dy * m); - break; - case Top: - y = top(); - m = double(qwtAbs(p1.y() - y)) / qwtAbs(dy); - x = p1.x() + int(dx * m); - break; - case Right: - x = right(); - m = double(qwtAbs(p1.x() - x)) / qwtAbs(dx); - y = p1.y() + int(dy * m); - break; - case Bottom: - y = bottom(); - m = double(qwtAbs(p1.y() - y)) / qwtAbs(dy); - x = p1.x() + int(dx * m); - break; - default: - break; - } - - return QPoint(x,y); -} - -void QwtPolygonClipper::clipEdge(Edge edge, - const QwtPolygon &pa, QwtPolygon &cpa) const -{ - if ( pa.count() == 0 ) - { - cpa.resize(0); - return; - } - - unsigned int count = 0; - - QPoint p1 = pa.point(0); - if ( insideEdge(p1, edge) ) - addPoint(cpa, count++, p1); - - const uint nPoints = pa.size(); - for ( uint i = 1; i < nPoints; i++ ) - { - const QPoint p2 = pa.point(i); - if ( insideEdge(p2, edge) ) + if ( points.size() < 2 ) { - if ( insideEdge(p1, edge) ) - addPoint(cpa, count++, p2); - else - { - addPoint(cpa, count++, intersectEdge(p1, p2, edge)); - addPoint(cpa, count++, p2); - } + if ( points.size() == 1 ) + clippedPoints.add( points[0] ); + return; + } + + const Edge edge( d_clipRect.x(), d_clipRect.x() + d_clipRect.width(), + d_clipRect.y(), d_clipRect.y() + d_clipRect.height() ); + + int lastPos, start; + if ( closePolygon ) + { + start = 0; + lastPos = points.size() - 1; } else { - if ( insideEdge(p1, edge) ) - addPoint(cpa, count++, intersectEdge(p1, p2, edge)); + start = 1; + lastPos = 0; + + if ( edge.isInside( points[0] ) ) + clippedPoints.add( points[0] ); } - p1 = p2; - } - cpa.resize(count); -} -QwtPolygonClipperF::QwtPolygonClipperF(const QwtDoubleRect &r): - QwtDoubleRect(r) -{ -} - -inline void QwtPolygonClipperF::addPoint(QwtPolygonF &pa, uint pos, const QwtDoublePoint &point) const -{ - if ( uint(pa.size()) <= pos ) - pa.resize(pos + 5); - - pa[(int)pos] = point; -} - -//! Sutherland-Hodgman polygon clipping -QwtPolygonF QwtPolygonClipperF::clipPolygon(const QwtPolygonF &pa) const -{ - if ( contains( ::boundingRect(pa) ) ) - return pa; - - QwtPolygonF cpa(pa.size()); - - clipEdge((Edge)0, pa, cpa); - - for ( uint edge = 1; edge < NEdges; edge++ ) - { - const QwtPolygonF rpa = cpa; -#if QT_VERSION < 0x040000 - cpa.detach(); -#endif - clipEdge((Edge)edge, rpa, cpa); - } - - return cpa; -} - -bool QwtPolygonClipperF::insideEdge(const QwtDoublePoint &p, Edge edge) const -{ - switch(edge) - { - case Left: - return p.x() > left(); - case Top: - return p.y() > top(); - case Right: - return p.x() < right(); - case Bottom: - return p.y() < bottom(); - default: - break; - } - - return false; -} - -QwtDoublePoint QwtPolygonClipperF::intersectEdge(const QwtDoublePoint &p1, - const QwtDoublePoint &p2, Edge edge ) const -{ - double x=0.0, y=0.0; - double m = 0; - - const double dy = p2.y() - p1.y(); - const double dx = p2.x() - p1.x(); - - switch ( edge ) - { - case Left: - x = left(); - m = double(qwtAbs(p1.x() - x)) / qwtAbs(dx); - y = p1.y() + int(dy * m); - break; - case Top: - y = top(); - m = double(qwtAbs(p1.y() - y)) / qwtAbs(dy); - x = p1.x() + int(dx * m); - break; - case Right: - x = right(); - m = double(qwtAbs(p1.x() - x)) / qwtAbs(dx); - y = p1.y() + int(dy * m); - break; - case Bottom: - y = bottom(); - m = double(qwtAbs(p1.y() - y)) / qwtAbs(dy); - x = p1.x() + int(dx * m); - break; - default: - break; - } - - return QwtDoublePoint(x,y); -} - -void QwtPolygonClipperF::clipEdge(Edge edge, - const QwtPolygonF &pa, QwtPolygonF &cpa) const -{ - if ( pa.count() == 0 ) - { - cpa.resize(0); - return; - } - - unsigned int count = 0; - - QwtDoublePoint p1 = pa[0]; - if ( insideEdge(p1, edge) ) - addPoint(cpa, count++, p1); - - const uint nPoints = pa.size(); - for ( uint i = 1; i < nPoints; i++ ) - { - const QwtDoublePoint p2 = pa[(int)i]; - if ( insideEdge(p2, edge) ) + const uint nPoints = points.size(); + for ( uint i = start; i < nPoints; i++ ) { - if ( insideEdge(p1, edge) ) - addPoint(cpa, count++, p2); + const Point &p1 = points[i]; + const Point &p2 = points[lastPos]; + + if ( edge.isInside( p1 ) ) + { + if ( edge.isInside( p2 ) ) + { + clippedPoints.add( p1 ); + } + else + { + clippedPoints.add( edge.intersection( p1, p2 ) ); + clippedPoints.add( p1 ); + } + } else { - addPoint(cpa, count++, intersectEdge(p1, p2, edge)); - addPoint(cpa, count++, p2); + if ( edge.isInside( p2 ) ) + { + clippedPoints.add( edge.intersection( p1, p2 ) ); + } } + lastPos = i; } - else - { - if ( insideEdge(p1, edge) ) - addPoint(cpa, count++, intersectEdge(p1, p2, edge)); - } - p1 = p2; } - cpa.resize(count); -} -#if QT_VERSION >= 0x040000 + const Rect d_clipRect; +}; -QwtCircleClipper::QwtCircleClipper(const QwtDoubleRect &r): - QwtDoubleRect(r) +class QwtCircleClipper +{ +public: + QwtCircleClipper( const QRectF &r ); + QVector clipCircle( const QPointF &, double radius ) const; + +private: + enum Edge + { + Left, + Top, + Right, + Bottom, + + NEdges + }; + + QList cuttingPoints( + Edge, const QPointF &pos, double radius ) const; + + double toAngle( const QPointF &, const QPointF & ) const; + + const QRectF d_rect; +}; + + +QwtCircleClipper::QwtCircleClipper( const QRectF &r ): + d_rect( r ) { } -QwtArray QwtCircleClipper::clipCircle( - const QwtDoublePoint &pos, double radius) const +QVector QwtCircleClipper::clipCircle( + const QPointF &pos, double radius ) const { - QList points; + QList points; for ( int edge = 0; edge < NEdges; edge++ ) - points += cuttingPoints((Edge)edge, pos, radius); + points += cuttingPoints( ( Edge )edge, pos, radius ); - QwtArray intv; + QVector intv; if ( points.size() <= 0 ) { - QwtDoubleRect cRect(0, 0, 2 * radius, 2* radius); - cRect.moveCenter(pos); - if ( contains(cRect) ) - intv += QwtDoubleInterval(0.0, 2 * M_PI); + QRectF cRect( 0, 0, 2 * radius, 2 * radius ); + cRect.moveCenter( pos ); + if ( d_rect.contains( cRect ) ) + intv += QwtInterval( 0.0, 2 * M_PI ); } else { QList angles; for ( int i = 0; i < points.size(); i++ ) - angles += toAngle(pos, points[i]); - qSort(angles); + angles += toAngle( pos, points[i] ); + qSort( angles ); + + const int in = d_rect.contains( qwtPolar2Pos( pos, radius, + angles[0] + ( angles[1] - angles[0] ) / 2 ) ); - const int in = contains(qwtPolar2Pos(pos, radius, - angles[0] + (angles[1] - angles[0]) / 2)); if ( in ) { - for ( int i = 0; i < angles.size() - 1; i += 2) - intv += QwtDoubleInterval(angles[i], angles[i+1]); + for ( int i = 0; i < angles.size() - 1; i += 2 ) + intv += QwtInterval( angles[i], angles[i+1] ); } else { - for ( int i = 1; i < angles.size() - 1; i += 2) - intv += QwtDoubleInterval(angles[i], angles[i+1]); - intv += QwtDoubleInterval(angles.last(), angles.first()); + for ( int i = 1; i < angles.size() - 1; i += 2 ) + intv += QwtInterval( angles[i], angles[i+1] ); + intv += QwtInterval( angles.last(), angles.first() ); } } @@ -407,16 +371,16 @@ QwtArray QwtCircleClipper::clipCircle( } double QwtCircleClipper::toAngle( - const QwtDoublePoint &from, const QwtDoublePoint &to) const + const QPointF &from, const QPointF &to ) const { if ( from.x() == to.x() ) return from.y() <= to.y() ? M_PI / 2.0 : 3 * M_PI / 2.0; - const double m = qwtAbs((to.y() - from.y()) / (to.x() - from.x()) ); + const double m = qAbs( ( to.y() - from.y() ) / ( to.x() - from.x() ) ); - double angle = ::atan(m); + double angle = qAtan( m ); if ( to.x() > from.x() ) - { + { if ( to.y() > from.y() ) angle = 2 * M_PI - angle; } @@ -431,79 +395,81 @@ double QwtCircleClipper::toAngle( return angle; } -QList QwtCircleClipper::cuttingPoints( - Edge edge, const QwtDoublePoint &pos, double radius) const +QList QwtCircleClipper::cuttingPoints( + Edge edge, const QPointF &pos, double radius ) const { - QList points; + QList points; if ( edge == Left || edge == Right ) { - const double x = (edge == Left) ? left() : right(); - if ( qwtAbs(pos.x() - x) < radius ) + const double x = ( edge == Left ) ? d_rect.left() : d_rect.right(); + if ( qAbs( pos.x() - x ) < radius ) { - const double off = ::sqrt(qwtSqr(radius) - qwtSqr(pos.x() - x)); - const double y1 = pos.y() + off; - if ( y1 >= top() && y1 <= bottom() ) - points += QwtDoublePoint(x, y1); - const double y2 = pos.y() - off; - if ( y2 >= top() && y2 <= bottom() ) - points += QwtDoublePoint(x, y2); + const double off = qSqrt( qwtSqr( radius ) - qwtSqr( pos.x() - x ) ); + const double m_y1 = pos.y() + off; + if ( m_y1 >= d_rect.top() && m_y1 <= d_rect.bottom() ) + points += QPointF( x, m_y1 ); + + const double m_y2 = pos.y() - off; + if ( m_y2 >= d_rect.top() && m_y2 <= d_rect.bottom() ) + points += QPointF( x, m_y2 ); } } else { - const double y = (edge == Top) ? top() : bottom(); - if ( qwtAbs(pos.y() - y) < radius ) + const double y = ( edge == Top ) ? d_rect.top() : d_rect.bottom(); + if ( qAbs( pos.y() - y ) < radius ) { - const double off = ::sqrt(qwtSqr(radius) - qwtSqr(pos.y() - y)); + const double off = qSqrt( qwtSqr( radius ) - qwtSqr( pos.y() - y ) ); const double x1 = pos.x() + off; - if ( x1 >= left() && x1 <= right() ) - points += QwtDoublePoint(x1, y); - const double x2 = pos.x() - off; - if ( x2 >= left() && x2 <= right() ) - points += QwtDoublePoint(x2, y); + if ( x1 >= d_rect.left() && x1 <= d_rect.right() ) + points += QPointF( x1, y ); + + const double m_x2 = pos.x() - off; + if ( m_x2 >= d_rect.left() && m_x2 <= d_rect.right() ) + points += QPointF( m_x2, y ); } } return points; } -#endif - -/*! + +/*! Sutherland-Hodgman polygon clipping \param clipRect Clip rectangle \param polygon Polygon + \param closePolygon True, when the polygon is closed \return Clipped polygon */ -QwtPolygon QwtClipper::clipPolygon( - const QRect &clipRect, const QwtPolygon &polygon) +QPolygon QwtClipper::clipPolygon( + const QRect &clipRect, const QPolygon &polygon, bool closePolygon ) { - QwtPolygonClipper clipper(clipRect); - return clipper.clipPolygon(polygon); + QwtPolygonClipper clipper( clipRect ); + return clipper.clipPolygon( polygon, closePolygon ); } -/*! +/*! Sutherland-Hodgman polygon clipping \param clipRect Clip rectangle \param polygon Polygon + \param closePolygon True, when the polygon is closed \return Clipped polygon */ -QwtPolygonF QwtClipper::clipPolygonF( - const QwtDoubleRect &clipRect, const QwtPolygonF &polygon) +QPolygonF QwtClipper::clipPolygonF( + const QRectF &clipRect, const QPolygonF &polygon, bool closePolygon ) { - QwtPolygonClipperF clipper(clipRect); - return clipper.clipPolygon(polygon); + QwtPolygonClipper clipper( clipRect ); + return clipper.clipPolygon( polygon, closePolygon ); } -#if QT_VERSION >= 0x040000 -/*! +/*! Circle clipping clipCircle() devides a circle into intervals of angles representing arcs - of the circle. When the circle is completely inside the clip rectangle + of the circle. When the circle is completely inside the clip rectangle an interval [0.0, 2 * M_PI] is returned. \param clipRect Clip rectangle @@ -512,11 +478,9 @@ QwtPolygonF QwtClipper::clipPolygonF( \return Arcs of the circle */ -QwtArray QwtClipper::clipCircle( - const QwtDoubleRect &clipRect, - const QwtDoublePoint ¢er, double radius) +QVector QwtClipper::clipCircle( const QRectF &clipRect, + const QPointF ¢er, double radius ) { - QwtCircleClipper clipper(clipRect); - return clipper.clipCircle(center, radius); + QwtCircleClipper clipper( clipRect ); + return clipper.clipCircle( center, radius ); } -#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_clipper.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_clipper.h index cdbe0d3d2..2f28f7982 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_clipper.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_clipper.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -11,12 +11,12 @@ #define QWT_CLIPPER_H #include "qwt_global.h" -#include "qwt_array.h" -#include "qwt_polygon.h" -#include "qwt_double_rect.h" -#include "qwt_double_interval.h" +#include "qwt_interval.h" +#include +#include class QRect; +class QRectF; /*! \brief Some clipping algos @@ -25,13 +25,13 @@ class QRect; class QWT_EXPORT QwtClipper { public: - static QwtPolygon clipPolygon(const QRect &, const QwtPolygon &); - static QwtPolygonF clipPolygonF(const QwtDoubleRect &, const QwtPolygonF &); + static QPolygon clipPolygon( const QRect &, + const QPolygon &, bool closePolygon = false ); + static QPolygonF clipPolygonF( const QRectF &, + const QPolygonF &, bool closePolygon = false ); -#if QT_VERSION >= 0x040000 - static QwtArray clipCircle( - const QwtDoubleRect &, const QwtDoublePoint &, double radius); -#endif + static QVector clipCircle( + const QRectF &, const QPointF &, double radius ); }; #endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_color_map.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_color_map.cpp index 312eec768..48ce721ed 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_color_map.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_color_map.cpp @@ -7,32 +7,23 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -#include "qwt_array.h" -#include "qwt_math.h" -#include "qwt_double_interval.h" #include "qwt_color_map.h" - -#if QT_VERSION < 0x040000 -#include -typedef QValueVector QwtColorTable; -#else -typedef QVector QwtColorTable; -#endif +#include "qwt_math.h" +#include "qwt_interval.h" +#include class QwtLinearColorMap::ColorStops { public: ColorStops() { -#if QT_VERSION >= 0x040000 - _stops.reserve(256); -#endif + _stops.reserve( 256 ); } - void insert(double pos, const QColor &color); - QRgb rgb(QwtLinearColorMap::Mode, double pos) const; + void insert( double pos, const QColor &color ); + QRgb rgb( QwtLinearColorMap::Mode, double pos ) const; - QwtArray stops() const; + QVector stops() const; private: @@ -40,18 +31,18 @@ private: { public: ColorStop(): - pos(0.0), - rgb(0) + pos( 0.0 ), + rgb( 0 ) { }; - ColorStop(double p, const QColor &c): - pos(p), - rgb(c.rgb()) + ColorStop( double p, const QColor &c ): + pos( p ), + rgb( c.rgb() ) { - r = qRed(rgb); - g = qGreen(rgb); - b = qBlue(rgb); + r = qRed( rgb ); + g = qGreen( rgb ); + b = qBlue( rgb ); } double pos; @@ -59,11 +50,11 @@ private: int r, g, b; }; - inline int findUpper(double pos) const; - QwtArray _stops; + inline int findUpper( double pos ) const; + QVector _stops; }; -void QwtLinearColorMap::ColorStops::insert(double pos, const QColor &color) +void QwtLinearColorMap::ColorStops::insert( double pos, const QColor &color ) { // Lookups need to be very fast, insertions are not so important. // Anyway, a balanced tree is what we need here. TODO ... @@ -75,57 +66,49 @@ void QwtLinearColorMap::ColorStops::insert(double pos, const QColor &color) if ( _stops.size() == 0 ) { index = 0; -#if QT_VERSION < 0x040000 - _stops.resize(1, QGArray::SpeedOptim); -#else - _stops.resize(1); -#endif + _stops.resize( 1 ); } else { - index = findUpper(pos); - if ( index == (int)_stops.size() || - qwtAbs(_stops[index].pos - pos) >= 0.001 ) + index = findUpper( pos ); + if ( index == _stops.size() || + qAbs( _stops[index].pos - pos ) >= 0.001 ) { -#if QT_VERSION < 0x040000 - _stops.resize(_stops.size() + 1, QGArray::SpeedOptim); -#else - _stops.resize(_stops.size() + 1); -#endif + _stops.resize( _stops.size() + 1 ); for ( int i = _stops.size() - 1; i > index; i-- ) _stops[i] = _stops[i-1]; } } - _stops[index] = ColorStop(pos, color); + _stops[index] = ColorStop( pos, color ); } -inline QwtArray QwtLinearColorMap::ColorStops::stops() const +inline QVector QwtLinearColorMap::ColorStops::stops() const { - QwtArray positions(_stops.size()); - for ( int i = 0; i < (int)_stops.size(); i++ ) + QVector positions( _stops.size() ); + for ( int i = 0; i < _stops.size(); i++ ) positions[i] = _stops[i].pos; return positions; } -inline int QwtLinearColorMap::ColorStops::findUpper(double pos) const +inline int QwtLinearColorMap::ColorStops::findUpper( double pos ) const { int index = 0; int n = _stops.size(); const ColorStop *stops = _stops.data(); - - while (n > 0) + + while ( n > 0 ) { const int half = n >> 1; const int middle = index + half; - if ( stops[middle].pos <= pos ) + if ( stops[middle].pos <= pos ) { index = middle + 1; n -= half + 1; - } - else + } + else n = half; } @@ -133,14 +116,14 @@ inline int QwtLinearColorMap::ColorStops::findUpper(double pos) const } inline QRgb QwtLinearColorMap::ColorStops::rgb( - QwtLinearColorMap::Mode mode, double pos) const + QwtLinearColorMap::Mode mode, double pos ) const { if ( pos <= 0.0 ) return _stops[0].rgb; if ( pos >= 1.0 ) - return _stops[(int)(_stops.size() - 1)].rgb; + return _stops[ _stops.size() - 1 ].rgb; - const int index = findUpper(pos); + const int index = findUpper( pos ); if ( mode == FixedColors ) { return _stops[index-1].rgb; @@ -150,19 +133,19 @@ inline QRgb QwtLinearColorMap::ColorStops::rgb( const ColorStop &s1 = _stops[index-1]; const ColorStop &s2 = _stops[index]; - const double ratio = (pos - s1.pos) / (s2.pos - s1.pos); + const double ratio = ( pos - s1.pos ) / ( s2.pos - s1.pos ); - const int r = s1.r + qRound(ratio * (s2.r - s1.r)); - const int g = s1.g + qRound(ratio * (s2.g - s1.g)); - const int b = s1.b + qRound(ratio * (s2.b - s1.b)); - - return qRgb(r, g, b); + const int r = s1.r + qRound( ratio * ( s2.r - s1.r ) ); + const int g = s1.g + qRound( ratio * ( s2.g - s1.g ) ); + const int b = s1.b + qRound( ratio * ( s2.b - s1.b ) ); + + return qRgb( r, g, b ); } } //! Constructor -QwtColorMap::QwtColorMap(Format format): - d_format(format) +QwtColorMap::QwtColorMap( Format format ): + d_format( format ) { } @@ -175,21 +158,20 @@ QwtColorMap::~QwtColorMap() Build and return a color map of 256 colors The color table is needed for rendering indexed images in combination - with using colorIndex(). + with using colorIndex(). \param interval Range for the values \return A color table, that can be used for a QImage */ -QwtColorTable QwtColorMap::colorTable( - const QwtDoubleInterval &interval) const +QVector QwtColorMap::colorTable( const QwtInterval &interval ) const { - QwtColorTable table(256); + QVector table( 256 ); if ( interval.isValid() ) { - const double step = interval.width() / (table.size() - 1); - for ( int i = 0; i < (int) table.size(); i++ ) - table[i] = rgb(interval, interval.minValue() + step * i); + const double step = interval.width() / ( table.size() - 1 ); + for ( int i = 0; i < table.size(); i++ ) + table[i] = rgb( interval, interval.minValue() + step * i ); } return table; @@ -202,43 +184,35 @@ public: QwtLinearColorMap::Mode mode; }; -/*! +/*! Build a color map with two stops at 0.0 and 1.0. The color at 0.0 is Qt::blue, at 1.0 it is Qt::yellow. \param format Preferred format of the color map */ -QwtLinearColorMap::QwtLinearColorMap(QwtColorMap::Format format): - QwtColorMap(format) +QwtLinearColorMap::QwtLinearColorMap( QwtColorMap::Format format ): + QwtColorMap( format ) { d_data = new PrivateData; d_data->mode = ScaledColors; - setColorInterval( Qt::blue, Qt::yellow); -} - -//! Copy constructor -QwtLinearColorMap::QwtLinearColorMap(const QwtLinearColorMap &other): - QwtColorMap(other) -{ - d_data = new PrivateData; - *this = other; + setColorInterval( Qt::blue, Qt::yellow ); } /*! - Build a color map with two stops at 0.0 and 1.0. + Build a color map with two stops at 0.0 and 1.0. \param color1 Color used for the minimum value of the value interval \param color2 Color used for the maximum value of the value interval \param format Preferred format of the coor map */ -QwtLinearColorMap::QwtLinearColorMap(const QColor &color1, - const QColor &color2, QwtColorMap::Format format): - QwtColorMap(format) +QwtLinearColorMap::QwtLinearColorMap( const QColor &color1, + const QColor &color2, QwtColorMap::Format format ): + QwtColorMap( format ) { d_data = new PrivateData; d_data->mode = ScaledColors; - setColorInterval(color1, color2); + setColorInterval( color1, color2 ); } //! Destructor @@ -247,34 +221,16 @@ QwtLinearColorMap::~QwtLinearColorMap() delete d_data; } -//! Assignment operator -QwtLinearColorMap &QwtLinearColorMap::operator=( - const QwtLinearColorMap &other) -{ - QwtColorMap::operator=(other); - *d_data = *other.d_data; - return *this; -} - -//! Clone the color map -QwtColorMap *QwtLinearColorMap::copy() const -{ - QwtLinearColorMap* map = new QwtLinearColorMap(); - *map = *this; - - return map; -} - /*! \brief Set the mode of the color map FixedColors means the color is calculated from the next lower color stop. ScaledColors means the color is calculated - by interpolating the colors of the adjacent stops. + by interpolating the colors of the adjacent stops. \sa mode() */ -void QwtLinearColorMap::setMode(Mode mode) +void QwtLinearColorMap::setMode( Mode mode ) { d_data->mode = mode; } @@ -289,9 +245,9 @@ QwtLinearColorMap::Mode QwtLinearColorMap::mode() const } /*! - Set the color range + Set the color range - Add stops at 0.0 and 1.0. + Add stops at 0.0 and 1.0. \param color1 Color used for the minimum value of the value interval \param color2 Color used for the maximum value of the value interval @@ -299,53 +255,53 @@ QwtLinearColorMap::Mode QwtLinearColorMap::mode() const \sa color1(), color2() */ void QwtLinearColorMap::setColorInterval( - const QColor &color1, const QColor &color2) + const QColor &color1, const QColor &color2 ) { d_data->colorStops = ColorStops(); - d_data->colorStops.insert(0.0, color1); - d_data->colorStops.insert(1.0, color2); + d_data->colorStops.insert( 0.0, color1 ); + d_data->colorStops.insert( 1.0, color2 ); } /*! Add a color stop - The value has to be in the range [0.0, 1.0]. + The value has to be in the range [0.0, 1.0]. F.e. a stop at position 17.0 for a range [10.0,20.0] must be passed as: (17.0 - 10.0) / (20.0 - 10.0) \param value Value between [0.0, 1.0] \param color Color stop */ -void QwtLinearColorMap::addColorStop(double value, const QColor& color) +void QwtLinearColorMap::addColorStop( double value, const QColor& color ) { if ( value >= 0.0 && value <= 1.0 ) - d_data->colorStops.insert(value, color); + d_data->colorStops.insert( value, color ); } /*! Return all positions of color stops in increasing order */ -QwtArray QwtLinearColorMap::colorStops() const +QVector QwtLinearColorMap::colorStops() const { return d_data->colorStops.stops(); } -/*! +/*! \return the first color of the color range \sa setColorInterval() */ QColor QwtLinearColorMap::color1() const { - return QColor(d_data->colorStops.rgb(d_data->mode, 0.0)); + return QColor( d_data->colorStops.rgb( d_data->mode, 0.0 ) ); } -/*! +/*! \return the second color of the color range \sa setColorInterval() */ QColor QwtLinearColorMap::color2() const { - return QColor(d_data->colorStops.rgb(d_data->mode, 1.0)); + return QColor( d_data->colorStops.rgb( d_data->mode, 1.0 ) ); } /*! @@ -355,15 +311,18 @@ QColor QwtLinearColorMap::color2() const \param value Value to map into a rgb value */ QRgb QwtLinearColorMap::rgb( - const QwtDoubleInterval &interval, double value) const + const QwtInterval &interval, double value ) const { + if ( qIsNaN(value) ) + return qRgba(0, 0, 0, 0); + const double width = interval.width(); double ratio = 0.0; if ( width > 0.0 ) - ratio = (value - interval.minValue()) / width; + ratio = ( value - interval.minValue() ) / width; - return d_data->colorStops.rgb(d_data->mode, ratio); + return d_data->colorStops.rgb( d_data->mode, ratio ); } /*! @@ -373,23 +332,23 @@ QRgb QwtLinearColorMap::rgb( \param value Value to map into a color index */ unsigned char QwtLinearColorMap::colorIndex( - const QwtDoubleInterval &interval, double value) const + const QwtInterval &interval, double value ) const { const double width = interval.width(); - if ( width <= 0.0 || value <= interval.minValue() ) + if ( qIsNaN(value) || width <= 0.0 || value <= interval.minValue() ) return 0; if ( value >= interval.maxValue() ) - return (unsigned char)255; + return ( unsigned char )255; + + const double ratio = ( value - interval.minValue() ) / width; - const double ratio = (value - interval.minValue()) / width; - unsigned char index; if ( d_data->mode == FixedColors ) - index = (unsigned char)(ratio * 255); // always floor + index = ( unsigned char )( ratio * 255 ); // always floor else - index = (unsigned char)qRound(ratio * 255); + index = ( unsigned char )qRound( ratio * 255 ); return index; } @@ -402,27 +361,16 @@ public: }; -/*! +/*! Constructor \param color Color of the map */ -QwtAlphaColorMap::QwtAlphaColorMap(const QColor &color): - QwtColorMap(QwtColorMap::RGB) +QwtAlphaColorMap::QwtAlphaColorMap( const QColor &color ): + QwtColorMap( QwtColorMap::RGB ) { d_data = new PrivateData; d_data->color = color; - d_data->rgb = color.rgb() & qRgba(255, 255, 255, 0); -} - -/*! - Copy constructor - \param other Other color map -*/ -QwtAlphaColorMap::QwtAlphaColorMap(const QwtAlphaColorMap &other): - QwtColorMap(other) -{ - d_data = new PrivateData; - *this = other; + d_data->rgb = color.rgb() & qRgba( 255, 255, 255, 0 ); } //! Destructor @@ -431,42 +379,20 @@ QwtAlphaColorMap::~QwtAlphaColorMap() delete d_data; } -/*! - Assignment operator - \param other Other color map - \return *this -*/ -QwtAlphaColorMap &QwtAlphaColorMap::operator=( - const QwtAlphaColorMap &other) -{ - QwtColorMap::operator=(other); - *d_data = *other.d_data; - return *this; -} - -//! Clone the color map -QwtColorMap *QwtAlphaColorMap::copy() const -{ - QwtAlphaColorMap* map = new QwtAlphaColorMap(); - *map = *this; - - return map; -} - /*! - Set the color + Set the color \param color Color \sa color() */ -void QwtAlphaColorMap::setColor(const QColor &color) +void QwtAlphaColorMap::setColor( const QColor &color ) { d_data->color = color; d_data->rgb = color.rgb(); } -/*! - \return the color +/*! + \return the color \sa setColor() */ QColor QwtAlphaColorMap::color() const @@ -483,33 +409,32 @@ QColor QwtAlphaColorMap::color() const \param value Value to map into a rgb value \return rgb value, with an alpha value */ -QRgb QwtAlphaColorMap::rgb(const QwtDoubleInterval &interval, - double value) const +QRgb QwtAlphaColorMap::rgb( const QwtInterval &interval, double value ) const { const double width = interval.width(); - if ( width >= 0.0 ) + if ( !qIsNaN(value) && width >= 0.0 ) { - const double ratio = (value - interval.minValue()) / width; - int alpha = qRound(255 * ratio); + const double ratio = ( value - interval.minValue() ) / width; + int alpha = qRound( 255 * ratio ); if ( alpha < 0 ) alpha = 0; if ( alpha > 255 ) alpha = 255; - return d_data->rgb | (alpha << 24); + return d_data->rgb | ( alpha << 24 ); } return d_data->rgb; } /*! Dummy function, needed to be implemented as it is pure virtual - in QwtColorMap. Color indices make no sense in combination with + in QwtColorMap. Color indices make no sense in combination with an alpha channel. \return Always 0 */ unsigned char QwtAlphaColorMap::colorIndex( - const QwtDoubleInterval &, double) const + const QwtInterval &, double ) const { return 0; } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_color_map.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_color_map.h index 5a4f32570..a59530c3f 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_color_map.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_color_map.h @@ -10,27 +10,16 @@ #ifndef QWT_COLOR_MAP_H #define QWT_COLOR_MAP_H -#include +#include "qwt_global.h" +#include "qwt_interval.h" #include -#if QT_VERSION < 0x040000 -#include -#else #include -#endif -#include "qwt_array.h" -#include "qwt_double_interval.h" - -#if defined(QWT_TEMPLATEDLL) -// MOC_SKIP_BEGIN -template class QWT_EXPORT QwtArray; -// MOC_SKIP_END -#endif /*! - \brief QwtColorMap is used to map values into colors. + \brief QwtColorMap is used to map values into colors. For displaying 3D data on a 2D plane the 3rd dimension is often - displayed using colors, like f.e in a spectrogram. + displayed using colors, like f.e in a spectrogram. Each color map is optimized to return colors for only one of the following image formats: @@ -44,69 +33,59 @@ template class QWT_EXPORT QwtArray; class QWT_EXPORT QwtColorMap { public: - /*! - - RGB\n - The map is intended to map into QRgb values. - - Indexed\n - The map is intended to map into 8 bit values, that - are indices into the color table. - + /*! + Format for color mapping \sa rgb(), colorIndex(), colorTable() */ enum Format { + //! The map is intended to map into QRgb values. RGB, + + /*! + The map is intended to map into 8 bit values, that + are indices into the color table. + */ Indexed }; - QwtColorMap(Format = QwtColorMap::RGB ); + QwtColorMap( Format = QwtColorMap::RGB ); virtual ~QwtColorMap(); - inline Format format() const; + Format format() const; - //! Clone the color map - virtual QwtColorMap *copy() const = 0; - - /*! + /*! Map a value of a given interval into a rgb value. \param interval Range for the values \param value Value \return rgb value, corresponding to value */ - virtual QRgb rgb( - const QwtDoubleInterval &interval, double value) const = 0; + virtual QRgb rgb( const QwtInterval &interval, + double value ) const = 0; - /*! + /*! Map a value of a given interval into a color index \param interval Range for the values \param value Value \return color index, corresponding to value */ virtual unsigned char colorIndex( - const QwtDoubleInterval &interval, double value) const = 0; + const QwtInterval &interval, double value ) const = 0; - QColor color(const QwtDoubleInterval &, double value) const; -#if QT_VERSION < 0x040000 - virtual QValueVector colorTable(const QwtDoubleInterval &) const; -#else - virtual QVector colorTable(const QwtDoubleInterval &) const; -#endif + QColor color( const QwtInterval &, double value ) const; + virtual QVector colorTable( const QwtInterval & ) const; private: Format d_format; }; - /*! \brief QwtLinearColorMap builds a color map from color stops. - + A color stop is a color at a specific position. The valid range for the positions is [0.0, 1.0]. When mapping a value - into a color it is translated into this interval. If - mode() == FixedColors the color is calculated from the next lower - color stop. If mode() == ScaledColors the color is calculated - by interpolating the colors of the adjacent stops. + into a color it is translated into this interval according to mode(). */ class QWT_EXPORT QwtLinearColorMap: public QwtColorMap { @@ -117,39 +96,40 @@ public: */ enum Mode { + //! Return the color from the next lower color stop FixedColors, + + //! Interpolating the colors of the adjacent stops. ScaledColors }; - QwtLinearColorMap(QwtColorMap::Format = QwtColorMap::RGB); + QwtLinearColorMap( QwtColorMap::Format = QwtColorMap::RGB ); QwtLinearColorMap( const QColor &from, const QColor &to, - QwtColorMap::Format = QwtColorMap::RGB); - - QwtLinearColorMap(const QwtLinearColorMap &); + QwtColorMap::Format = QwtColorMap::RGB ); virtual ~QwtLinearColorMap(); - QwtLinearColorMap &operator=(const QwtLinearColorMap &); - - virtual QwtColorMap *copy() const; - - void setMode(Mode); + void setMode( Mode ); Mode mode() const; - void setColorInterval(const QColor &color1, const QColor &color2); - void addColorStop(double value, const QColor&); - QwtArray colorStops() const; + void setColorInterval( const QColor &color1, const QColor &color2 ); + void addColorStop( double value, const QColor& ); + QVector colorStops() const; QColor color1() const; QColor color2() const; - virtual QRgb rgb(const QwtDoubleInterval &, double value) const; + virtual QRgb rgb( const QwtInterval &, double value ) const; virtual unsigned char colorIndex( - const QwtDoubleInterval &, double value) const; + const QwtInterval &, double value ) const; class ColorStops; private: + // Disabled copy constructor and operator= + QwtLinearColorMap( const QwtLinearColorMap & ); + QwtLinearColorMap &operator=( const QwtLinearColorMap & ); + class PrivateData; PrivateData *d_data; }; @@ -160,23 +140,20 @@ private: class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap { public: - QwtAlphaColorMap(const QColor & = QColor(Qt::gray)); - QwtAlphaColorMap(const QwtAlphaColorMap &); - + QwtAlphaColorMap( const QColor & = QColor( Qt::gray ) ); virtual ~QwtAlphaColorMap(); - QwtAlphaColorMap &operator=(const QwtAlphaColorMap &); - - virtual QwtColorMap *copy() const; - - void setColor(const QColor &); + void setColor( const QColor & ); QColor color() const; - virtual QRgb rgb(const QwtDoubleInterval &, double value) const; + virtual QRgb rgb( const QwtInterval &, double value ) const; private: + QwtAlphaColorMap( const QwtAlphaColorMap & ); + QwtAlphaColorMap &operator=( const QwtAlphaColorMap & ); + virtual unsigned char colorIndex( - const QwtDoubleInterval &, double value) const; + const QwtInterval &, double value ) const; class PrivateData; PrivateData *d_data; @@ -196,16 +173,16 @@ private: color table once and find the color using colorIndex(). */ inline QColor QwtColorMap::color( - const QwtDoubleInterval &interval, double value) const + const QwtInterval &interval, double value ) const { if ( d_format == RGB ) { - return QColor( rgb(interval, value) ); + return QColor( rgb( interval, value ) ); } else { - const unsigned int index = colorIndex(interval, value); - return colorTable(interval)[index]; // slow + const unsigned int index = colorIndex( interval, value ); + return colorTable( interval )[index]; // slow } } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_column_symbol.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_column_symbol.cpp new file mode 100644 index 000000000..f46d79ad7 --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_column_symbol.cpp @@ -0,0 +1,296 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#include "qwt_column_symbol.h" +#include "qwt_math.h" +#include "qwt_text.h" +#include "qwt_painter.h" +#include +#include + +static void drawBox( QPainter *p, const QRectF &rect, + const QPalette &pal, double lw ) +{ + if ( lw > 0.0 ) + { + if ( rect.width() == 0.0 ) + { + p->setPen( pal.dark().color() ); + p->drawLine( rect.topLeft(), rect.bottomLeft() ); + return; + } + + if ( rect.height() == 0.0 ) + { + p->setPen( pal.dark().color() ); + p->drawLine( rect.topLeft(), rect.topRight() ); + return; + } + + lw = qMin( lw, rect.height() / 2.0 - 1.0 ); + lw = qMin( lw, rect.width() / 2.0 - 1.0 ); + + const QRectF outerRect = rect.adjusted( 0, 0, 1, 1 ); + QPolygonF polygon( outerRect ); + + if ( outerRect.width() > 2 * lw && + outerRect.height() > 2 * lw ) + { + const QRectF innerRect = outerRect.adjusted( lw, lw, -lw, -lw ); + polygon = polygon.subtracted( innerRect ); + } + + p->setPen( Qt::NoPen ); + + p->setBrush( pal.dark() ); + p->drawPolygon( polygon ); + } + + const QRectF windowRect = rect.adjusted( lw, lw, -lw + 1, -lw + 1 ); + if ( windowRect.isValid() ) + p->fillRect( windowRect, pal.window() ); +} + +static void drawPanel( QPainter *painter, const QRectF &rect, + const QPalette &pal, double lw ) +{ + if ( lw > 0.0 ) + { + if ( rect.width() == 0.0 ) + { + painter->setPen( pal.window().color() ); + painter->drawLine( rect.topLeft(), rect.bottomLeft() ); + return; + } + + if ( rect.height() == 0.0 ) + { + painter->setPen( pal.window().color() ); + painter->drawLine( rect.topLeft(), rect.topRight() ); + return; + } + + lw = qMin( lw, rect.height() / 2.0 - 1.0 ); + lw = qMin( lw, rect.width() / 2.0 - 1.0 ); + + const QRectF outerRect = rect.adjusted( 0, 0, 1, 1 ); + const QRectF innerRect = outerRect.adjusted( lw, lw, -lw, -lw ); + + QPolygonF lines[2]; + + lines[0] += outerRect.bottomLeft(); + lines[0] += outerRect.topLeft(); + lines[0] += outerRect.topRight(); + lines[0] += innerRect.topRight(); + lines[0] += innerRect.topLeft(); + lines[0] += innerRect.bottomLeft(); + + lines[1] += outerRect.topRight(); + lines[1] += outerRect.bottomRight(); + lines[1] += outerRect.bottomLeft(); + lines[1] += innerRect.bottomLeft(); + lines[1] += innerRect.bottomRight(); + lines[1] += innerRect.topRight(); + + painter->setPen( Qt::NoPen ); + + painter->setBrush( pal.light() ); + painter->drawPolygon( lines[0] ); + painter->setBrush( pal.dark() ); + painter->drawPolygon( lines[1] ); + } + + painter->fillRect( rect.adjusted( lw, lw, -lw + 1, -lw + 1 ), pal.window() ); +} + +class QwtColumnSymbol::PrivateData +{ +public: + PrivateData(): + style( QwtColumnSymbol::Box ), + frameStyle( QwtColumnSymbol::Raised ), + lineWidth( 2 ) + { + palette = QPalette( Qt::gray ); + } + + QwtColumnSymbol::Style style; + QwtColumnSymbol::FrameStyle frameStyle; + + QPalette palette; + QwtText label; + + int lineWidth; +}; + +/*! + Constructor + + \param style Style of the symbol + \sa setStyle(), style(), Style +*/ +QwtColumnSymbol::QwtColumnSymbol( Style style ) +{ + d_data = new PrivateData(); + d_data->style = style; +} + +//! Destructor +QwtColumnSymbol::~QwtColumnSymbol() +{ + delete d_data; +} + +/*! + Specify the symbol style + + \param style Style + \sa style(), setPalette() +*/ +void QwtColumnSymbol::setStyle( Style style ) +{ + d_data->style = style; +} + +/*! + \return Current symbol style + \sa setStyle() +*/ +QwtColumnSymbol::Style QwtColumnSymbol::style() const +{ + return d_data->style; +} + +/*! + Assign a palette for the symbol + + \param palette Palette + \sa palette(), setStyle() +*/ +void QwtColumnSymbol::setPalette( const QPalette &palette ) +{ + d_data->palette = palette; +} + +/*! + \return Current palette + \sa setPalette() +*/ +const QPalette& QwtColumnSymbol::palette() const +{ + return d_data->palette; +} + +/*! + Set the frame, that is used for the Box style. + + \param frameStyle Frame style + \sa frameStyle(), setLineWidth(), setStyle() +*/ +void QwtColumnSymbol::setFrameStyle( FrameStyle frameStyle ) +{ + d_data->frameStyle = frameStyle; +} + +/*! + \return Current frame style, that is used for the Box style. + \sa setFrameStyle(), lineWidth(), setStyle() +*/ +QwtColumnSymbol::FrameStyle QwtColumnSymbol::frameStyle() const +{ + return d_data->frameStyle; +} + +/*! + Set the line width of the frame, that is used for the Box style. + + \param width Width + \sa lineWidth(), setFrameStyle() +*/ +void QwtColumnSymbol::setLineWidth( int width ) +{ + if ( width < 0 ) + width = 0; + + d_data->lineWidth = width; +} + +/*! + \return Line width of the frame, that is used for the Box style. + \sa setLineWidth(), frameStyle(), setStyle() +*/ +int QwtColumnSymbol::lineWidth() const +{ + return d_data->lineWidth; +} + +/*! + Draw the symbol depending on its style. + + \param painter Painter + \param rect Directed rectangle + + \sa drawBox() +*/ +void QwtColumnSymbol::draw( QPainter *painter, + const QwtColumnRect &rect ) const +{ + painter->save(); + + switch ( d_data->style ) + { + case QwtColumnSymbol::Box: + { + drawBox( painter, rect ); + break; + } + default:; + } + + painter->restore(); +} + +/*! + Draw the symbol when it is in Box style. + + \param painter Painter + \param rect Directed rectangle + + \sa draw() +*/ +void QwtColumnSymbol::drawBox( QPainter *painter, + const QwtColumnRect &rect ) const +{ + QRectF r = rect.toRect(); + if ( QwtPainter::roundingAlignment( painter ) ) + { + r.setLeft( qRound( r.left() ) ); + r.setRight( qRound( r.right() ) ); + r.setTop( qRound( r.top() ) ); + r.setBottom( qRound( r.bottom() ) ); + } + + switch ( d_data->frameStyle ) + { + case QwtColumnSymbol::Raised: + { + ::drawPanel( painter, r, d_data->palette, d_data->lineWidth ); + break; + } + case QwtColumnSymbol::Plain: + { + ::drawBox( painter, r, d_data->palette, d_data->lineWidth ); + break; + } + default: + { + painter->fillRect( r, d_data->palette.window() ); + } + } +} diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_column_symbol.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_column_symbol.h new file mode 100644 index 000000000..5c38960a3 --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_column_symbol.h @@ -0,0 +1,161 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#ifndef QWT_COLUMN_SYMBOL_H +#define QWT_COLUMN_SYMBOL_H + +#include "qwt_global.h" +#include "qwt_interval.h" +#include +#include +#include + +class QPainter; +class QPalette; +class QRect; +class QwtText; + +/*! + \brief Directed rectangle representing bounding rectangle und orientation + of a column. +*/ +class QWT_EXPORT QwtColumnRect +{ +public: + //! Direction of the column + enum Direction + { + //! From left to right + LeftToRight, + + //! From right to left + RightToLeft, + + //! From bottom to top + BottomToTop, + + //! From top to bottom + TopToBottom + }; + + //! Build an rectangle with invalid intervals directed BottomToTop. + QwtColumnRect(): + direction( BottomToTop ) + { + } + + //! \return A normalized QRect built from the intervals + QRectF toRect() const + { + QRectF r( hInterval.minValue(), vInterval.minValue(), + hInterval.maxValue() - hInterval.minValue(), + vInterval.maxValue() - vInterval.minValue() ); + r = r.normalized(); + + if ( hInterval.borderFlags() & QwtInterval::ExcludeMinimum ) + r.adjust( 1, 0, 0, 0 ); + if ( hInterval.borderFlags() & QwtInterval::ExcludeMaximum ) + r.adjust( 0, 0, -1, 0 ); + if ( vInterval.borderFlags() & QwtInterval::ExcludeMinimum ) + r.adjust( 0, 1, 0, 0 ); + if ( vInterval.borderFlags() & QwtInterval::ExcludeMaximum ) + r.adjust( 0, 0, 0, -1 ); + + return r; + } + + //! \return Orientation + Qt::Orientation orientation() const + { + if ( direction == LeftToRight || direction == RightToLeft ) + return Qt::Horizontal; + + return Qt::Vertical; + } + + //! Interval for the horizontal coordinates + QwtInterval hInterval; + + //! Interval for the vertical coordinates + QwtInterval vInterval; + + //! Direction + Direction direction; +}; + +//! A drawing primitive for columns +class QWT_EXPORT QwtColumnSymbol +{ +public: + /*! + Style + \sa setStyle(), style() + */ + enum Style + { + //! No Style, the symbol draws nothing + NoStyle = -1, + + /*! + The column is painted with a frame depending on the frameStyle() + and lineWidth() using the palette(). + */ + Box, + + /*! + Styles >= QwtColumnSymbol::UserStyle are reserved for derived + classes of QwtColumnSymbol that overload draw() with + additional application specific symbol types. + */ + UserStyle = 1000 + }; + + /*! + Frame Style used in Box style(). + \sa Style, setFrameStyle(), frameStyle(), setStyle(), setPalette() + */ + enum FrameStyle + { + //! No frame + NoFrame, + + //! A plain frame style + Plain, + + //! A raised frame style + Raised + }; + +public: + QwtColumnSymbol( Style = NoStyle ); + virtual ~QwtColumnSymbol(); + + void setFrameStyle( FrameStyle style ); + FrameStyle frameStyle() const; + + void setLineWidth( int width ); + int lineWidth() const; + + void setPalette( const QPalette & ); + const QPalette &palette() const; + + void setStyle( Style ); + Style style() const; + + virtual void draw( QPainter *, const QwtColumnRect & ) const; + +protected: + void drawBox( QPainter *, const QwtColumnRect & ) const; + +private: + class PrivateData; + PrivateData* d_data; +}; + +#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_compass.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_compass.cpp index ee94b619b..1aaf9f8bc 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_compass.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_compass.cpp @@ -7,25 +7,21 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - -#include +#include "qwt_compass.h" +#include "qwt_compass_rose.h" +#include "qwt_math.h" +#include "qwt_scale_draw.h" +#include "qwt_painter.h" +#include "qwt_dial_needle.h" #include #include #include -#include "qwt_math.h" -#include "qwt_scale_draw.h" -#include "qwt_paint_buffer.h" -#include "qwt_painter.h" -#include "qwt_dial_needle.h" -#include "qwt_compass_rose.h" -#include "qwt_compass.h" class QwtCompass::PrivateData { public: PrivateData(): - rose(NULL) + rose( NULL ) { } @@ -42,39 +38,19 @@ public: \brief Constructor \param parent Parent widget - Create a compass widget with a scale, no needle and no rose. + Create a compass widget with a scale, no needle and no rose. The default origin is 270.0 with no valid value. It accepts mouse and keyboard inputs and has no step size. The default mode is QwtDial::RotateNeedle. -*/ -QwtCompass::QwtCompass(QWidget* parent): - QwtDial(parent) +*/ +QwtCompass::QwtCompass( QWidget* parent ): + QwtDial( parent ) { initCompass(); } -#if QT_VERSION < 0x040000 - -/*! - \brief Constructor - \param parent Parent widget - \param name Object name - - Create a compass widget with a scale, no needle and no rose. - The default origin is 270.0 with no valid value. It accepts - mouse and keyboard inputs and has no step size. The default mode - is QwtDial::RotateNeedle. -*/ -QwtCompass::QwtCompass(QWidget* parent, const char *name): - QwtDial(parent, name) -{ - initCompass(); -} - -#endif - //! Destructor -QwtCompass::~QwtCompass() +QwtCompass::~QwtCompass() { delete d_data; } @@ -83,42 +59,43 @@ void QwtCompass::initCompass() { d_data = new PrivateData; - setScaleOptions(ScaleLabel); // Only labels, no backbone, no ticks + // Only labels, no backbone, no ticks + setScaleComponents( QwtAbstractScaleDraw::Labels ); - setOrigin(270.0); - setWrapping(true); + setOrigin( 270.0 ); + setWrapping( true ); - d_data->labelMap.insert(0.0, QString::fromLatin1("N")); - d_data->labelMap.insert(45.0, QString::fromLatin1("NE")); - d_data->labelMap.insert(90.0, QString::fromLatin1("E")); - d_data->labelMap.insert(135.0, QString::fromLatin1("SE")); - d_data->labelMap.insert(180.0, QString::fromLatin1("S")); - d_data->labelMap.insert(225.0, QString::fromLatin1("SW")); - d_data->labelMap.insert(270.0, QString::fromLatin1("W")); - d_data->labelMap.insert(315.0, QString::fromLatin1("NW")); + d_data->labelMap.insert( 0.0, QString::fromLatin1( "N" ) ); + d_data->labelMap.insert( 45.0, QString::fromLatin1( "NE" ) ); + d_data->labelMap.insert( 90.0, QString::fromLatin1( "E" ) ); + d_data->labelMap.insert( 135.0, QString::fromLatin1( "SE" ) ); + d_data->labelMap.insert( 180.0, QString::fromLatin1( "S" ) ); + d_data->labelMap.insert( 225.0, QString::fromLatin1( "SW" ) ); + d_data->labelMap.insert( 270.0, QString::fromLatin1( "W" ) ); + d_data->labelMap.insert( 315.0, QString::fromLatin1( "NW" ) ); #if 0 - d_data->labelMap.insert(22.5, QString::fromLatin1("NNE")); - d_data->labelMap.insert(67.5, QString::fromLatin1("NEE")); - d_data->labelMap.insert(112.5, QString::fromLatin1("SEE")); - d_data->labelMap.insert(157.5, QString::fromLatin1("SSE")); - d_data->labelMap.insert(202.5, QString::fromLatin1("SSW")); - d_data->labelMap.insert(247.5, QString::fromLatin1("SWW")); - d_data->labelMap.insert(292.5, QString::fromLatin1("NWW")); - d_data->labelMap.insert(337.5, QString::fromLatin1("NNW")); + d_data->labelMap.insert( 22.5, QString::fromLatin1( "NNE" ) ); + d_data->labelMap.insert( 67.5, QString::fromLatin1( "NEE" ) ); + d_data->labelMap.insert( 112.5, QString::fromLatin1( "SEE" ) ); + d_data->labelMap.insert( 157.5, QString::fromLatin1( "SSE" ) ); + d_data->labelMap.insert( 202.5, QString::fromLatin1( "SSW" ) ); + d_data->labelMap.insert( 247.5, QString::fromLatin1( "SWW" ) ); + d_data->labelMap.insert( 292.5, QString::fromLatin1( "NWW" ) ); + d_data->labelMap.insert( 337.5, QString::fromLatin1( "NNW" ) ); #endif } -/*! +/*! Draw the contents of the scale \param painter Painter \param center Center of the content circle \param radius Radius of the content circle */ -void QwtCompass::drawScaleContents(QPainter *painter, - const QPoint ¢er, int radius) const +void QwtCompass::drawScaleContents( QPainter *painter, + const QPointF ¢er, double radius ) const { QPalette::ColorGroup cg; if ( isEnabled() ) @@ -130,27 +107,27 @@ void QwtCompass::drawScaleContents(QPainter *painter, if ( isValid() ) { if ( mode() == RotateScale ) - north -= value(); + north -= value(); } const int margin = 4; - drawRose(painter, center, radius - margin, 360.0 - north, cg); + drawRose( painter, center, radius - margin, 360.0 - north, cg ); } /*! Draw the compass rose - + \param painter Painter \param center Center of the compass \param radius of the circle, where to paint the rose \param north Direction pointing north, in degrees counter clockwise \param cg Color group */ -void QwtCompass::drawRose(QPainter *painter, const QPoint ¢er, - int radius, double north, QPalette::ColorGroup cg) const +void QwtCompass::drawRose( QPainter *painter, const QPointF ¢er, + double radius, double north, QPalette::ColorGroup cg ) const { if ( d_data->rose ) - d_data->rose->draw(painter, center, radius, north, cg); + d_data->rose->draw( painter, center, radius, north, cg ); } /*! @@ -160,7 +137,7 @@ void QwtCompass::drawRose(QPainter *painter, const QPoint ¢er, set or in ~QwtCompass \sa rose() */ -void QwtCompass::setRose(QwtCompassRose *rose) +void QwtCompass::setRose( QwtCompassRose *rose ) { if ( rose != d_data->rose ) { @@ -172,25 +149,25 @@ void QwtCompass::setRose(QwtCompassRose *rose) } } -/*! +/*! \return rose \sa setRose() */ -const QwtCompassRose *QwtCompass::rose() const -{ - return d_data->rose; +const QwtCompassRose *QwtCompass::rose() const +{ + return d_data->rose; } -/*! +/*! \return rose \sa setRose() */ -QwtCompassRose *QwtCompass::rose() -{ - return d_data->rose; +QwtCompassRose *QwtCompass::rose() +{ + return d_data->rose; } -/*! +/*! Handles key events Beside the keys described in QwtDial::keyPressEvent numbers @@ -199,9 +176,9 @@ QwtCompassRose *QwtCompass::rose() \sa isReadOnly() */ -void QwtCompass::keyPressEvent(QKeyEvent *kev) +void QwtCompass::keyPressEvent( QKeyEvent *kev ) { - if (isReadOnly()) + if ( isReadOnly() ) return; #if 0 @@ -219,39 +196,39 @@ void QwtCompass::keyPressEvent(QKeyEvent *kev) if ( mode() != RotateNeedle || kev->key() == Qt::Key_5 ) return; - switch (kev->key()) + switch ( kev->key() ) { - case Qt::Key_6: + case Qt::Key_6: newValue = 180.0 * 0.0; break; - case Qt::Key_3: + case Qt::Key_3: newValue = 180.0 * 0.25; break; - case Qt::Key_2: + case Qt::Key_2: newValue = 180.0 * 0.5; break; - case Qt::Key_1: + case Qt::Key_1: newValue = 180.0 * 0.75; break; - case Qt::Key_4: + case Qt::Key_4: newValue = 180.0 * 1.0; break; - case Qt::Key_7: + case Qt::Key_7: newValue = 180.0 * 1.25; break; - case Qt::Key_8: + case Qt::Key_8: newValue = 180.0 * 1.5; break; - case Qt::Key_9: + case Qt::Key_9: newValue = 180.0 * 1.75; break; } newValue -= origin(); - setValue(newValue); + setValue( newValue ); } else { - QwtDial::keyPressEvent(kev); + QwtDial::keyPressEvent( kev ); } } @@ -259,18 +236,18 @@ void QwtCompass::keyPressEvent(QKeyEvent *kev) \return map, mapping values to labels \sa setLabelMap() */ -const QMap &QwtCompass::labelMap() const -{ - return d_data->labelMap; +const QMap &QwtCompass::labelMap() const +{ + return d_data->labelMap; } /*! \return map, mapping values to labels \sa setLabelMap() */ -QMap &QwtCompass::labelMap() -{ - return d_data->labelMap; +QMap &QwtCompass::labelMap() +{ + return d_data->labelMap; } /*! @@ -285,9 +262,9 @@ QMap &QwtCompass::labelMap() \sa labelMap(), scaleDraw(), setScale() */ -void QwtCompass::setLabelMap(const QMap &map) -{ - d_data->labelMap = map; +void QwtCompass::setLabelMap( const QMap &map ) +{ + d_data->labelMap = map; } /*! @@ -300,18 +277,15 @@ void QwtCompass::setLabelMap(const QMap &map) \sa labelMap(), setLabelMap() */ -QwtText QwtCompass::scaleLabel(double value) const +QwtText QwtCompass::scaleLabel( double value ) const { -#if 0 - // better solution ??? - if ( value == -0 ) + if ( qFuzzyCompare( value, 0.0 ) ) value = 0.0; -#endif if ( value < 0.0 ) value += 360.0; - if ( d_data->labelMap.contains(value) ) + if ( d_data->labelMap.contains( value ) ) return d_data->labelMap[value]; return QwtText(); diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_compass.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_compass.h index 02772f934..294cb3b81 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_compass.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_compass.h @@ -10,27 +10,10 @@ #ifndef QWT_COMPASS_H #define QWT_COMPASS_H 1 +#include "qwt_global.h" +#include "qwt_dial.h" #include #include -#include "qwt_dial.h" - -#if defined(QWT_TEMPLATEDLL) - -#if defined(QT_NO_STL) || QT_VERSION < 0x040000 || QT_VERSION > 0x040001 -/* - Unfortunately Qt 4.0.0/Qt 4.0.1 contains uncompilable - code in the STL adaptors of qmap.h. The declaration below - instantiates this code resulting in compiler errors. - If you really need the map to be exported, remove the condition above - and fix the qmap.h -*/ -// MOC_SKIP_BEGIN -template class QWT_EXPORT QMap; -// MOC_SKIP_END -#endif - -#endif - class QwtCompassRose; @@ -38,42 +21,39 @@ class QwtCompassRose; \brief A Compass Widget QwtCompass is a widget to display and enter directions. It consists - of a scale, an optional needle and rose. + of a scale, an optional needle and rose. - \image html dials1.png + \image html dials1.png \note The examples/dials example shows how to use QwtCompass. */ -class QWT_EXPORT QwtCompass: public QwtDial +class QWT_EXPORT QwtCompass: public QwtDial { Q_OBJECT public: - explicit QwtCompass( QWidget* parent = NULL); -#if QT_VERSION < 0x040000 - explicit QwtCompass(QWidget* parent, const char *name); -#endif + explicit QwtCompass( QWidget* parent = NULL ); virtual ~QwtCompass(); - void setRose(QwtCompassRose *rose); + void setRose( QwtCompassRose *rose ); const QwtCompassRose *rose() const; QwtCompassRose *rose(); const QMap &labelMap() const; QMap &labelMap(); - void setLabelMap(const QMap &map); + void setLabelMap( const QMap &map ); protected: - virtual QwtText scaleLabel(double value) const; + virtual QwtText scaleLabel( double value ) const; - virtual void drawRose(QPainter *, const QPoint ¢er, - int radius, double north, QPalette::ColorGroup) const; + virtual void drawRose( QPainter *, const QPointF ¢er, + double radius, double north, QPalette::ColorGroup ) const; - virtual void drawScaleContents(QPainter *, - const QPoint ¢er, int radius) const; + virtual void drawScaleContents( QPainter *, + const QPointF ¢er, double radius ) const; - virtual void keyPressEvent(QKeyEvent *); + virtual void keyPressEvent( QKeyEvent * ); private: void initCompass(); diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_compass_rose.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_compass_rose.cpp index 6f0b7df45..bc83c5663 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_compass_rose.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_compass_rose.cpp @@ -7,83 +7,93 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -#include -#include -#include "qwt_math.h" -#include "qwt_painter.h" #include "qwt_compass_rose.h" +#include "qwt_point_polar.h" +#include "qwt_painter.h" +#include -static QPoint cutPoint(QPoint p11, QPoint p12, QPoint p21, QPoint p22) +static QPointF qwtIntersection( + QPointF p11, QPointF p12, QPointF p21, QPointF p22 ) { - double dx1 = p12.x() - p11.x(); - double dy1 = p12.y() - p11.y(); - double dx2 = p22.x() - p21.x(); - double dy2 = p22.y() - p21.y(); + const QLineF line1( p11, p12 ); + const QLineF line2( p21, p22 ); - if ( dx1 == 0.0 && dx2 == 0.0 ) - return QPoint(); + QPointF pos; + if ( line1.intersect( line2, &pos ) == QLineF::NoIntersection ) + return QPointF(); - if ( dx1 == 0.0 ) - { - const double m = dy2 / dx2; - const double t = p21.y() - m * p21.x(); - return QPoint(p11.x(), qRound(m * p11.x() + t)); - } - - if ( dx2 == 0 ) - { - const double m = dy1 / dx1; - const double t = p11.y() - m * p11.x(); - return QPoint(p21.x(), qRound(m * p21.x() + t)); - } - - const double m1 = dy1 / dx1; - const double t1 = p11.y() - m1 * p11.x(); - - const double m2 = dy2 / dx2; - const double t2 = p21.y() - m2 * p21.x(); - - if ( m1 == m2 ) - return QPoint(); - - const double x = ( t2 - t1 ) / ( m1 - m2 ); - const double y = t1 + m1 * x; - - return QPoint(qRound(x), qRound(y)); + return pos; } +class QwtSimpleCompassRose::PrivateData +{ +public: + PrivateData(): + width( 0.2 ), + numThorns( 8 ), + numThornLevels( -1 ), + shrinkFactor( 0.9 ) + { + } + + double width; + int numThorns; + int numThornLevels; + double shrinkFactor; +}; + /*! Constructor \param numThorns Number of thorns \param numThornLevels Number of thorn levels */ -QwtSimpleCompassRose::QwtSimpleCompassRose(int numThorns, int numThornLevels): - d_width(0.2), - d_numThorns(numThorns), - d_numThornLevels(numThornLevels), - d_shrinkFactor(0.9) +QwtSimpleCompassRose::QwtSimpleCompassRose( + int numThorns, int numThornLevels ) { - const QColor dark(128,128,255); - const QColor light(192,255,255); - + d_data = new PrivateData(); + d_data->numThorns = numThorns; + d_data->numThornLevels = numThornLevels; + + const QColor dark( 128, 128, 255 ); + const QColor light( 192, 255, 255 ); + QPalette palette; for ( int i = 0; i < QPalette::NColorGroups; i++ ) { -#if QT_VERSION < 0x040000 - palette.setColor((QPalette::ColorGroup)i, - QColorGroup::Dark, dark); - palette.setColor((QPalette::ColorGroup)i, - QColorGroup::Light, light); -#else - palette.setColor((QPalette::ColorGroup)i, - QPalette::Dark, dark); - palette.setColor((QPalette::ColorGroup)i, - QPalette::Light, light); -#endif + palette.setColor( ( QPalette::ColorGroup )i, + QPalette::Dark, dark ); + palette.setColor( ( QPalette::ColorGroup )i, + QPalette::Light, light ); } - setPalette(palette); + setPalette( palette ); +} + +//! Destructor +QwtSimpleCompassRose::~QwtSimpleCompassRose() +{ + delete d_data; +} + +/*! + Set the Factor how to shrink the thorns with each level + The default value is 0.9. + + \sa shrinkFactor() +*/ +void QwtSimpleCompassRose::setShrinkFactor( double factor ) +{ + d_data->shrinkFactor = factor; +} + +/*! + \return Factor how to shrink the thorns with each level + \sa setShrinkFactor() +*/ +double QwtSimpleCompassRose::shrinkFactor() const +{ + return d_data->shrinkFactor; } /*! @@ -95,29 +105,14 @@ QwtSimpleCompassRose::QwtSimpleCompassRose(int numThorns, int numThornLevels): \param north Position \param cg Color group */ -void QwtSimpleCompassRose::draw(QPainter *painter, const QPoint ¢er, - int radius, double north, QPalette::ColorGroup cg) const +void QwtSimpleCompassRose::draw( QPainter *painter, const QPointF ¢er, + double radius, double north, QPalette::ColorGroup cg ) const { -#if QT_VERSION < 0x040000 - QColorGroup colorGroup; - switch(cg) - { - case QPalette::Disabled: - colorGroup = palette().disabled(); - case QPalette::Inactive: - colorGroup = palette().inactive(); - default: - colorGroup = palette().active(); - } - - drawRose(painter, colorGroup, center, radius, north, d_width, - d_numThorns, d_numThornLevels, d_shrinkFactor); -#else QPalette pal = palette(); - pal.setCurrentColorGroup(cg); - drawRose(painter, pal, center, radius, north, d_width, - d_numThorns, d_numThornLevels, d_shrinkFactor); -#endif + pal.setCurrentColorGroup( cg ); + + drawRose( painter, pal, center, radius, north, d_data->width, + d_data->numThorns, d_data->numThornLevels, d_data->shrinkFactor ); } /*! @@ -134,14 +129,10 @@ void QwtSimpleCompassRose::draw(QPainter *painter, const QPoint ¢er, \param shrinkFactor Factor to shrink the thorns with each level */ void QwtSimpleCompassRose::drawRose( - QPainter *painter, -#if QT_VERSION < 0x040000 - const QColorGroup &cg, -#else + QPainter *painter, const QPalette &palette, -#endif - const QPoint ¢er, int radius, double north, double width, - int numThorns, int numThornLevels, double shrinkFactor) + const QPointF ¢er, double radius, double north, double width, + int numThorns, int numThornLevels, double shrinkFactor ) { if ( numThorns < 4 ) numThorns = 4; @@ -160,11 +151,11 @@ void QwtSimpleCompassRose::drawRose( painter->save(); - painter->setPen(Qt::NoPen); + painter->setPen( Qt::NoPen ); for ( int j = 1; j <= numThornLevels; j++ ) { - double step = pow(2.0, j) * M_PI / (double)numThorns; + double step = qPow( 2.0, j ) * M_PI / numThorns; if ( step > M_PI_2 ) break; @@ -180,37 +171,30 @@ void QwtSimpleCompassRose::drawRose( leafWidth = 16; const double origin = north / 180.0 * M_PI; - for ( double angle = origin; - angle < 2.0 * M_PI + origin; angle += step) + for ( double angle = origin; + angle < 2.0 * M_PI + origin; angle += step ) { - const QPoint p = qwtPolar2Pos(center, r, angle); - QPoint p1 = qwtPolar2Pos(center, leafWidth, angle + M_PI_2); - QPoint p2 = qwtPolar2Pos(center, leafWidth, angle - M_PI_2); + const QPointF p = qwtPolar2Pos( center, r, angle ); + const QPointF p1 = qwtPolar2Pos( center, leafWidth, angle + M_PI_2 ); + const QPointF p2 = qwtPolar2Pos( center, leafWidth, angle - M_PI_2 ); + const QPointF p3 = qwtPolar2Pos( center, r, angle + step / 2.0 ); + const QPointF p4 = qwtPolar2Pos( center, r, angle - step / 2.0 ); - QwtPolygon pa(3); - pa.setPoint(0, center); - pa.setPoint(1, p); + QPainterPath darkPath; + darkPath.moveTo( center ); + darkPath.lineTo( p ); + darkPath.lineTo( qwtIntersection( center, p3, p1, p ) ); - QPoint p3 = qwtPolar2Pos(center, r, angle + step / 2.0); - p1 = cutPoint(center, p3, p1, p); - pa.setPoint(2, p1); -#if QT_VERSION < 0x040000 - painter->setBrush(cg.brush(QColorGroup::Dark)); -#else - painter->setBrush(palette.brush(QPalette::Dark)); -#endif - painter->drawPolygon(pa); + painter->setBrush( palette.brush( QPalette::Dark ) ); + painter->drawPath( darkPath ); - QPoint p4 = qwtPolar2Pos(center, r, angle - step / 2.0); - p2 = cutPoint(center, p4, p2, p); + QPainterPath lightPath; + lightPath.moveTo( center ); + lightPath.lineTo( p ); + lightPath.lineTo( qwtIntersection( center, p4, p2, p ) ); - pa.setPoint(2, p2); -#if QT_VERSION < 0x040000 - painter->setBrush(cg.brush(QColorGroup::Light)); -#else - painter->setBrush(palette.brush(QPalette::Light)); -#endif - painter->drawPolygon(pa); + painter->setBrush( palette.brush( QPalette::Light ) ); + painter->drawPath( lightPath ); } } painter->restore(); @@ -222,25 +206,30 @@ void QwtSimpleCompassRose::drawRose( \param width Width */ - -void QwtSimpleCompassRose::setWidth(double width) +void QwtSimpleCompassRose::setWidth( double width ) { - d_width = width; - if (d_width < 0.03) - d_width = 0.03; + d_data->width = width; + if ( d_data->width < 0.03 ) + d_data->width = 0.03; - if (d_width > 0.4) - d_width = 0.4; + if ( d_data->width > 0.4 ) + d_data->width = 0.4; +} + +//! \sa setWidth() +double QwtSimpleCompassRose::width() const +{ + return d_data->width; } /*! Set the number of thorns on one level - The number is aligned to a multiple of 4, with a minimum of 4 + The number is aligned to a multiple of 4, with a minimum of 4 \param numThorns Number of thorns \sa numThorns(), setNumThornLevels() */ -void QwtSimpleCompassRose::setNumThorns(int numThorns) +void QwtSimpleCompassRose::setNumThorns( int numThorns ) { if ( numThorns < 4 ) numThorns = 4; @@ -248,7 +237,7 @@ void QwtSimpleCompassRose::setNumThorns(int numThorns) if ( numThorns % 4 ) numThorns += 4 - numThorns % 4; - d_numThorns = numThorns; + d_data->numThorns = numThorns; } /*! @@ -257,7 +246,7 @@ void QwtSimpleCompassRose::setNumThorns(int numThorns) */ int QwtSimpleCompassRose::numThorns() const { - return d_numThorns; + return d_data->numThorns; } /*! @@ -266,9 +255,9 @@ int QwtSimpleCompassRose::numThorns() const \param numThornLevels Number of thorns levels \sa setNumThorns(), numThornLevels() */ -void QwtSimpleCompassRose::setNumThornLevels(int numThornLevels) +void QwtSimpleCompassRose::setNumThornLevels( int numThornLevels ) { - d_numThornLevels = numThornLevels; + d_data->numThornLevels = numThornLevels; } /*! @@ -277,5 +266,5 @@ void QwtSimpleCompassRose::setNumThornLevels(int numThornLevels) */ int QwtSimpleCompassRose::numThornLevels() const { - return d_numThornLevels; + return d_data->numThornLevels; } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_compass_rose.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_compass_rose.h index 649fa114f..8a8f1ce17 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_compass_rose.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_compass_rose.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -10,8 +10,8 @@ #ifndef QWT_COMPASS_ROSE_H #define QWT_COMPASS_ROSE_H 1 -#include #include "qwt_global.h" +#include class QPainter; @@ -21,13 +21,20 @@ class QPainter; class QWT_EXPORT QwtCompassRose { public: + //! Destructor virtual ~QwtCompassRose() {}; //! Assign a palette - virtual void setPalette(const QPalette &p) { d_palette = p; } + virtual void setPalette( const QPalette &p ) + { + d_palette = p; + } //! \return Current palette - const QPalette &palette() const { return d_palette; } + const QPalette &palette() const + { + return d_palette; + } /*! Draw the rose @@ -38,9 +45,9 @@ public: \param north Position \param colorGroup Color group */ - virtual void draw(QPainter *painter, const QPoint ¢er, - int radius, double north, - QPalette::ColorGroup colorGroup = QPalette::Active) const = 0; + virtual void draw( QPainter *painter, + const QPointF ¢er, double radius, double north, + QPalette::ColorGroup colorGroup = QPalette::Active ) const = 0; private: QPalette d_palette; @@ -52,39 +59,31 @@ private: class QWT_EXPORT QwtSimpleCompassRose: public QwtCompassRose { public: - QwtSimpleCompassRose(int numThorns = 8, int numThornLevels = -1); + QwtSimpleCompassRose( int numThorns = 8, int numThornLevels = -1 ); + virtual ~QwtSimpleCompassRose(); - void setWidth(double w); + void setWidth( double w ); + double width() const; - //! \sa setWidth() - double width() const { return d_width; } - - void setNumThorns(int count); + void setNumThorns( int count ); int numThorns() const; - void setNumThornLevels(int count); + void setNumThornLevels( int count ); int numThornLevels() const; - void setShrinkFactor(double factor) { d_shrinkFactor = factor; } - double shrinkFactor() const { return d_shrinkFactor; } + void setShrinkFactor( double factor ); + double shrinkFactor() const; - virtual void draw(QPainter *, const QPoint ¢er, int radius, - double north, QPalette::ColorGroup = QPalette::Active) const; + virtual void draw( QPainter *, const QPointF ¢er, double radius, + double north, QPalette::ColorGroup = QPalette::Active ) const; - static void drawRose(QPainter *, -#if QT_VERSION < 0x040000 - const QColorGroup &, -#else - const QPalette &, -#endif - const QPoint ¢er, int radius, double origin, double width, - int numThorns, int numThornLevels, double shrinkFactor); + static void drawRose( QPainter *, const QPalette &, + const QPointF ¢er, double radius, double origin, double width, + int numThorns, int numThornLevels, double shrinkFactor ); private: - double d_width; - int d_numThorns; - int d_numThornLevels; - double d_shrinkFactor; + class PrivateData; + PrivateData *d_data; }; -#endif // QWT_COMPASS_ROSE_H +#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_compat.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_compat.h new file mode 100644 index 000000000..81b45ca22 --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_compat.h @@ -0,0 +1,40 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#ifndef _QWT_COMPAT_H_ +#define _QWT_COMPAT_H_ + +#include "qwt_global.h" +#include +#include +#include +#include +#include +#include + +// A couple of definition for Qwt5 compatibility + +#define qwtMax qMax +#define qwtMin qMin +#define qwtAbs qAbs +#define qwtRound qRound + +#define QwtArray QVector + +typedef QList QwtValueList; +typedef QPointF QwtDoublePoint; +typedef QSizeF QwtDoubleSize; +typedef QRectF QwtDoubleRect; + +typedef QPolygon QwtPolygon; +typedef QPolygonF QwtPolygonF; +typedef QwtInterval QwtDoubleInterval; +typedef QwtPoint3D QwtDoublePoint3D; + +#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_counter.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_counter.cpp index 1f8eca6c3..bb7f201dd 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_counter.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_counter.cpp @@ -7,22 +7,20 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - +#include "qwt_arrow_button.h" +#include "qwt_math.h" +#include "qwt_counter.h" #include #include #include #include #include -#include "qwt_math.h" -#include "qwt_counter.h" -#include "qwt_arrow_button.h" class QwtCounter::PrivateData { public: PrivateData(): - editable(true) + editable( true ) { increment[Button1] = 1; increment[Button2] = 10; @@ -34,7 +32,7 @@ public: QLineEdit *valueEdit; int increment[ButtonCnt]; - int nButtons; + int numButtons; bool editable; }; @@ -47,96 +45,67 @@ public: \param parent */ -QwtCounter::QwtCounter(QWidget *parent): - QWidget(parent) +QwtCounter::QwtCounter( QWidget *parent ): + QWidget( parent ) { initCounter(); } -#if QT_VERSION < 0x040000 -/*! - The default number of buttons is set to 2. The default increments are: - \li Button 1: 1 step - \li Button 2: 10 steps - \li Button 3: 100 steps - - \param parent - */ -QwtCounter::QwtCounter(QWidget *parent, const char *name): - QWidget(parent, name) -{ - initCounter(); -} -#endif - void QwtCounter::initCounter() { d_data = new PrivateData; -#if QT_VERSION >= 0x040000 - using namespace Qt; -#endif + QHBoxLayout *layout = new QHBoxLayout( this ); + layout->setSpacing( 0 ); + layout->setMargin( 0 ); - QHBoxLayout *layout = new QHBoxLayout(this); - layout->setSpacing(0); - layout->setMargin(0); - - int i; - for(i = ButtonCnt - 1; i >= 0; i--) + for ( int i = ButtonCnt - 1; i >= 0; i-- ) { QwtArrowButton *btn = - new QwtArrowButton(i+1, Qt::DownArrow,this); - btn->setFocusPolicy(NoFocus); - btn->installEventFilter(this); - layout->addWidget(btn); + new QwtArrowButton( i + 1, Qt::DownArrow, this ); + btn->setFocusPolicy( Qt::NoFocus ); + btn->installEventFilter( this ); + layout->addWidget( btn ); - connect(btn, SIGNAL(released()), SLOT(btnReleased())); - connect(btn, SIGNAL(clicked()), SLOT(btnClicked())); + connect( btn, SIGNAL( released() ), SLOT( btnReleased() ) ); + connect( btn, SIGNAL( clicked() ), SLOT( btnClicked() ) ); d_data->buttonDown[i] = btn; } - d_data->valueEdit = new QLineEdit(this); - d_data->valueEdit->setReadOnly(false); - d_data->valueEdit->setValidator(new QDoubleValidator(d_data->valueEdit)); - layout->addWidget(d_data->valueEdit); + d_data->valueEdit = new QLineEdit( this ); + d_data->valueEdit->setReadOnly( false ); + d_data->valueEdit->setValidator( new QDoubleValidator( d_data->valueEdit ) ); + layout->addWidget( d_data->valueEdit ); -#if QT_VERSION >= 0x040000 - connect( d_data->valueEdit, SIGNAL(editingFinished()), - SLOT(textChanged()) ); -#else - connect( d_data->valueEdit, SIGNAL(returnPressed()), SLOT(textChanged()) ); - connect( d_data->valueEdit, SIGNAL(lostFocus()), SLOT(textChanged()) ); -#endif + connect( d_data->valueEdit, SIGNAL( editingFinished() ), + SLOT( textChanged() ) ); - layout->setStretchFactor(d_data->valueEdit, 10); + layout->setStretchFactor( d_data->valueEdit, 10 ); - for(i = 0; i < ButtonCnt; i++) + for ( int i = 0; i < ButtonCnt; i++ ) { -#if QT_VERSION >= 0x040000 - using namespace Qt; -#endif QwtArrowButton *btn = - new QwtArrowButton(i+1, Qt::UpArrow, this); - btn->setFocusPolicy(NoFocus); - btn->installEventFilter(this); - layout->addWidget(btn); + new QwtArrowButton( i + 1, Qt::UpArrow, this ); + btn->setFocusPolicy( Qt::NoFocus ); + btn->installEventFilter( this ); + layout->addWidget( btn ); + + connect( btn, SIGNAL( released() ), SLOT( btnReleased() ) ); + connect( btn, SIGNAL( clicked() ), SLOT( btnClicked() ) ); - connect(btn, SIGNAL(released()), SLOT(btnReleased())); - connect(btn, SIGNAL(clicked()), SLOT(btnClicked())); - d_data->buttonUp[i] = btn; } - setNumButtons(2); - setRange(0.0,1.0,0.001); - setValue(0.0); + setNumButtons( 2 ); + setRange( 0.0, 1.0, 0.001 ); + setValue( 0.0 ); setSizePolicy( - QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); + QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ) ); - setFocusProxy(d_data->valueEdit); - setFocusPolicy(StrongFocus); + setFocusProxy( d_data->valueEdit ); + setFocusPolicy( Qt::StrongFocus ); } //! Destructor @@ -145,35 +114,17 @@ QwtCounter::~QwtCounter() delete d_data; } -/*! - Sets the minimum width for the buttons -*/ -void QwtCounter::polish() -{ - const int w = d_data->valueEdit->fontMetrics().width("W") + 8; - - for ( int i = 0; i < ButtonCnt; i++ ) - { - d_data->buttonDown[i]->setMinimumWidth(w); - d_data->buttonUp[i]->setMinimumWidth(w); - } - -#if QT_VERSION < 0x040000 - QWidget::polish(); -#endif -} - //! Set from lineedit -void QwtCounter::textChanged() +void QwtCounter::textChanged() { - if ( !d_data->editable ) + if ( !d_data->editable ) return; bool converted = false; - const double value = d_data->valueEdit->text().toDouble(&converted); - if ( converted ) - setValue( value ); + const double value = d_data->valueEdit->text().toDouble( &converted ); + if ( converted ) + setValue( value ); } /** @@ -182,156 +133,152 @@ void QwtCounter::textChanged() \param editable true enables editing \sa editable() */ -void QwtCounter::setEditable(bool editable) +void QwtCounter::setEditable( bool editable ) { -#if QT_VERSION >= 0x040000 - using namespace Qt; -#endif - if ( editable == d_data->editable ) + if ( editable == d_data->editable ) return; d_data->editable = editable; - d_data->valueEdit->setReadOnly(!editable); + d_data->valueEdit->setReadOnly( !editable ); } //! returns whether the line edit is edatble. (default is yes) -bool QwtCounter::editable() const -{ +bool QwtCounter::editable() const +{ return d_data->editable; } /*! - Handle PolishRequest events + Handle PolishRequest events + \param event Event */ -bool QwtCounter::event ( QEvent * e ) +bool QwtCounter::event( QEvent *event ) { -#if QT_VERSION >= 0x040000 - if ( e->type() == QEvent::PolishRequest ) - polish(); -#endif - return QWidget::event(e); + if ( event->type() == QEvent::PolishRequest ) + { + const int w = d_data->valueEdit->fontMetrics().width( "W" ) + 8; + for ( int i = 0; i < ButtonCnt; i++ ) + { + d_data->buttonDown[i]->setMinimumWidth( w ); + d_data->buttonUp[i]->setMinimumWidth( w ); + } + } + + return QWidget::event( event ); } /*! Handle key events - - Ctrl + Qt::Key_Home + - Ctrl + Qt::Key_Home\n Step to minValue() - - Ctrl + Qt::Key_End + - Ctrl + Qt::Key_End\n Step to maxValue() - - Qt::Key_Up + - Qt::Key_Up\n Increment by incSteps(QwtCounter::Button1) - - Qt::Key_Down + - Qt::Key_Down\n Decrement by incSteps(QwtCounter::Button1) - - Qt::Key_PageUp + - Qt::Key_PageUp\n Increment by incSteps(QwtCounter::Button2) - - Qt::Key_PageDown + - Qt::Key_PageDown\n Decrement by incSteps(QwtCounter::Button2) - - Shift + Qt::Key_PageUp + - Shift + Qt::Key_PageUp\n Increment by incSteps(QwtCounter::Button3) - - Shift + Qt::Key_PageDown + - Shift + Qt::Key_PageDown\n Decrement by incSteps(QwtCounter::Button3) + + \param event Key event */ -void QwtCounter::keyPressEvent (QKeyEvent *e) +void QwtCounter::keyPressEvent ( QKeyEvent *event ) { bool accepted = true; - switch ( e->key() ) + switch ( event->key() ) { case Qt::Key_Home: -#if QT_VERSION >= 0x040000 - if ( e->modifiers() & Qt::ControlModifier ) -#else - if ( e->state() & Qt::ControlButton ) -#endif - setValue(minValue()); + { + if ( event->modifiers() & Qt::ControlModifier ) + setValue( minValue() ); else accepted = false; break; + } case Qt::Key_End: -#if QT_VERSION >= 0x040000 - if ( e->modifiers() & Qt::ControlModifier ) -#else - if ( e->state() & Qt::ControlButton ) -#endif - setValue(maxValue()); + { + if ( event->modifiers() & Qt::ControlModifier ) + setValue( maxValue() ); else accepted = false; break; + } case Qt::Key_Up: - incValue(d_data->increment[0]); + { + incValue( d_data->increment[0] ); break; + } case Qt::Key_Down: - incValue(-d_data->increment[0]); + { + incValue( -d_data->increment[0] ); break; + } case Qt::Key_PageUp: case Qt::Key_PageDown: { int increment = d_data->increment[0]; - if ( d_data->nButtons >= 2 ) + if ( d_data->numButtons >= 2 ) increment = d_data->increment[1]; - if ( d_data->nButtons >= 3 ) + if ( d_data->numButtons >= 3 ) { -#if QT_VERSION >= 0x040000 - if ( e->modifiers() & Qt::ShiftModifier ) -#else - if ( e->state() & Qt::ShiftButton ) -#endif + if ( event->modifiers() & Qt::ShiftModifier ) increment = d_data->increment[2]; } - if ( e->key() == Qt::Key_PageDown ) + if ( event->key() == Qt::Key_PageDown ) increment = -increment; - incValue(increment); + incValue( increment ); break; } default: + { accepted = false; + } } if ( accepted ) { - e->accept(); + event->accept(); return; } - QWidget::keyPressEvent (e); + QWidget::keyPressEvent ( event ); } /*! Handle wheel events - \param e Wheel event + \param event Wheel event */ -void QwtCounter::wheelEvent(QWheelEvent *e) +void QwtCounter::wheelEvent( QWheelEvent *event ) { - e->accept(); + event->accept(); - if ( d_data->nButtons <= 0 ) + if ( d_data->numButtons <= 0 ) return; int increment = d_data->increment[0]; - if ( d_data->nButtons >= 2 ) + if ( d_data->numButtons >= 2 ) { -#if QT_VERSION >= 0x040000 - if ( e->modifiers() & Qt::ControlModifier ) -#else - if ( e->state() & Qt::ControlButton ) -#endif + if ( event->modifiers() & Qt::ControlModifier ) increment = d_data->increment[1]; } - if ( d_data->nButtons >= 3 ) + if ( d_data->numButtons >= 3 ) { -#if QT_VERSION >= 0x040000 - if ( e->modifiers() & Qt::ShiftModifier ) -#else - if ( e->state() & Qt::ShiftButton ) -#endif + if ( event->modifiers() & Qt::ShiftModifier ) increment = d_data->increment[2]; } - - for ( int i = 0; i < d_data->nButtons; i++ ) + + for ( int i = 0; i < d_data->numButtons; i++ ) { - if ( d_data->buttonDown[i]->geometry().contains(e->pos()) || - d_data->buttonUp[i]->geometry().contains(e->pos()) ) + if ( d_data->buttonDown[i]->geometry().contains( event->pos() ) || + d_data->buttonUp[i]->geometry().contains( event->pos() ) ) { increment = d_data->increment[i]; } @@ -339,11 +286,11 @@ void QwtCounter::wheelEvent(QWheelEvent *e) const int wheel_delta = 120; - int delta = e->delta(); + int delta = event->delta(); if ( delta >= 2 * wheel_delta ) delta /= 2; // Never saw an abs(delta) < 240 - incValue(delta / wheel_delta * increment); + incValue( delta / wheel_delta * increment ); } /*! @@ -351,42 +298,46 @@ void QwtCounter::wheelEvent(QWheelEvent *e) is incremented or decremented when a specified button is pushed. - \param btn One of \c QwtCounter::Button1, \c QwtCounter::Button2, - \c QwtCounter::Button3 + \param button Button index \param nSteps Number of steps + + \sa incSteps() */ -void QwtCounter::setIncSteps(QwtCounter::Button btn, int nSteps) +void QwtCounter::setIncSteps( QwtCounter::Button button, int nSteps ) { - if (( btn >= 0) && (btn < ButtonCnt)) - d_data->increment[btn] = nSteps; + if ( button >= 0 && button < ButtonCnt ) + d_data->increment[button] = nSteps; } /*! \return the number of steps by which a specified button increments the value or 0 if the button is invalid. - \param btn One of \c QwtCounter::Button1, \c QwtCounter::Button2, - \c QwtCounter::Button3 + \param button Button index + + \sa setIncSteps() */ -int QwtCounter::incSteps(QwtCounter::Button btn) const +int QwtCounter::incSteps( QwtCounter::Button button ) const { - if (( btn >= 0) && (btn < ButtonCnt)) - return d_data->increment[btn]; + if ( button >= 0 && button < ButtonCnt ) + return d_data->increment[button]; return 0; } /*! \brief Set a new value - \param v new value + Calls QwtDoubleRange::setValue and does all visual updates. + + \param value New value \sa QwtDoubleRange::setValue() */ -void QwtCounter::setValue(double v) +void QwtCounter::setValue( double value ) { - QwtDoubleRange::setValue(v); + QwtDoubleRange::setValue( value ); - showNum(value()); + showNum( this->value() ); updateButtons(); } @@ -396,14 +347,14 @@ void QwtCounter::setValue(double v) void QwtCounter::valueChange() { if ( isValid() ) - showNum(value()); + showNum( value() ); else - d_data->valueEdit->setText(QString::null); + d_data->valueEdit->setText( QString::null ); updateButtons(); if ( isValid() ) - emit valueChanged(value()); + Q_EMIT valueChanged( value() ); } /*! @@ -421,34 +372,34 @@ void QwtCounter::updateButtons() // 1. save enabled state of the smallest down- and up-button // 2. change enabled state on under- or over-flow - for ( int i = 0; i < ButtonCnt; i++ ) + for ( int i = 0; i < QwtCounter::ButtonCnt; i++ ) { - d_data->buttonDown[i]->setEnabled(value() > minValue()); - d_data->buttonUp[i]->setEnabled(value() < maxValue()); + d_data->buttonDown[i]->setEnabled( value() > minValue() ); + d_data->buttonUp[i]->setEnabled( value() < maxValue() ); } } else { - for ( int i = 0; i < ButtonCnt; i++ ) + for ( int i = 0; i < QwtCounter::ButtonCnt; i++ ) { - d_data->buttonDown[i]->setEnabled(false); - d_data->buttonUp[i]->setEnabled(false); + d_data->buttonDown[i]->setEnabled( false ); + d_data->buttonUp[i]->setEnabled( false ); } } } /*! \brief Specify the number of buttons on each side of the label - \param n Number of buttons + \param numButtons Number of buttons */ -void QwtCounter::setNumButtons(int n) +void QwtCounter::setNumButtons( int numButtons ) { - if ( n<0 || n>ButtonCnt ) + if ( numButtons < 0 || numButtons > QwtCounter::ButtonCnt ) return; - for ( int i = 0; i < ButtonCnt; i++ ) + for ( int i = 0; i < QwtCounter::ButtonCnt; i++ ) { - if ( i < n ) + if ( i < numButtons ) { d_data->buttonDown[i]->show(); d_data->buttonUp[i]->show(); @@ -460,30 +411,30 @@ void QwtCounter::setNumButtons(int n) } } - d_data->nButtons = n; + d_data->numButtons = numButtons; } /*! \return The number of buttons on each side of the widget. */ -int QwtCounter::numButtons() const -{ - return d_data->nButtons; +int QwtCounter::numButtons() const +{ + return d_data->numButtons; } -/*! +/*! Display number string \param number Number */ -void QwtCounter::showNum(double number) +void QwtCounter::showNum( double number ) { - QString v; - v.setNum(number); + QString text; + text.setNum( number ); const int cursorPos = d_data->valueEdit->cursorPosition(); - d_data->valueEdit->setText(v); - d_data->valueEdit->setCursorPosition(cursorPos); + d_data->valueEdit->setText( text ); + d_data->valueEdit->setCursorPosition( cursorPos ); } //! Button clicked @@ -492,17 +443,17 @@ void QwtCounter::btnClicked() for ( int i = 0; i < ButtonCnt; i++ ) { if ( d_data->buttonUp[i] == sender() ) - incValue(d_data->increment[i]); + incValue( d_data->increment[i] ); if ( d_data->buttonDown[i] == sender() ) - incValue(-d_data->increment[i]); + incValue( -d_data->increment[i] ); } } //! Button released void QwtCounter::btnReleased() { - emit buttonReleased(value()); + Q_EMIT buttonReleased( value() ); } /*! @@ -521,36 +472,32 @@ QSize QwtCounter::sizeHint() const { QString tmp; - int w = tmp.setNum(minValue()).length(); - int w1 = tmp.setNum(maxValue()).length(); + int w = tmp.setNum( minValue() ).length(); + int w1 = tmp.setNum( maxValue() ).length(); if ( w1 > w ) w = w1; - w1 = tmp.setNum(minValue() + step()).length(); + w1 = tmp.setNum( minValue() + step() ).length(); if ( w1 > w ) w = w1; - w1 = tmp.setNum(maxValue() - step()).length(); + w1 = tmp.setNum( maxValue() - step() ).length(); if ( w1 > w ) w = w1; - tmp.fill('9', w); + tmp.fill( '9', w ); - QFontMetrics fm(d_data->valueEdit->font()); - w = fm.width(tmp) + 2; -#if QT_VERSION >= 0x040000 + QFontMetrics fm( d_data->valueEdit->font() ); + w = fm.width( tmp ) + 2; if ( d_data->valueEdit->hasFrame() ) - w += 2 * style()->pixelMetric(QStyle::PM_DefaultFrameWidth); -#else - w += 2 * d_data->valueEdit->frameWidth(); -#endif + w += 2 * style()->pixelMetric( QStyle::PM_DefaultFrameWidth ); // Now we replace default sizeHint contribution of d_data->valueEdit by // what we really need. w += QWidget::sizeHint().width() - d_data->valueEdit->sizeHint().width(); - const int h = qwtMin(QWidget::sizeHint().height(), - d_data->valueEdit->minimumSizeHint().height()); - return QSize(w, h); + const int h = qMin( QWidget::sizeHint().height(), + d_data->valueEdit->minimumSizeHint().height() ); + return QSize( w, h ); } //! returns the step size @@ -558,94 +505,94 @@ double QwtCounter::step() const { return QwtDoubleRange::step(); } - -/*! + +/*! Set the step size \param stepSize Step size \sa QwtDoubleRange::setStep() */ -void QwtCounter::setStep(double stepSize) +void QwtCounter::setStep( double stepSize ) { - QwtDoubleRange::setStep(stepSize); + QwtDoubleRange::setStep( stepSize ); } //! returns the minimum value of the range -double QwtCounter::minVal() const +double QwtCounter::minValue() const { - return minValue(); + return QwtDoubleRange::minValue(); } -/*! +/*! Set the minimum value of the range \param value Minimum value - \sa setMaxValue(), minVal() + \sa setMaxValue(), minValue() */ -void QwtCounter::setMinValue(double value) +void QwtCounter::setMinValue( double value ) { - setRange(value, maxValue(), step()); + setRange( value, maxValue(), step() ); } //! returns the maximum value of the range -double QwtCounter::maxVal() const +double QwtCounter::maxValue() const { return QwtDoubleRange::maxValue(); } -/*! +/*! Set the maximum value of the range \param value Maximum value \sa setMinValue(), maxVal() */ -void QwtCounter::setMaxValue(double value) +void QwtCounter::setMaxValue( double value ) { - setRange(minValue(), value, step()); + setRange( minValue(), value, step() ); } -/*! +/*! Set the number of increment steps for button 1 \param nSteps Number of steps */ -void QwtCounter::setStepButton1(int nSteps) +void QwtCounter::setStepButton1( int nSteps ) { - setIncSteps(Button1, nSteps); + setIncSteps( Button1, nSteps ); } //! returns the number of increment steps for button 1 int QwtCounter::stepButton1() const { - return incSteps(Button1); + return incSteps( Button1 ); } -/*! +/*! Set the number of increment steps for button 2 \param nSteps Number of steps */ -void QwtCounter::setStepButton2(int nSteps) +void QwtCounter::setStepButton2( int nSteps ) { - setIncSteps(Button2, nSteps); + setIncSteps( Button2, nSteps ); } //! returns the number of increment steps for button 2 int QwtCounter::stepButton2() const { - return incSteps(Button2); + return incSteps( Button2 ); } -/*! +/*! Set the number of increment steps for button 3 \param nSteps Number of steps */ -void QwtCounter::setStepButton3(int nSteps) +void QwtCounter::setStepButton3( int nSteps ) { - setIncSteps(Button3, nSteps); + setIncSteps( Button3, nSteps ); } //! returns the number of increment steps for button 3 int QwtCounter::stepButton3() const { - return incSteps(Button3); + return incSteps( Button3 ); } //! \return Current value diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_counter.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_counter.h index 8a9f8b121..e3d40ada8 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_counter.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_counter.h @@ -2,19 +2,17 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - #ifndef QWT_COUNTER_H #define QWT_COUNTER_H -#include #include "qwt_global.h" #include "qwt_double_range.h" +#include /*! \brief The Counter Widget @@ -63,8 +61,8 @@ class QWT_EXPORT QwtCounter : public QWidget, public QwtDoubleRange Q_PROPERTY( int numButtons READ numButtons WRITE setNumButtons ) Q_PROPERTY( double basicstep READ step WRITE setStep ) - Q_PROPERTY( double minValue READ minVal WRITE setMinValue ) - Q_PROPERTY( double maxValue READ maxVal WRITE setMaxValue ) + Q_PROPERTY( double minValue READ minValue WRITE setMinValue ) + Q_PROPERTY( double maxValue READ maxValue WRITE setMaxValue ) Q_PROPERTY( int stepButton1 READ stepButton1 WRITE setStepButton1 ) Q_PROPERTY( int stepButton2 READ stepButton2 WRITE setStepButton2 ) Q_PROPERTY( int stepButton3 READ stepButton3 WRITE setStepButton3 ) @@ -72,74 +70,79 @@ class QWT_EXPORT QwtCounter : public QWidget, public QwtDoubleRange Q_PROPERTY( bool editable READ editable WRITE setEditable ) public: - /*! - Button index - */ + //! Button index + enum Button + { + //! Button intended for minor steps + Button1, - enum Button - { - Button1, - Button2, - Button3, - ButtonCnt + //! Button intended for medium steps + Button2, + + //! Button intended for large steps + Button3, + + //! Number of buttons + ButtonCnt }; - explicit QwtCounter(QWidget *parent = NULL); -#if QT_VERSION < 0x040000 - explicit QwtCounter(QWidget *parent, const char *name); -#endif + explicit QwtCounter( QWidget *parent = NULL ); virtual ~QwtCounter(); bool editable() const; - void setEditable(bool); - - void setNumButtons(int n); + void setEditable( bool ); + + void setNumButtons( int n ); int numButtons() const; - - void setIncSteps(QwtCounter::Button btn, int nSteps); - int incSteps(QwtCounter::Button btn) const; - virtual void setValue(double); + void setIncSteps( QwtCounter::Button btn, int nSteps ); + int incSteps( QwtCounter::Button btn ) const; + + virtual void setValue( double ); virtual QSize sizeHint() const; - virtual void polish(); - // a set of dummies to help the designer double step() const; - void setStep(double s); - double minVal() const; - void setMinValue(double m); - double maxVal() const; - void setMaxValue(double m); - void setStepButton1(int nSteps); + void setStep( double s ); + + double minValue() const; + void setMinValue( double m ); + + double maxValue() const; + void setMaxValue( double m ); + + void setStepButton1( int nSteps ); int stepButton1() const; - void setStepButton2(int nSteps); + + void setStepButton2( int nSteps ); int stepButton2() const; - void setStepButton3(int nSteps); + + void setStepButton3( int nSteps ); int stepButton3() const; + virtual double value() const; -signals: +Q_SIGNALS: /*! This signal is emitted when a button has been released \param value The new value */ - void buttonReleased (double value); + void buttonReleased ( double value ); /*! This signal is emitted when the counter's value has changed \param value The new value */ - void valueChanged (double value); + void valueChanged ( double value ); protected: - virtual bool event(QEvent *); - virtual void wheelEvent(QWheelEvent *); - virtual void keyPressEvent(QKeyEvent *); + virtual bool event( QEvent * ); + virtual void wheelEvent( QWheelEvent * ); + virtual void keyPressEvent( QKeyEvent * ); virtual void rangeChange(); -private slots: +private Q_SLOTS: void btnReleased(); void btnClicked(); void textChanged(); @@ -147,9 +150,9 @@ private slots: private: void initCounter(); void updateButtons(); - void showNum(double); + void showNum( double ); virtual void valueChange(); - + class PrivateData; PrivateData *d_data; }; diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_curve_fitter.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_curve_fitter.cpp index 9b8e3e59d..275954f08 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_curve_fitter.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_curve_fitter.cpp @@ -2,14 +2,20 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ +#include "qwt_curve_fitter.h" #include "qwt_math.h" #include "qwt_spline.h" -#include "qwt_curve_fitter.h" +#include +#include + +#if QT_VERSION < 0x040601 +#define qFabs(x) ::fabs(x) +#endif //! Constructor QwtCurveFitter::QwtCurveFitter() @@ -25,8 +31,8 @@ class QwtSplineCurveFitter::PrivateData { public: PrivateData(): - fitMode(QwtSplineCurveFitter::Auto), - splineSize(250) + fitMode( QwtSplineCurveFitter::Auto ), + splineSize( 250 ) { } @@ -53,7 +59,7 @@ QwtSplineCurveFitter::~QwtSplineCurveFitter() \param mode Mode representing a spline algorithm \sa fitMode() */ -void QwtSplineCurveFitter::setFitMode(FitMode mode) +void QwtSplineCurveFitter::setFitMode( FitMode mode ) { d_data->fitMode = mode; } @@ -67,27 +73,51 @@ QwtSplineCurveFitter::FitMode QwtSplineCurveFitter::fitMode() const return d_data->fitMode; } -void QwtSplineCurveFitter::setSpline(const QwtSpline &spline) +/*! + Assign a spline + + \param spline Spline + \sa spline() +*/ +void QwtSplineCurveFitter::setSpline( const QwtSpline &spline ) { d_data->spline = spline; d_data->spline.reset(); } +/*! + \return Spline + \sa setSpline() +*/ const QwtSpline &QwtSplineCurveFitter::spline() const { return d_data->spline; } -QwtSpline &QwtSplineCurveFitter::spline() +/*! + \return Spline + \sa setSpline() +*/ +QwtSpline &QwtSplineCurveFitter::spline() { return d_data->spline; } -void QwtSplineCurveFitter::setSplineSize(int splineSize) +/*! + Assign a spline size ( has to be at least 10 points ) + + \param splineSize Spline size + \sa splineSize() +*/ +void QwtSplineCurveFitter::setSplineSize( int splineSize ) { - d_data->splineSize = qwtMax(splineSize, 10); + d_data->splineSize = qMax( splineSize, 10 ); } +/*! + \return Spline size + \sa setSplineSize() +*/ int QwtSplineCurveFitter::splineSize() const { return d_data->splineSize; @@ -99,14 +129,9 @@ int QwtSplineCurveFitter::splineSize() const \param points Series of data points \return Curve points */ -#if QT_VERSION < 0x040000 -QwtArray QwtSplineCurveFitter::fitCurve( - const QwtArray & points) const -#else -QPolygonF QwtSplineCurveFitter::fitCurve(const QPolygonF &points) const -#endif +QPolygonF QwtSplineCurveFitter::fitCurve( const QPolygonF &points ) const { - const int size = (int)points.size(); + const int size = points.size(); if ( size <= 2 ) return points; @@ -115,7 +140,7 @@ QPolygonF QwtSplineCurveFitter::fitCurve(const QPolygonF &points) const { fitMode = Spline; - const QwtDoublePoint *p = points.data(); + const QPointF *p = points.data(); for ( int i = 1; i < size; i++ ) { if ( p[i].x() <= p[i-1].x() ) @@ -127,114 +152,254 @@ QPolygonF QwtSplineCurveFitter::fitCurve(const QPolygonF &points) const } if ( fitMode == ParametricSpline ) - return fitParametric(points); + return fitParametric( points ); else - return fitSpline(points); + return fitSpline( points ); } -#if QT_VERSION < 0x040000 -QwtArray QwtSplineCurveFitter::fitSpline( - const QwtArray &points) const -#else -QPolygonF QwtSplineCurveFitter::fitSpline( - const QPolygonF &points) const -#endif +QPolygonF QwtSplineCurveFitter::fitSpline( const QPolygonF &points ) const { - d_data->spline.setPoints(points); + d_data->spline.setPoints( points ); if ( !d_data->spline.isValid() ) return points; -#if QT_VERSION < 0x040000 - QwtArray fittedPoints(d_data->splineSize); -#else - QPolygonF fittedPoints(d_data->splineSize); -#endif + QPolygonF fittedPoints( d_data->splineSize ); const double x1 = points[0].x(); - const double x2 = points[int(points.size() - 1)].x(); + const double x2 = points[int( points.size() - 1 )].x(); const double dx = x2 - x1; - const double delta = dx / (d_data->splineSize - 1); + const double delta = dx / ( d_data->splineSize - 1 ); - for (int i = 0; i < d_data->splineSize; i++) + for ( int i = 0; i < d_data->splineSize; i++ ) { - QwtDoublePoint &p = fittedPoints[i]; + QPointF &p = fittedPoints[i]; const double v = x1 + i * delta; - const double sv = d_data->spline.value(v); + const double sv = d_data->spline.value( v ); - p.setX(qRound(v)); - p.setY(qRound(sv)); + p.setX( v ); + p.setY( sv ); } d_data->spline.reset(); return fittedPoints; } -#if QT_VERSION < 0x040000 -QwtArray QwtSplineCurveFitter::fitParametric( - const QwtArray &points) const -#else -QPolygonF QwtSplineCurveFitter::fitParametric( - const QPolygonF &points) const -#endif +QPolygonF QwtSplineCurveFitter::fitParametric( const QPolygonF &points ) const { int i; const int size = points.size(); -#if QT_VERSION < 0x040000 - QwtArray fittedPoints(d_data->splineSize); - QwtArray splinePointsX(size); - QwtArray splinePointsY(size); -#else - QPolygonF fittedPoints(d_data->splineSize); - QPolygonF splinePointsX(size); - QPolygonF splinePointsY(size); -#endif + QPolygonF fittedPoints( d_data->splineSize ); + QPolygonF splinePointsX( size ); + QPolygonF splinePointsY( size ); - const QwtDoublePoint *p = points.data(); - QwtDoublePoint *spX = splinePointsX.data(); - QwtDoublePoint *spY = splinePointsY.data(); + const QPointF *p = points.data(); + QPointF *spX = splinePointsX.data(); + QPointF *spY = splinePointsY.data(); double param = 0.0; - for (i = 0; i < size; i++) + for ( i = 0; i < size; i++ ) { const double x = p[i].x(); const double y = p[i].y(); if ( i > 0 ) { - const double delta = sqrt( qwtSqr(x - spX[i-1].y()) + const double delta = qSqrt( qwtSqr( x - spX[i-1].y() ) + qwtSqr( y - spY[i-1].y() ) ); - param += qwtMax(delta, 1.0); + param += qMax( delta, 1.0 ); } - spX[i].setX(param); - spX[i].setY(x); - spY[i].setX(param); - spY[i].setY(y); + spX[i].setX( param ); + spX[i].setY( x ); + spY[i].setX( param ); + spY[i].setY( y ); } - d_data->spline.setPoints(splinePointsX); + d_data->spline.setPoints( splinePointsX ); if ( !d_data->spline.isValid() ) return points; const double deltaX = - splinePointsX[size - 1].x() / (d_data->splineSize-1); - for (i = 0; i < d_data->splineSize; i++) + splinePointsX[size - 1].x() / ( d_data->splineSize - 1 ); + for ( i = 0; i < d_data->splineSize; i++ ) { const double dtmp = i * deltaX; - fittedPoints[i].setX(qRound(d_data->spline.value(dtmp))); + fittedPoints[i].setX( d_data->spline.value( dtmp ) ); } - d_data->spline.setPoints(splinePointsY); + d_data->spline.setPoints( splinePointsY ); if ( !d_data->spline.isValid() ) return points; const double deltaY = - splinePointsY[size - 1].x() / (d_data->splineSize-1); - for (i = 0; i < d_data->splineSize; i++) + splinePointsY[size - 1].x() / ( d_data->splineSize - 1 ); + for ( i = 0; i < d_data->splineSize; i++ ) { const double dtmp = i * deltaY; - fittedPoints[i].setY(qRound(d_data->spline.value(dtmp))); + fittedPoints[i].setY( d_data->spline.value( dtmp ) ); } return fittedPoints; } + +class QwtWeedingCurveFitter::PrivateData +{ +public: + PrivateData(): + tolerance( 1.0 ) + { + } + + double tolerance; +}; + +class QwtWeedingCurveFitter::Line +{ +public: + Line( int i1 = 0, int i2 = 0 ): + from( i1 ), + to( i2 ) + { + } + + int from; + int to; +}; + +/*! + Constructor + + \param tolerance Tolerance + \sa setTolerance(), tolerance() +*/ +QwtWeedingCurveFitter::QwtWeedingCurveFitter( double tolerance ) +{ + d_data = new PrivateData; + setTolerance( tolerance ); +} + +//! Destructor +QwtWeedingCurveFitter::~QwtWeedingCurveFitter() +{ + delete d_data; +} + +/*! + Assign the tolerance + + The tolerance is the maximum distance, that is accaptable + between the original curve and the smoothed curve. + + Increasing the tolerance will reduce the number of the + resulting points. + + \param tolerance Tolerance + + \sa tolerance() +*/ +void QwtWeedingCurveFitter::setTolerance( double tolerance ) +{ + d_data->tolerance = qMax( tolerance, 0.0 ); +} + +/*! + \return Tolerance + \sa setTolerance() +*/ +double QwtWeedingCurveFitter::tolerance() const +{ + return d_data->tolerance; +} + +/*! + \param points Series of data points + \return Curve points +*/ +QPolygonF QwtWeedingCurveFitter::fitCurve( const QPolygonF &points ) const +{ + QStack stack; + stack.reserve( 500 ); + + const QPointF *p = points.data(); + const int nPoints = points.size(); + + QVector usePoint( nPoints, false ); + + double distToSegment; + + stack.push( Line( 0, nPoints - 1 ) ); + + while ( !stack.isEmpty() ) + { + const Line r = stack.pop(); + + // initialize line segment + const double vecX = p[r.to].x() - p[r.from].x(); + const double vecY = p[r.to].y() - p[r.from].y(); + + const double vecLength = qSqrt( vecX * vecX + vecY * vecY ); + + const double unitVecX = ( vecLength != 0.0 ) ? vecX / vecLength : 0.0; + const double unitVecY = ( vecLength != 0.0 ) ? vecY / vecLength : 0.0; + + double maxDist = 0.0; + int nVertexIndexMaxDistance = r.from + 1; + for ( int i = r.from + 1; i < r.to; i++ ) + { + //compare to anchor + const double fromVecX = p[i].x() - p[r.from].x(); + const double fromVecY = p[i].y() - p[r.from].y(); + const double fromVecLength = + qSqrt( fromVecX * fromVecX + fromVecY * fromVecY ); + + if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 ) + { + distToSegment = fromVecLength; + } + if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 ) + { + distToSegment = fromVecLength; + } + else + { + const double toVecX = p[i].x() - p[r.to].x(); + const double toVecY = p[i].y() - p[r.to].y(); + const double toVecLength = qSqrt( toVecX * toVecX + toVecY * toVecY ); + const double s = toVecX * ( -unitVecX ) + toVecY * ( -unitVecY ); + if ( s < 0.0 ) + distToSegment = toVecLength; + else + { + distToSegment = qSqrt( qFabs( toVecLength * toVecLength - s * s ) ); + } + } + + if ( maxDist < distToSegment ) + { + maxDist = distToSegment; + nVertexIndexMaxDistance = i; + } + } + if ( maxDist <= d_data->tolerance ) + { + usePoint[r.from] = true; + usePoint[r.to] = true; + } + else + { + stack.push( Line( r.from, nVertexIndexMaxDistance ) ); + stack.push( Line( nVertexIndexMaxDistance, r.to ) ); + } + } + + int cnt = 0; + + QPolygonF stripped( nPoints ); + for ( int i = 0; i < nPoints; i++ ) + { + if ( usePoint[i] ) + stripped[cnt++] = p[i]; + } + stripped.resize( cnt ); + return stripped; +} diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_curve_fitter.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_curve_fitter.h index bb7b9cac2..b84ad2069 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_curve_fitter.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_curve_fitter.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -11,31 +11,11 @@ #define QWT_CURVE_FITTER_H #include "qwt_global.h" -#include "qwt_double_rect.h" +#include +#include class QwtSpline; -#if QT_VERSION >= 0x040000 -#include -#else -#include "qwt_array.h" -#endif - -// MOC_SKIP_BEGIN - -#if defined(QWT_TEMPLATEDLL) - -#if QT_VERSION < 0x040000 -#ifndef QWTARRAY_TEMPLATE_QWTDOUBLEPOINT // by mjo3 -#define QWTARRAY_TEMPLATE_QWTDOUBLEPOINT -template class QWT_EXPORT QwtArray; -#endif //end of QWTARRAY_TEMPLATE_QWTDOUBLEPOINT -#endif - -#endif - -// MOC_SKIP_END - /*! \brief Abstract base class for a curve fitter */ @@ -44,18 +24,13 @@ class QWT_EXPORT QwtCurveFitter public: virtual ~QwtCurveFitter(); -#if QT_VERSION < 0x040000 - virtual QwtArray fitCurve( - const QwtArray&) const = 0; -#else /*! Find a curve which has the best fit to a series of data points \param polygon Series of data points \return Curve points */ - virtual QPolygonF fitCurve(const QPolygonF &polygon) const = 0; -#endif + virtual QPolygonF fitCurve( const QPolygonF &polygon ) const = 0; protected: QwtCurveFitter(); @@ -71,44 +46,81 @@ private: class QWT_EXPORT QwtSplineCurveFitter: public QwtCurveFitter { public: + /*! + Spline type + The default setting is Auto + \sa setFitMode(), FitMode() + */ enum FitMode { + /*! + Use the default spline algorithm for polygons with + increasing x values ( p[i-1] < p[i] ), otherwise use + a parametric spline algorithm. + */ Auto, + + //! Use a default spline algorithm Spline, + + //! Use a parametric spline algorithm ParametricSpline }; QwtSplineCurveFitter(); virtual ~QwtSplineCurveFitter(); - void setFitMode(FitMode); + void setFitMode( FitMode ); FitMode fitMode() const; - void setSpline(const QwtSpline&); + void setSpline( const QwtSpline& ); const QwtSpline &spline() const; QwtSpline &spline(); - void setSplineSize(int size); + void setSplineSize( int size ); int splineSize() const; -#if QT_VERSION < 0x040000 - virtual QwtArray fitCurve( - const QwtArray &) const; -#else - virtual QPolygonF fitCurve(const QPolygonF &) const; -#endif + virtual QPolygonF fitCurve( const QPolygonF & ) const; private: -#if QT_VERSION < 0x040000 - QwtArray fitSpline( - const QwtArray &) const; - QwtArray fitParametric( - const QwtArray &) const; -#else - QPolygonF fitSpline(const QPolygonF &) const; - QPolygonF fitParametric(const QPolygonF &) const; -#endif - + QPolygonF fitSpline( const QPolygonF & ) const; + QPolygonF fitParametric( const QPolygonF & ) const; + + class PrivateData; + PrivateData *d_data; +}; + +/*! + \brief A curve fitter implementing Douglas and Peucker algorithm + + The purpose of the Douglas and Peucker algorithm is that given a 'curve' + composed of line segments to find a curve not too dissimilar but that + has fewer points. The algorithm defines 'too dissimilar' based on the + maximum distance (tolerance) between the original curve and the + smoothed curve. + + The smoothed curve consists of a subset of the points that defined the + original curve. + + In opposite to QwtSplineCurveFitter the Douglas and Peucker algorithm reduces + the number of points. By adjusting the tolerance parameter according to the + axis scales QwtSplineCurveFitter can be used to implement different + level of details to speed up painting of curves of many points. +*/ +class QWT_EXPORT QwtWeedingCurveFitter: public QwtCurveFitter +{ +public: + QwtWeedingCurveFitter( double tolerance = 1.0 ); + virtual ~QwtWeedingCurveFitter(); + + void setTolerance( double ); + double tolerance() const; + + virtual QPolygonF fitCurve( const QPolygonF & ) const; + +private: + class Line; + class PrivateData; PrivateData *d_data; }; diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_data.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_data.cpp deleted file mode 100644 index 31b6a136e..000000000 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_data.cpp +++ /dev/null @@ -1,384 +0,0 @@ -/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** - * Qwt Widget Library - * Copyright (C) 1997 Josef Wilgen - * Copyright (C) 2002 Uwe Rathmann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the Qwt License, Version 1.0 - *****************************************************************************/ - -#include "qwt_math.h" -#include "qwt_data.h" - -//! Constructor -QwtData::QwtData() -{ -} - -//! Destructor -QwtData::~QwtData() -{ -} - -/*! - Returns the bounding rectangle of the data. If there is - no bounding rect, like for empty data the rectangle is invalid: - QwtDoubleRect::isValid() == false - - \warning This is an slow implementation iterating over all points. - It is intended to be overloaded by derived classes. In case of - auto scaling boundingRect() is called for every replot, so it - might be worth to implement a cache, or use x(0), x(size() - 1) - for ordered data ... -*/ -QwtDoubleRect QwtData::boundingRect() const -{ - const size_t sz = size(); - - if ( sz <= 0 ) - return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid - - double minX, maxX, minY, maxY; - minX = maxX = x(0); - minY = maxY = y(0); - - for ( size_t i = 1; i < sz; i++ ) - { - const double xv = x(i); - if ( xv < minX ) - minX = xv; - if ( xv > maxX ) - maxX = xv; - - const double yv = y(i); - if ( yv < minY ) - minY = yv; - if ( yv > maxY ) - maxY = yv; - } - return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY); -} - -/*! - Constructor - - \param polygon Polygon data - \sa QwtPlotCurve::setData() -*/ -#if QT_VERSION >= 0x040000 -QwtPolygonFData::QwtPolygonFData(const QPolygonF &polygon): -#else -QwtPolygonFData::QwtPolygonFData(const QwtArray &polygon): -#endif - d_data(polygon) -{ -} - -//! Assignment -QwtPolygonFData& QwtPolygonFData::operator=( - const QwtPolygonFData &data) -{ - if (this != &data) - { - d_data = data.d_data; - } - return *this; -} - -//! \return Size of the data set -size_t QwtPolygonFData::size() const -{ - return d_data.size(); -} - -/*! - Return the x value of data point i - - \param i Index - \return x X value of data point i -*/ -double QwtPolygonFData::x(size_t i) const -{ - return d_data[int(i)].x(); -} - -/*! - Return the y value of data point i - - \param i Index - \return y Y value of data point i -*/ -double QwtPolygonFData::y(size_t i) const -{ - return d_data[int(i)].y(); -} - -//! \return Point array -#if QT_VERSION >= 0x040000 -const QPolygonF &QwtPolygonFData::data() const -#else -const QwtArray &QwtPolygonFData::data() const -#endif -{ - return d_data; -} - -/*! - \return Pointer to a copy (virtual copy constructor) -*/ -QwtData *QwtPolygonFData::copy() const -{ - return new QwtPolygonFData(d_data); -} - -/*! - Constructor - - \param x Array of x values - \param y Array of y values - - \sa QwtPlotCurve::setData() -*/ -QwtArrayData::QwtArrayData( - const QwtArray &x, const QwtArray &y): - d_x(x), - d_y(y) -{ -} - -/*! - Constructor - - \param x Array of x values - \param y Array of y values - \param size Size of the x and y arrays - \sa QwtPlotCurve::setData() -*/ -QwtArrayData::QwtArrayData(const double *x, const double *y, size_t size) -{ -#if QT_VERSION >= 0x040000 - d_x.resize(size); - qMemCopy(d_x.data(), x, size * sizeof(double)); - - d_y.resize(size); - qMemCopy(d_y.data(), y, size * sizeof(double)); -#else - d_x.detach(); - d_x.duplicate(x, size); - - d_y.detach(); - d_y.duplicate(y, size); -#endif -} - -//! Assignment -QwtArrayData& QwtArrayData::operator=(const QwtArrayData &data) -{ - if (this != &data) - { - d_x = data.d_x; - d_y = data.d_y; - } - return *this; -} - -//! \return Size of the data set -size_t QwtArrayData::size() const -{ - return qwtMin(d_x.size(), d_y.size()); -} - -/*! - Return the x value of data point i - - \param i Index - \return x X value of data point i -*/ -double QwtArrayData::x(size_t i) const -{ - return d_x[int(i)]; -} - -/*! - Return the y value of data point i - - \param i Index - \return y Y value of data point i -*/ -double QwtArrayData::y(size_t i) const -{ - return d_y[int(i)]; -} - -//! \return Array of the x-values -const QwtArray &QwtArrayData::xData() const -{ - return d_x; -} - -//! \return Array of the y-values -const QwtArray &QwtArrayData::yData() const -{ - return d_y; -} - -/*! - \return Pointer to a copy (virtual copy constructor) -*/ -QwtData *QwtArrayData::copy() const -{ - return new QwtArrayData(d_x, d_y); -} - -/*! - Returns the bounding rectangle of the data. If there is - no bounding rect, like for empty data the rectangle is invalid: - QwtDoubleRect::isValid() == false -*/ -QwtDoubleRect QwtArrayData::boundingRect() const -{ - const size_t sz = size(); - - if ( sz <= 0 ) - return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid - - double minX, maxX, minY, maxY; - QwtArray::ConstIterator xIt = d_x.begin(); - QwtArray::ConstIterator yIt = d_y.begin(); - QwtArray::ConstIterator end = d_x.begin() + sz; - minX = maxX = *xIt++; - minY = maxY = *yIt++; - - while ( xIt < end ) - { - const double xv = *xIt++; - if ( xv < minX ) - minX = xv; - if ( xv > maxX ) - maxX = xv; - - const double yv = *yIt++; - if ( yv < minY ) - minY = yv; - if ( yv > maxY ) - maxY = yv; - } - return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY); -} - -/*! - Constructor - - \param x Array of x values - \param y Array of y values - \param size Size of the x and y arrays - - \warning The programmer must assure that the memory blocks referenced - by the pointers remain valid during the lifetime of the - QwtPlotCPointer object. - - \sa QwtPlotCurve::setData(), QwtPlotCurve::setRawData() -*/ -QwtCPointerData::QwtCPointerData( - const double *x, const double *y, size_t size): - d_x(x), - d_y(y), - d_size(size) -{ -} - -//! Assignment -QwtCPointerData& QwtCPointerData::operator=(const QwtCPointerData &data) -{ - if (this != &data) - { - d_x = data.d_x; - d_y = data.d_y; - d_size = data.d_size; - } - return *this; -} - -//! \return Size of the data set -size_t QwtCPointerData::size() const -{ - return d_size; -} - -/*! - Return the x value of data point i - - \param i Index - \return x X value of data point i -*/ -double QwtCPointerData::x(size_t i) const -{ - return d_x[int(i)]; -} - -/*! - Return the y value of data point i - - \param i Index - \return y Y value of data point i -*/ -double QwtCPointerData::y(size_t i) const -{ - return d_y[int(i)]; -} - -//! \return Array of the x-values -const double *QwtCPointerData::xData() const -{ - return d_x; -} - -//! \return Array of the y-values -const double *QwtCPointerData::yData() const -{ - return d_y; -} - -/*! - \return Pointer to a copy (virtual copy constructor) -*/ -QwtData *QwtCPointerData::copy() const -{ - return new QwtCPointerData(d_x, d_y, d_size); -} - -/*! - Returns the bounding rectangle of the data. If there is - no bounding rect, like for empty data the rectangle is invalid: - QwtDoubleRect::isValid() == false -*/ -QwtDoubleRect QwtCPointerData::boundingRect() const -{ - const size_t sz = size(); - - if ( sz <= 0 ) - return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid - - double minX, maxX, minY, maxY; - const double *xIt = d_x; - const double *yIt = d_y; - const double *end = d_x + sz; - minX = maxX = *xIt++; - minY = maxY = *yIt++; - - while ( xIt < end ) - { - const double xv = *xIt++; - if ( xv < minX ) - minX = xv; - if ( xv > maxX ) - maxX = xv; - - const double yv = *yIt++; - if ( yv < minY ) - minY = yv; - if ( yv > maxY ) - maxY = yv; - } - return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY); -} diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_data.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_data.h deleted file mode 100644 index 01e72b877..000000000 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_data.h +++ /dev/null @@ -1,166 +0,0 @@ -/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** - * Qwt Widget Library - * Copyright (C) 1997 Josef Wilgen - * Copyright (C) 2002 Uwe Rathmann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the Qwt License, Version 1.0 - *****************************************************************************/ - -// vim: expandtab - -#ifndef QWT_DATA_H -#define QWT_DATA_H 1 - -#include "qwt_global.h" -#include "qwt_array.h" -#include "qwt_double_rect.h" -#if QT_VERSION >= 0x040000 -#include -#endif - -// MOC_SKIP_BEGIN - -#if defined(QWT_TEMPLATEDLL) - -template class QWT_EXPORT QwtArray; - -#if QT_VERSION < 0x040000 -#ifndef QWTARRAY_TEMPLATE_QWTDOUBLEPOINT // by mjo3 -#define QWTARRAY_TEMPLATE_QWTDOUBLEPOINT -template class QWT_EXPORT QwtArray; -#endif //end of QWTARRAY_TEMPLATE_QWTDOUBLEPOINT -#endif - -#endif - -// MOC_SKIP_END - -/*! - \brief QwtData defines an interface to any type of curve data. - - Classes, derived from QwtData may: - - store the data in almost any type of container - - calculate the data on the fly instead of storing it - */ - -class QWT_EXPORT QwtData -{ -public: - QwtData(); - virtual ~QwtData(); - - //! \return Pointer to a copy (virtual copy constructor) - virtual QwtData *copy() const = 0; - - //! \return Size of the data set - virtual size_t size() const = 0; - - /*! - Return the x value of data point i - \param i Index - \return x X value of data point i - */ - virtual double x(size_t i) const = 0; - /*! - Return the y value of data point i - \param i Index - \return y Y value of data point i - */ - virtual double y(size_t i) const = 0; - - virtual QwtDoubleRect boundingRect() const; - -protected: - /*! - Assignment operator (virtualized) - */ - QwtData &operator=(const QwtData &); -}; - - -/*! - \brief Data class containing a single QwtArray object. - */ -class QWT_EXPORT QwtPolygonFData: public QwtData -{ -public: -#if QT_VERSION < 0x040000 - QwtPolygonFData(const QwtArray &); -#else - QwtPolygonFData(const QPolygonF &); -#endif - - QwtPolygonFData &operator=(const QwtPolygonFData &); - virtual QwtData *copy() const; - - virtual size_t size() const; - virtual double x(size_t i) const; - virtual double y(size_t i) const; - -#if QT_VERSION < 0x040000 - const QwtArray &data() const; -#else - const QPolygonF &data() const; -#endif - -private: -#if QT_VERSION < 0x040000 - QwtArray d_data; -#else - QPolygonF d_data; -#endif -}; - -/*! - \brief Data class containing two QwtArray objects. - */ - -class QWT_EXPORT QwtArrayData: public QwtData -{ -public: - QwtArrayData(const QwtArray &x, const QwtArray &y); - QwtArrayData(const double *x, const double *y, size_t size); - QwtArrayData &operator=(const QwtArrayData &); - virtual QwtData *copy() const; - - virtual size_t size() const; - virtual double x(size_t i) const; - virtual double y(size_t i) const; - - const QwtArray &xData() const; - const QwtArray &yData() const; - - virtual QwtDoubleRect boundingRect() const; - -private: - QwtArray d_x; - QwtArray d_y; -}; - -/*! - \brief Data class containing two pointers to memory blocks of doubles. - */ -class QWT_EXPORT QwtCPointerData: public QwtData -{ -public: - QwtCPointerData(const double *x, const double *y, size_t size); - QwtCPointerData &operator=(const QwtCPointerData &); - virtual QwtData *copy() const; - - virtual size_t size() const; - virtual double x(size_t i) const; - virtual double y(size_t i) const; - - const double *xData() const; - const double *yData() const; - - virtual QwtDoubleRect boundingRect() const; - -private: - const double *d_x; - const double *d_y; - size_t d_size; -}; - -#endif // !QWT_DATA diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_dial.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_dial.cpp index c4b473a7f..f7e00a1e9 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_dial.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_dial.cpp @@ -7,39 +7,43 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -#include -#include -#if QT_VERSION >= 0x040000 -#include -#include -#endif -#include -#include +#include "qwt_dial.h" +#include "qwt_dial_needle.h" #include "qwt_math.h" #include "qwt_scale_engine.h" #include "qwt_scale_map.h" -#include "qwt_paint_buffer.h" #include "qwt_painter.h" -#include "qwt_dial_needle.h" -#include "qwt_dial.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if QT_VERSION < 0x040601 +#define qAtan(x) ::atan(x) +#endif class QwtDial::PrivateData { public: PrivateData(): - visibleBackground(true), - frameShadow(Sunken), - lineWidth(0), - mode(RotateNeedle), - direction(Clockwise), - origin(90.0), - minScaleArc(0.0), - maxScaleArc(0.0), - scaleDraw(0), - maxMajIntv(36), - maxMinIntv(10), - scaleStep(0.0), - needle(0) + frameShadow( Sunken ), + lineWidth( 0 ), + mode( RotateNeedle ), + direction( Clockwise ), + origin( 90.0 ), + minScaleArc( 0.0 ), + maxScaleArc( 0.0 ), + scaleDraw( 0 ), + maxMajIntv( 36 ), + maxMinIntv( 10 ), + scaleStep( 0.0 ), + needle( 0 ) { } @@ -48,7 +52,6 @@ public: delete scaleDraw; delete needle; } - bool visibleBackground; Shadow frameShadow; int lineWidth; @@ -76,9 +79,9 @@ double QwtDial::PrivateData::previousDir = -1.0; \param parent Parent dial widget */ -QwtDialScaleDraw::QwtDialScaleDraw(QwtDial *parent): - d_parent(parent), - d_penWidth(1) +QwtDialScaleDraw::QwtDialScaleDraw( QwtDial *parent ): + d_parent( parent ), + d_penWidth( 1.0 ) { } @@ -88,148 +91,89 @@ QwtDialScaleDraw::QwtDialScaleDraw(QwtDial *parent): \param penWidth Pen width \sa penWidth(), QwtDial::drawScale() */ - -void QwtDialScaleDraw::setPenWidth(uint penWidth) + +void QwtDialScaleDraw::setPenWidth( double penWidth ) { - d_penWidth = penWidth; + d_penWidth = qMax( penWidth, 0.0 ); } /*! \return Pen width used for painting the scale \sa setPenWidth, QwtDial::drawScale() */ -uint QwtDialScaleDraw::penWidth() const +double QwtDialScaleDraw::penWidth() const { return d_penWidth; } -/*! +/*! Call QwtDial::scaleLabel of the parent dial widget. \param value Value to display - + \sa QwtDial::scaleLabel() -*/ -QwtText QwtDialScaleDraw::label(double value) const +*/ +QwtText QwtDialScaleDraw::label( double value ) const { if ( d_parent == NULL ) - return QwtRoundScaleDraw::label(value); + return QwtRoundScaleDraw::label( value ); - return d_parent->scaleLabel(value); + return d_parent->scaleLabel( value ); } /*! \brief Constructor \param parent Parent widget - Create a dial widget with no scale and no needle. + Create a dial widget with no scale and no needle. The default origin is 90.0 with no valid value. It accepts mouse and keyboard inputs and has no step size. The default mode is QwtDial::RotateNeedle. -*/ - -QwtDial::QwtDial(QWidget* parent): - QwtAbstractSlider(Qt::Horizontal, parent) +*/ +QwtDial::QwtDial( QWidget* parent ): + QwtAbstractSlider( Qt::Horizontal, parent ) { initDial(); } -#if QT_VERSION < 0x040000 -/*! - \brief Constructor - \param parent Parent widget - \param name Object name - - Create a dial widget with no scale and no needle. - The default origin is 90.0 with no valid value. It accepts - mouse and keyboard inputs and has no step size. The default mode - is QwtDial::RotateNeedle. -*/ -QwtDial::QwtDial(QWidget* parent, const char *name): - QwtAbstractSlider(Qt::Horizontal, parent) -{ - setName(name); - initDial(); -} -#endif - void QwtDial::initDial() { d_data = new PrivateData; -#if QT_VERSION < 0x040000 - setWFlags(Qt::WNoAutoErase); -#endif - -#if QT_VERSION >= 0x040000 - using namespace Qt; -#endif - setFocusPolicy(TabFocus); + setFocusPolicy( Qt::TabFocus ); QPalette p = palette(); for ( int i = 0; i < QPalette::NColorGroups; i++ ) { - const QPalette::ColorGroup cg = (QPalette::ColorGroup)i; + const QPalette::ColorGroup cg = ( QPalette::ColorGroup )i; // Base: background color of the circle inside the frame. - // Foreground: background color of the circle inside the scale + // WindowText: background color of the circle inside the scale -#if QT_VERSION < 0x040000 - p.setColor(cg, QColorGroup::Foreground, - p.color(cg, QColorGroup::Base)); -#else - p.setColor(cg, QPalette::Foreground, - p.color(cg, QPalette::Base)); -#endif + p.setColor( cg, QPalette::WindowText, + p.color( cg, QPalette::Base ) ); } - setPalette(p); + setPalette( p ); - d_data->scaleDraw = new QwtDialScaleDraw(this); - d_data->scaleDraw->setRadius(0); + d_data->scaleDraw = new QwtDialScaleDraw( this ); + d_data->scaleDraw->setRadius( 0 ); - setScaleArc(0.0, 360.0); // scale as a full circle - setRange(0.0, 360.0, 1.0, 10); // degrees as deafult + setScaleArc( 0.0, 360.0 ); // scale as a full circle + setRange( 0.0, 360.0, 1.0, 10 ); // degrees as deafult } //! Destructor -QwtDial::~QwtDial() +QwtDial::~QwtDial() { delete d_data; } -/*! - Show/Hide the area outside of the frame - \param show Show if true, hide if false - - \sa hasVisibleBackground(), setMask() - \warning When QwtDial is a toplevel widget the window - border might disappear too. -*/ -void QwtDial::showBackground(bool show) -{ - if ( d_data->visibleBackground != show ) - { - d_data->visibleBackground = show; - updateMask(); - } -} - -/*! - true when the area outside of the frame is visible - - \sa showBackground(), setMask() -*/ -bool QwtDial::hasVisibleBackground() const -{ - return d_data->visibleBackground; -} - /*! Sets the frame shadow value from the frame style. \param shadow Frame shadow \sa setLineWidth(), QFrame::setFrameShadow() */ -void QwtDial::setFrameShadow(Shadow shadow) +void QwtDial::setFrameShadow( Shadow shadow ) { if ( shadow != d_data->frameShadow ) { @@ -243,9 +187,9 @@ void QwtDial::setFrameShadow(Shadow shadow) \return Frame shadow /sa setFrameShadow(), lineWidth(), QFrame::frameShadow */ -QwtDial::Shadow QwtDial::frameShadow() const -{ - return d_data->frameShadow; +QwtDial::Shadow QwtDial::frameShadow() const +{ + return d_data->frameShadow; } /*! @@ -254,7 +198,7 @@ QwtDial::Shadow QwtDial::frameShadow() const \param lineWidth Line width \sa setFrameShadow() */ -void QwtDial::setLineWidth(int lineWidth) +void QwtDial::setLineWidth( int lineWidth ) { if ( lineWidth < 0 ) lineWidth = 0; @@ -270,99 +214,90 @@ void QwtDial::setLineWidth(int lineWidth) \return Line width of the frame \sa setLineWidth(), frameShadow(), lineWidth() */ -int QwtDial::lineWidth() const -{ - return d_data->lineWidth; +int QwtDial::lineWidth() const +{ + return d_data->lineWidth; } /*! \return bounding rect of the circle inside the frame - \sa setLineWidth(), scaleContentsRect(), boundingRect() + \sa setLineWidth(), scaleInnerRect(), boundingRect() */ -QRect QwtDial::contentsRect() const +QRectF QwtDial::innerRect() const { - const int lw = lineWidth(); - - QRect r = boundingRect(); - if ( lw > 0 ) - { - r.setRect(r.x() + lw, r.y() + lw, - r.width() - 2 * lw, r.height() - 2 * lw); - } - return r; + const double lw = lineWidth(); + return boundingRect().adjusted( lw, lw, -lw, -lw ); } /*! \return bounding rect of the dial including the frame - \sa setLineWidth(), scaleContentsRect(), contentsRect() + \sa setLineWidth(), scaleInnerRect(), innerRect() */ -QRect QwtDial::boundingRect() const +QRectF QwtDial::boundingRect() const { - const int radius = qwtMin(width(), height()) / 2; + const QRectF cr = contentsRect(); - QRect r(0, 0, 2 * radius, 2 * radius); - r.moveCenter(rect().center()); - return r; + const double dim = qMin( cr.width(), cr.height() ); + + QRectF inner( 0, 0, dim, dim ); + inner.moveCenter( cr.center() ); + + return inner; } /*! \return rect inside the scale - \sa setLineWidth(), boundingRect(), contentsRect() + \sa setLineWidth(), boundingRect(), innerRect() */ -QRect QwtDial::scaleContentsRect() const +QRectF QwtDial::scaleInnerRect() const { -#if QT_VERSION < 0x040000 - const QPen scalePen(colorGroup().text(), 0, Qt::NoPen); -#else - const QPen scalePen(palette().text(), 0, Qt::NoPen); -#endif + QRectF rect = innerRect(); - int scaleDist = 0; if ( d_data->scaleDraw ) { - scaleDist = d_data->scaleDraw->extent(scalePen, font()); + double scaleDist = qCeil( d_data->scaleDraw->extent( font() ) ); scaleDist++; // margin + + rect.adjust( scaleDist, scaleDist, -scaleDist, -scaleDist ); } - const QRect rect = contentsRect(); - return QRect(rect.x() + scaleDist, rect.y() + scaleDist, - rect.width() - 2 * scaleDist, rect.height() - 2 * scaleDist); + return rect; } /*! \brief Change the mode of the meter. - \param mode New mode - + \param mode New mode + The value of the meter is indicated by the difference between north of the scale and the direction of the needle. In case of QwtDial::RotateNeedle north is pointing to the origin() and the needle is rotating, in case of QwtDial::RotateScale, the needle points to origin() and the scale is rotating. - + The default mode is QwtDial::RotateNeedle. \sa mode(), setValue(), setOrigin() -*/ -void QwtDial::setMode(Mode mode) -{ +*/ +void QwtDial::setMode( Mode mode ) +{ if ( mode != d_data->mode ) { d_data->mode = mode; - update(); + update(); } -} +} -/*! +/*! \return mode of the dial. - + The value of the dial is indicated by the difference between the origin and the direction of the needle. In case of QwtDial::RotateNeedle the scale arc is fixed to the origin() and the needle is rotating, in case of QwtDial::RotateScale, the needle points to origin() and the scale is rotating. - + The default mode is QwtDial::RotateNeedle. \sa setMode(), origin(), setScaleArc(), value() @@ -372,29 +307,29 @@ QwtDial::Mode QwtDial::mode() const return d_data->mode; } -/*! - Sets whether it is possible to step the value from the highest value to +/*! + Sets whether it is possible to step the value from the highest value to the lowest value and vice versa to on. \param wrapping en/disables wrapping \sa wrapping(), QwtDoubleRange::periodic() \note The meaning of wrapping is like the wrapping property of QSpinBox, - but not like it is used in QDial. + but not like it is used in QDial. */ -void QwtDial::setWrapping(bool wrapping) +void QwtDial::setWrapping( bool wrapping ) { - setPeriodic(wrapping); -} + setPeriodic( wrapping ); +} -/*! - wrapping() holds whether it is possible to step the value from the - highest value to the lowest value and vice versa. +/*! + wrapping() holds whether it is possible to step the value from the + highest value to the lowest value and vice versa. \sa setWrapping(), QwtDoubleRange::setPeriodic() \note The meaning of wrapping is like the wrapping property of QSpinBox, - but not like it is used in QDial. -*/ + but not like it is used in QDial. +*/ bool QwtDial::wrapping() const { return periodic(); @@ -403,10 +338,10 @@ bool QwtDial::wrapping() const /*! Set the direction of the dial (clockwise/counterclockwise) - Direction direction + \param direction Direction \sa direction() */ -void QwtDial::setDirection(Direction direction) +void QwtDial::setDirection( Direction direction ) { if ( direction != d_data->direction ) { @@ -427,46 +362,31 @@ QwtDial::Direction QwtDial::direction() const return d_data->direction; } -/*! - Resize the dial widget - \param e Resize event +/*! + Paint the dial + \param event Paint event */ -void QwtDial::resizeEvent(QResizeEvent *e) +void QwtDial::paintEvent( QPaintEvent *event ) { - QWidget::resizeEvent(e); + QPainter painter( this ); + painter.setClipRegion( event->region() ); - if ( !hasVisibleBackground() ) - updateMask(); -} + QStyleOption opt; + opt.init(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); -/*! - Paint the dial - \param e Paint event -*/ -void QwtDial::paintEvent(QPaintEvent *e) -{ - const QRect &ur = e->rect(); - if ( ur.isValid() ) - { -#if QT_VERSION < 0x040000 - QwtPaintBuffer paintBuffer(this, ur); - QPainter &painter = *paintBuffer.painter(); -#else - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing, true); -#endif + painter.setRenderHint( QPainter::Antialiasing, true ); - painter.save(); - drawContents(&painter); - painter.restore(); + painter.save(); + drawContents( &painter ); + painter.restore(); - painter.save(); - drawFrame(&painter); - painter.restore(); + painter.save(); + drawFrame( &painter ); + painter.restore(); - if ( hasFocus() ) - drawFocusIndicator(&painter); - } + if ( hasFocus() ) + drawFocusIndicator( &painter ); } /*! @@ -474,43 +394,31 @@ void QwtDial::paintEvent(QPaintEvent *e) \param painter Painter */ -void QwtDial::drawFocusIndicator(QPainter *painter) const +void QwtDial::drawFocusIndicator( QPainter *painter ) const { if ( !isReadOnly() ) { - QRect focusRect = contentsRect(); + QRectF focusRect = innerRect(); const int margin = 2; - focusRect.setRect( - focusRect.x() + margin, - focusRect.y() + margin, - focusRect.width() - 2 * margin, - focusRect.height() - 2 * margin); + focusRect.adjust( margin, margin, -margin, -margin ); -#if QT_VERSION < 0x040000 - QColor color = colorGroup().color(QColorGroup::Base); -#else - QColor color = palette().color(QPalette::Base); -#endif - if (color.isValid()) + QColor color = palette().color( QPalette::Base ); + if ( color.isValid() ) { - const QColor gray(Qt::gray); + const QColor gray( Qt::gray ); int h, s, v; -#if QT_VERSION < 0x040000 - color.hsv(&h, &s, &v); -#else - color.getHsv(&h, &s, &v); -#endif - color = (v > 128) ? gray.dark(120) : gray.light(120); + color.getHsv( &h, &s, &v ); + color = ( v > 128 ) ? gray.dark( 120 ) : gray.light( 120 ); } else color = Qt::darkGray; painter->save(); - painter->setBrush(Qt::NoBrush); - painter->setPen(QPen(color, 0, Qt::DotLine)); - painter->drawEllipse(focusRect); + painter->setBrush( Qt::NoBrush ); + painter->setPen( QPen( color, 0, Qt::DotLine ) ); + painter->drawEllipse( focusRect ); painter->restore(); } } @@ -521,140 +429,111 @@ void QwtDial::drawFocusIndicator(QPainter *painter) const \param painter Painter \sa lineWidth(), frameShadow() */ -void QwtDial::drawFrame(QPainter *painter) +void QwtDial::drawFrame( QPainter *painter ) { - const int lw = lineWidth(); - const int off = (lw + 1) % 2; + if ( lineWidth() <= 0 ) + return; - QRect r = boundingRect(); - r.setRect(r.x() + lw / 2 - off, r.y() + lw / 2 - off, - r.width() - lw + off + 1, r.height() - lw + off + 1); -#if QT_VERSION >= 0x040000 - r.setX(r.x() + 1); - r.setY(r.y() + 1); - r.setWidth(r.width() - 2); - r.setHeight(r.height() - 2); -#endif + const double lw2 = 0.5 * lineWidth(); - if ( lw > 0 ) + QRectF r = boundingRect(); + r.adjust( lw2, lw2, -lw2, -lw2 ); + + QPen pen; + + switch ( d_data->frameShadow ) { - switch(d_data->frameShadow) + case QwtDial::Raised: + case QwtDial::Sunken: { - case QwtDial::Raised: -#if QT_VERSION < 0x040000 - QwtPainter::drawRoundFrame(painter, r, - lw, colorGroup(), false); -#else - QwtPainter::drawRoundFrame(painter, r, - lw, palette(), false); + QColor c1 = palette().color( QPalette::Light ); + QColor c2 = palette().color( QPalette::Dark ); + + if ( d_data->frameShadow == QwtDial::Sunken ) + qSwap( c1, c2 ); + + QLinearGradient gradient( r.topLeft(), r.bottomRight() ); + gradient.setColorAt( 0.0, c1 ); +#if 0 + gradient.setColorAt( 0.3, c1 ); + gradient.setColorAt( 0.7, c2 ); #endif - break; - case QwtDial::Sunken: -#if QT_VERSION < 0x040000 - QwtPainter::drawRoundFrame(painter, r, - lw, colorGroup(), true); -#else - QwtPainter::drawRoundFrame(painter, r, - lw, palette(), true); -#endif - break; - default: // Plain - { - painter->save(); - painter->setPen(QPen(Qt::black, lw)); - painter->setBrush(Qt::NoBrush); - painter->drawEllipse(r); - painter->restore(); - } + gradient.setColorAt( 1.0, c2 ); + + pen = QPen( gradient, lineWidth() ); + break; + } + default: // Plain + { + pen = QPen( palette().brush( QPalette::Dark ), lineWidth() ); } } + + painter->save(); + + painter->setPen( pen ); + painter->setBrush( Qt::NoBrush ); + painter->drawEllipse( r ); + + painter->restore(); } /*! \brief Draw the contents inside the frame - - QColorGroup::Background is the background color outside of the frame. - QColorGroup::Base is the background color inside the frame. - QColorGroup::Foreground is the background color inside the scale. + + QPalette::Window is the background color outside of the frame. + QPalette::Base is the background color inside the frame. + QPalette::WindowText is the background color inside the scale. \param painter Painter - \sa boundingRect(), contentsRect(), - scaleContentsRect(), QWidget::setPalette() + \sa boundingRect(), innerRect(), + scaleInnerRect(), QWidget::setPalette() */ -void QwtDial::drawContents(QPainter *painter) const +void QwtDial::drawContents( QPainter *painter ) const { -#if QT_VERSION < 0x040000 - if ( backgroundMode() == Qt::NoBackground || - colorGroup().brush(QColorGroup::Base) != - colorGroup().brush(QColorGroup::Background) ) -#else - if ( testAttribute(Qt::WA_NoSystemBackground) || - palette().brush(QPalette::Base) != - palette().brush(QPalette::Background) ) -#endif + if ( testAttribute( Qt::WA_NoSystemBackground ) || + palette().brush( QPalette::Base ) != + palette().brush( QPalette::Window ) ) { - - const QRect br = boundingRect(); + const QRectF br = boundingRect(); painter->save(); - painter->setPen(Qt::NoPen); - -#if QT_VERSION < 0x040000 - painter->setBrush(colorGroup().brush(QColorGroup::Base)); -#else - painter->setBrush(palette().brush(QPalette::Base)); -#endif - - painter->drawEllipse(br); + painter->setPen( Qt::NoPen ); + painter->setBrush( palette().brush( QPalette::Base ) ); + painter->drawEllipse( br ); painter->restore(); } - const QRect insideScaleRect = scaleContentsRect(); -#if QT_VERSION < 0x040000 - if ( colorGroup().brush(QColorGroup::Foreground) != - colorGroup().brush(QColorGroup::Base) ) -#else - if ( palette().brush(QPalette::Foreground) != - palette().brush(QPalette::Base) ) -#endif + const QRectF insideScaleRect = scaleInnerRect(); + if ( palette().brush( QPalette::WindowText ) != + palette().brush( QPalette::Base ) ) { painter->save(); - painter->setPen(Qt::NoPen); - -#if QT_VERSION < 0x040000 - painter->setBrush(colorGroup().brush(QColorGroup::Foreground)); -#else - painter->setBrush(palette().brush(QPalette::Foreground)); -#endif - - painter->drawEllipse(insideScaleRect.x() - 1, insideScaleRect.y() - 1, - insideScaleRect.width(), insideScaleRect.height() ); - + painter->setPen( Qt::NoPen ); + painter->setBrush( palette().brush( QPalette::WindowText ) ); + painter->drawEllipse( insideScaleRect ); painter->restore(); } - const QPoint center = insideScaleRect.center(); - const int radius = insideScaleRect.width() / 2; - - painter->save(); - drawScaleContents(painter, center, radius); - painter->restore(); + const QPointF center = insideScaleRect.center(); + const double radius = 0.5 * insideScaleRect.width(); double direction = d_data->origin; - if (isValid()) + if ( isValid() ) { direction = d_data->minScaleArc; - if ( maxValue() > minValue() && d_data->maxScaleArc > d_data->minScaleArc ) + if ( maxValue() > minValue() && + d_data->maxScaleArc > d_data->minScaleArc ) { - const double ratio = - (value() - minValue()) / (maxValue() - minValue()); - direction += ratio * (d_data->maxScaleArc - d_data->minScaleArc); + const double ratio = + ( value() - minValue() ) / ( maxValue() - minValue() ); + direction += ratio * ( d_data->maxScaleArc - d_data->minScaleArc ); } if ( d_data->direction == QwtDial::CounterClockwise ) - direction = d_data->maxScaleArc - (direction - d_data->minScaleArc); + direction = d_data->maxScaleArc - ( direction - d_data->minScaleArc ); direction += d_data->origin; if ( direction >= 360.0 ) @@ -671,8 +550,12 @@ void QwtDial::drawContents(QPainter *painter) const } painter->save(); - drawScale(painter, center, radius, origin, - d_data->minScaleArc, d_data->maxScaleArc); + drawScale( painter, center, radius, origin, + d_data->minScaleArc, d_data->maxScaleArc ); + painter->restore(); + + painter->save(); + drawScaleContents( painter, center, radius ); painter->restore(); if ( isValid() ) @@ -684,7 +567,7 @@ void QwtDial::drawContents(QPainter *painter) const cg = QPalette::Disabled; painter->save(); - drawNeedle(painter, center, radius, direction, cg); + drawNeedle( painter, center, radius, direction, cg ); painter->restore(); } } @@ -698,13 +581,13 @@ void QwtDial::drawContents(QPainter *painter) const \param direction Direction of the needle in degrees, counter clockwise \param cg ColorGroup */ -void QwtDial::drawNeedle(QPainter *painter, const QPoint ¢er, - int radius, double direction, QPalette::ColorGroup cg) const +void QwtDial::drawNeedle( QPainter *painter, const QPointF ¢er, + double radius, double direction, QPalette::ColorGroup cg ) const { if ( d_data->needle ) { direction = 360.0 - direction; // counter clockwise - d_data->needle->draw(painter, center, radius, direction, cg); + d_data->needle->draw( painter, center, radius, direction, cg ); } } @@ -715,13 +598,13 @@ void QwtDial::drawNeedle(QPainter *painter, const QPoint ¢er, \param center Center of the dial \param radius Radius of the scale \param origin Origin of the scale - \param minArc Minimum of the arc - \param maxArc Minimum of the arc - - \sa QwtAbstractScaleDraw::setAngleRange() + \param minArc Minimum of the arc + \param maxArc Minimum of the arc + + \sa QwtRoundScaleDraw::setAngleRange() */ -void QwtDial::drawScale(QPainter *painter, const QPoint ¢er, - int radius, double origin, double minArc, double maxArc) const +void QwtDial::drawScale( QPainter *painter, const QPointF ¢er, + double radius, double origin, double minArc, double maxArc ) const { if ( d_data->scaleDraw == NULL ) return; @@ -730,67 +613,70 @@ void QwtDial::drawScale(QPainter *painter, const QPoint ¢er, double angle = maxArc - minArc; if ( angle > 360.0 ) - angle = ::fmod(angle, 360.0); + angle = ::fmod( angle, 360.0 ); minArc += origin; if ( minArc < -360.0 ) - minArc = ::fmod(minArc, 360.0); - + minArc = ::fmod( minArc, 360.0 ); + maxArc = minArc + angle; if ( maxArc > 360.0 ) { - // QwtAbstractScaleDraw::setAngleRange accepts only values + // QwtRoundScaleDraw::setAngleRange accepts only values // in the range [-360.0..360.0] minArc -= 360.0; maxArc -= 360.0; } if ( d_data->direction == QwtDial::CounterClockwise ) - qSwap(minArc, maxArc); - - painter->setFont(font()); + qSwap( minArc, maxArc ); - d_data->scaleDraw->setAngleRange(minArc, maxArc); - d_data->scaleDraw->setRadius(radius); - d_data->scaleDraw->moveCenter(center); + painter->setFont( font() ); -#if QT_VERSION < 0x040000 - QColorGroup cg = colorGroup(); + d_data->scaleDraw->setAngleRange( minArc, maxArc ); + d_data->scaleDraw->setRadius( radius ); + d_data->scaleDraw->moveCenter( center ); - const QColor textColor = cg.color(QColorGroup::Text); - cg.setColor(QColorGroup::Foreground, textColor); - painter->setPen(QPen(textColor, d_data->scaleDraw->penWidth())); - - d_data->scaleDraw->draw(painter, cg); -#else QPalette pal = palette(); - const QColor textColor = pal.color(QPalette::Text); - pal.setColor(QPalette::Foreground, textColor); //ticks, backbone - - painter->setPen(QPen(textColor, d_data->scaleDraw->penWidth())); + const QColor textColor = pal.color( QPalette::Text ); + pal.setColor( QPalette::WindowText, textColor ); //ticks, backbone - d_data->scaleDraw->draw(painter, pal); -#endif + painter->setPen( QPen( textColor, d_data->scaleDraw->penWidth() ) ); + + painter->setBrush( Qt::red ); + d_data->scaleDraw->draw( painter, pal ); } -void QwtDial::drawScaleContents(QPainter *, - const QPoint &, int) const +/*! + Draw the contents inside the scale + + Paints nothing. + + \param painter Painter + \param center Center of the contents circle + \param radius Radius of the contents circle +*/ + +void QwtDial::drawScaleContents( QPainter *painter, + const QPointF ¢er, double radius ) const { - // empty default implementation + Q_UNUSED(painter); + Q_UNUSED(center); + Q_UNUSED(radius); } /*! Set a needle for the dial - Qwt is missing a set of good looking needles. + Qwt is missing a set of good looking needles. Contributions are very welcome. \param needle Needle \warning The needle will be deleted, when a different needle is set or in ~QwtDial() */ -void QwtDial::setNeedle(QwtDialNeedle *needle) +void QwtDial::setNeedle( QwtDialNeedle *needle ) { if ( needle != d_data->needle ) { @@ -802,22 +688,22 @@ void QwtDial::setNeedle(QwtDialNeedle *needle) } } -/*! +/*! \return needle \sa setNeedle() */ -const QwtDialNeedle *QwtDial::needle() const -{ - return d_data->needle; +const QwtDialNeedle *QwtDial::needle() const +{ + return d_data->needle; } -/*! +/*! \return needle \sa setNeedle() */ -QwtDialNeedle *QwtDial::needle() -{ - return d_data->needle; +QwtDialNeedle *QwtDial::needle() +{ + return d_data->needle; } //! QwtDoubleRange update hook @@ -826,7 +712,7 @@ void QwtDial::rangeChange() updateScale(); } -/*! +/*! Update the scale with the current attributes \sa setScale() */ @@ -837,24 +723,24 @@ void QwtDial::updateScale() QwtLinearScaleEngine scaleEngine; const QwtScaleDiv scaleDiv = scaleEngine.divideScale( - minValue(), maxValue(), - d_data->maxMajIntv, d_data->maxMinIntv, d_data->scaleStep); + minValue(), maxValue(), + d_data->maxMajIntv, d_data->maxMinIntv, d_data->scaleStep ); - d_data->scaleDraw->setTransformation(scaleEngine.transformation()); - d_data->scaleDraw->setScaleDiv(scaleDiv); + d_data->scaleDraw->setTransformation( scaleEngine.transformation() ); + d_data->scaleDraw->setScaleDiv( scaleDiv ); } } //! Return the scale draw -QwtDialScaleDraw *QwtDial::scaleDraw() -{ - return d_data->scaleDraw; +QwtDialScaleDraw *QwtDial::scaleDraw() +{ + return d_data->scaleDraw; } //! Return the scale draw -const QwtDialScaleDraw *QwtDial::scaleDraw() const -{ - return d_data->scaleDraw; +const QwtDialScaleDraw *QwtDial::scaleDraw() const +{ + return d_data->scaleDraw; } /*! @@ -863,13 +749,13 @@ const QwtDialScaleDraw *QwtDial::scaleDraw() const \param scaleDraw Scale draw \warning The previous scale draw is deleted */ -void QwtDial::setScaleDraw(QwtDialScaleDraw *scaleDraw) +void QwtDial::setScaleDraw( QwtDialScaleDraw *scaleDraw ) { if ( scaleDraw != d_data->scaleDraw ) { if ( d_data->scaleDraw ) delete d_data->scaleDraw; - + d_data->scaleDraw = scaleDraw; updateScale(); update(); @@ -878,9 +764,14 @@ void QwtDial::setScaleDraw(QwtDialScaleDraw *scaleDraw) /*! Change the intervals of the scale - \sa QwtAbstractScaleDraw::setScale() + + \param maxMajIntv Maximum for the number of major steps + \param maxMinIntv Maximum number of minor steps + \param step Step size + + \sa QwtScaleEngine::divideScale() */ -void QwtDial::setScale(int maxMajIntv, int maxMinIntv, double step) +void QwtDial::setScale( int maxMajIntv, int maxMinIntv, double step ) { d_data->maxMajIntv = maxMajIntv; d_data->maxMinIntv = maxMinIntv; @@ -890,39 +781,32 @@ void QwtDial::setScale(int maxMajIntv, int maxMinIntv, double step) } /*! - A wrapper method for accessing the scale draw. + A wrapper method for accessing the scale draw. - - options == 0\n - No visible scale: setScaleDraw(NULL) - - options & ScaleBackbone\n - En/disable the backbone of the scale. - - options & ScaleTicks\n - En/disable the ticks of the scale. - - options & ScaleLabel\n - En/disable scale labels - + \param components Scale components \sa QwtAbstractScaleDraw::enableComponent() */ -void QwtDial::setScaleOptions(int options) +void QwtDial::setScaleComponents( + QwtAbstractScaleDraw::ScaleComponents components ) { - if ( options == 0 ) - setScaleDraw(NULL); + if ( components == 0 ) + setScaleDraw( NULL ); QwtDialScaleDraw *sd = d_data->scaleDraw; if ( sd == NULL ) return; - sd->enableComponent(QwtAbstractScaleDraw::Backbone, - options & ScaleBackbone); + sd->enableComponent( QwtAbstractScaleDraw::Backbone, + components & QwtAbstractScaleDraw::Backbone ); - sd->enableComponent(QwtAbstractScaleDraw::Ticks, - options & ScaleTicks); - - sd->enableComponent(QwtAbstractScaleDraw::Labels, - options & ScaleLabel); + sd->enableComponent( QwtAbstractScaleDraw::Ticks, + components & QwtAbstractScaleDraw::Ticks ); + + sd->enableComponent( QwtAbstractScaleDraw::Labels, + components & QwtAbstractScaleDraw::Labels ); } -/*! +/*! Assign length and width of the ticks \param minLen Length of the minor ticks @@ -932,16 +816,16 @@ void QwtDial::setScaleOptions(int options) \sa QwtAbstractScaleDraw::setTickLength(), QwtDialScaleDraw::setPenWidth() */ -void QwtDial::setScaleTicks(int minLen, int medLen, - int majLen, int penWidth) +void QwtDial::setScaleTicks( int minLen, int medLen, + int majLen, int penWidth ) { QwtDialScaleDraw *sd = d_data->scaleDraw; if ( sd ) { - sd->setTickLength(QwtScaleDiv::MinorTick, minLen); - sd->setTickLength(QwtScaleDiv::MediumTick, medLen); - sd->setTickLength(QwtScaleDiv::MajorTick, majLen); - sd->setPenWidth(penWidth); + sd->setTickLength( QwtScaleDiv::MinorTick, minLen ); + sd->setTickLength( QwtScaleDiv::MediumTick, medLen ); + sd->setTickLength( QwtScaleDiv::MajorTick, majLen ); + sd->setPenWidth( penWidth ); } } @@ -949,39 +833,39 @@ void QwtDial::setScaleTicks(int minLen, int medLen, Find the label for a value \param value Value - \return label + \return label */ -QwtText QwtDial::scaleLabel(double value) const +QwtText QwtDial::scaleLabel( double value ) const { #if 1 if ( value == -0 ) value = 0; #endif - return QString::number(value); + return QString::number( value ); } //! \return Lower limit of the scale arc -double QwtDial::minScaleArc() const -{ - return d_data->minScaleArc; +double QwtDial::minScaleArc() const +{ + return d_data->minScaleArc; } //! \return Upper limit of the scale arc -double QwtDial::maxScaleArc() const -{ - return d_data->maxScaleArc; +double QwtDial::maxScaleArc() const +{ + return d_data->maxScaleArc; } /*! - \brief Change the origin - + \brief Change the origin + The origin is the angle where scale and needle is relative to. \param origin New origin \sa origin() */ -void QwtDial::setOrigin(double origin) +void QwtDial::setOrigin( double origin ) { d_data->origin = origin; update(); @@ -1004,18 +888,18 @@ double QwtDial::origin() const \param minArc Lower limit \param maxArc Upper limit */ -void QwtDial::setScaleArc(double minArc, double maxArc) +void QwtDial::setScaleArc( double minArc, double maxArc ) { if ( minArc != 360.0 && minArc != -360.0 ) - minArc = fmod(minArc, 360.0); + minArc = ::fmod( minArc, 360.0 ); if ( maxArc != 360.0 && maxArc != -360.0 ) - maxArc = fmod(maxArc, 360.0); + maxArc = ::fmod( maxArc, 360.0 ); - d_data->minScaleArc = qwtMin(minArc, maxArc); - d_data->maxScaleArc = qwtMax(minArc, maxArc); + d_data->minScaleArc = qMin( minArc, maxArc ); + d_data->maxScaleArc = qMax( minArc, maxArc ); if ( d_data->maxScaleArc - d_data->minScaleArc > 360.0 ) d_data->maxScaleArc = d_data->minScaleArc + 360.0; - + update(); } @@ -1033,40 +917,44 @@ QSize QwtDial::sizeHint() const { int sh = 0; if ( d_data->scaleDraw ) - sh = d_data->scaleDraw->extent( QPen(), font() ); + sh = qCeil( d_data->scaleDraw->extent( font() ) ); const int d = 6 * sh + 2 * lineWidth(); - - return QSize( d, d ); + + QSize hint( d, d ); + if ( !isReadOnly() ) + hint = hint.expandedTo( QApplication::globalStrut() ); + + return hint; } -/*! +/*! \brief Return a minimum size hint \warning The return value of QwtDial::minimumSizeHint() depends on the font and the scale. -*/ +*/ QSize QwtDial::minimumSizeHint() const -{ +{ int sh = 0; if ( d_data->scaleDraw ) - sh = d_data->scaleDraw->extent(QPen(), font() ); + sh = qCeil( d_data->scaleDraw->extent( font() ) ); const int d = 3 * sh + 2 * lineWidth(); - + return QSize( d, d ); } -static double line2Radians(const QPoint &p1, const QPoint &p2) +static double line2Radians( const QPointF &p1, const QPointF &p2 ) { - const QPoint p = p2 - p1; + const QPointF p = p2 - p1; double angle; if ( p.x() == 0 ) - angle = ( p.y() <= 0 ) ? M_PI_2 : 3 * M_PI_2; + angle = ( p.y() <= 0.0 ) ? M_PI_2 : 3 * M_PI_2; else { - angle = atan(double(-p.y()) / double(p.x())); - if ( p.x() < 0 ) + angle = qAtan( double( -p.y() ) / double( p.x() ) ); + if ( p.x() < 0.0 ) angle += M_PI; if ( angle < 0.0 ) angle += 2 * M_PI; @@ -1080,12 +968,12 @@ static double line2Radians(const QPoint &p1, const QPoint &p2) \param pos Position \return Value */ -double QwtDial::getValue(const QPoint &pos) +double QwtDial::getValue( const QPoint &pos ) { if ( d_data->maxScaleArc == d_data->minScaleArc || maxValue() == minValue() ) return minValue(); - double dir = line2Radians(rect().center(), pos) - d_data->origin; + double dir = line2Radians( innerRect().center(), pos ) - d_data->origin; if ( dir < 0.0 ) dir += 360.0; @@ -1095,8 +983,8 @@ double QwtDial::getValue(const QPoint &pos) // The position might be in the area that is outside the scale arc. // We need the range of the scale if it was a complete circle. - const double completeCircle = 360.0 / (d_data->maxScaleArc - d_data->minScaleArc) - * (maxValue() - minValue()); + const double completeCircle = 360.0 / ( d_data->maxScaleArc - d_data->minScaleArc ) + * ( maxValue() - minValue() ); double posValue = minValue() + completeCircle * dir / 360.0; @@ -1110,7 +998,7 @@ double QwtDial::getValue(const QPoint &pos) bool clockWise = false; const double angle = dir - d_data->previousDir; - if ( (angle >= 0.0 && angle <= 180.0) || angle < -180.0 ) + if ( ( angle >= 0.0 && angle <= 180.0 ) || angle < -180.0 ) clockWise = true; if ( clockWise ) @@ -1118,7 +1006,7 @@ double QwtDial::getValue(const QPoint &pos) if ( dir < d_data->previousDir && mouseOffset() > 0.0 ) { // We passed 360 -> 0 - setMouseOffset(mouseOffset() - completeCircle); + setMouseOffset( mouseOffset() - completeCircle ); } if ( wrapping() ) @@ -1128,18 +1016,18 @@ double QwtDial::getValue(const QPoint &pos) // We passed maxValue and the value will be set // to minValue. We have to adjust the mouseOffset. - setMouseOffset(posValue - minValue()); + setMouseOffset( posValue - minValue() ); } } else { if ( posValue - mouseOffset() > maxValue() || - value() == maxValue() ) + value() == maxValue() ) { // We fix the value at maxValue by adjusting // the mouse offset. - setMouseOffset(posValue - maxValue()); + setMouseOffset( posValue - maxValue() ); } } } @@ -1147,8 +1035,8 @@ double QwtDial::getValue(const QPoint &pos) { if ( dir > d_data->previousDir && mouseOffset() < 0.0 ) { - // We passed 0 -> 360 - setMouseOffset(mouseOffset() + completeCircle); + // We passed 0 -> 360 + setMouseOffset( mouseOffset() + completeCircle ); } if ( wrapping() ) @@ -1158,7 +1046,7 @@ double QwtDial::getValue(const QPoint &pos) // We passed minValue and the value will be set // to maxValue. We have to adjust the mouseOffset. - setMouseOffset(posValue - maxValue()); + setMouseOffset( posValue - maxValue() ); } } else @@ -1169,7 +1057,7 @@ double QwtDial::getValue(const QPoint &pos) // We fix the value at minValue by adjusting // the mouse offset. - setMouseOffset(posValue - minValue()); + setMouseOffset( posValue - minValue() ); } } } @@ -1189,20 +1077,21 @@ double QwtDial::getValue(const QPoint &pos) \sa QwtAbstractSlider::getScrollMode() */ -void QwtDial::getScrollMode(const QPoint &pos, int &scrollMode, int &direction) +void QwtDial::getScrollMode( const QPoint &pos, + QwtAbstractSlider::ScrollMode &scrollMode, int &direction ) const { direction = 0; - scrollMode = ScrNone; + scrollMode = QwtAbstractSlider::ScrNone; - const QRegion region(contentsRect(), QRegion::Ellipse); - if ( region.contains(pos) && pos != rect().center() ) + const QRegion region( innerRect().toRect(), QRegion::Ellipse ); + if ( region.contains( pos ) && pos != innerRect().center() ) { - scrollMode = ScrMouse; + scrollMode = QwtAbstractSlider::ScrMouse; d_data->previousDir = -1.0; } } -/*! +/*! Handles key events - Key_Down, KeyLeft\n @@ -1222,7 +1111,7 @@ void QwtDial::getScrollMode(const QPoint &pos, int &scrollMode, int &direction) \param event Key event \sa isReadOnly() */ -void QwtDial::keyPressEvent(QKeyEvent *event) +void QwtDial::keyPressEvent( QKeyEvent *event ) { if ( isReadOnly() ) { @@ -1238,53 +1127,29 @@ void QwtDial::keyPressEvent(QKeyEvent *event) { case Qt::Key_Down: case Qt::Key_Left: - QwtDoubleRange::incValue(-1); + QwtDoubleRange::incValue( -1 ); break; -#if QT_VERSION < 0x040000 - case Qt::Key_Prior: -#else case Qt::Key_PageUp: -#endif - QwtDoubleRange::incValue(-pageSize()); + QwtDoubleRange::incValue( -pageSize() ); break; case Qt::Key_Home: - setValue(minValue()); + setValue( minValue() ); break; case Qt::Key_Up: case Qt::Key_Right: - QwtDoubleRange::incValue(1); + QwtDoubleRange::incValue( 1 ); break; -#if QT_VERSION < 0x040000 - case Qt::Key_Next: -#else case Qt::Key_PageDown: -#endif - QwtDoubleRange::incValue(pageSize()); + QwtDoubleRange::incValue( pageSize() ); break; case Qt::Key_End: - setValue(maxValue()); + setValue( maxValue() ); break; default:; event->ignore(); } - if (value() != previous) - emit sliderMoved(value()); -} - -/*! - \brief Update the mask of the dial - - In case of "hasVisibleBackground() == false", the backgound is - transparent by a mask. - - \sa showBackground(), hasVisibleBackground() -*/ -void QwtDial::updateMask() -{ - if ( d_data->visibleBackground ) - clearMask(); - else - setMask(QRegion(boundingRect(), QRegion::Ellipse)); + if ( value() != previous ) + Q_EMIT sliderMoved( value() ); } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_dial.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_dial.h index 621795762..969b529c0 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_dial.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_dial.h @@ -7,59 +7,58 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - #ifndef QWT_DIAL_H #define QWT_DIAL_H 1 -#include -#include #include "qwt_global.h" #include "qwt_abstract_slider.h" #include "qwt_round_scale_draw.h" +#include +#include class QwtDialNeedle; class QwtDial; /*! \brief A special scale draw made for QwtDial - + \sa QwtDial, QwtCompass */ class QWT_EXPORT QwtDialScaleDraw: public QwtRoundScaleDraw { public: - explicit QwtDialScaleDraw(QwtDial *); - virtual QwtText label(double value) const; + explicit QwtDialScaleDraw( QwtDial * ); - void setPenWidth(uint); - uint penWidth() const; + virtual QwtText label( double value ) const; + + void setPenWidth( double ); + double penWidth() const; private: QwtDial *d_parent; - int d_penWidth; + double d_penWidth; }; /*! - \brief QwtDial class provides a rounded range control. + \brief QwtDial class provides a rounded range control. QwtDial is intended as base class for dial widgets like - speedometers, compass widgets, clocks ... + speedometers, compass widgets, clocks ... \image html dials2.png A dial contains a scale and a needle indicating the current value - of the dial. Depending on Mode one of them is fixed and the + of the dial. Depending on Mode one of them is fixed and the other is rotating. If not isReadOnly() the - dial can be rotated by dragging the mouse or using keyboard inputs + dial can be rotated by dragging the mouse or using keyboard inputs (see keyPressEvent()). A dial might be wrapping, what means a rotation below/above one limit continues on the other limit (f.e compass). The scale might cover any arc of the dial, its values are related to the origin() of the dial. - + Qwt is missing a set of good looking needles (QwtDialNeedle). Contributions are very welcome. - + \sa QwtCompass, QwtAnalogClock, QwtDialNeedle \note The examples/dials example shows different types of dials. */ @@ -68,17 +67,16 @@ class QWT_EXPORT QwtDial: public QwtAbstractSlider { Q_OBJECT - Q_ENUMS(Shadow) - Q_ENUMS(Mode) - Q_ENUMS(Direction) + Q_ENUMS( Shadow ) + Q_ENUMS( Mode ) + Q_ENUMS( Direction ) - Q_PROPERTY(bool visibleBackground READ hasVisibleBackground WRITE showBackground) - Q_PROPERTY(int lineWidth READ lineWidth WRITE setLineWidth) - Q_PROPERTY(Shadow frameShadow READ frameShadow WRITE setFrameShadow) - Q_PROPERTY(Mode mode READ mode WRITE setMode) - Q_PROPERTY(double origin READ origin WRITE setOrigin) - Q_PROPERTY(bool wrapping READ wrapping WRITE setWrapping) - Q_PROPERTY(Direction direction READ direction WRITE setDirection) + Q_PROPERTY( int lineWidth READ lineWidth WRITE setLineWidth ) + Q_PROPERTY( Shadow frameShadow READ frameShadow WRITE setFrameShadow ) + Q_PROPERTY( Mode mode READ mode WRITE setMode ) + Q_PROPERTY( double origin READ origin WRITE setOrigin ) + Q_PROPERTY( bool wrapping READ wrapping WRITE setWrapping ) + Q_PROPERTY( Direction direction READ direction WRITE setDirection ) friend class QwtDialScaleDraw; public: @@ -93,105 +91,94 @@ public: */ enum Shadow { + //! QFrame::Plain Plain = QFrame::Plain, + + //! QFrame::Raised Raised = QFrame::Raised, + + //! QFrame::Sunken Sunken = QFrame::Sunken }; - //! see QwtDial::setScaleOptions - enum ScaleOptions - { - ScaleBackbone = 1, - ScaleTicks = 2, - ScaleLabel = 4 - }; - - /*! - In case of RotateNeedle the needle is rotating, in case of - RotateScale, the needle points to origin() - and the scale is rotating. - */ + //! Mode controlling wether the needle or the scale is rotating enum Mode { + //! The needle is rotating RotateNeedle, + + //! The needle is fixed, the scales are rotating RotateScale }; - /*! - Direction of the dial - */ + //! Direction of the dial enum Direction { + //! Clockwise Clockwise, + + //! Counter clockwise CounterClockwise }; - explicit QwtDial( QWidget *parent = NULL); -#if QT_VERSION < 0x040000 - explicit QwtDial( QWidget *parent, const char *name); -#endif - + explicit QwtDial( QWidget *parent = NULL ); virtual ~QwtDial(); - void setFrameShadow(Shadow); + void setFrameShadow( Shadow ); Shadow frameShadow() const; - bool hasVisibleBackground() const; - void showBackground(bool); - - void setLineWidth(int); + void setLineWidth( int ); int lineWidth() const; - void setMode(Mode); + void setMode( Mode ); Mode mode() const; - virtual void setWrapping(bool); + virtual void setWrapping( bool ); bool wrapping() const; - virtual void setScale(int maxMajIntv, int maxMinIntv, double step = 0.0); + virtual void setScale( int maxMajIntv, int maxMinIntv, double step = 0.0 ); - void setScaleArc(double min, double max); - void setScaleOptions(int); - void setScaleTicks(int minLen, int medLen, int majLen, int penWidth = 1); + void setScaleArc( double min, double max ); + void setScaleComponents( QwtAbstractScaleDraw::ScaleComponents ); + void setScaleTicks( int minLen, int medLen, int majLen, int penWidth = 1 ); double minScaleArc() const; double maxScaleArc() const; - virtual void setOrigin(double); + virtual void setOrigin( double ); double origin() const; - void setDirection(Direction); + void setDirection( Direction ); Direction direction() const; - virtual void setNeedle(QwtDialNeedle *); + virtual void setNeedle( QwtDialNeedle * ); const QwtDialNeedle *needle() const; QwtDialNeedle *needle(); - QRect boundingRect() const; - QRect contentsRect() const; - virtual QRect scaleContentsRect() const; + QRectF boundingRect() const; + QRectF innerRect() const; + virtual QRectF scaleInnerRect() const; virtual QSize sizeHint() const; virtual QSize minimumSizeHint() const; - virtual void setScaleDraw(QwtDialScaleDraw *); + virtual void setScaleDraw( QwtDialScaleDraw * ); QwtDialScaleDraw *scaleDraw(); const QwtDialScaleDraw *scaleDraw() const; protected: - virtual void paintEvent(QPaintEvent *); - virtual void resizeEvent(QResizeEvent *); - virtual void keyPressEvent(QKeyEvent *); + virtual void paintEvent( QPaintEvent * ); + virtual void keyPressEvent( QKeyEvent * ); - virtual void updateMask(); + virtual void drawFrame( QPainter *p ); + virtual void drawContents( QPainter * ) const; + virtual void drawFocusIndicator( QPainter * ) const; - virtual void drawFrame(QPainter *p); - virtual void drawContents(QPainter *) const; - virtual void drawFocusIndicator(QPainter *) const; - - virtual void drawScale(QPainter *, const QPoint ¢er, - int radius, double origin, double arcMin, double arcMax) const; + virtual void drawScale( + QPainter *, const QPointF ¢er, + double radius, double origin, + double arcMin, double arcMax ) const; /*! Draw the contents inside the scale @@ -202,21 +189,21 @@ protected: \param center Center of the contents circle \param radius Radius of the contents circle */ - virtual void drawScaleContents(QPainter *painter, const QPoint ¢er, - int radius) const; + virtual void drawScaleContents( QPainter *painter, + const QPointF ¢er, double radius ) const; - virtual void drawNeedle(QPainter *, const QPoint &, - int radius, double direction, QPalette::ColorGroup) const; + virtual void drawNeedle( QPainter *, const QPointF &, + double radius, double direction, QPalette::ColorGroup ) const; - virtual QwtText scaleLabel(double) const; + virtual QwtText scaleLabel( double ) const; void updateScale(); virtual void rangeChange(); virtual void valueChange(); - virtual double getValue(const QPoint &); - virtual void getScrollMode(const QPoint &, - int &scrollMode, int &direction); + virtual double getValue( const QPoint & ); + virtual void getScrollMode( const QPoint &, + QwtAbstractSlider::ScrollMode &, int &direction ) const; private: void initDial(); diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_dial_needle.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_dial_needle.cpp index f7c38f0fd..d4c03e73a 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_dial_needle.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_dial_needle.cpp @@ -7,28 +7,186 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -#include -#include -#include +#include "qwt_dial_needle.h" +#include "qwt_global.h" #include "qwt_math.h" #include "qwt_painter.h" -#include "qwt_polygon.h" -#include "qwt_dial_needle.h" +#include +#include -#if QT_VERSION < 0x040000 -typedef QColorGroup QwtPalette; -#else -typedef QPalette QwtPalette; -#endif +static void qwtDrawStyle1Needle( QPainter *painter, + const QPalette &palette, QPalette::ColorGroup colorGroup, + double length ) +{ + const double r[] = { 0.4, 0.3, 1, 0.8, 1, 0.3, 0.4 }; + const double a[] = { -45, -20, -15, 0, 15, 20, 45 }; + + QPainterPath path; + for ( int i = 0; i < 7; i++ ) + { + const double angle = a[i] / 180.0 * M_PI; + const double radius = r[i] * length; + + const double x = radius * qCos( angle ); + const double y = radius * qSin( angle ); + + path.lineTo( x, -y ); + } + + painter->setPen( Qt::NoPen ); + painter->setBrush( palette.brush( colorGroup, QPalette::Light ) ); + painter->drawPath( path ); +} + +static void qwtDrawStyle2Needle( QPainter *painter, + const QPalette &palette, QPalette::ColorGroup colorGroup, double length ) +{ + const double ratioX = 0.7; + const double ratioY = 0.3; + + QPainterPath path1; + path1.lineTo( ratioX * length, 0.0 ); + path1.lineTo( length, ratioY * length ); + + QPainterPath path2; + path2.lineTo( ratioX * length, 0.0 ); + path2.lineTo( length, -ratioY * length ); + + painter->setPen( Qt::NoPen ); + + painter->setBrush( palette.brush( colorGroup, QPalette::Light ) ); + painter->drawPath( path1 ); + + painter->setBrush( palette.brush( colorGroup, QPalette::Dark ) ); + painter->drawPath( path2 ); +} + +static void qwtDrawShadedPointer( QPainter *painter, + const QColor &lightColor, const QColor &darkColor, + double length, double width ) +{ + const double peak = qMax( length / 10.0, 5.0 ); + + const double knobWidth = width + 8; + QRectF knobRect( 0, 0, knobWidth, knobWidth ); + knobRect.moveCenter( QPointF(0, 0) ); + + QPainterPath path1; + path1.lineTo( 0.0, 0.5 * width ); + path1.lineTo( length - peak, 0.5 * width ); + path1.lineTo( length, 0.0 ); + path1.lineTo( 0.0, 0.0 ); + + QPainterPath arcPath1; + arcPath1.arcTo( knobRect, 0.0, -90.0 ); + + path1 = path1.united( arcPath1 ); + + QPainterPath path2; + path2.lineTo( 0.0, -0.5 * width ); + path2.lineTo( length - peak, -0.5 * width ); + path2.lineTo( length, 0.0 ); + path2.lineTo( 0.0, 0.0 ); + + QPainterPath arcPath2; + arcPath2.arcTo( knobRect, 0.0, 90.0 ); + + path2 = path2.united( arcPath2 ); + + painter->setPen( Qt::NoPen ); + + painter->setBrush( lightColor ); + painter->drawPath( path1 ); + + painter->setBrush( darkColor ); + painter->drawPath( path2 ); +} + +static void qwtDrawArrowNeedle( QPainter *painter, + const QPalette &palette, QPalette::ColorGroup colorGroup, + double length, double width ) +{ + if ( width <= 0 ) + width = qMax( length * 0.06, 9.0 ); + + const double peak = qMax( 2.0, 0.4 * width ); + + QPainterPath path; + path.moveTo( 0.0, 0.5 * width ); + path.lineTo( length - peak, 0.3 * width ); + path.lineTo( length, 0.0 ); + path.lineTo( length - peak, -0.3 * width ); + path.lineTo( 0.0, -0.5 * width ); + + QRectF br = path.boundingRect(); + + QPalette pal( palette.color( QPalette::Mid ) ); + QColor c1 = pal.color( QPalette::Light ); + QColor c2 = pal.color( QPalette::Dark ); + + QLinearGradient gradient( br.topLeft(), br.bottomLeft() ); + gradient.setColorAt( 0.0, c1 ); + gradient.setColorAt( 0.5, c1 ); + gradient.setColorAt( 0.5001, c2 ); + gradient.setColorAt( 1.0, c2 ); + + QPen pen( gradient, 1 ); + pen.setJoinStyle( Qt::MiterJoin ); + + painter->setPen( pen ); + painter->setBrush( palette.brush( colorGroup, QPalette::Mid ) ); + + painter->drawPath( path ); +} + +static void qwtDrawTriangleNeedle( QPainter *painter, + const QPalette &palette, QPalette::ColorGroup colorGroup, + double length ) +{ + const double width = qRound( length / 3.0 ); + + QPainterPath path[4]; + + path[0].lineTo( length, 0.0 ); + path[0].lineTo( 0.0, width / 2 ); + + path[1].lineTo( length, 0.0 ); + path[1].lineTo( 0.0, -width / 2 ); + + path[2].lineTo( -length, 0.0 ); + path[2].lineTo( 0.0, width / 2 ); + + path[3].lineTo( -length, 0.0 ); + path[3].lineTo( 0.0, -width / 2 ); + + + const int colorOffset = 10; + const QColor darkColor = palette.color( colorGroup, QPalette::Dark ); + const QColor lightColor = palette.color( colorGroup, QPalette::Light ); + + QColor color[4]; + color[0] = darkColor.light( 100 + colorOffset ); + color[1] = darkColor.dark( 100 + colorOffset ); + color[2] = lightColor.light( 100 + colorOffset ); + color[3] = lightColor.dark( 100 + colorOffset ); + + painter->setPen( Qt::NoPen ); + + for ( int i = 0; i < 4; i++ ) + { + painter->setBrush( color[i] ); + painter->drawPath( path[i] ); + } +} //! Constructor QwtDialNeedle::QwtDialNeedle(): - d_palette(QApplication::palette()) + d_palette( QApplication::palette() ) { } //! Destructor -QwtDialNeedle::~QwtDialNeedle() +QwtDialNeedle::~QwtDialNeedle() { } @@ -37,50 +195,70 @@ QwtDialNeedle::~QwtDialNeedle() \param palette New Palette */ -void QwtDialNeedle::setPalette(const QPalette &palette) -{ - d_palette = palette; +void QwtDialNeedle::setPalette( const QPalette &palette ) +{ + d_palette = palette; } /*! \return the palette of the needle. */ -const QPalette &QwtDialNeedle::palette() const -{ - return d_palette; +const QPalette &QwtDialNeedle::palette() const +{ + return d_palette; } -//! Draw the knob -void QwtDialNeedle::drawKnob(QPainter *painter, - const QPoint &pos, int width, const QBrush &brush, bool sunken) +/*! + Draw the needle + + \param painter Painter + \param center Center of the dial, start position for the needle + \param length Length of the needle + \param direction Direction of the needle, in degrees counter clockwise + \param colorGroup Color group, used for painting +*/ +void QwtDialNeedle::draw( QPainter *painter, + const QPointF ¢er, double length, double direction, + QPalette::ColorGroup colorGroup ) const { painter->save(); - QRect rect(0, 0, width, width); - rect.moveCenter(pos); + painter->translate( center ); + painter->rotate( -direction ); - painter->setPen(Qt::NoPen); - painter->setBrush(brush); - painter->drawEllipse(rect); + drawNeedle( painter, length, colorGroup ); - painter->setBrush(Qt::NoBrush); + painter->restore(); +} - const int colorOffset = 20; +//! Draw the knob +void QwtDialNeedle::drawKnob( QPainter *painter, + double width, const QBrush &brush, bool sunken ) const +{ + QPalette palette( brush.color() ); + + QColor c1 = palette.color( QPalette::Light ); + QColor c2 = palette.color( QPalette::Dark ); - int startAngle = 45; if ( sunken ) - startAngle += 180; + qSwap( c1, c2 ); - QPen pen; - pen.setWidth(1); + QRectF rect( 0.0, 0.0, width, width ); + rect.moveCenter( painter->combinedTransform().map( QPointF() ) ); - pen.setColor(brush.color().dark(100 - colorOffset)); - painter->setPen(pen); - painter->drawArc(rect, startAngle * 16, 180 * 16); + QLinearGradient gradient( rect.topLeft(), rect.bottomRight() ); + gradient.setColorAt( 0.0, c1 ); + gradient.setColorAt( 0.3, c1 ); + gradient.setColorAt( 0.7, c2 ); + gradient.setColorAt( 1.0, c2 ); - pen.setColor(brush.color().dark(100 + colorOffset)); - painter->setPen(pen); - painter->drawArc(rect, (startAngle + 180) * 16, 180 * 16); + painter->save(); + + painter->resetTransform(); + + painter->setPen( QPen( gradient, 1 ) ); + painter->setBrush( brush ); + painter->drawEllipse( rect ); painter->restore(); } @@ -93,30 +271,30 @@ void QwtDialNeedle::drawKnob(QPainter *painter, \param mid Middle color \param base Base color */ -QwtDialSimpleNeedle::QwtDialSimpleNeedle(Style style, bool hasKnob, - const QColor &mid, const QColor &base): - d_style(style), - d_hasKnob(hasKnob), - d_width(-1) +QwtDialSimpleNeedle::QwtDialSimpleNeedle( Style style, bool hasKnob, + const QColor &mid, const QColor &base ): + d_style( style ), + d_hasKnob( hasKnob ), + d_width( -1 ) { QPalette palette; for ( int i = 0; i < QPalette::NColorGroups; i++ ) { - palette.setColor((QPalette::ColorGroup)i, - QwtPalette::Mid, mid); - palette.setColor((QPalette::ColorGroup)i, - QwtPalette::Base, base); + palette.setColor( ( QPalette::ColorGroup )i, + QPalette::Mid, mid ); + palette.setColor( ( QPalette::ColorGroup )i, + QPalette::Base, base ); } - setPalette(palette); + setPalette( palette ); } -/*! +/*! Set the width of the needle \param width Width \sa width() */ -void QwtDialSimpleNeedle::setWidth(int width) +void QwtDialSimpleNeedle::setWidth( double width ) { d_width = width; } @@ -125,7 +303,7 @@ void QwtDialSimpleNeedle::setWidth(int width) \return the width of the needle \sa setWidth() */ -int QwtDialSimpleNeedle::width() const +double QwtDialSimpleNeedle::width() const { return d_width; } @@ -134,479 +312,141 @@ int QwtDialSimpleNeedle::width() const Draw the needle \param painter Painter - \param center Center of the dial, start position for the needle \param length Length of the needle - \param direction Direction of the needle, in degrees counter clockwise \param colorGroup Color group, used for painting */ -void QwtDialSimpleNeedle::draw(QPainter *painter, const QPoint ¢er, - int length, double direction, QPalette::ColorGroup colorGroup) const +void QwtDialSimpleNeedle::drawNeedle( QPainter *painter, + double length, QPalette::ColorGroup colorGroup ) const { + double knobWidth = 0.0; + double width = d_width; + if ( d_style == Arrow ) { - drawArrowNeedle(painter, palette(), colorGroup, - center, length, d_width, direction, d_hasKnob); + if ( width <= 0.0 ) + width = qMax(length * 0.06, 6.0); + + qwtDrawArrowNeedle( painter, + palette(), colorGroup, length, width ); + + knobWidth = qMin( width * 2.0, 0.2 * length ); } else { - drawRayNeedle(painter, palette(), colorGroup, - center, length, d_width, direction, d_hasKnob); + if ( width <= 0.0 ) + width = 5.0; + + QPen pen ( palette().brush( colorGroup, QPalette::Mid ), width ); + pen.setCapStyle( Qt::FlatCap ); + + painter->setPen( pen ); + painter->drawLine( 0, 0, length, 0 ); + + knobWidth = qMax( width * 3.0, 5.0 ); } -} -/*! - Draw a needle looking like a ray - - \param painter Painter - \param palette Palette - \param colorGroup Color group - \param center center of the needle - \param length Length of the needle - \param width Width of the needle - \param direction Current Direction - \param hasKnob With/Without knob -*/ -void QwtDialSimpleNeedle::drawRayNeedle(QPainter *painter, - const QPalette &palette, QPalette::ColorGroup colorGroup, - const QPoint ¢er, int length, int width, double direction, - bool hasKnob) -{ - if ( width <= 0 ) - width = 5; - - direction *= M_PI / 180.0; - - painter->save(); - - const QPoint p1(center.x() + 1, center.y() + 2); - const QPoint p2 = qwtPolar2Pos(p1, length, direction); - - if ( width == 1 ) + if ( d_hasKnob && knobWidth > 0.0 ) { - const QColor midColor = - palette.color(colorGroup, QwtPalette::Mid); - - painter->setPen(QPen(midColor, 1)); - painter->drawLine(p1, p2); + drawKnob( painter, knobWidth, + palette().brush( colorGroup, QPalette::Base ), false ); } - else - { - QwtPolygon pa(4); - pa.setPoint(0, qwtPolar2Pos(p1, width / 2, direction + M_PI_2)); - pa.setPoint(1, qwtPolar2Pos(p2, width / 2, direction + M_PI_2)); - pa.setPoint(2, qwtPolar2Pos(p2, width / 2, direction - M_PI_2)); - pa.setPoint(3, qwtPolar2Pos(p1, width / 2, direction - M_PI_2)); - - painter->setPen(Qt::NoPen); - painter->setBrush(palette.brush(colorGroup, QwtPalette::Mid)); - painter->drawPolygon(pa); - } - if ( hasKnob ) - { - int knobWidth = qwtMax(qRound(width * 0.7), 5); - if ( knobWidth % 2 == 0 ) - knobWidth++; - - drawKnob(painter, center, knobWidth, - palette.brush(colorGroup, QwtPalette::Base), - false); - } - - painter->restore(); -} - -/*! - Draw a needle looking like an arrow - - \param painter Painter - \param palette Palette - \param colorGroup Color group - \param center center of the needle - \param length Length of the needle - \param width Width of the needle - \param direction Current Direction - \param hasKnob With/Without knob -*/ -void QwtDialSimpleNeedle::drawArrowNeedle(QPainter *painter, - const QPalette &palette, QPalette::ColorGroup colorGroup, - const QPoint ¢er, int length, int width, - double direction, bool hasKnob) -{ - direction *= M_PI / 180.0; - - painter->save(); - - if ( width <= 0 ) - { - width = (int)qwtMax(length * 0.06, 9.0); - if ( width % 2 == 0 ) - width++; - } - - const int peak = 3; - const QPoint p1(center.x() + 1, center.y() + 1); - const QPoint p2 = qwtPolar2Pos(p1, length - peak, direction); - const QPoint p3 = qwtPolar2Pos(p1, length, direction); - - QwtPolygon pa(5); - pa.setPoint(0, qwtPolar2Pos(p1, width / 2, direction - M_PI_2)); - pa.setPoint(1, qwtPolar2Pos(p2, 1, direction - M_PI_2)); - pa.setPoint(2, p3); - pa.setPoint(3, qwtPolar2Pos(p2, 1, direction + M_PI_2)); - pa.setPoint(4, qwtPolar2Pos(p1, width / 2, direction + M_PI_2)); - - painter->setPen(Qt::NoPen); - painter->setBrush(palette.brush(colorGroup, QwtPalette::Mid)); - painter->drawPolygon(pa); - - QwtPolygon shadowPa(3); - - const int colorOffset = 10; - - int i; - for ( i = 0; i < 3; i++ ) - shadowPa.setPoint(i, pa[i]); - - const QColor midColor = palette.color(colorGroup, QwtPalette::Mid); - - painter->setPen(midColor.dark(100 + colorOffset)); - painter->drawPolyline(shadowPa); - - for ( i = 0; i < 3; i++ ) - shadowPa.setPoint(i, pa[i + 2]); - - painter->setPen(midColor.dark(100 - colorOffset)); - painter->drawPolyline(shadowPa); - - if ( hasKnob ) - { - drawKnob(painter, center, qRound(width * 1.3), - palette.brush(colorGroup, QwtPalette::Base), - false); - } - - painter->restore(); } //! Constructor -QwtCompassMagnetNeedle::QwtCompassMagnetNeedle(Style style, - const QColor &light, const QColor &dark): - d_style(style) -{ +QwtCompassMagnetNeedle::QwtCompassMagnetNeedle( Style style, + const QColor &light, const QColor &dark ): + d_style( style ) +{ QPalette palette; for ( int i = 0; i < QPalette::NColorGroups; i++ ) { - palette.setColor((QPalette::ColorGroup)i, - QwtPalette::Light, light); - palette.setColor((QPalette::ColorGroup)i, - QwtPalette::Dark, dark); - palette.setColor((QPalette::ColorGroup)i, - QwtPalette::Base, Qt::darkGray); + palette.setColor( ( QPalette::ColorGroup )i, + QPalette::Light, light ); + palette.setColor( ( QPalette::ColorGroup )i, + QPalette::Dark, dark ); + palette.setColor( ( QPalette::ColorGroup )i, + QPalette::Base, Qt::gray ); } - setPalette(palette); + setPalette( palette ); } /*! Draw the needle \param painter Painter - \param center Center of the dial, start position for the needle \param length Length of the needle - \param direction Direction of the needle, in degrees counter clockwise \param colorGroup Color group, used for painting */ -void QwtCompassMagnetNeedle::draw(QPainter *painter, const QPoint ¢er, - int length, double direction, QPalette::ColorGroup colorGroup) const +void QwtCompassMagnetNeedle::drawNeedle( QPainter *painter, + double length, QPalette::ColorGroup colorGroup ) const { if ( d_style == ThinStyle ) { - drawThinNeedle(painter, palette(), colorGroup, - center, length, direction); + const double width = qMax( length / 6.0, 3.0 ); + + const int colorOffset = 10; + + const QColor light = palette().color( colorGroup, QPalette::Light ); + const QColor dark = palette().color( colorGroup, QPalette::Dark ); + + qwtDrawShadedPointer( painter, + dark.light( 100 + colorOffset ), + dark.dark( 100 + colorOffset ), + length, width ); + + painter->rotate( 180.0 ); + + qwtDrawShadedPointer( painter, + light.light( 100 + colorOffset ), + light.dark( 100 + colorOffset ), + length, width ); + + const QBrush baseBrush = palette().brush( colorGroup, QPalette::Base ); + drawKnob( painter, width, baseBrush, true ); } else { - drawTriangleNeedle(painter, palette(), colorGroup, - center, length, direction); + qwtDrawTriangleNeedle( painter, palette(), colorGroup, length ); } } /*! - Draw a compass needle - - \param painter Painter - \param palette Palette - \param colorGroup Color group - \param center Center, where the needle starts - \param length Length of the needle - \param direction Direction -*/ -void QwtCompassMagnetNeedle::drawTriangleNeedle(QPainter *painter, - const QPalette &palette, QPalette::ColorGroup colorGroup, - const QPoint ¢er, int length, double direction) -{ - const QBrush darkBrush = palette.brush(colorGroup, QwtPalette::Dark); - const QBrush lightBrush = palette.brush(colorGroup, QwtPalette::Light); - - QBrush brush; - - const int width = qRound(length / 3.0); - const int colorOffset = 10; - - painter->save(); - painter->setPen(Qt::NoPen); - - const QPoint arrowCenter(center.x() + 1, center.y() + 1); - - QwtPolygon pa(3); - pa.setPoint(0, arrowCenter); - pa.setPoint(1, qwtDegree2Pos(arrowCenter, length, direction)); - - pa.setPoint(2, qwtDegree2Pos(arrowCenter, width / 2, direction + 90.0)); - - brush = darkBrush; - brush.setColor(brush.color().dark(100 + colorOffset)); - painter->setBrush(brush); - painter->drawPolygon(pa); - - pa.setPoint(2, qwtDegree2Pos(arrowCenter, width / 2, direction - 90.0)); - - brush = darkBrush; - brush.setColor(brush.color().dark(100 - colorOffset)); - painter->setBrush(brush); - painter->drawPolygon(pa); - - // -- - - pa.setPoint(1, qwtDegree2Pos(arrowCenter, length, direction + 180.0)); - - pa.setPoint(2, qwtDegree2Pos(arrowCenter, width / 2, direction + 90.0)); - - brush = lightBrush; - brush.setColor(brush.color().dark(100 + colorOffset)); - painter->setBrush(brush); - painter->drawPolygon(pa); - - pa.setPoint(2, qwtDegree2Pos(arrowCenter, width / 2, direction - 90.0)); - - brush = lightBrush; - brush.setColor(brush.color().dark(100 - colorOffset)); - painter->setBrush(brush); - painter->drawPolygon(pa); - - painter->restore(); -} - -/*! - Draw a compass needle - - \param painter Painter - \param palette Palette - \param colorGroup Color group - \param center Center, where the needle starts - \param length Length of the needle - \param direction Direction -*/ -void QwtCompassMagnetNeedle::drawThinNeedle(QPainter *painter, - const QPalette &palette, QPalette::ColorGroup colorGroup, - const QPoint ¢er, int length, double direction) -{ - const QBrush darkBrush = palette.brush(colorGroup, QwtPalette::Dark); - const QBrush lightBrush = palette.brush(colorGroup, QwtPalette::Light); - const QBrush baseBrush = palette.brush(colorGroup, QwtPalette::Base); - - const int colorOffset = 10; - const int width = qwtMax(qRound(length / 6.0), 3); - - painter->save(); - - const QPoint arrowCenter(center.x() + 1, center.y() + 1); - - drawPointer(painter, darkBrush, colorOffset, - arrowCenter, length, width, direction); - drawPointer(painter, lightBrush, -colorOffset, - arrowCenter, length, width, direction + 180.0); - - drawKnob(painter, arrowCenter, width, baseBrush, true); - - painter->restore(); -} - -/*! - Draw a compass needle - - \param painter Painter - \param brush Brush - \param colorOffset Color offset - \param center Center, where the needle starts - \param length Length of the needle - \param width Width of the needle - \param direction Direction -*/ -void QwtCompassMagnetNeedle::drawPointer( - QPainter *painter, const QBrush &brush, - int colorOffset, const QPoint ¢er, int length, - int width, double direction) -{ - painter->save(); - - const int peak = qwtMax(qRound(length / 10.0), 5); - - const int knobWidth = width + 8; - QRect knobRect(0, 0, knobWidth, knobWidth); - knobRect.moveCenter(center); - - QwtPolygon pa(5); - - pa.setPoint(0, qwtDegree2Pos(center, width / 2, direction + 90.0)); - pa.setPoint(1, center); - pa.setPoint(2, qwtDegree2Pos(pa.point(1), length - peak, direction)); - pa.setPoint(3, qwtDegree2Pos(center, length, direction)); - pa.setPoint(4, qwtDegree2Pos(pa.point(0), length - peak, direction)); - - painter->setPen(Qt::NoPen); - - QBrush darkBrush = brush; - darkBrush.setColor(darkBrush.color().dark(100 + colorOffset)); - painter->setBrush(darkBrush); - painter->drawPolygon(pa); - painter->drawPie(knobRect, qRound(direction * 16), 90 * 16); - - pa.setPoint(0, qwtDegree2Pos(center, width / 2, direction - 90.0)); - pa.setPoint(4, qwtDegree2Pos(pa.point(0), length - peak, direction)); - - QBrush lightBrush = brush; - lightBrush.setColor(lightBrush.color().dark(100 - colorOffset)); - painter->setBrush(lightBrush); - painter->drawPolygon(pa); - painter->drawPie(knobRect, qRound(direction * 16), -90 * 16); - - painter->restore(); -} - -/*! Constructor \param style Arrow style \param light Light color \param dark Dark color */ -QwtCompassWindArrow::QwtCompassWindArrow(Style style, - const QColor &light, const QColor &dark): - d_style(style) +QwtCompassWindArrow::QwtCompassWindArrow( Style style, + const QColor &light, const QColor &dark ): + d_style( style ) { QPalette palette; for ( int i = 0; i < QPalette::NColorGroups; i++ ) { - palette.setColor((QPalette::ColorGroup)i, - QwtPalette::Light, light); - palette.setColor((QPalette::ColorGroup)i, - QwtPalette::Dark, dark); + palette.setColor( ( QPalette::ColorGroup )i, + QPalette::Light, light ); + palette.setColor( ( QPalette::ColorGroup )i, + QPalette::Dark, dark ); } - setPalette(palette); + setPalette( palette ); } /*! Draw the needle \param painter Painter - \param center Center of the dial, start position for the needle \param length Length of the needle - \param direction Direction of the needle, in degrees counter clockwise \param colorGroup Color group, used for painting */ -void QwtCompassWindArrow::draw(QPainter *painter, const QPoint ¢er, - int length, double direction, QPalette::ColorGroup colorGroup) const +void QwtCompassWindArrow::drawNeedle( QPainter *painter, + double length, QPalette::ColorGroup colorGroup ) const { if ( d_style == Style1 ) - { - drawStyle1Needle(painter, palette(), colorGroup, - center, length, direction); - } + qwtDrawStyle1Needle( painter, palette(), colorGroup, length ); else - { - drawStyle2Needle(painter, palette(), colorGroup, - center, length, direction); - } + qwtDrawStyle2Needle( painter, palette(), colorGroup, length ); } - -/*! - Draw a compass needle - - \param painter Painter - \param palette Palette - \param colorGroup colorGroup - \param center Center of the dial, start position for the needle - \param length Length of the needle - \param direction Direction of the needle, in degrees counter clockwise -*/ -void QwtCompassWindArrow::drawStyle1Needle(QPainter *painter, - const QPalette &palette, QPalette::ColorGroup colorGroup, - const QPoint ¢er, int length, double direction) -{ - const QBrush lightBrush = palette.brush(colorGroup, QwtPalette::Light); - - const double AR1[] = {0, 0.4, 0.3, 1, 0.8, 1, 0.3, 0.4}; - const double AW1[] = {0, -45, -20, -15, 0, 15, 20, 45}; - - const QPoint arrowCenter(center.x() + 1, center.y() + 1); - - QwtPolygon pa(8); - pa.setPoint(0, arrowCenter); - for (int i=1; i<8; i++) - { - const QPoint p = qwtDegree2Pos(center, - AR1[i] * length, direction + AW1[i]); - pa.setPoint(i, p); - } - - painter->save(); - painter->setPen(Qt::NoPen); - painter->setBrush(lightBrush); - painter->drawPolygon(pa); - painter->restore(); -} - -/*! - Draw a compass needle - - \param painter Painter - \param palette Palette - \param colorGroup colorGroup - \param center Center of the dial, start position for the needle - \param length Length of the needle - \param direction Direction of the needle, in degrees counter clockwise -*/ -void QwtCompassWindArrow::drawStyle2Needle(QPainter *painter, - const QPalette &palette, QPalette::ColorGroup colorGroup, - const QPoint ¢er, int length, double direction) -{ - const QBrush lightBrush = palette.brush(colorGroup, QwtPalette::Light); - const QBrush darkBrush = palette.brush(colorGroup, QwtPalette::Dark); - - painter->save(); - painter->setPen(Qt::NoPen); - - const double angle = 12.0; - const double ratio = 0.7; - - const QPoint arrowCenter(center.x() + 1, center.y() + 1); - - QwtPolygon pa(3); - - pa.setPoint(0, center); - pa.setPoint(2, qwtDegree2Pos(arrowCenter, ratio * length, direction)); - - pa.setPoint(1, qwtDegree2Pos(arrowCenter, length, direction + angle)); - painter->setBrush(darkBrush); - painter->drawPolygon(pa); - - pa.setPoint(1, qwtDegree2Pos(arrowCenter, length, direction - angle)); - painter->setBrush(lightBrush); - painter->drawPolygon(pa); - - painter->restore(); -} - diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_dial_needle.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_dial_needle.h index 595db80fe..49beebb59 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_dial_needle.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_dial_needle.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -10,8 +10,8 @@ #ifndef QWT_DIAL_NEEDLE_H #define QWT_DIAL_NEEDLE_H 1 -#include #include "qwt_global.h" +#include class QPainter; class QPoint; @@ -19,10 +19,10 @@ class QPoint; /*! \brief Base class for needles that can be used in a QwtDial. - QwtDialNeedle is a pointer that indicates a value by pointing - to a specific direction. - - Qwt is missing a set of good looking needles. + QwtDialNeedle is a pointer that indicates a value by pointing + to a specific direction. + + Qwt is missing a set of good looking needles. Contributions are very welcome. \sa QwtDial, QwtCompass @@ -34,25 +34,34 @@ public: QwtDialNeedle(); virtual ~QwtDialNeedle(); - /*! - Draw the needle + virtual void setPalette( const QPalette & ); + const QPalette &palette() const; - \param painter Painter - \param center Center of the dial, start position for the needle - \param length Length of the needle - \param direction Direction of the needle, in degrees counter clockwise - \param cg Color group, used for painting - */ - virtual void draw(QPainter *painter, const QPoint ¢er, - int length, double direction, - QPalette::ColorGroup cg = QPalette::Active) const = 0; - - virtual void setPalette(const QPalette &); - const QPalette &palette() const; + virtual void draw( QPainter *painter, const QPointF ¢er, + double length, double direction, + QPalette::ColorGroup = QPalette::Active ) const; protected: - static void drawKnob(QPainter *, const QPoint &pos, - int width, const QBrush &, bool sunken); + /*! + \brief Draw the needle + + The origin of the needle is at position (0.0, 0.0 ) + pointing in direction 0.0 ( = east ). + + The painter is already initilaized with translation and + rotation. + + \param painter Painter + \param length Length of the needle + \param colorGroup Color group, used for painting + + \sa setPalette(), palette() + */ + virtual void drawNeedle( QPainter *painter, + double length, QPalette::ColorGroup colorGroup ) const = 0; + + virtual void drawKnob( QPainter *, double width, + const QBrush &, bool sunken ) const; private: QPalette d_palette; @@ -62,9 +71,10 @@ private: \brief A needle for dial widgets The following colors are used: - - QColorGroup::Mid\n + + - QPalette::Mid\n Pointer - - QColorGroup::base\n + - QPalette::Base\n Knob \sa QwtDial, QwtCompass @@ -76,33 +86,27 @@ public: //! Style of the needle enum Style { + //! Arrow Arrow, + + //! A straight line from the center Ray }; - QwtDialSimpleNeedle(Style, bool hasKnob = true, - const QColor &mid = Qt::gray, const QColor &base = Qt::darkGray); + QwtDialSimpleNeedle( Style, bool hasKnob = true, + const QColor &mid = Qt::gray, const QColor &base = Qt::darkGray ); - virtual void draw(QPainter *, const QPoint &, int length, - double direction, QPalette::ColorGroup = QPalette::Active) const; + void setWidth( double width ); + double width() const; - static void drawArrowNeedle(QPainter *, - const QPalette&, QPalette::ColorGroup, - const QPoint &, int length, int width, double direction, - bool hasKnob); - - static void drawRayNeedle(QPainter *, - const QPalette&, QPalette::ColorGroup, - const QPoint &, int length, int width, double direction, - bool hasKnob); - - void setWidth(int width); - int width() const; +protected: + virtual void drawNeedle( QPainter *, double length, + QPalette::ColorGroup ) const; private: Style d_style; bool d_hasKnob; - int d_width; + double d_width; }; /*! @@ -112,11 +116,11 @@ private: north and south. The following colors are used: - - QColorGroup::Light\n + - QPalette::Light\n Used for pointing south - - QColorGroup::Dark\n + - QPalette::Dark\n Used for pointing north - - QColorGroup::Base\n + - QPalette::Base\n Knob (ThinStyle only) \sa QwtDial, QwtCompass @@ -128,27 +132,19 @@ public: //! Style of the needle enum Style { + //! A needle with a triangular shape TriangleStyle, + + //! A thin needle ThinStyle }; - QwtCompassMagnetNeedle(Style = TriangleStyle, - const QColor &light = Qt::white, const QColor &dark = Qt::red); - virtual void draw(QPainter *, const QPoint &, int length, - double direction, QPalette::ColorGroup = QPalette::Active) const; - - static void drawTriangleNeedle(QPainter *, - const QPalette &, QPalette::ColorGroup, - const QPoint &, int length, double direction); - - static void drawThinNeedle(QPainter *, - const QPalette &, QPalette::ColorGroup, - const QPoint &, int length, double direction); + QwtCompassMagnetNeedle( Style = TriangleStyle, + const QColor &light = Qt::white, const QColor &dark = Qt::red ); protected: - static void drawPointer(QPainter *painter, const QBrush &brush, - int colorOffset, const QPoint ¢er, - int length, int width, double direction); + virtual void drawNeedle( QPainter *, + double length, QPalette::ColorGroup ) const; private: Style d_style; @@ -159,9 +155,9 @@ private: QwtCompassWindArrow shows the direction where the wind comes from. - - QColorGroup::Light\n + - QPalette::Light\n Used for Style1, or the light half of Style2 - - QColorGroup::Dark\n + - QPalette::Dark\n Used for the dark half of Style2 \sa QwtDial, QwtCompass @@ -173,26 +169,22 @@ public: //! Style of the arrow enum Style { + //! A needle pointing to the center Style1, + + //! A needle pointing to the center Style2 }; - QwtCompassWindArrow(Style, const QColor &light = Qt::white, - const QColor &dark = Qt::gray); + QwtCompassWindArrow( Style, const QColor &light = Qt::white, + const QColor &dark = Qt::gray ); - virtual void draw(QPainter *, const QPoint &, int length, - double direction, QPalette::ColorGroup = QPalette::Active) const; - - static void drawStyle1Needle(QPainter *, - const QPalette &, QPalette::ColorGroup, - const QPoint &, int length, double direction); - - static void drawStyle2Needle(QPainter *, - const QPalette &, QPalette::ColorGroup, - const QPoint &, int length, double direction); +protected: + virtual void drawNeedle( QPainter *, + double length, QPalette::ColorGroup ) const; private: Style d_style; }; -#endif // QWT_DIAL_NEEDLE_H +#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_double_interval.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_double_interval.h deleted file mode 100644 index 6a89ea76c..000000000 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_double_interval.h +++ /dev/null @@ -1,284 +0,0 @@ -/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** - * Qwt Widget Library - * Copyright (C) 1997 Josef Wilgen - * Copyright (C) 2002 Uwe Rathmann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the Qwt License, Version 1.0 - *****************************************************************************/ - -#ifndef QWT_DOUBLE_INTERVAL_H -#define QWT_DOUBLE_INTERVAL_H - -#include "qwt_global.h" - -/*! - \brief A class representing an interval - - The interval is represented by 2 doubles, the lower and the upper limit. -*/ - -class QWT_EXPORT QwtDoubleInterval -{ -public: - /*! - Flag indicating if a border is included/excluded from an interval - - - IncludeBorders\n - min/max values are inside the interval - - ExcludeMinimum\n - min value is not included in the interval - - ExcludeMaximum\n - max value is not included in the interval - - ExcludeBorders\n - min/max values are not included in the interval - - \sa setBorderMode(), testBorderMode() - */ - enum BorderMode - { - IncludeBorders = 0, - - ExcludeMinimum = 1, - ExcludeMaximum = 2, - - ExcludeBorders = ExcludeMinimum | ExcludeMaximum - }; - - inline QwtDoubleInterval(); - inline QwtDoubleInterval(double minValue, double maxValue, - int borderFlags = IncludeBorders); - - inline void setInterval(double minValue, double maxValue, - int borderFlags = IncludeBorders); - - QwtDoubleInterval normalized() const; - QwtDoubleInterval inverted() const; - QwtDoubleInterval limited(double minValue, double maxValue) const; - - inline int operator==(const QwtDoubleInterval &) const; - inline int operator!=(const QwtDoubleInterval &) const; - - inline void setBorderFlags(int); - inline int borderFlags() const; - - inline double minValue() const; - inline double maxValue() const; - - inline double width() const; - - inline void setMinValue(double); - inline void setMaxValue(double); - - bool contains(double value) const; - - bool intersects(const QwtDoubleInterval &) const; - QwtDoubleInterval intersect(const QwtDoubleInterval &) const; - QwtDoubleInterval unite(const QwtDoubleInterval &) const; - - inline QwtDoubleInterval operator|(const QwtDoubleInterval &) const; - inline QwtDoubleInterval operator&(const QwtDoubleInterval &) const; - - QwtDoubleInterval &operator|=(const QwtDoubleInterval &); - QwtDoubleInterval &operator&=(const QwtDoubleInterval &); - - QwtDoubleInterval extend(double value) const; - inline QwtDoubleInterval operator|(double) const; - QwtDoubleInterval &operator|=(double); - - inline bool isValid() const; - inline bool isNull() const; - inline void invalidate(); - - QwtDoubleInterval symmetrize(double value) const; - -private: - double d_minValue; - double d_maxValue; - int d_borderFlags; -}; - -/*! - \brief Default Constructor - - Creates an invalid interval [0.0, -1.0] - \sa setInterval(), isValid() -*/ -inline QwtDoubleInterval::QwtDoubleInterval(): - d_minValue(0.0), - d_maxValue(-1.0), - d_borderFlags(IncludeBorders) -{ -} - -/*! - Constructor - - Build an interval with from min/max values - - \param minValue Minimum value - \param maxValue Maximum value - \param borderFlags Include/Exclude borders -*/ -inline QwtDoubleInterval::QwtDoubleInterval( - double minValue, double maxValue, int borderFlags): - d_minValue(minValue), - d_maxValue(maxValue), - d_borderFlags(borderFlags) -{ -} - -/*! - Assign the limits of the interval - - \param minValue Minimum value - \param maxValue Maximum value - \param borderFlags Include/Exclude borders -*/ -inline void QwtDoubleInterval::setInterval( - double minValue, double maxValue, int borderFlags) -{ - d_minValue = minValue; - d_maxValue = maxValue; - d_borderFlags = borderFlags; -} - -/*! - Change the border flags - - \param borderFlags Or'd BorderMode flags - \sa borderFlags() -*/ -inline void QwtDoubleInterval::setBorderFlags(int borderFlags) -{ - d_borderFlags = borderFlags; -} - -/*! - \return Border flags - \sa setBorderFlags() -*/ -inline int QwtDoubleInterval::borderFlags() const -{ - return d_borderFlags; -} - -/*! - Assign the lower limit of the interval - - \param minValue Minimum value -*/ -inline void QwtDoubleInterval::setMinValue(double minValue) -{ - d_minValue = minValue; -} - -/*! - Assign the upper limit of the interval - - \param maxValue Maximum value -*/ -inline void QwtDoubleInterval::setMaxValue(double maxValue) -{ - d_maxValue = maxValue; -} - -//! \return Lower limit of the interval -inline double QwtDoubleInterval::minValue() const -{ - return d_minValue; -} - -//! \return Upper limit of the interval -inline double QwtDoubleInterval::maxValue() const -{ - return d_maxValue; -} - -/*! - Return the width of an interval - The width of invalid intervals is 0.0, otherwise the result is - maxValue() - minValue(). - - \sa isValid() -*/ -inline double QwtDoubleInterval::width() const -{ - return isValid() ? (d_maxValue - d_minValue) : 0.0; -} - -/*! - Intersection of two intervals - \sa intersect() -*/ -inline QwtDoubleInterval QwtDoubleInterval::operator&( - const QwtDoubleInterval &interval ) const -{ - return intersect(interval); -} - -/*! - Union of two intervals - \sa unite() -*/ -inline QwtDoubleInterval QwtDoubleInterval::operator|( - const QwtDoubleInterval &interval) const -{ - return unite(interval); -} - -//! Compare two intervals -inline int QwtDoubleInterval::operator==(const QwtDoubleInterval &other) const -{ - return (d_minValue == other.d_minValue) && - (d_maxValue == other.d_maxValue) && - (d_borderFlags == other.d_borderFlags); -} - -//! Compare two intervals -inline int QwtDoubleInterval::operator!=(const QwtDoubleInterval &other) const -{ - return (!(*this == other)); -} - -/*! - Extend an interval - \sa extend() -*/ -inline QwtDoubleInterval QwtDoubleInterval::operator|(double value) const -{ - return extend(value); -} - -//! \return true, if isValid() && (minValue() >= maxValue()) -inline bool QwtDoubleInterval::isNull() const -{ - return isValid() && d_minValue >= d_maxValue; -} - -/*! - A interval is valid when minValue() <= maxValue(). - In case of QwtDoubleInterval::ExcludeBorders it is true - when minValue() < maxValue() -*/ -inline bool QwtDoubleInterval::isValid() const -{ - if ( (d_borderFlags & ExcludeBorders) == 0 ) - return d_minValue <= d_maxValue; - else - return d_minValue < d_maxValue; -} - -/*! - Invalidate the interval - - The limits are set to interval [0.0, -1.0] - \sa isValid() -*/ -inline void QwtDoubleInterval::invalidate() -{ - d_minValue = 0.0; - d_maxValue = -1.0; -} - -#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_double_range.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_double_range.cpp index c51ed5f45..6e9216457 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_double_range.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_double_range.cpp @@ -2,48 +2,70 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -#include #include "qwt_double_range.h" #include "qwt_math.h" -static double MinRelStep = 1.0e-10; -static double DefaultRelStep = 1.0e-2; -static double MinEps = 1.0e-10; +#if QT_VERSION < 0x040601 +#define qFabs(x) ::fabs(x) +#endif + +class QwtDoubleRange::PrivateData +{ +public: + PrivateData(): + minValue( 0.0 ), + maxValue( 0.0 ), + step( 1.0 ), + pageSize( 1 ), + isValid( false ), + value( 0.0 ), + exactValue( 0.0 ), + exactPrevValue( 0.0 ), + prevValue( 0.0 ), + periodic( false ) + { + } + + double minValue; + double maxValue; + double step; + int pageSize; + + bool isValid; + double value; + double exactValue; + double exactPrevValue; + double prevValue; + + bool periodic; +}; /*! The range is initialized to [0.0, 100.0], the step size to 1.0, and the value to 0.0. */ -QwtDoubleRange::QwtDoubleRange(): - d_minValue(0.0), - d_maxValue(0.0), - d_step(1.0), - d_pageSize(1), - d_isValid(false), - d_value(0.0), - d_exactValue(0.0), - d_exactPrevValue(0.0), - d_prevValue(0.0), - d_periodic(false) +QwtDoubleRange::QwtDoubleRange() { + d_data = new PrivateData(); } //! Destroys the QwtDoubleRange QwtDoubleRange::~QwtDoubleRange() { + delete d_data; } //! Set the value to be valid/invalid -void QwtDoubleRange::setValid(bool isValid) +void QwtDoubleRange::setValid( bool isValid ) { - if ( isValid != d_isValid ) + if ( isValid != d_data->isValid ) { - d_isValid = isValid; + d_data->isValid = isValid; valueChange(); } } @@ -51,74 +73,67 @@ void QwtDoubleRange::setValid(bool isValid) //! Indicates if the value is valid bool QwtDoubleRange::isValid() const { - return d_isValid; + return d_data->isValid; } -/*! - \brief No docs - - Description - \param x ??? - \param align - \todo Documentation -*/ -void QwtDoubleRange::setNewValue(double x, bool align) +void QwtDoubleRange::setNewValue( double value, bool align ) { - double vmin,vmax; - - d_prevValue = d_value; + d_data->prevValue = d_data->value; - vmin = qwtMin(d_minValue, d_maxValue); - vmax = qwtMax(d_minValue, d_maxValue); + const double vmin = qMin( d_data->minValue, d_data->maxValue ); + const double vmax = qMax( d_data->minValue, d_data->maxValue ); - // - // Range check - // - if (x < vmin) + if ( value < vmin ) { - if ((d_periodic) && (vmin != vmax)) - d_value = x + ::ceil( (vmin - x) / (vmax - vmin ) ) - * (vmax - vmin); - else - d_value = vmin; - } - else if (x > vmax) - { - if ((d_periodic) && (vmin != vmax)) - d_value = x - ::ceil( ( x - vmax) / (vmax - vmin )) - * (vmax - vmin); - else - d_value = vmax; - } - else - d_value = x; - - d_exactPrevValue = d_exactValue; - d_exactValue = d_value; - - // align to grid - if (align) - { - if (d_step != 0.0) + if ( d_data->periodic && vmin != vmax ) { - d_value = d_minValue + - qwtRound((d_value - d_minValue) / d_step) * d_step; + d_data->value = value + + qwtCeilF( ( vmin - value ) / ( vmax - vmin ) ) * ( vmax - vmin ); } else - d_value = d_minValue; - - // correct rounding error at the border - if (fabs(d_value - d_maxValue) < MinEps * qwtAbs(d_step)) - d_value = d_maxValue; - - // correct rounding error if value = 0 - if (::fabs(d_value) < MinEps * qwtAbs(d_step)) - d_value = 0.0; + d_data->value = vmin; + } + else if ( value > vmax ) + { + if ( ( d_data->periodic ) && ( vmin != vmax ) ) + { + d_data->value = value - + qwtCeilF( ( value - vmax ) / ( vmax - vmin ) ) * ( vmax - vmin ); + } + else + d_data->value = vmax; + } + else + { + d_data->value = value; } - if (!d_isValid || d_prevValue != d_value) + d_data->exactPrevValue = d_data->exactValue; + d_data->exactValue = d_data->value; + + if ( align ) { - d_isValid = true; + if ( d_data->step != 0.0 ) + { + d_data->value = d_data->minValue + + qRound( ( d_data->value - d_data->minValue ) / d_data->step ) * d_data->step; + } + else + d_data->value = d_data->minValue; + + const double minEps = 1.0e-10; + // correct rounding error at the border + if ( qFabs( d_data->value - d_data->maxValue ) < minEps * qAbs( d_data->step ) ) + d_data->value = d_data->maxValue; + + // correct rounding error if value = 0 + if ( qFabs( d_data->value ) < minEps * qAbs( d_data->step ) ) + d_data->value = 0.0; + } + + if ( !d_data->isValid || d_data->prevValue != d_data->value ) + { + d_data->isValid = true; valueChange(); } } @@ -132,9 +147,9 @@ void QwtDoubleRange::setNewValue(double x, bool align) \verbatim new value := x + n * (max. value - min. value)\endverbatim with an integer number n. */ -void QwtDoubleRange::fitValue(double x) +void QwtDoubleRange::fitValue( double x ) { - setNewValue(x, true); + setNewValue( x, true ); } @@ -147,9 +162,9 @@ void QwtDoubleRange::fitValue(double x) \verbatim new value := x + n * (max. value - min. value)\endverbatim with an integer number n. */ -void QwtDoubleRange::setValue(double x) +void QwtDoubleRange::setValue( double x ) { - setNewValue(x, false); + setNewValue( x, false ); } /*! @@ -169,66 +184,67 @@ void QwtDoubleRange::setValue(double x) \li If the step size has an absurd value, it will be corrected to a better one. */ -void QwtDoubleRange::setRange(double vmin, double vmax, double vstep, int pageSize) +void QwtDoubleRange::setRange( + double vmin, double vmax, double vstep, int pageSize ) { - bool rchg = ((d_maxValue != vmax) || (d_minValue != vmin)); - - if (rchg) - { - d_minValue = vmin; - d_maxValue = vmax; - } - - // - // look if the step width has an acceptable - // value or otherwise change it. - // - setStep(vstep); + const bool rchg = ( d_data->maxValue != vmax || d_data->minValue != vmin ); + + if ( rchg ) + { + d_data->minValue = vmin; + d_data->maxValue = vmax; + } + + // look if the step width has an acceptable + // value or otherwise change it. + setStep( vstep ); - // // limit page size - // - d_pageSize = qwtLim(pageSize,0, - int(qwtAbs((d_maxValue - d_minValue) / d_step))); - - // - // If the value lies out of the range, it - // will be changed. Note that it will not be adjusted to + const int max = + int( qAbs( ( d_data->maxValue - d_data->minValue ) / d_data->step ) ); + d_data->pageSize = qBound( 0, pageSize, max ); + + // If the value lies out of the range, it + // will be changed. Note that it will not be adjusted to // the new step width. - setNewValue(d_value, false); - - // call notifier after the step width has been + setNewValue( d_data->value, false ); + + // call notifier after the step width has been // adjusted. - if (rchg) - rangeChange(); + if ( rchg ) + rangeChange(); } /*! - \brief Change the step raster + \brief Change the step raster \param vstep new step width \warning The value will \e not be adjusted to the new step raster. */ -void QwtDoubleRange::setStep(double vstep) +void QwtDoubleRange::setStep( double vstep ) { - double intv = d_maxValue - d_minValue; - + const double intv = d_data->maxValue - d_data->minValue; + double newStep; - if (vstep == 0.0) - newStep = intv * DefaultRelStep; + if ( vstep == 0.0 ) + { + const double defaultRelStep = 1.0e-2; + newStep = intv * defaultRelStep; + } else { - if (((intv > 0) && (vstep < 0)) || ((intv < 0) && (vstep > 0))) - newStep = -vstep; + if ( ( intv > 0.0 && vstep < 0.0 ) || ( intv < 0.0 && vstep > 0.0 ) ) + newStep = -vstep; else - newStep = vstep; - - if ( fabs(newStep) < fabs(MinRelStep * intv) ) - newStep = MinRelStep * intv; + newStep = vstep; + + const double minRelStep = 1.0e-10; + if ( qFabs( newStep ) < qFabs( minRelStep * intv ) ) + newStep = minRelStep * intv; } - - if (newStep != d_step) + + if ( newStep != d_data->step ) { - d_step = newStep; + d_data->step = newStep; stepChange(); } } @@ -248,9 +264,9 @@ void QwtDoubleRange::setStep(double vstep) \param tf true for a periodic range */ -void QwtDoubleRange::setPeriodic(bool tf) +void QwtDoubleRange::setPeriodic( bool tf ) { - d_periodic = tf; + d_data->periodic = tf; } /*! @@ -259,10 +275,10 @@ void QwtDoubleRange::setPeriodic(bool tf) \warning As a result of this operation, the new value will always be adjusted to the step raster. */ -void QwtDoubleRange::incValue(int nSteps) +void QwtDoubleRange::incValue( int nSteps ) { if ( isValid() ) - setNewValue(d_value + double(nSteps) * d_step, true); + setNewValue( d_data->value + double( nSteps ) * d_data->step, true ); } /*! @@ -271,10 +287,13 @@ void QwtDoubleRange::incValue(int nSteps) A negative number decrements the value. \warning The Page size is specified in the constructor. */ -void QwtDoubleRange::incPages(int nPages) +void QwtDoubleRange::incPages( int nPages ) { if ( isValid() ) - setNewValue(d_value + double(nPages) * double(d_pageSize) * d_step, true); + { + const double off = d_data->step * d_data->pageSize * nPages; + setNewValue( d_data->value + off, true ); + } } /*! @@ -315,7 +334,7 @@ void QwtDoubleRange::stepChange() */ double QwtDoubleRange::step() const { - return qwtAbs(d_step); + return qAbs( d_data->step ); } /*! @@ -323,46 +342,46 @@ double QwtDoubleRange::step() const maxValue returns the value which has been specified as the second parameter in QwtDoubleRange::setRange. - - \sa setRange() -*/ -double QwtDoubleRange::maxValue() const -{ - return d_maxValue; -} - -/*! - \brief Returns the value at the first border of the range - - minValue returns the value which has been specified - as the first parameter in setRange(). - + \sa setRange() */ -double QwtDoubleRange::minValue() const +double QwtDoubleRange::maxValue() const { - return d_minValue; -} + return d_data->maxValue; +} + +/*! + \brief Returns the value at the first border of the range + + minValue returns the value which has been specified + as the first parameter in setRange(). + + \sa setRange() +*/ +double QwtDoubleRange::minValue() const +{ + return d_data->minValue; +} /*! \brief Returns true if the range is periodic \sa setPeriodic() */ -bool QwtDoubleRange::periodic() const -{ - return d_periodic; +bool QwtDoubleRange::periodic() const +{ + return d_data->periodic; } //! Returns the page size in steps. -int QwtDoubleRange::pageSize() const -{ - return d_pageSize; +int QwtDoubleRange::pageSize() const +{ + return d_data->pageSize; } //! Returns the current value. -double QwtDoubleRange::value() const -{ - return d_value; +double QwtDoubleRange::value() const +{ + return d_data->value; } /*! @@ -370,23 +389,22 @@ double QwtDoubleRange::value() const The exact value is the value which QwtDoubleRange::value would return if the value were not adjusted to the step raster. It differs from - the current value only if QwtDoubleRange::fitValue or - QwtDoubleRange::incValue have been used before. This function - is intended for internal use in derived classes. + the current value only if fitValue() or incValue() have been used before. + This function is intended for internal use in derived classes. */ -double QwtDoubleRange::exactValue() const -{ - return d_exactValue; +double QwtDoubleRange::exactValue() const +{ + return d_data->exactValue; } //! Returns the exact previous value -double QwtDoubleRange::exactPrevValue() const -{ - return d_exactPrevValue; +double QwtDoubleRange::exactPrevValue() const +{ + return d_data->exactPrevValue; } //! Returns the previous value -double QwtDoubleRange::prevValue() const -{ - return d_prevValue; +double QwtDoubleRange::prevValue() const +{ + return d_data->prevValue; } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_double_range.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_double_range.h index 21c6b27cb..bd9ad8332 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_double_range.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_double_range.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -17,14 +17,14 @@ This class is useful as a base class or a member for sliders. It represents an interval of type double within which a value can - be moved. The value can be either an arbitrary point inside + be moved. The value can be either an arbitrary point inside the interval (see QwtDoubleRange::setValue), or it can be fitted into a step raster (see QwtDoubleRange::fitValue and QwtDoubleRange::incValue). As a special case, a QwtDoubleRange can be periodic, which means that a value outside the interval will be mapped to a value inside the - interval when QwtDoubleRange::setValue(), QwtDoubleRange::fitValue(), + interval when QwtDoubleRange::setValue(), QwtDoubleRange::fitValue(), QwtDoubleRange::incValue() or QwtDoubleRange::incPages() are called. */ @@ -34,29 +34,29 @@ public: QwtDoubleRange(); virtual ~QwtDoubleRange(); - void setRange(double vmin, double vmax, double vstep = 0.0, - int pagesize = 1); + void setRange( double vmin, double vmax, + double vstep = 0.0, int pagesize = 1 ); - void setValid(bool); + void setValid( bool ); bool isValid() const; - virtual void setValue(double); + virtual void setValue( double ); double value() const; - void setPeriodic(bool tf); + void setPeriodic( bool tf ); bool periodic() const; - void setStep(double); + void setStep( double ); double step() const; double maxValue() const; - double minValue() const; + double minValue() const; int pageSize() const; - virtual void incValue(int); - virtual void incPages(int); - virtual void fitValue(double); + virtual void incValue( int ); + virtual void incPages( int ); + virtual void fitValue( double ); protected: @@ -69,20 +69,10 @@ protected: virtual void rangeChange(); private: - void setNewValue(double x, bool align = false); + void setNewValue( double value, bool align = false ); - double d_minValue; - double d_maxValue; - double d_step; - int d_pageSize; - - bool d_isValid; - double d_value; - double d_exactValue; - double d_exactPrevValue; - double d_prevValue; - - bool d_periodic; + class PrivateData; + PrivateData *d_data; }; #endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_double_rect.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_double_rect.cpp deleted file mode 100644 index 12d6cf4d1..000000000 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_double_rect.cpp +++ /dev/null @@ -1,605 +0,0 @@ -/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** - * Qwt Widget Library - * Copyright (C) 1997 Josef Wilgen - * Copyright (C) 2002 Uwe Rathmann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the Qwt License, Version 1.0 - *****************************************************************************/ - -#include - -#if QT_VERSION < 0x040000 - -#include "qwt_math.h" -#include "qwt_double_rect.h" - -/*! - Constructs a null point. - - \sa QwtDoublePoint::isNull() -*/ -QwtDoublePoint::QwtDoublePoint(): - d_x(0.0), - d_y(0.0) -{ -} - -//! Constructs a point with coordinates specified by x and y. -QwtDoublePoint::QwtDoublePoint(double x, double y ): - d_x(x), - d_y(y) -{ -} - -/*! - Copy constructor. - - Constructs a point using the values of the point specified. -*/ -QwtDoublePoint::QwtDoublePoint(const QPoint &p): - d_x(double(p.x())), - d_y(double(p.y())) -{ -} - -/*! - Returns true if point1 is equal to point2; otherwise returns false. - - Two points are equal to each other if both x-coordinates and - both y-coordinates are the same. -*/ -bool QwtDoublePoint::operator==(const QwtDoublePoint &other) const -{ - return (d_x == other.d_x) && (d_y == other.d_y); -} - -//! Returns true if point1 is not equal to point2; otherwise returns false. -bool QwtDoublePoint::operator!=(const QwtDoublePoint &other) const -{ - return !operator==(other); -} - -/*! - Negates the coordinates of the point, and returns a point with the - new coordinates. (Inversion). -*/ -const QwtDoublePoint QwtDoublePoint::operator-() const -{ - return QwtDoublePoint(-d_x, -d_y); -} - -/*! - Adds the coordinates of the point to the corresponding coordinates of - the other point, and returns a point with the new coordinates. - (Vector addition.) -*/ -const QwtDoublePoint QwtDoublePoint::operator+( - const QwtDoublePoint &other) const -{ - return QwtDoublePoint(d_x + other.d_x, d_y + other.d_y); -} - -/*! - Subtracts the coordinates of the other point from the corresponding - coordinates of the given point, and returns a point with the new - coordinates. (Vector subtraction.) -*/ -const QwtDoublePoint QwtDoublePoint::operator-( - const QwtDoublePoint &other) const -{ - return QwtDoublePoint(d_x - other.d_x, d_y - other.d_y); -} - -/*! - Multiplies the coordinates of the point by the given scale factor, - and returns a point with the new coordinates. - (Scalar multiplication of a vector.) -*/ -const QwtDoublePoint QwtDoublePoint::operator*(double factor) const -{ - return QwtDoublePoint(d_x * factor, d_y * factor); -} - -/*! - Divides the coordinates of the point by the given scale factor, - and returns a point with the new coordinates. - (Scalar division of a vector.) -*/ -const QwtDoublePoint QwtDoublePoint::operator/(double factor) const -{ - return QwtDoublePoint(d_x / factor, d_y / factor); -} - -/*! - Adds the coordinates of this point to the corresponding coordinates - of the other point, and returns a reference to this point with the - new coordinates. This is equivalent to vector addition. -*/ -QwtDoublePoint &QwtDoublePoint::operator+=(const QwtDoublePoint &other) -{ - d_x += other.d_x; - d_y += other.d_y; - return *this; -} - -/*! - Subtracts the coordinates of the other point from the corresponding - coordinates of this point, and returns a reference to this point with - the new coordinates. This is equivalent to vector subtraction. -*/ -QwtDoublePoint &QwtDoublePoint::operator-=(const QwtDoublePoint &other) -{ - d_x -= other.d_x; - d_y -= other.d_y; - return *this; -} - -/*! - Multiplies the coordinates of this point by the given scale factor, - and returns a reference to this point with the new coordinates. - This is equivalent to scalar multiplication of a vector. -*/ -QwtDoublePoint &QwtDoublePoint::operator*=(double factor) -{ - d_x *= factor; - d_y *= factor; - return *this; -} - -/*! - Divides the coordinates of this point by the given scale factor, - and returns a references to this point with the new coordinates. - This is equivalent to scalar division of a vector. -*/ -QwtDoublePoint &QwtDoublePoint::operator/=(double factor) -{ - d_x /= factor; - d_y /= factor; - return *this; -} - -//! Constructs an invalid size. -QwtDoubleSize::QwtDoubleSize(): - d_width(-1.0), - d_height(-1.0) -{ -} - -//! Constructs a size with width width and height height. -QwtDoubleSize::QwtDoubleSize( double width, double height ): - d_width(width), - d_height(height) -{ -} - -//! Constructs a size with floating point accuracy from the given size. -QwtDoubleSize::QwtDoubleSize(const QSize &sz): - d_width(double(sz.width())), - d_height(double(sz.height())) -{ -} - -//! Swaps the width and height values. -void QwtDoubleSize::transpose() -{ - double tmp = d_width; - d_width = d_height; - d_height = tmp; -} - -/*! - Returns a size with the maximum width and height of this - size and other. -*/ -QwtDoubleSize QwtDoubleSize::expandedTo( - const QwtDoubleSize &other) const -{ - return QwtDoubleSize( - qwtMax(d_width, other.d_width), - qwtMax(d_height, other.d_height) - ); -} - -/*! - Returns a size with the minimum width and height of this size and other. -*/ -QwtDoubleSize QwtDoubleSize::boundedTo( - const QwtDoubleSize &other) const -{ - return QwtDoubleSize( - qwtMin(d_width, other.d_width), - qwtMin(d_height, other.d_height) - ); -} - -//! Returns true if s1 and s2 are equal; otherwise returns false. -bool QwtDoubleSize::operator==(const QwtDoubleSize &other) const -{ - return d_width == other.d_width && d_height == other.d_height; -} - -//! Returns true if s1 and s2 are different; otherwise returns false. -bool QwtDoubleSize::operator!=(const QwtDoubleSize &other) const -{ - return !operator==(other); -} - -/*! - Returns the size formed by adding both components by - the components of other. Each component is added separately. -*/ -const QwtDoubleSize QwtDoubleSize::operator+( - const QwtDoubleSize &other) const -{ - return QwtDoubleSize(d_width + other.d_width, - d_height + other.d_height); -} - -/*! - Returns the size formed by subtracting both components by - the components of other. Each component is subtracted separately. -*/ -const QwtDoubleSize QwtDoubleSize::operator-( - const QwtDoubleSize &other) const -{ - return QwtDoubleSize(d_width - other.d_width, - d_height - other.d_height); -} - -//! Returns the size formed by multiplying both components by c. -const QwtDoubleSize QwtDoubleSize::operator*(double c) const -{ - return QwtDoubleSize(d_width * c, d_height * c); -} - -//! Returns the size formed by dividing both components by c. -const QwtDoubleSize QwtDoubleSize::operator/(double c) const -{ - return QwtDoubleSize(d_width / c, d_height / c); -} - -//! Adds size other to this size and returns a reference to this size. -QwtDoubleSize &QwtDoubleSize::operator+=(const QwtDoubleSize &other) -{ - d_width += other.d_width; - d_height += other.d_height; - return *this; -} - -//! Subtracts size other from this size and returns a reference to this size. -QwtDoubleSize &QwtDoubleSize::operator-=(const QwtDoubleSize &other) -{ - d_width -= other.d_width; - d_height -= other.d_height; - return *this; -} - -/* - Multiplies this size's width and height by c, - and returns a reference to this size. -*/ -QwtDoubleSize &QwtDoubleSize::operator*=(double c) -{ - d_width *= c; - d_height *= c; - return *this; -} - -/* - Devides this size's width and height by c, - and returns a reference to this size. -*/ -QwtDoubleSize &QwtDoubleSize::operator/=(double c) -{ - d_width /= c; - d_height /= c; - return *this; -} - -//! Constructs an rectangle with all components set to 0.0 -QwtDoubleRect::QwtDoubleRect(): - d_left(0.0), - d_right(0.0), - d_top(0.0), - d_bottom(0.0) -{ -} - -/*! - Constructs an rectangle with x1 to x2 as x-range and, - y1 to y2 as y-range. -*/ -QwtDoubleRect::QwtDoubleRect(double left, double top, - double width, double height): - d_left(left), - d_right(left + width), - d_top(top), - d_bottom(top + height) -{ -} - -/*! - Constructs a rectangle with topLeft as the top-left corner and - size as the rectangle size. -*/ -QwtDoubleRect::QwtDoubleRect( - const QwtDoublePoint &p, const QwtDoubleSize &size): - d_left(p.x()), - d_right(p.x() + size.width()), - d_top(p.y()), - d_bottom(p.y() + size.height()) -{ -} - -QwtDoubleRect::QwtDoubleRect(const QRect &rect): - d_left(rect.left()), - d_right(rect.right()), - d_top(rect.top()), - d_bottom(rect.bottom()) -{ -} - -QRect QwtDoubleRect::toRect() const -{ - return QRect(qRound(x()), qRound(y()), qRound(width()), qRound(height())); -} - -/*! - Set the x-range from x1 to x2 and the y-range from y1 to y2. -*/ -void QwtDoubleRect::setRect(double left, double top, - double width, double height) -{ - d_left = left; - d_right = left + width; - d_top = top; - d_bottom = top + height; -} - -/*! - Sets the size of the rectangle to size. - Changes x2 and y2 only. -*/ -void QwtDoubleRect::setSize(const QwtDoubleSize &size) -{ - setWidth(size.width()); - setHeight(size.height()); -} - -/*! - Returns a normalized rectangle, i.e. a rectangle that has a non-negative - width and height. - - It swaps x1 and x2 if x1() > x2(), and swaps y1 and y2 if y1() > y2(). -*/ -QwtDoubleRect QwtDoubleRect::normalized() const -{ - QwtDoubleRect r; - if ( d_right < d_left ) - { - r.d_left = d_right; - r.d_right = d_left; - } - else - { - r.d_left = d_left; - r.d_right = d_right; - } - if ( d_bottom < d_top ) - { - r.d_top = d_bottom; - r.d_bottom = d_top; - } - else - { - r.d_top = d_top; - r.d_bottom = d_bottom; - } - return r; -} - -/*! - Returns the bounding rectangle of this rectangle and rectangle other. - r.unite(s) is equivalent to r|s. -*/ -QwtDoubleRect QwtDoubleRect::unite(const QwtDoubleRect &other) const -{ - return *this | other; -} - -/*! - Returns the intersection of this rectangle and rectangle other. - r.intersect(s) is equivalent to r&s. -*/ -QwtDoubleRect QwtDoubleRect::intersect(const QwtDoubleRect &other) const -{ - return *this & other; -} - -/*! - Returns true if this rectangle intersects with rectangle other; - otherwise returns false. -*/ -bool QwtDoubleRect::intersects(const QwtDoubleRect &other) const -{ - return ( qwtMax(d_left, other.d_left) <= qwtMin(d_right, other.d_right) ) && - ( qwtMax(d_top, other.d_top ) <= qwtMin(d_bottom, other.d_bottom) ); -} - -//! Returns true if this rect and other are equal; otherwise returns false. -bool QwtDoubleRect::operator==(const QwtDoubleRect &other) const -{ - return d_left == other.d_left && d_right == other.d_right && - d_top == other.d_top && d_bottom == other.d_bottom; -} - -//! Returns true if this rect and other are different; otherwise returns false. -bool QwtDoubleRect::operator!=(const QwtDoubleRect &other) const -{ - return !operator==(other); -} - -/*! - Returns the bounding rectangle of this rectangle and rectangle other. - The bounding rectangle of a nonempty rectangle and an empty or - invalid rectangle is defined to be the nonempty rectangle. -*/ -QwtDoubleRect QwtDoubleRect::operator|(const QwtDoubleRect &other) const -{ - if ( isEmpty() ) - return other; - - if ( other.isEmpty() ) - return *this; - - const double minX = qwtMin(d_left, other.d_left); - const double maxX = qwtMax(d_right, other.d_right); - const double minY = qwtMin(d_top, other.d_top); - const double maxY = qwtMax(d_bottom, other.d_bottom); - - return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY); -} - -/*! - Returns the intersection of this rectangle and rectangle other. - Returns an empty rectangle if there is no intersection. -*/ -QwtDoubleRect QwtDoubleRect::operator&(const QwtDoubleRect &other) const -{ - if (isNull() || other.isNull()) - return QwtDoubleRect(); - - const QwtDoubleRect r1 = normalized(); - const QwtDoubleRect r2 = other.normalized(); - - const double minX = qwtMax(r1.left(), r2.left()); - const double maxX = qwtMin(r1.right(), r2.right()); - const double minY = qwtMax(r1.top(), r2.top()); - const double maxY = qwtMin(r1.bottom(), r2.bottom()); - - return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY); -} - -//! Unites this rectangle with rectangle other. -QwtDoubleRect &QwtDoubleRect::operator|=(const QwtDoubleRect &other) -{ - *this = *this | other; - return *this; -} - -//! Intersects this rectangle with rectangle other. -QwtDoubleRect &QwtDoubleRect::operator&=(const QwtDoubleRect &other) -{ - *this = *this & other; - return *this; -} - -//! Returns the center point of the rectangle. -QwtDoublePoint QwtDoubleRect::center() const -{ - return QwtDoublePoint(d_left + (d_right - d_left) / 2.0, - d_top + (d_bottom - d_top) / 2.0); -} - -/*! - Returns true if the point (x, y) is inside or on the edge of the rectangle; - otherwise returns false. - - If proper is true, this function returns true only if p is inside - (not on the edge). -*/ -bool QwtDoubleRect::contains(double x, double y, bool proper) const -{ - if ( proper ) - return x > d_left && x < d_right && y > d_top && y < d_bottom; - else - return x >= d_left && x <= d_right && y >= d_top && y <= d_bottom; -} - -/*! - Returns true if the point p is inside or on the edge of the rectangle; - otherwise returns false. - - If proper is true, this function returns true only if p is inside - (not on the edge). -*/ -bool QwtDoubleRect::contains(const QwtDoublePoint &p, bool proper) const -{ - return contains(p.x(), p.y(), proper); -} - -/*! - Returns true if the rectangle other is inside this rectangle; - otherwise returns false. - - If proper is true, this function returns true only if other is entirely - inside (not on the edge). -*/ -bool QwtDoubleRect::contains(const QwtDoubleRect &other, bool proper) const -{ - return contains(other.d_left, other.d_top, proper) && - contains(other.d_right, other.d_bottom, proper); -} - -//! moves x1() to x, leaving the size unchanged -void QwtDoubleRect::moveLeft(double x) -{ - const double w = width(); - d_left = x; - d_right = d_left + w; -} - -//! moves x1() to x, leaving the size unchanged -void QwtDoubleRect::moveRight(double x) -{ - const double w = width(); - d_right = x; - d_left = d_right - w; -} - -//! moves y1() to y, leaving the size unchanged -void QwtDoubleRect::moveTop(double y) -{ - const double h = height(); - d_top = y; - d_bottom = d_top + h; -} - -//! moves y1() to y, leaving the size unchanged -void QwtDoubleRect::moveBottom(double y) -{ - const double h = height(); - d_bottom = y; - d_top = d_bottom - h; -} - -//! moves left() to x and top() to y, leaving the size unchanged -void QwtDoubleRect::moveTo(double x, double y) -{ - moveLeft(x); - moveTop(y); -} - -//! moves x1() by dx and y1() by dy. leaving the size unchanged -void QwtDoubleRect::moveBy(double dx, double dy) -{ - d_left += dx; - d_right += dx; - d_top += dy; - d_bottom += dy; -} - -//! moves the center to pos, leaving the size unchanged -void QwtDoubleRect::moveCenter(const QwtDoublePoint &pos) -{ - moveCenter(pos.x(), pos.y()); -} - -//! moves the center to (x, y), leaving the size unchanged -void QwtDoubleRect::moveCenter(double x, double y) -{ - moveTo(x - width() / 2.0, y - height() / 2.0); -} - -#endif // QT_VERSION < 0x040000 diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_double_rect.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_double_rect.h deleted file mode 100644 index 17be81c37..000000000 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_double_rect.h +++ /dev/null @@ -1,501 +0,0 @@ -/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** - * Qwt Widget Library - * Copyright (C) 1997 Josef Wilgen - * Copyright (C) 2002 Uwe Rathmann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the Qwt License, Version 1.0 - *****************************************************************************/ - -/*! \file */ -#ifndef QWT_DOUBLE_RECT_H -#define QWT_DOUBLE_RECT_H 1 - -#include "qwt_global.h" -#include "qwt_array.h" - -#if QT_VERSION >= 0x040000 - -#include -#include -#include - -/*! - \typedef QPointF QwtDoublePoint - \brief This is a typedef, see Trolltech Documentation for QPointF - in QT assistant 4.x. As soon as Qt3 compatibility is dropped - this typedef will disappear. -*/ -typedef QPointF QwtDoublePoint; - -/*! - \typedef QSizeF QwtDoubleSize - \brief This is a typedef, see Trolltech Documentation for QSizeF - in QT assistant 4.x. As soon as Qt3 compatibility is dropped - this typedef will disappear. -*/ -typedef QSizeF QwtDoubleSize; - -/*! - \typedef QRectF QwtDoubleRect - \brief This is a typedef, see Trolltech Documentation for QRectF - in QT assistant 4.x. As soon as Qt3 compatibility is dropped - this typedef will disappear. -*/ -typedef QRectF QwtDoubleRect; - -#else - -#include -#include -#include - -/*! - \brief The QwtDoublePoint class defines a point in double coordinates -*/ - -class QWT_EXPORT QwtDoublePoint -{ -public: - QwtDoublePoint(); - QwtDoublePoint(double x, double y); - QwtDoublePoint(const QPoint &); - - QPoint toPoint() const; - - bool isNull() const; - - double x() const; - double y() const; - - double &rx(); - double &ry(); - - void setX(double x); - void setY(double y); - - bool operator==(const QwtDoublePoint &) const; - bool operator!=(const QwtDoublePoint &) const; - - const QwtDoublePoint operator-() const; - const QwtDoublePoint operator+(const QwtDoublePoint &) const; - const QwtDoublePoint operator-(const QwtDoublePoint &) const; - const QwtDoublePoint operator*(double) const; - const QwtDoublePoint operator/(double) const; - - QwtDoublePoint &operator+=(const QwtDoublePoint &); - QwtDoublePoint &operator-=(const QwtDoublePoint &); - QwtDoublePoint &operator*=(double); - QwtDoublePoint &operator/=(double); - -private: - double d_x; - double d_y; -}; - -/*! - The QwtDoubleSize class defines a size in double coordinates -*/ - -class QWT_EXPORT QwtDoubleSize -{ -public: - QwtDoubleSize(); - QwtDoubleSize(double width, double height); - QwtDoubleSize(const QSize &); - - bool isNull() const; - bool isEmpty() const; - bool isValid() const; - - double width() const; - double height() const; - void setWidth( double w ); - void setHeight( double h ); - void transpose(); - - QwtDoubleSize expandedTo(const QwtDoubleSize &) const; - QwtDoubleSize boundedTo(const QwtDoubleSize &) const; - - bool operator==(const QwtDoubleSize &) const; - bool operator!=(const QwtDoubleSize &) const; - - const QwtDoubleSize operator+(const QwtDoubleSize &) const; - const QwtDoubleSize operator-(const QwtDoubleSize &) const; - const QwtDoubleSize operator*(double) const; - const QwtDoubleSize operator/(double) const; - - QwtDoubleSize &operator+=(const QwtDoubleSize &); - QwtDoubleSize &operator-=(const QwtDoubleSize &); - QwtDoubleSize &operator*=(double c); - QwtDoubleSize &operator/=(double c); - -private: - double d_width; - double d_height; -}; - -/*! - The QwtDoubleRect class defines a size in double coordinates. -*/ - -class QWT_EXPORT QwtDoubleRect -{ -public: - QwtDoubleRect(); - QwtDoubleRect(double left, double top, double width, double height); - QwtDoubleRect(const QwtDoublePoint&, const QwtDoubleSize &); - - QwtDoubleRect(const QRect &); - QRect toRect() const; - - bool isNull() const; - bool isEmpty() const; - bool isValid() const; - - QwtDoubleRect normalized() const; - - double x() const; - double y() const; - - double left() const; - double right() const; - double top() const; - double bottom() const; - - void setX(double); - void setY(double); - - void setLeft(double); - void setRight(double); - void setTop(double); - void setBottom(double); - - QwtDoublePoint center() const; - - void moveLeft(double x); - void moveRight(double x); - void moveTop(double y ); - void moveBottom(double y ); - void moveTo(double x, double y); - void moveTo(const QwtDoublePoint &); - void moveBy(double dx, double dy); - void moveCenter(const QwtDoublePoint &); - void moveCenter(double dx, double dy); - - void setRect(double x1, double x2, double width, double height); - - double width() const; - double height() const; - QwtDoubleSize size() const; - - void setWidth(double w ); - void setHeight(double h ); - void setSize(const QwtDoubleSize &); - - QwtDoubleRect operator|(const QwtDoubleRect &r) const; - QwtDoubleRect operator&(const QwtDoubleRect &r) const; - QwtDoubleRect &operator|=(const QwtDoubleRect &r); - QwtDoubleRect &operator&=(const QwtDoubleRect &r); - bool operator==( const QwtDoubleRect &) const; - bool operator!=( const QwtDoubleRect &) const; - - bool contains(const QwtDoublePoint &p, bool proper = false) const; - bool contains(double x, double y, bool proper = false) const; - bool contains(const QwtDoubleRect &r, bool proper=false) const; - - QwtDoubleRect unite(const QwtDoubleRect &) const; - QwtDoubleRect intersect(const QwtDoubleRect &) const; - bool intersects(const QwtDoubleRect &) const; - - QwtDoublePoint bottomRight() const; - QwtDoublePoint topRight() const; - QwtDoublePoint topLeft() const; - QwtDoublePoint bottomLeft() const; - -private: - double d_left; - double d_right; - double d_top; - double d_bottom; -}; - -/*! - Returns true if the point is null; otherwise returns false. - - A point is considered to be null if both the x- and y-coordinates - are equal to zero. -*/ -inline bool QwtDoublePoint::isNull() const -{ - return d_x == 0.0 && d_y == 0.0; -} - -//! Returns the x-coordinate of the point. -inline double QwtDoublePoint::x() const -{ - return d_x; -} - -//! Returns the y-coordinate of the point. -inline double QwtDoublePoint::y() const -{ - return d_y; -} - -//! Returns a reference to the x-coordinate of the point. -inline double &QwtDoublePoint::rx() -{ - return d_x; -} - -//! Returns a reference to the y-coordinate of the point. -inline double &QwtDoublePoint::ry() -{ - return d_y; -} - -//! Sets the x-coordinate of the point to the value specified by x. -inline void QwtDoublePoint::setX(double x) -{ - d_x = x; -} - -//! Sets the y-coordinate of the point to the value specified by y. -inline void QwtDoublePoint::setY(double y) -{ - d_y = y; -} - -/*! - Rounds the coordinates of this point to the nearest integer and - returns a QPoint with these rounded coordinates. -*/ -inline QPoint QwtDoublePoint::toPoint() const -{ - return QPoint(qRound(d_x), qRound(d_y)); -} - -/*! - Returns true if the width is 0 and the height is 0; - otherwise returns false. -*/ -inline bool QwtDoubleSize::isNull() const -{ - return d_width == 0.0 && d_height == 0.0; -} - -/*! - Returns true if the width is <= 0.0 or the height is <= 0.0, - otherwise false. -*/ -inline bool QwtDoubleSize::isEmpty() const -{ - return d_width <= 0.0 || d_height <= 0.0; -} - -/*! - Returns true if the width is equal to or greater than 0.0 and the height - is equal to or greater than 0.0; otherwise returns false. -*/ -inline bool QwtDoubleSize::isValid() const -{ - return d_width >= 0.0 && d_height >= 0.0; -} - -//! Returns the width. -inline double QwtDoubleSize::width() const -{ - return d_width; -} - -//! Returns the height. -inline double QwtDoubleSize::height() const -{ - return d_height; -} - -//! Sets the width to width. -inline void QwtDoubleSize::setWidth(double width) -{ - d_width = width; -} - -//! Sets the height to height. -inline void QwtDoubleSize::setHeight(double height) -{ - d_height = height; -} - -/*! - Returns true if the rectangle is a null rectangle; otherwise returns false. - A null rectangle has both the width and the height set to 0. - A null rectangle is also empty and invalid. - - \sa isEmpty(), isValid() -*/ -inline bool QwtDoubleRect::isNull() const -{ - return d_right == d_left && d_bottom == d_top; -} - -/*! - Returns true if the rectangle is empty; otherwise returns false. - An empty rectangle has a width() <= 0 or height() <= 0. - An empty rectangle is not valid. isEmpty() == !isValid() - - \sa isNull(), isValid() -*/ -inline bool QwtDoubleRect::isEmpty() const -{ - return d_left >= d_right || d_top >= d_bottom; -} - -/*! - Returns true if the rectangle is valid; otherwise returns false. - A valid rectangle has a width() > 0 and height() > 0. - Note that non-trivial operations like intersections are not defined - for invalid rectangles. isValid() == !isEmpty() - - \sa isNull(), isEmpty(), and normalized(). -*/ -inline bool QwtDoubleRect::isValid() const -{ - return d_left < d_right && d_top < d_bottom; -} - -//! Returns x -inline double QwtDoubleRect::x() const -{ - return d_left; -} - -//! Returns y -inline double QwtDoubleRect::y() const -{ - return d_top; -} - -//! Returns left -inline double QwtDoubleRect::left() const -{ - return d_left; -} - -//! Returns right -inline double QwtDoubleRect::right() const -{ - return d_right; -} - -//! Returns top -inline double QwtDoubleRect::top() const -{ - return d_top; -} - -//! Returns bottom -inline double QwtDoubleRect::bottom() const -{ - return d_bottom; -} - -//! Set left -inline void QwtDoubleRect::setX(double x) -{ - d_left = x; -} - -//! Set left -inline void QwtDoubleRect::setY(double y) -{ - d_top = y; -} - -//! Set left -inline void QwtDoubleRect::setLeft(double x) -{ - d_left = x; -} - -//! Set right -inline void QwtDoubleRect::setRight(double x) -{ - d_right = x; -} - -//! Set top -inline void QwtDoubleRect::setTop(double y) -{ - d_top = y; -} - -//! Set bottom -inline void QwtDoubleRect::setBottom(double y) -{ - d_bottom = y; -} - -//! Returns the width -inline double QwtDoubleRect::width() const -{ - return d_right - d_left; -} - -//! Returns the height -inline double QwtDoubleRect::height() const -{ - return d_bottom - d_top; -} - -//! Returns the size -inline QwtDoubleSize QwtDoubleRect::size() const -{ - return QwtDoubleSize(width(), height()); -} - -//! Set the width, by right = left + w; -inline void QwtDoubleRect::setWidth(double w) -{ - d_right = d_left + w; -} - -//! Set the height, by bottom = top + h; -inline void QwtDoubleRect::setHeight(double h) -{ - d_bottom = d_top + h; -} - -/*! - Moves the top left corner of the rectangle to p, - without changing the rectangles size. -*/ -inline void QwtDoubleRect::moveTo(const QwtDoublePoint &p) -{ - moveTo(p.x(), p.y()); -} - -inline QwtDoublePoint QwtDoubleRect::bottomRight() const -{ - return QwtDoublePoint(bottom(), right()); -} - -inline QwtDoublePoint QwtDoubleRect::topRight() const -{ - return QwtDoublePoint(top(), right()); -} - -inline QwtDoublePoint QwtDoubleRect::topLeft() const -{ - return QwtDoublePoint(top(), left()); -} - -inline QwtDoublePoint QwtDoubleRect::bottomLeft() const -{ - return QwtDoublePoint(bottom(), left()); -} - - -#endif // QT_VERSION < 0x040000 - -#endif // QWT_DOUBLE_RECT_H diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_dyngrid_layout.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_dyngrid_layout.cpp index 43e0c28a2..26ccac2f8 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_dyngrid_layout.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_dyngrid_layout.cpp @@ -7,96 +7,47 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -#include #include "qwt_dyngrid_layout.h" #include "qwt_math.h" - -#if QT_VERSION < 0x040000 -#include -#else +#include #include -#endif class QwtDynGridLayout::PrivateData { public: - -#if QT_VERSION < 0x040000 - class LayoutIterator: public QGLayoutIterator - { - public: - LayoutIterator(PrivateData *data): - d_data(data) - { - d_iterator = d_data->itemList.begin(); - } - - virtual QLayoutItem *current() - { - if (d_iterator == d_data->itemList.end()) - return NULL; - - return *d_iterator; - } - - virtual QLayoutItem *next() - { - if (d_iterator == d_data->itemList.end()) - return NULL; - - d_iterator++; - if (d_iterator == d_data->itemList.end()) - return NULL; - - return *d_iterator; - } - - virtual QLayoutItem *takeCurrent() - { - if ( d_iterator == d_data->itemList.end() ) - return NULL; - - QLayoutItem *item = *d_iterator; - - d_data->isDirty = true; - d_iterator = d_data->itemList.remove(d_iterator); - return item; - } - - private: - - QValueListIterator d_iterator; - QwtDynGridLayout::PrivateData *d_data; - }; -#endif - PrivateData(): - isDirty(true) + isDirty( true ) { } -#if QT_VERSION < 0x040000 - typedef QValueList LayoutItemList; -#else - typedef QList LayoutItemList; -#endif + void updateLayoutCache(); - mutable LayoutItemList itemList; + mutable QList itemList; uint maxCols; uint numRows; uint numCols; -#if QT_VERSION < 0x040000 - QSizePolicy::ExpandData expanding; -#else Qt::Orientations expanding; -#endif bool isDirty; - QwtArray itemSizeHints; + QVector itemSizeHints; }; +void QwtDynGridLayout::PrivateData::updateLayoutCache() +{ + itemSizeHints.resize( itemList.count() ); + + int index = 0; + + for ( QList::iterator it = itemList.begin(); + it != itemList.end(); ++it, index++ ) + { + itemSizeHints[ index ] = ( *it )->sizeHint(); + } + + isDirty = false; +} /*! \param parent Parent widget @@ -104,36 +55,24 @@ public: \param spacing Spacing */ -QwtDynGridLayout::QwtDynGridLayout(QWidget *parent, - int margin, int spacing): - QLayout(parent) +QwtDynGridLayout::QwtDynGridLayout( QWidget *parent, + int margin, int spacing ): + QLayout( parent ) { init(); - setSpacing(spacing); - setMargin(margin); + setSpacing( spacing ); + setMargin( margin ); } -#if QT_VERSION < 0x040000 -/*! - \param parent Parent widget - \param spacing Spacing -*/ -QwtDynGridLayout::QwtDynGridLayout(QLayout *parent, int spacing): - QLayout(parent, spacing) -{ - init(); -} -#endif - /*! \param spacing Spacing */ -QwtDynGridLayout::QwtDynGridLayout(int spacing) +QwtDynGridLayout::QwtDynGridLayout( int spacing ) { init(); - setSpacing(spacing); + setSpacing( spacing ); } /*! @@ -142,24 +81,16 @@ QwtDynGridLayout::QwtDynGridLayout(int spacing) void QwtDynGridLayout::init() { d_data = new QwtDynGridLayout::PrivateData; - d_data->maxCols = d_data->numRows - = d_data->numCols = 0; - -#if QT_VERSION < 0x040000 - d_data->expanding = QSizePolicy::NoDirection; - setSupportsMargin(true); -#else + d_data->maxCols = d_data->numRows = d_data->numCols = 0; d_data->expanding = 0; -#endif } //! Destructor QwtDynGridLayout::~QwtDynGridLayout() { -#if QT_VERSION < 0x040000 - deleteAllItems(); -#endif + for ( int i = 0; i < d_data->itemList.size(); i++ ) + delete d_data->itemList[i]; delete d_data; } @@ -171,28 +102,12 @@ void QwtDynGridLayout::invalidate() QLayout::invalidate(); } -void QwtDynGridLayout::updateLayoutCache() -{ - d_data->itemSizeHints.resize(itemCount()); - - int index = 0; - - for (PrivateData::LayoutItemList::iterator it = d_data->itemList.begin(); - it != d_data->itemList.end(); ++it, index++) - { - d_data->itemSizeHints[int(index)] = (*it)->sizeHint(); - } - - d_data->isDirty = false; -} - /*! Limit the number of columns. \param maxCols upper limit, 0 means unlimited \sa maxCols() */ - -void QwtDynGridLayout::setMaxCols(uint maxCols) +void QwtDynGridLayout::setMaxCols( uint maxCols ) { d_data->maxCols = maxCols; } @@ -203,21 +118,21 @@ void QwtDynGridLayout::setMaxCols(uint maxCols) \sa setMaxCols() */ -uint QwtDynGridLayout::maxCols() const -{ - return d_data->maxCols; +uint QwtDynGridLayout::maxCols() const +{ + return d_data->maxCols; } //! Adds item to the next free position. -void QwtDynGridLayout::addItem(QLayoutItem *item) +void QwtDynGridLayout::addItem( QLayoutItem *item ) { - d_data->itemList.append(item); + d_data->itemList.append( item ); invalidate(); } -/*! - \return true if this layout is empty. +/*! + \return true if this layout is empty. */ bool QwtDynGridLayout::isEmpty() const @@ -225,7 +140,7 @@ bool QwtDynGridLayout::isEmpty() const return d_data->itemList.isEmpty(); } -/*! +/*! \return number of layout items */ @@ -234,29 +149,6 @@ uint QwtDynGridLayout::itemCount() const return d_data->itemList.count(); } -#if QT_VERSION < 0x040000 -/*! - \return An iterator over the children of this layout. -*/ - -QLayoutIterator QwtDynGridLayout::iterator() -{ - return QLayoutIterator( - new QwtDynGridLayout::PrivateData::LayoutIterator(d_data) ); -} - -void QwtDynGridLayout::setExpanding(QSizePolicy::ExpandData expanding) -{ - d_data->expanding = expanding; -} - -QSizePolicy::ExpandData QwtDynGridLayout::expanding() const -{ - return d_data->expanding; -} - -#else // QT_VERSION >= 0x040000 - /*! Find the item at a spcific index @@ -268,9 +160,9 @@ QLayoutItem *QwtDynGridLayout::itemAt( int index ) const if ( index < 0 || index >= d_data->itemList.count() ) return NULL; - return d_data->itemList.at(index); + return d_data->itemList.at( index ); } - + /*! Find the item at a spcific index and remove it from the layout @@ -281,9 +173,9 @@ QLayoutItem *QwtDynGridLayout::takeAt( int index ) { if ( index < 0 || index >= d_data->itemList.count() ) return NULL; - + d_data->isDirty = true; - return d_data->itemList.takeAt(index); + return d_data->itemList.takeAt( index ); } //! \return Number of items in the layout @@ -295,13 +187,13 @@ int QwtDynGridLayout::count() const /*! Set whether this layout can make use of more space than sizeHint(). A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only - one dimension, while Qt::Vertical | Qt::Horizontal means that it wants + one dimension, while Qt::Vertical | Qt::Horizontal means that it wants to grow in both dimensions. The default value is 0. \param expanding Or'd orientations \sa expandingDirections() */ -void QwtDynGridLayout::setExpandingDirections(Qt::Orientations expanding) +void QwtDynGridLayout::setExpandingDirections( Qt::Orientations expanding ) { d_data->expanding = expanding; } @@ -309,7 +201,7 @@ void QwtDynGridLayout::setExpandingDirections(Qt::Orientations expanding) /*! Returns whether this layout can make use of more space than sizeHint(). A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only - one dimension, while Qt::Vertical | Qt::Horizontal means that it wants + one dimension, while Qt::Vertical | Qt::Horizontal means that it wants to grow in both dimensions. \sa setExpandingDirections() */ @@ -318,46 +210,40 @@ Qt::Orientations QwtDynGridLayout::expandingDirections() const return d_data->expanding; } -#endif - /*! - Reorganizes columns and rows and resizes managed widgets within - the rectangle rect. + Reorganizes columns and rows and resizes managed widgets within + the rectangle rect. \param rect Layout geometry */ -void QwtDynGridLayout::setGeometry(const QRect &rect) +void QwtDynGridLayout::setGeometry( const QRect &rect ) { - QLayout::setGeometry(rect); + QLayout::setGeometry( rect ); if ( isEmpty() ) return; - d_data->numCols = columnsForWidth(rect.width()); + d_data->numCols = columnsForWidth( rect.width() ); d_data->numRows = itemCount() / d_data->numCols; if ( itemCount() % d_data->numCols ) d_data->numRows++; -#if QT_VERSION < 0x040000 - QValueList itemGeometries = layoutItems(rect, d_data->numCols); -#else - QList itemGeometries = layoutItems(rect, d_data->numCols); -#endif + QList itemGeometries = layoutItems( rect, d_data->numCols ); int index = 0; - for (PrivateData::LayoutItemList::iterator it = d_data->itemList.begin(); - it != d_data->itemList.end(); ++it) + for ( QList::iterator it = d_data->itemList.begin(); + it != d_data->itemList.end(); ++it ) { - QWidget *w = (*it)->widget(); + QWidget *w = ( *it )->widget(); if ( w ) { - w->setGeometry(itemGeometries[index]); + w->setGeometry( itemGeometries[index] ); index++; } } } -/*! +/*! Calculate the number of columns for a given width. It tries to use as many columns as possible (limited by maxCols()) @@ -365,18 +251,18 @@ void QwtDynGridLayout::setGeometry(const QRect &rect) \sa maxCols(), setMaxCols() */ -uint QwtDynGridLayout::columnsForWidth(int width) const +uint QwtDynGridLayout::columnsForWidth( int width ) const { if ( isEmpty() ) return 0; - const int maxCols = (d_data->maxCols > 0) ? d_data->maxCols : itemCount(); - if ( maxRowWidth(maxCols) <= width ) + const int maxCols = ( d_data->maxCols > 0 ) ? d_data->maxCols : itemCount(); + if ( maxRowWidth( maxCols ) <= width ) return maxCols; - for (int numCols = 2; numCols <= maxCols; numCols++ ) + for ( int numCols = 2; numCols <= maxCols; numCols++ ) { - const int rowWidth = maxRowWidth(numCols); + const int rowWidth = maxRowWidth( numCols ); if ( rowWidth > width ) return numCols - 1; } @@ -384,34 +270,34 @@ uint QwtDynGridLayout::columnsForWidth(int width) const return 1; // At least 1 column } -/*! +/*! Calculate the width of a layout for a given number of columns. \param numCols Given number of columns \param itemWidth Array of the width hints for all items */ -int QwtDynGridLayout::maxRowWidth(int numCols) const +int QwtDynGridLayout::maxRowWidth( int numCols ) const { int col; - QwtArray colWidth(numCols); - for ( col = 0; col < (int)numCols; col++ ) + QVector colWidth( numCols ); + for ( col = 0; col < numCols; col++ ) colWidth[col] = 0; if ( d_data->isDirty ) - ((QwtDynGridLayout*)this)->updateLayoutCache(); + d_data->updateLayoutCache(); - for ( uint index = 0; - index < (uint)d_data->itemSizeHints.count(); index++ ) + for ( int index = 0; + index < d_data->itemSizeHints.count(); index++ ) { col = index % numCols; - colWidth[col] = qwtMax(colWidth[col], - d_data->itemSizeHints[int(index)].width()); + colWidth[col] = qMax( colWidth[col], + d_data->itemSizeHints[int( index )].width() ); } - int rowWidth = 2 * margin() + (numCols - 1) * spacing(); - for ( col = 0; col < (int)numCols; col++ ) + int rowWidth = 2 * margin() + ( numCols - 1 ) * spacing(); + for ( col = 0; col < numCols; col++ ) rowWidth += colWidth[col]; return rowWidth; @@ -426,12 +312,12 @@ int QwtDynGridLayout::maxItemWidth() const return 0; if ( d_data->isDirty ) - ((QwtDynGridLayout*)this)->updateLayoutCache(); + d_data->updateLayoutCache(); int w = 0; - for ( uint i = 0; i < (uint)d_data->itemSizeHints.count(); i++ ) + for ( int i = 0; i < d_data->itemSizeHints.count(); i++ ) { - const int itemW = d_data->itemSizeHints[int(i)].width(); + const int itemW = d_data->itemSizeHints[i].width(); if ( itemW > w ) w = itemW; } @@ -448,74 +334,59 @@ int QwtDynGridLayout::maxItemWidth() const \return item geometries */ -#if QT_VERSION < 0x040000 -QValueList QwtDynGridLayout::layoutItems(const QRect &rect, - uint numCols) const -#else -QList QwtDynGridLayout::layoutItems(const QRect &rect, - uint numCols) const -#endif +QList QwtDynGridLayout::layoutItems( const QRect &rect, + uint numCols ) const { -#if QT_VERSION < 0x040000 - QValueList itemGeometries; -#else QList itemGeometries; -#endif if ( numCols == 0 || isEmpty() ) return itemGeometries; uint numRows = itemCount() / numCols; if ( numRows % itemCount() ) numRows++; - - QwtArray rowHeight(numRows); - QwtArray colWidth(numCols); - - layoutGrid(numCols, rowHeight, colWidth); + + QVector rowHeight( numRows ); + QVector colWidth( numCols ); + + layoutGrid( numCols, rowHeight, colWidth ); bool expandH, expandV; -#if QT_VERSION >= 0x040000 expandH = expandingDirections() & Qt::Horizontal; expandV = expandingDirections() & Qt::Vertical; -#else - expandH = expanding() & QSizePolicy::Horizontally; - expandV = expanding() & QSizePolicy::Vertically; -#endif if ( expandH || expandV ) - stretchGrid(rect, numCols, rowHeight, colWidth); + stretchGrid( rect, numCols, rowHeight, colWidth ); - QwtDynGridLayout *that = (QwtDynGridLayout *)this; const int maxCols = d_data->maxCols; - that->d_data->maxCols = numCols; - const QRect alignedRect = alignmentRect(rect); - that->d_data->maxCols = maxCols; + d_data->maxCols = numCols; + const QRect alignedRect = alignmentRect( rect ); + d_data->maxCols = maxCols; const int xOffset = expandH ? 0 : alignedRect.x(); const int yOffset = expandV ? 0 : alignedRect.y(); - QwtArray colX(numCols); - QwtArray rowY(numRows); + QVector colX( numCols ); + QVector rowY( numRows ); const int xySpace = spacing(); rowY[0] = yOffset + margin(); - for ( int r = 1; r < (int)numRows; r++ ) + for ( int r = 1; r < ( int )numRows; r++ ) rowY[r] = rowY[r-1] + rowHeight[r-1] + xySpace; colX[0] = xOffset + margin(); - for ( int c = 1; c < (int)numCols; c++ ) + for ( int c = 1; c < ( int )numCols; c++ ) colX[c] = colX[c-1] + colWidth[c-1] + xySpace; - + const int itemCount = d_data->itemList.size(); for ( int i = 0; i < itemCount; i++ ) { const int row = i / numCols; const int col = i % numCols; - QRect itemGeometry(colX[col], rowY[row], - colWidth[col], rowHeight[row]); - itemGeometries.append(itemGeometry); + QRect itemGeometry( colX[col], rowY[row], + colWidth[col], rowHeight[row] ); + itemGeometries.append( itemGeometry ); } return itemGeometries; @@ -531,27 +402,27 @@ QList QwtDynGridLayout::layoutItems(const QRect &rect, \param colWidth Array where to fill in the calculated column widths. */ -void QwtDynGridLayout::layoutGrid(uint numCols, - QwtArray& rowHeight, QwtArray& colWidth) const +void QwtDynGridLayout::layoutGrid( uint numCols, + QVector& rowHeight, QVector& colWidth ) const { if ( numCols <= 0 ) return; if ( d_data->isDirty ) - ((QwtDynGridLayout*)this)->updateLayoutCache(); + d_data->updateLayoutCache(); - for ( uint index = 0; - index < (uint)d_data->itemSizeHints.count(); index++ ) + for ( uint index = 0; + index < ( uint )d_data->itemSizeHints.count(); index++ ) { const int row = index / numCols; const int col = index % numCols; - const QSize &size = d_data->itemSizeHints[int(index)]; + const QSize &size = d_data->itemSizeHints[int( index )]; - rowHeight[row] = (col == 0) - ? size.height() : qwtMax(rowHeight[row], size.height()); - colWidth[col] = (row == 0) - ? size.width() : qwtMax(colWidth[col], size.width()); + rowHeight[row] = ( col == 0 ) + ? size.height() : qMax( rowHeight[row], size.height() ); + colWidth[col] = ( row == 0 ) + ? size.width() : qMax( colWidth[col], size.width() ); } } @@ -565,26 +436,26 @@ bool QwtDynGridLayout::hasHeightForWidth() const } /*! - \return The preferred height for this layout, given the width w. + \return The preferred height for this layout, given the width w. \sa hasHeightForWidth() */ -int QwtDynGridLayout::heightForWidth(int width) const +int QwtDynGridLayout::heightForWidth( int width ) const { if ( isEmpty() ) return 0; - const uint numCols = columnsForWidth(width); + const uint numCols = columnsForWidth( width ); uint numRows = itemCount() / numCols; if ( itemCount() % numCols ) numRows++; - QwtArray rowHeight(numRows); - QwtArray colWidth(numCols); + QVector rowHeight( numRows ); + QVector colWidth( numCols ); - layoutGrid(numCols, rowHeight, colWidth); + layoutGrid( numCols, rowHeight, colWidth ); - int h = 2 * margin() + (numRows - 1) * spacing(); - for ( int row = 0; row < (int)numRows; row++ ) + int h = 2 * margin() + ( numRows - 1 ) * spacing(); + for ( int row = 0; row < ( int )numRows; row++ ) h += rowHeight[row]; return h; @@ -597,32 +468,27 @@ int QwtDynGridLayout::heightForWidth(int width) const \sa setExpanding(), expanding() */ -void QwtDynGridLayout::stretchGrid(const QRect &rect, - uint numCols, QwtArray& rowHeight, QwtArray& colWidth) const +void QwtDynGridLayout::stretchGrid( const QRect &rect, + uint numCols, QVector& rowHeight, QVector& colWidth ) const { if ( numCols == 0 || isEmpty() ) return; bool expandH, expandV; -#if QT_VERSION >= 0x040000 expandH = expandingDirections() & Qt::Horizontal; expandV = expandingDirections() & Qt::Vertical; -#else - expandH = expanding() & QSizePolicy::Horizontally; - expandV = expanding() & QSizePolicy::Vertically; -#endif if ( expandH ) { - int xDelta = rect.width() - 2 * margin() - (numCols - 1) * spacing(); - for ( int col = 0; col < (int)numCols; col++ ) + int xDelta = rect.width() - 2 * margin() - ( numCols - 1 ) * spacing(); + for ( int col = 0; col < ( int )numCols; col++ ) xDelta -= colWidth[col]; if ( xDelta > 0 ) { - for ( int col = 0; col < (int)numCols; col++ ) + for ( int col = 0; col < ( int )numCols; col++ ) { - const int space = xDelta / (numCols - col); + const int space = xDelta / ( numCols - col ); colWidth[col] += space; xDelta -= space; } @@ -635,15 +501,15 @@ void QwtDynGridLayout::stretchGrid(const QRect &rect, if ( itemCount() % numCols ) numRows++; - int yDelta = rect.height() - 2 * margin() - (numRows - 1) * spacing(); - for ( int row = 0; row < (int)numRows; row++ ) + int yDelta = rect.height() - 2 * margin() - ( numRows - 1 ) * spacing(); + for ( int row = 0; row < ( int )numRows; row++ ) yDelta -= rowHeight[row]; if ( yDelta > 0 ) { - for ( int row = 0; row < (int)numRows; row++ ) + for ( int row = 0; row < ( int )numRows; row++ ) { - const int space = yDelta / (numRows - row); + const int space = yDelta / ( numRows - row ); rowHeight[row] += space; yDelta -= space; } @@ -663,25 +529,25 @@ QSize QwtDynGridLayout::sizeHint() const if ( isEmpty() ) return QSize(); - const uint numCols = (d_data->maxCols > 0 ) ? d_data->maxCols : itemCount(); + const uint numCols = ( d_data->maxCols > 0 ) ? d_data->maxCols : itemCount(); uint numRows = itemCount() / numCols; if ( itemCount() % numCols ) numRows++; - QwtArray rowHeight(numRows); - QwtArray colWidth(numCols); + QVector rowHeight( numRows ); + QVector colWidth( numCols ); - layoutGrid(numCols, rowHeight, colWidth); + layoutGrid( numCols, rowHeight, colWidth ); - int h = 2 * margin() + (numRows - 1) * spacing(); - for ( int row = 0; row < (int)numRows; row++ ) + int h = 2 * margin() + ( numRows - 1 ) * spacing(); + for ( int row = 0; row < ( int )numRows; row++ ) h += rowHeight[row]; - int w = 2 * margin() + (numCols - 1) * spacing(); - for ( int col = 0; col < (int)numCols; col++ ) + int w = 2 * margin() + ( numCols - 1 ) * spacing(); + for ( int col = 0; col < ( int )numCols; col++ ) w += colWidth[col]; - return QSize(w, h); + return QSize( w, h ); } /*! @@ -689,9 +555,9 @@ QSize QwtDynGridLayout::sizeHint() const \sa numCols() \warning The number of rows might change whenever the geometry changes */ -uint QwtDynGridLayout::numRows() const -{ - return d_data->numRows; +uint QwtDynGridLayout::numRows() const +{ + return d_data->numRows; } /*! @@ -699,7 +565,7 @@ uint QwtDynGridLayout::numRows() const \sa numRows() \warning The number of columns might change whenever the geometry changes */ -uint QwtDynGridLayout::numCols() const -{ - return d_data->numCols; +uint QwtDynGridLayout::numCols() const +{ + return d_data->numCols; } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_dyngrid_layout.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_dyngrid_layout.h index 099c3921d..c4262b849 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_dyngrid_layout.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_dyngrid_layout.h @@ -10,22 +10,17 @@ #ifndef QWT_DYNGRID_LAYOUT_H #define QWT_DYNGRID_LAYOUT_H +#include "qwt_global.h" #include #include -#if QT_VERSION >= 0x040000 #include -#else -#include -#endif -#include "qwt_global.h" -#include "qwt_array.h" /*! \brief The QwtDynGridLayout class lays out widgets in a grid, adjusting the number of columns and rows to the current size. - - QwtDynGridLayout takes the space it gets, divides it up into rows and - columns, and puts each of the widgets it manages into the correct cell(s). + + QwtDynGridLayout takes the space it gets, divides it up into rows and + columns, and puts each of the widgets it manages into the correct cell(s). It lays out as many number of columns as possible (limited by maxCols()). */ @@ -33,74 +28,55 @@ class QWT_EXPORT QwtDynGridLayout : public QLayout { Q_OBJECT public: - explicit QwtDynGridLayout(QWidget *, int margin = 0, int space = -1); -#if QT_VERSION < 0x040000 - explicit QwtDynGridLayout(QLayout *, int space = -1); -#endif - explicit QwtDynGridLayout(int space = -1); + explicit QwtDynGridLayout( QWidget *, int margin = 0, int space = -1 ); + explicit QwtDynGridLayout( int space = -1 ); virtual ~QwtDynGridLayout(); virtual void invalidate(); - void setMaxCols(uint maxCols); + void setMaxCols( uint maxCols ); uint maxCols() const; - uint numRows () const; + uint numRows () const; uint numCols () const; - virtual void addItem(QLayoutItem *); + virtual void addItem( QLayoutItem * ); -#if QT_VERSION >= 0x040000 virtual QLayoutItem *itemAt( int index ) const; virtual QLayoutItem *takeAt( int index ); virtual int count() const; - void setExpandingDirections(Qt::Orientations); + void setExpandingDirections( Qt::Orientations ); virtual Qt::Orientations expandingDirections() const; - QList layoutItems(const QRect &, uint numCols) const; -#else - virtual QLayoutIterator iterator(); - - void setExpanding(QSizePolicy::ExpandData); - virtual QSizePolicy::ExpandData expanding() const; - QValueList layoutItems(const QRect &, uint numCols) const; -#endif + QList layoutItems( const QRect &, uint numCols ) const; virtual int maxItemWidth() const; - virtual void setGeometry(const QRect &rect); + virtual void setGeometry( const QRect &rect ); virtual bool hasHeightForWidth() const; - virtual int heightForWidth(int) const; + virtual int heightForWidth( int ) const; virtual QSize sizeHint() const; virtual bool isEmpty() const; uint itemCount() const; - virtual uint columnsForWidth(int width) const; + virtual uint columnsForWidth( int width ) const; protected: - void layoutGrid(uint numCols, - QwtArray& rowHeight, QwtArray& colWidth) const; - void stretchGrid(const QRect &rect, uint numCols, - QwtArray& rowHeight, QwtArray& colWidth) const; - + void layoutGrid( uint numCols, + QVector& rowHeight, QVector& colWidth ) const; + void stretchGrid( const QRect &rect, uint numCols, + QVector& rowHeight, QVector& colWidth ) const; private: void init(); - int maxRowWidth(int numCols) const; - void updateLayoutCache(); + int maxRowWidth( int numCols ) const; -#if QT_VERSION < 0x040000 -// xlC 5.1, the IBM/AIX C++ compiler, needs it to be public -public: -#endif - class PrivateData; - -private: + class PrivateData; PrivateData *d_data; }; diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_event_pattern.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_event_pattern.cpp index cedf4f7bc..82d844508 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_event_pattern.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_event_pattern.cpp @@ -7,21 +7,21 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -#include #include "qwt_event_pattern.h" +#include -/*! +/*! Constructor \sa MousePatternCode, KeyPatternCode */ QwtEventPattern::QwtEventPattern(): - d_mousePattern(MousePatternCount), - d_keyPattern(KeyPatternCount) + d_mousePattern( MousePatternCount ), + d_keyPattern( KeyPatternCount ) { initKeyPattern(); - initMousePattern(3); + initMousePattern( 3 ); } //! Destructor @@ -35,48 +35,42 @@ QwtEventPattern::~QwtEventPattern() \param numButtons Number of mouse buttons ( <= 3 ) \sa MousePatternCode */ -void QwtEventPattern::initMousePattern(int numButtons) +void QwtEventPattern::initMousePattern( int numButtons ) { -#if QT_VERSION < 0x040000 - const int altButton = Qt::AltButton; - const int controlButton = Qt::ControlButton; - const int shiftButton = Qt::ShiftButton; -#else const int altButton = Qt::AltModifier; const int controlButton = Qt::ControlModifier; const int shiftButton = Qt::ShiftModifier; -#endif - d_mousePattern.resize(MousePatternCount); + d_mousePattern.resize( MousePatternCount ); - switch(numButtons) + switch ( numButtons ) { case 1: { - setMousePattern(MouseSelect1, Qt::LeftButton); - setMousePattern(MouseSelect2, Qt::LeftButton, controlButton); - setMousePattern(MouseSelect3, Qt::LeftButton, altButton); + setMousePattern( MouseSelect1, Qt::LeftButton ); + setMousePattern( MouseSelect2, Qt::LeftButton, controlButton ); + setMousePattern( MouseSelect3, Qt::LeftButton, altButton ); break; } case 2: { - setMousePattern(MouseSelect1, Qt::LeftButton); - setMousePattern(MouseSelect2, Qt::RightButton); - setMousePattern(MouseSelect3, Qt::LeftButton, altButton); + setMousePattern( MouseSelect1, Qt::LeftButton ); + setMousePattern( MouseSelect2, Qt::RightButton ); + setMousePattern( MouseSelect3, Qt::LeftButton, altButton ); break; } default: { - setMousePattern(MouseSelect1, Qt::LeftButton); - setMousePattern(MouseSelect2, Qt::RightButton); - setMousePattern(MouseSelect3, Qt::MidButton); + setMousePattern( MouseSelect1, Qt::LeftButton ); + setMousePattern( MouseSelect2, Qt::RightButton ); + setMousePattern( MouseSelect3, Qt::MidButton ); } } for ( int i = 0; i < 3; i++ ) { - setMousePattern(MouseSelect4 + i, - d_mousePattern[MouseSelect1 + i].button, - d_mousePattern[MouseSelect1 + i].state | shiftButton); + setMousePattern( MouseSelect4 + i, + d_mousePattern[MouseSelect1 + i].button, + d_mousePattern[MouseSelect1 + i].state | shiftButton ); } } @@ -87,20 +81,20 @@ void QwtEventPattern::initMousePattern(int numButtons) */ void QwtEventPattern::initKeyPattern() { - d_keyPattern.resize(KeyPatternCount); + d_keyPattern.resize( KeyPatternCount ); - setKeyPattern(KeySelect1, Qt::Key_Return); - setKeyPattern(KeySelect2, Qt::Key_Space); - setKeyPattern(KeyAbort, Qt::Key_Escape); + setKeyPattern( KeySelect1, Qt::Key_Return ); + setKeyPattern( KeySelect2, Qt::Key_Space ); + setKeyPattern( KeyAbort, Qt::Key_Escape ); - setKeyPattern(KeyLeft, Qt::Key_Left); - setKeyPattern(KeyRight, Qt::Key_Right); - setKeyPattern(KeyUp, Qt::Key_Up); - setKeyPattern(KeyDown, Qt::Key_Down); + setKeyPattern( KeyLeft, Qt::Key_Left ); + setKeyPattern( KeyRight, Qt::Key_Right ); + setKeyPattern( KeyUp, Qt::Key_Up ); + setKeyPattern( KeyDown, Qt::Key_Down ); - setKeyPattern(KeyRedo, Qt::Key_Plus); - setKeyPattern(KeyUndo, Qt::Key_Minus); - setKeyPattern(KeyHome, Qt::Key_Escape); + setKeyPattern( KeyRedo, Qt::Key_Plus ); + setKeyPattern( KeyUndo, Qt::Key_Minus ); + setKeyPattern( KeyHome, Qt::Key_Escape ); } /*! @@ -112,12 +106,12 @@ void QwtEventPattern::initKeyPattern() \sa QMouseEvent */ -void QwtEventPattern::setMousePattern(uint pattern, int button, int state) +void QwtEventPattern::setMousePattern( uint pattern, int button, int state ) { - if ( pattern < (uint)d_mousePattern.count() ) + if ( pattern < ( uint )d_mousePattern.count() ) { - d_mousePattern[int(pattern)].button = button; - d_mousePattern[int(pattern)].state = state; + d_mousePattern[int( pattern )].button = button; + d_mousePattern[int( pattern )].state = state; } } @@ -130,159 +124,151 @@ void QwtEventPattern::setMousePattern(uint pattern, int button, int state) \sa QKeyEvent */ -void QwtEventPattern::setKeyPattern(uint pattern, int key, int state) +void QwtEventPattern::setKeyPattern( uint pattern, int key, int state ) { - if ( pattern < (uint)d_keyPattern.count() ) + if ( pattern < ( uint )d_keyPattern.count() ) { - d_keyPattern[int(pattern)].key = key; - d_keyPattern[int(pattern)].state = state; + d_keyPattern[int( pattern )].key = key; + d_keyPattern[int( pattern )].state = state; } } //! Change the mouse event patterns -void QwtEventPattern::setMousePattern(const QwtArray &pattern) +void QwtEventPattern::setMousePattern( const QVector &pattern ) { d_mousePattern = pattern; } //! Change the key event patterns -void QwtEventPattern::setKeyPattern(const QwtArray &pattern) +void QwtEventPattern::setKeyPattern( const QVector &pattern ) { d_keyPattern = pattern; } //! Return mouse patterns -const QwtArray & +const QVector & QwtEventPattern::mousePattern() const { return d_mousePattern; } //! Return key patterns -const QwtArray & +const QVector & QwtEventPattern::keyPattern() const { return d_keyPattern; } //! Return ,ouse patterns -QwtArray &QwtEventPattern::mousePattern() +QVector &QwtEventPattern::mousePattern() { return d_mousePattern; } //! Return Key patterns -QwtArray &QwtEventPattern::keyPattern() +QVector &QwtEventPattern::keyPattern() { return d_keyPattern; } /*! - \brief Compare a mouse event with an event pattern. + \brief Compare a mouse event with an event pattern. A mouse event matches the pattern when both have the same button value and in the state value the same key flags(Qt::KeyButtonMask) are set. - + \param pattern Index of the event pattern - \param e Mouse event + \param event Mouse event \return true if matches \sa keyMatch() */ -bool QwtEventPattern::mouseMatch(uint pattern, const QMouseEvent *e) const +bool QwtEventPattern::mouseMatch( uint pattern, + const QMouseEvent *event ) const { bool ok = false; - if ( e && pattern < (uint)d_mousePattern.count() ) - ok = mouseMatch(d_mousePattern[int(pattern)], e); + if ( event && pattern < ( uint )d_mousePattern.count() ) + ok = mouseMatch( d_mousePattern[int( pattern )], event ); return ok; } /*! - \brief Compare a mouse event with an event pattern. + \brief Compare a mouse event with an event pattern. A mouse event matches the pattern when both have the same button value and in the state value the same key flags(Qt::KeyButtonMask) are set. - + \param pattern Mouse event pattern - \param e Mouse event + \param event Mouse event \return true if matches \sa keyMatch() */ -bool QwtEventPattern::mouseMatch(const MousePattern &pattern, - const QMouseEvent *e) const +bool QwtEventPattern::mouseMatch( const MousePattern &pattern, + const QMouseEvent *event ) const { - if ( e->button() != pattern.button ) + if ( event->button() != pattern.button ) return false; const bool matched = -#if QT_VERSION < 0x040000 - (e->state() & Qt::KeyButtonMask) == - (pattern.state & Qt::KeyButtonMask); -#else - (e->modifiers() & Qt::KeyboardModifierMask) == - (int)(pattern.state & Qt::KeyboardModifierMask); -#endif + ( event->modifiers() & Qt::KeyboardModifierMask ) == + ( int )( pattern.state & Qt::KeyboardModifierMask ); return matched; } /*! - \brief Compare a key event with an event pattern. + \brief Compare a key event with an event pattern. A key event matches the pattern when both have the same key value and in the state value the same key flags (Qt::KeyButtonMask) are set. - + \param pattern Index of the event pattern - \param e Key event + \param event Key event \return true if matches \sa mouseMatch() */ -bool QwtEventPattern::keyMatch(uint pattern, const QKeyEvent *e) const +bool QwtEventPattern::keyMatch( uint pattern, + const QKeyEvent *event ) const { bool ok = false; - if ( e && pattern < (uint)d_keyPattern.count() ) - ok = keyMatch(d_keyPattern[int(pattern)], e); + if ( event && pattern < ( uint )d_keyPattern.count() ) + ok = keyMatch( d_keyPattern[int( pattern )], event ); return ok; } /*! - \brief Compare a key event with an event pattern. + \brief Compare a key event with an event pattern. A key event matches the pattern when both have the same key value and in the state value the same key flags (Qt::KeyButtonMask) are set. - + \param pattern Key event pattern - \param e Key event + \param event Key event \return true if matches \sa mouseMatch() */ bool QwtEventPattern::keyMatch( - const KeyPattern &pattern, const QKeyEvent *e) const + const KeyPattern &pattern, const QKeyEvent *event ) const { - if ( e->key() != pattern.key) + if ( event->key() != pattern.key ) return false; const bool matched = -#if QT_VERSION < 0x040000 - (e->state() & Qt::KeyButtonMask) == - (pattern.state & Qt::KeyButtonMask); -#else - (e->modifiers() & Qt::KeyboardModifierMask) == - (int)(pattern.state & Qt::KeyboardModifierMask); -#endif + ( event->modifiers() & Qt::KeyboardModifierMask ) == + ( int )( pattern.state & Qt::KeyboardModifierMask ); return matched; } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_event_pattern.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_event_pattern.h index a90ec48d8..5aaaaea0a 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_event_pattern.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_event_pattern.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -10,8 +10,9 @@ #ifndef QWT_EVENT_PATTERN #define QWT_EVENT_PATTERN 1 +#include "qwt_global.h" #include -#include "qwt_array.h" +#include class QMouseEvent; class QKeyEvent; @@ -20,7 +21,7 @@ class QKeyEvent; \brief A collection of event patterns QwtEventPattern introduces an level of indirection for mouse and - keyboard inputs. Those are represented by symbolic names, so + keyboard inputs. Those are represented by symbolic names, so the application code can be configured by individual mappings. \sa QwtPicker, QwtPickerMachine, QwtPlotZoomer @@ -137,13 +138,17 @@ public: class MousePattern { public: - MousePattern(int btn = Qt::NoButton, int st = Qt::NoButton) - { + //! Constructor + MousePattern( int btn = Qt::NoButton, int st = Qt::NoButton ) + { button = btn; state = st; } + //! Button code int button; + + //! State int state; }; @@ -151,71 +156,70 @@ public: class KeyPattern { public: - KeyPattern(int k = 0, int st = Qt::NoButton) - { - key = k; + //! Constructor + KeyPattern( int k = 0, int st = Qt::NoButton ) + { + key = k; state = st; } + //! Key code int key; + + //! State int state; }; QwtEventPattern(); virtual ~QwtEventPattern(); - void initMousePattern(int numButtons); + void initMousePattern( int numButtons ); void initKeyPattern(); - void setMousePattern(uint pattern, int button, int state = Qt::NoButton); - void setKeyPattern(uint pattern, int key, int state = Qt::NoButton); + void setMousePattern( uint pattern, int button, int state = Qt::NoButton ); + void setKeyPattern( uint pattern, int key, int state = Qt::NoButton ); - void setMousePattern(const QwtArray &); - void setKeyPattern(const QwtArray &); + void setMousePattern( const QVector & ); + void setKeyPattern( const QVector & ); - const QwtArray &mousePattern() const; - const QwtArray &keyPattern() const; + const QVector &mousePattern() const; + const QVector &keyPattern() const; - QwtArray &mousePattern(); - QwtArray &keyPattern(); + QVector &mousePattern(); + QVector &keyPattern(); - bool mouseMatch(uint pattern, const QMouseEvent *) const; - bool keyMatch(uint pattern, const QKeyEvent *) const; + bool mouseMatch( uint pattern, const QMouseEvent * ) const; + bool keyMatch( uint pattern, const QKeyEvent * ) const; protected: - virtual bool mouseMatch(const MousePattern &, const QMouseEvent *) const; - virtual bool keyMatch(const KeyPattern &, const QKeyEvent *) const; - + virtual bool mouseMatch( const MousePattern &, const QMouseEvent * ) const; + virtual bool keyMatch( const KeyPattern &, const QKeyEvent * ) const; + private: #if defined(_MSC_VER) #pragma warning(push) #pragma warning(disable: 4251) #endif - QwtArray d_mousePattern; - QwtArray d_keyPattern; + QVector d_mousePattern; + QVector d_keyPattern; #if defined(_MSC_VER) #pragma warning(pop) #endif }; -inline bool operator==(QwtEventPattern::MousePattern b1, - QwtEventPattern::MousePattern b2) -{ - return b1.button == b2.button && b1.state == b2.state; +//! Compare operator +inline bool operator==( QwtEventPattern::MousePattern b1, + QwtEventPattern::MousePattern b2 ) +{ + return b1.button == b2.button && b1.state == b2.state; } -inline bool operator==(QwtEventPattern::KeyPattern b1, - QwtEventPattern::KeyPattern b2) -{ - return b1.key == b2.key && b1.state == b2.state; +//! Compare operator +inline bool operator==( QwtEventPattern::KeyPattern b1, + QwtEventPattern::KeyPattern b2 ) +{ + return b1.key == b2.key && b1.state == b2.state; } -#if defined(QWT_TEMPLATEDLL) -// MOC_SKIP_BEGIN -template class QWT_EXPORT QwtArray; -template class QWT_EXPORT QwtArray; -// MOC_SKIP_END -#endif - #endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_global.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_global.h index baf371f49..d1f27ab38 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_global.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_global.h @@ -2,27 +2,22 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - #ifndef QWT_GLOBAL_H #define QWT_GLOBAL_H #include -#if QT_VERSION < 0x040000 -#include -#endif // QWT_VERSION is (major << 16) + (minor << 8) + patch. -#define QWT_VERSION 0x050200 -#define QWT_VERSION_STR "5.2.0" +#define QWT_VERSION 0x060001 +#define QWT_VERSION_STR "6.0.1" -#if defined(Q_WS_WIN) +#if defined(Q_WS_WIN) || defined(Q_WS_S60) #if defined(_MSC_VER) /* MSVC Compiler */ /* template-class specialization 'identifier' is already instantiated */ @@ -40,7 +35,7 @@ #endif // QWT_DLL -#endif // Q_WS_WIN +#endif // Q_WS_WIN || Q_WS_S60 #ifndef QWT_EXPORT #define QWT_EXPORT @@ -48,4 +43,4 @@ // #define QWT_NO_COMPAT 1 // disable withdrawn functionality -#endif // QWT_GLOBAL_H +#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_double_interval.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_interval.cpp similarity index 57% rename from ground/openpilotgcs/src/libs/qwt/src/qwt_double_interval.cpp rename to ground/openpilotgcs/src/libs/qwt/src/qwt_interval.cpp index 287b20b00..59de21b42 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_double_interval.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_interval.cpp @@ -2,20 +2,14 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -#include -#if QT_VERSION >= 0x040000 -#include -#else -#include -#endif - +#include "qwt_interval.h" #include "qwt_math.h" -#include "qwt_double_interval.h" +#include /*! \brief Normalize the limits of the interval @@ -25,7 +19,7 @@ \sa isValid(), inverted() */ -QwtDoubleInterval QwtDoubleInterval::normalized() const +QwtInterval QwtInterval::normalized() const { if ( d_minValue > d_maxValue ) { @@ -44,15 +38,15 @@ QwtDoubleInterval QwtDoubleInterval::normalized() const \return Inverted interval \sa normalized() */ -QwtDoubleInterval QwtDoubleInterval::inverted() const +QwtInterval QwtInterval::inverted() const { - int borderFlags = 0; + BorderFlags borderFlags = IncludeBorders; if ( d_borderFlags & ExcludeMinimum ) borderFlags |= ExcludeMaximum; if ( d_borderFlags & ExcludeMaximum ) borderFlags |= ExcludeMinimum; - return QwtDoubleInterval(d_maxValue, d_minValue, borderFlags); + return QwtInterval( d_maxValue, d_minValue, borderFlags ); } /*! @@ -61,7 +55,7 @@ QwtDoubleInterval QwtDoubleInterval::inverted() const \param value Value \return true, if value >= minValue() && value <= maxValue() */ -bool QwtDoubleInterval::contains(double value) const +bool QwtInterval::contains( double value ) const { if ( !isValid() ) return false; @@ -79,8 +73,7 @@ bool QwtDoubleInterval::contains(double value) const } //! Unite 2 intervals -QwtDoubleInterval QwtDoubleInterval::unite( - const QwtDoubleInterval &other) const +QwtInterval QwtInterval::unite( const QwtInterval &other ) const { /* If one of the intervals is invalid return the other one. @@ -89,80 +82,79 @@ QwtDoubleInterval QwtDoubleInterval::unite( if ( !isValid() ) { if ( !other.isValid() ) - return QwtDoubleInterval(); + return QwtInterval(); else return other; } if ( !other.isValid() ) return *this; - QwtDoubleInterval united; - int flags = 0; + QwtInterval united; + BorderFlags flags = IncludeBorders; // minimum if ( d_minValue < other.minValue() ) { - united.setMinValue(d_minValue); + united.setMinValue( d_minValue ); flags &= d_borderFlags & ExcludeMinimum; } else if ( other.minValue() < d_minValue ) { - united.setMinValue(other.minValue()); + united.setMinValue( other.minValue() ); flags &= other.borderFlags() & ExcludeMinimum; } else // d_minValue == other.minValue() { - united.setMinValue(d_minValue); - flags &= (d_borderFlags & other.borderFlags()) & ExcludeMinimum; + united.setMinValue( d_minValue ); + flags &= ( d_borderFlags & other.borderFlags() ) & ExcludeMinimum; } // maximum if ( d_maxValue > other.maxValue() ) { - united.setMaxValue(d_maxValue); + united.setMaxValue( d_maxValue ); flags &= d_borderFlags & ExcludeMaximum; } else if ( other.maxValue() > d_maxValue ) { - united.setMaxValue(other.maxValue()); + united.setMaxValue( other.maxValue() ); flags &= other.borderFlags() & ExcludeMaximum; } else // d_maxValue == other.maxValue() ) { - united.setMaxValue(d_maxValue); + united.setMaxValue( d_maxValue ); flags &= d_borderFlags & other.borderFlags() & ExcludeMaximum; } - united.setBorderFlags(flags); + united.setBorderFlags( flags ); return united; } //! Intersect 2 intervals -QwtDoubleInterval QwtDoubleInterval::intersect( - const QwtDoubleInterval &other) const +QwtInterval QwtInterval::intersect( const QwtInterval &other ) const { if ( !other.isValid() || !isValid() ) - return QwtDoubleInterval(); + return QwtInterval(); - QwtDoubleInterval i1 = *this; - QwtDoubleInterval i2 = other; + QwtInterval i1 = *this; + QwtInterval i2 = other; // swap i1/i2, so that the minimum of i1 // is smaller then the minimum of i2 - if ( i1.minValue() > i2.minValue() ) + if ( i1.minValue() > i2.minValue() ) { - qSwap(i1, i2); + qSwap( i1, i2 ); } else if ( i1.minValue() == i2.minValue() ) { if ( i1.borderFlags() & ExcludeMinimum ) - qSwap(i1, i2); + qSwap( i1, i2 ); } if ( i1.maxValue() < i2.minValue() ) { - return QwtDoubleInterval(); + return QwtInterval(); } if ( i1.maxValue() == i2.minValue() ) @@ -170,47 +162,45 @@ QwtDoubleInterval QwtDoubleInterval::intersect( if ( i1.borderFlags() & ExcludeMaximum || i2.borderFlags() & ExcludeMinimum ) { - return QwtDoubleInterval(); + return QwtInterval(); } } - QwtDoubleInterval intersected; - int flags = 0; + QwtInterval intersected; + BorderFlags flags = IncludeBorders; - intersected.setMinValue(i2.minValue()); + intersected.setMinValue( i2.minValue() ); flags |= i2.borderFlags() & ExcludeMinimum; if ( i1.maxValue() < i2.maxValue() ) { - intersected.setMaxValue(i1.maxValue()); + intersected.setMaxValue( i1.maxValue() ); flags |= i1.borderFlags() & ExcludeMaximum; } else if ( i2.maxValue() < i1.maxValue() ) { - intersected.setMaxValue(i2.maxValue()); + intersected.setMaxValue( i2.maxValue() ); flags |= i2.borderFlags() & ExcludeMaximum; } else // i1.maxValue() == i2.maxValue() { - intersected.setMaxValue(i1.maxValue() ); + intersected.setMaxValue( i1.maxValue() ); flags |= i1.borderFlags() & i2.borderFlags() & ExcludeMaximum; } - intersected.setBorderFlags(flags); + intersected.setBorderFlags( flags ); return intersected; } //! Unites this interval with the given interval. -QwtDoubleInterval& QwtDoubleInterval::operator|=( - const QwtDoubleInterval &interval) +QwtInterval& QwtInterval::operator|=( const QwtInterval & interval ) { *this = *this | interval; return *this; } //! Intersects this interval with the given interval. -QwtDoubleInterval& QwtDoubleInterval::operator&=( - const QwtDoubleInterval &interval) +QwtInterval& QwtInterval::operator&=( const QwtInterval & interval ) { *this = *this & interval; return *this; @@ -219,25 +209,25 @@ QwtDoubleInterval& QwtDoubleInterval::operator&=( /*! Test if two intervals overlap */ -bool QwtDoubleInterval::intersects(const QwtDoubleInterval &other) const +bool QwtInterval::intersects( const QwtInterval &other ) const { if ( !isValid() || !other.isValid() ) return false; - QwtDoubleInterval i1 = *this; - QwtDoubleInterval i2 = other; + QwtInterval i1 = *this; + QwtInterval i2 = other; // swap i1/i2, so that the minimum of i1 // is smaller then the minimum of i2 - if ( i1.minValue() > i2.minValue() ) + if ( i1.minValue() > i2.minValue() ) { - qSwap(i1, i2); + qSwap( i1, i2 ); } else if ( i1.minValue() == i2.minValue() && - i1.borderFlags() & ExcludeMinimum ) + i1.borderFlags() & ExcludeMinimum ) { - qSwap(i1, i2); + qSwap( i1, i2 ); } if ( i1.maxValue() > i2.minValue() ) @@ -246,8 +236,8 @@ bool QwtDoubleInterval::intersects(const QwtDoubleInterval &other) const } if ( i1.maxValue() == i2.minValue() ) { - return !( (i1.borderFlags() & ExcludeMaximum) || - (i2.borderFlags() & ExcludeMinimum) ); + return !( ( i1.borderFlags() & ExcludeMaximum ) || + ( i2.borderFlags() & ExcludeMinimum ) ); } return false; } @@ -259,15 +249,15 @@ bool QwtDoubleInterval::intersects(const QwtDoubleInterval &other) const \param value Center \return Interval with value as center */ -QwtDoubleInterval QwtDoubleInterval::symmetrize(double value) const +QwtInterval QwtInterval::symmetrize( double value ) const { if ( !isValid() ) return *this; const double delta = - qwtMax(qwtAbs(value - d_maxValue), qwtAbs(value - d_minValue)); + qMax( qAbs( value - d_maxValue ), qAbs( value - d_minValue ) ); - return QwtDoubleInterval(value - delta, value + delta); + return QwtInterval( value - delta, value + delta ); } /*! @@ -278,19 +268,18 @@ QwtDoubleInterval QwtDoubleInterval::symmetrize(double value) const \return Limited interval */ -QwtDoubleInterval QwtDoubleInterval::limited( - double lowerBound, double upperBound) const +QwtInterval QwtInterval::limited( double lowerBound, double upperBound ) const { if ( !isValid() || lowerBound > upperBound ) - return QwtDoubleInterval(); + return QwtInterval(); - double minValue = qwtMax(d_minValue, lowerBound); - minValue = qwtMin(minValue, upperBound); + double minValue = qMax( d_minValue, lowerBound ); + minValue = qMin( minValue, upperBound ); - double maxValue = qwtMax(d_maxValue, lowerBound); - maxValue = qwtMin(maxValue, upperBound); + double maxValue = qMax( d_maxValue, lowerBound ); + maxValue = qMin( maxValue, upperBound ); - return QwtDoubleInterval(minValue, maxValue, d_borderFlags); + return QwtInterval( minValue, maxValue, d_borderFlags ); } /*! @@ -304,17 +293,42 @@ QwtDoubleInterval QwtDoubleInterval::limited( \param value Value \sa isValid() */ -QwtDoubleInterval QwtDoubleInterval::extend(double value) const +QwtInterval QwtInterval::extend( double value ) const { if ( !isValid() ) return *this; - return QwtDoubleInterval( qwtMin(value, d_minValue), - qwtMax(value, d_maxValue), d_borderFlags ); + return QwtInterval( qMin( value, d_minValue ), + qMax( value, d_maxValue ), d_borderFlags ); } -QwtDoubleInterval& QwtDoubleInterval::operator|=(double value) +/*! + Extend an interval + + \param value Value + \return Reference of the extended interval + + \sa extend() +*/ +QwtInterval& QwtInterval::operator|=( double value ) { *this = *this | value; return *this; } + +#ifndef QT_NO_DEBUG_STREAM + +QDebug operator<<( QDebug debug, const QwtInterval &interval ) +{ + const int flags = interval.borderFlags(); + + debug.nospace() << "QwtInterval(" + << ( ( flags & QwtInterval::ExcludeMinimum ) ? "]" : "[" ) + << interval.minValue() << "," << interval.maxValue() + << ( ( flags & QwtInterval::ExcludeMaximum ) ? "[" : "]" ) + << ")"; + + return debug.space(); +} + +#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_interval.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_interval.h new file mode 100644 index 000000000..5666f7206 --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_interval.h @@ -0,0 +1,296 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#ifndef QWT_INTERVAL_H +#define QWT_INTERVAL_H + +#include "qwt_global.h" +#ifndef QT_NO_DEBUG_STREAM +#include +#endif + +/*! + \brief A class representing an interval + + The interval is represented by 2 doubles, the lower and the upper limit. +*/ + +class QWT_EXPORT QwtInterval +{ +public: + /*! + Flag indicating if a border is included or excluded + \sa setBorderFlags(), borderFlags() + */ + enum BorderFlag + { + //! Min/Max values are inside the interval + IncludeBorders = 0x00, + + //! Min value is not included in the interval + ExcludeMinimum = 0x01, + + //! Max value is not included in the interval + ExcludeMaximum = 0x02, + + //! Min/Max values are not included in the interval + ExcludeBorders = ExcludeMinimum | ExcludeMaximum + }; + + //! Border flags + typedef QFlags BorderFlags; + + QwtInterval(); + QwtInterval( double minValue, double maxValue, + BorderFlags = IncludeBorders ); + + void setInterval( double minValue, double maxValue, + BorderFlags = IncludeBorders ); + + QwtInterval normalized() const; + QwtInterval inverted() const; + QwtInterval limited( double minValue, double maxValue ) const; + + bool operator==( const QwtInterval & ) const; + bool operator!=( const QwtInterval & ) const; + + void setBorderFlags( BorderFlags ); + BorderFlags borderFlags() const; + + double minValue() const; + double maxValue() const; + + double width() const; + + void setMinValue( double ); + void setMaxValue( double ); + + bool contains( double value ) const; + + bool intersects( const QwtInterval & ) const; + QwtInterval intersect( const QwtInterval & ) const; + QwtInterval unite( const QwtInterval & ) const; + + QwtInterval operator|( const QwtInterval & ) const; + QwtInterval operator&( const QwtInterval & ) const; + + QwtInterval &operator|=( const QwtInterval & ); + QwtInterval &operator&=( const QwtInterval & ); + + QwtInterval extend( double value ) const; + QwtInterval operator|( double ) const; + QwtInterval &operator|=( double ); + + bool isValid() const; + bool isNull() const; + void invalidate(); + + QwtInterval symmetrize( double value ) const; + +private: + double d_minValue; + double d_maxValue; + BorderFlags d_borderFlags; +}; + +Q_DECLARE_TYPEINFO(QwtInterval, Q_MOVABLE_TYPE); + +/*! + \brief Default Constructor + + Creates an invalid interval [0.0, -1.0] + \sa setInterval(), isValid() +*/ +inline QwtInterval::QwtInterval(): + d_minValue( 0.0 ), + d_maxValue( -1.0 ), + d_borderFlags( IncludeBorders ) +{ +} + +/*! + Constructor + + Build an interval with from min/max values + + \param minValue Minimum value + \param maxValue Maximum value + \param borderFlags Include/Exclude borders +*/ +inline QwtInterval::QwtInterval( + double minValue, double maxValue, BorderFlags borderFlags ): + d_minValue( minValue ), + d_maxValue( maxValue ), + d_borderFlags( borderFlags ) +{ +} + +/*! + Assign the limits of the interval + + \param minValue Minimum value + \param maxValue Maximum value + \param borderFlags Include/Exclude borders +*/ +inline void QwtInterval::setInterval( + double minValue, double maxValue, BorderFlags borderFlags ) +{ + d_minValue = minValue; + d_maxValue = maxValue; + d_borderFlags = borderFlags; +} + +/*! + Change the border flags + + \param borderFlags Or'd BorderMode flags + \sa borderFlags() +*/ +inline void QwtInterval::setBorderFlags( BorderFlags borderFlags ) +{ + d_borderFlags = borderFlags; +} + +/*! + \return Border flags + \sa setBorderFlags() +*/ +inline QwtInterval::BorderFlags QwtInterval::borderFlags() const +{ + return d_borderFlags; +} + +/*! + Assign the lower limit of the interval + + \param minValue Minimum value +*/ +inline void QwtInterval::setMinValue( double minValue ) +{ + d_minValue = minValue; +} + +/*! + Assign the upper limit of the interval + + \param maxValue Maximum value +*/ +inline void QwtInterval::setMaxValue( double maxValue ) +{ + d_maxValue = maxValue; +} + +//! \return Lower limit of the interval +inline double QwtInterval::minValue() const +{ + return d_minValue; +} + +//! \return Upper limit of the interval +inline double QwtInterval::maxValue() const +{ + return d_maxValue; +} + +/*! + Return the width of an interval + The width of invalid intervals is 0.0, otherwise the result is + maxValue() - minValue(). + + \sa isValid() +*/ +inline double QwtInterval::width() const +{ + return isValid() ? ( d_maxValue - d_minValue ) : 0.0; +} + +/*! + Intersection of two intervals + \sa intersect() +*/ +inline QwtInterval QwtInterval::operator&( + const QwtInterval &interval ) const +{ + return intersect( interval ); +} + +/*! + Union of two intervals + \sa unite() +*/ +inline QwtInterval QwtInterval::operator|( + const QwtInterval &interval ) const +{ + return unite( interval ); +} + +//! Compare two intervals +inline bool QwtInterval::operator==( const QwtInterval &other ) const +{ + return ( d_minValue == other.d_minValue ) && + ( d_maxValue == other.d_maxValue ) && + ( d_borderFlags == other.d_borderFlags ); +} + +//! Compare two intervals +inline bool QwtInterval::operator!=( const QwtInterval &other ) const +{ + return ( !( *this == other ) ); +} + +/*! + Extend an interval + + \param value Value + \return Extended interval + \sa extend() +*/ +inline QwtInterval QwtInterval::operator|( double value ) const +{ + return extend( value ); +} + +//! \return true, if isValid() && (minValue() >= maxValue()) +inline bool QwtInterval::isNull() const +{ + return isValid() && d_minValue >= d_maxValue; +} + +/*! + A interval is valid when minValue() <= maxValue(). + In case of QwtInterval::ExcludeBorders it is true + when minValue() < maxValue() +*/ +inline bool QwtInterval::isValid() const +{ + if ( ( d_borderFlags & ExcludeBorders ) == 0 ) + return d_minValue <= d_maxValue; + else + return d_minValue < d_maxValue; +} + +/*! + Invalidate the interval + + The limits are set to interval [0.0, -1.0] + \sa isValid() +*/ +inline void QwtInterval::invalidate() +{ + d_minValue = 0.0; + d_maxValue = -1.0; +} + +Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags ) + +#ifndef QT_NO_DEBUG_STREAM +QWT_EXPORT QDebug operator<<( QDebug, const QwtInterval & ); +#endif + +#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_interval_data.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_interval_data.cpp deleted file mode 100644 index 368680320..000000000 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_interval_data.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** - * Qwt Widget Library - * Copyright (C) 1997 Josef Wilgen - * Copyright (C) 2002 Uwe Rathmann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the Qwt License, Version 1.0 - *****************************************************************************/ - -#include "qwt_math.h" -#include "qwt_interval_data.h" - -//! Constructor -QwtIntervalData::QwtIntervalData() -{ -} - -//! Constructor -QwtIntervalData::QwtIntervalData( - const QwtArray &intervals, - const QwtArray &values): - d_intervals(intervals), - d_values(values) -{ -} - -//! Destructor -QwtIntervalData::~QwtIntervalData() -{ -} - -//! Assign samples -void QwtIntervalData::setData( - const QwtArray &intervals, - const QwtArray &values) -{ - d_intervals = intervals; - d_values = values; -} - -/*! - Calculate the bounding rectangle of the samples - - The x coordinates of the rectangle are built from the intervals, - the y coordinates from the values. - - \return Bounding rectangle -*/ -QwtDoubleRect QwtIntervalData::boundingRect() const -{ - double minX, maxX, minY, maxY; - minX = maxX = minY = maxY = 0.0; - - bool isValid = false; - - const size_t sz = size(); - for ( size_t i = 0; i < sz; i++ ) - { - const QwtDoubleInterval intv = interval(i); - if ( !intv.isValid() ) - continue; - - const double v = value(i); - - if ( !isValid ) - { - minX = intv.minValue(); - maxX = intv.maxValue(); - minY = maxY = v; - - isValid = true; - } - else - { - if ( intv.minValue() < minX ) - minX = intv.minValue(); - if ( intv.maxValue() > maxX ) - maxX = intv.maxValue(); - - if ( v < minY ) - minY = v; - if ( v > maxY ) - maxY = v; - } - } - if ( !isValid ) - return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid - - return QwtDoubleRect(minX, minY, maxX - minX, maxY - minY); -} diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_interval_data.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_interval_data.h deleted file mode 100644 index 68ac33a7c..000000000 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_interval_data.h +++ /dev/null @@ -1,90 +0,0 @@ -/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** - * Qwt Widget Library - * Copyright (C) 1997 Josef Wilgen - * Copyright (C) 2002 Uwe Rathmann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the Qwt License, Version 1.0 - *****************************************************************************/ - -#ifndef QWT_INTERVAL_DATA_H -#define QWT_INTERVAL_DATA_H 1 - -#include "qwt_global.h" -#include "qwt_math.h" -#include "qwt_array.h" -#include "qwt_double_interval.h" -#include "qwt_double_rect.h" - -#if defined(_MSC_VER) && (_MSC_VER > 1310) -#include -#endif - -#if defined(QWT_TEMPLATEDLL) -// MOC_SKIP_BEGIN -template class QWT_EXPORT QwtArray; -template class QWT_EXPORT QwtArray; -// MOC_SKIP_END -#endif - -/*! - \brief Series of samples of a value and an interval - - QwtIntervalData is a series of samples of a value and an interval. - F.e. error bars are built from samples [x, y1-y2], while a - histogram might consist of [x1-x2, y] samples. -*/ -class QWT_EXPORT QwtIntervalData -{ -public: - QwtIntervalData(); - QwtIntervalData(const QwtArray &, - const QwtArray &); - - ~QwtIntervalData(); - - void setData(const QwtArray &, - const QwtArray &); - - size_t size() const; - const QwtDoubleInterval &interval(size_t i) const; - double value(size_t i) const; - - QwtDoubleRect boundingRect() const; - -private: - QwtArray d_intervals; - QwtArray d_values; -}; - -//! \return Number of samples -inline size_t QwtIntervalData::size() const -{ - return qwtMin(d_intervals.size(), d_values.size()); -} - -/*! - Interval of a sample - - \param i Sample index - \return Interval - \sa value(), size() -*/ -inline const QwtDoubleInterval &QwtIntervalData::interval(size_t i) const -{ - return d_intervals[int(i)]; -} - -/*! - Value of a sample - - \param i Sample index - \return Value - \sa interval(), size() -*/ -inline double QwtIntervalData::value(size_t i) const -{ - return d_values[int(i)]; -} - -#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_interval_symbol.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_interval_symbol.cpp new file mode 100644 index 000000000..69ab0b4c0 --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_interval_symbol.cpp @@ -0,0 +1,298 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#include "qwt_interval_symbol.h" +#include "qwt_painter.h" +#include "qwt_math.h" +#include + +#if QT_VERSION < 0x040601 +#define qAtan2(y, x) ::atan2(y, x) +#endif + +class QwtIntervalSymbol::PrivateData +{ +public: + PrivateData(): + style( QwtIntervalSymbol::NoSymbol ), + width( 6 ) + { + } + + bool operator==( const PrivateData &other ) const + { + return ( style == other.style ) + && ( width == other.width ) + && ( brush == other.brush ) + && ( pen == other.pen ); + } + + QwtIntervalSymbol::Style style; + int width; + + QPen pen; + QBrush brush; +}; + +/*! + Constructor + + \param style Style of the symbol + \sa setStyle(), style(), Style +*/ +QwtIntervalSymbol::QwtIntervalSymbol( Style style ) +{ + d_data = new PrivateData(); + d_data->style = style; +} + +//! Copy constructor +QwtIntervalSymbol::QwtIntervalSymbol( const QwtIntervalSymbol &other ) +{ + d_data = new PrivateData(); + *d_data = *other.d_data; +} + +//! Destructor +QwtIntervalSymbol::~QwtIntervalSymbol() +{ + delete d_data; +} + +//! \brief Assignment operator +QwtIntervalSymbol &QwtIntervalSymbol::operator=( + const QwtIntervalSymbol &other ) +{ + *d_data = *other.d_data; + return *this; +} + +//! \brief Compare two symbols +bool QwtIntervalSymbol::operator==( + const QwtIntervalSymbol &other ) const +{ + return *d_data == *other.d_data; +} + +//! \brief Compare two symbols +bool QwtIntervalSymbol::operator!=( + const QwtIntervalSymbol &other ) const +{ + return !( *d_data == *other.d_data ); +} + +/*! + Specify the symbol style + + \param style Style + \sa style(), Style +*/ +void QwtIntervalSymbol::setStyle( Style style ) +{ + d_data->style = style; +} + +/*! + \return Current symbol style + \sa setStyle() +*/ +QwtIntervalSymbol::Style QwtIntervalSymbol::style() const +{ + return d_data->style; +} + +/*! + Specify the width of the symbol + It is used depending on the style. + + \param width Width + \sa width(), setStyle() +*/ +void QwtIntervalSymbol::setWidth( int width ) +{ + d_data->width = width; +} + +/*! + \return Width of the symbol. + \sa setWidth(), setStyle() +*/ +int QwtIntervalSymbol::width() const +{ + return d_data->width; +} + +/*! + \brief Assign a brush + + The brush is used for the Box style. + + \param brush Brush + \sa brush() +*/ +void QwtIntervalSymbol::setBrush( const QBrush &brush ) +{ + d_data->brush = brush; +} + +/*! + \return Brush + \sa setBrush() +*/ +const QBrush& QwtIntervalSymbol::brush() const +{ + return d_data->brush; +} + +/*! + Assign a pen + + \param pen Pen + \sa pen(), setBrush() +*/ +void QwtIntervalSymbol::setPen( const QPen &pen ) +{ + d_data->pen = pen; +} + +/*! + \return Pen + \sa setPen(), brush() +*/ +const QPen& QwtIntervalSymbol::pen() const +{ + return d_data->pen; +} + +/*! + Draw a symbol depending on its style + + \param painter Painter + \param orientation Orientation + \param from Start point of the interval in target device coordinates + \param to End point of the interval in target device coordinates + + \sa setStyle() +*/ +void QwtIntervalSymbol::draw( QPainter *painter, Qt::Orientation orientation, + const QPointF &from, const QPointF &to ) const +{ + const qreal pw = qMax( painter->pen().widthF(), qreal( 1.0 ) ); + + QPointF p1 = from; + QPointF p2 = to; + if ( QwtPainter::roundingAlignment( painter ) ) + { + p1 = p1.toPoint(); + p2 = p2.toPoint(); + } + + switch ( d_data->style ) + { + case QwtIntervalSymbol::Bar: + { + QwtPainter::drawLine( painter, p1, p2 ); + if ( d_data->width > pw ) + { + if ( ( orientation == Qt::Horizontal ) + && ( p1.y() == p2.y() ) ) + { + const double sw = d_data->width; + + const double y = p1.y() - sw / 2; + QwtPainter::drawLine( painter, + p1.x(), y, p1.x(), y + sw ); + QwtPainter::drawLine( painter, + p2.x(), y, p2.x(), y + sw ); + } + else if ( ( orientation == Qt::Vertical ) + && ( p1.x() == p2.x() ) ) + { + const double sw = d_data->width; + + const double x = p1.x() - sw / 2; + QwtPainter::drawLine( painter, + x, p1.y(), x + sw, p1.y() ); + QwtPainter::drawLine( painter, + x, p2.y(), x + sw, p2.y() ); + } + else + { + const double sw = d_data->width; + + const double dx = p2.x() - p1.x(); + const double dy = p2.y() - p1.y(); + const double angle = qAtan2( dy, dx ) + M_PI_2; + double dw2 = sw / 2.0; + + const double cx = qCos( angle ) * dw2; + const double sy = qSin( angle ) * dw2; + + QwtPainter::drawLine( painter, + p1.x() - cx, p1.y() - sy, + p1.x() + cx, p1.y() + sy ); + QwtPainter::drawLine( painter, + p2.x() - cx, p2.y() - sy, + p2.x() + cx, p2.y() + sy ); + } + } + break; + } + case QwtIntervalSymbol::Box: + { + if ( d_data->width <= pw ) + { + QwtPainter::drawLine( painter, p1, p2 ); + } + else + { + if ( ( orientation == Qt::Horizontal ) + && ( p1.y() == p2.y() ) ) + { + const double sw = d_data->width; + + const double y = p1.y() - d_data->width / 2; + QwtPainter::drawRect( painter, + p1.x(), y, p2.x() - p1.x(), sw ); + } + else if ( ( orientation == Qt::Vertical ) + && ( p1.x() == p2.x() ) ) + { + const double sw = d_data->width; + + const double x = p1.x() - d_data->width / 2; + QwtPainter::drawRect( painter, + x, p1.y(), sw, p2.y() - p1.y() ); + } + else + { + const double sw = d_data->width; + + const double dx = p2.x() - p1.x(); + const double dy = p2.y() - p1.y(); + const double angle = qAtan2( dy, dx ) + M_PI_2; + double dw2 = sw / 2.0; + + const int cx = qCos( angle ) * dw2; + const int sy = qSin( angle ) * dw2; + + QPolygonF polygon; + polygon += QPointF( p1.x() - cx, p1.y() - sy ); + polygon += QPointF( p1.x() + cx, p1.y() + sy ); + polygon += QPointF( p2.x() + cx, p2.y() + sy ); + polygon += QPointF( p2.x() - cx, p2.y() - sy ); + + QwtPainter::drawPolygon( painter, polygon ); + } + } + break; + } + default:; + } +} diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_interval_symbol.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_interval_symbol.h new file mode 100644 index 000000000..e0397c73c --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_interval_symbol.h @@ -0,0 +1,86 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#ifndef QWT_INTERVAL_SYMBOL_H +#define QWT_INTERVAL_SYMBOL_H + +#include "qwt_global.h" +#include +#include + +class QPainter; +class QRect; +class QPointF; + +/*! + \brief A drawing primitive for displaying an interval like an error bar + + \sa QwtPlotIntervalCurve +*/ +class QWT_EXPORT QwtIntervalSymbol +{ +public: + //! Symbol style + enum Style + { + //! No Style. The symbol cannot be drawn. + NoSymbol = -1, + + /*! + The symbol displays a line with caps at the beginning/end. + The size of the caps depends on the symbol width(). + */ + Bar, + + /*! + The symbol displays a plain rectangle using pen() and brush(). + The size of the rectangle depends on the translated interval and + the width(), + */ + Box, + + /*! + Styles >= UserSymbol are reserved for derived + classes of QwtIntervalSymbol that overload draw() with + additional application specific symbol types. + */ + UserSymbol = 1000 + }; + +public: + QwtIntervalSymbol( Style = NoSymbol ); + QwtIntervalSymbol( const QwtIntervalSymbol & ); + virtual ~QwtIntervalSymbol(); + + QwtIntervalSymbol &operator=( const QwtIntervalSymbol & ); + bool operator==( const QwtIntervalSymbol & ) const; + bool operator!=( const QwtIntervalSymbol & ) const; + + void setWidth( int ); + int width() const; + + void setBrush( const QBrush& b ); + const QBrush& brush() const; + + void setPen( const QPen & ); + const QPen& pen() const; + + void setStyle( Style ); + Style style() const; + + virtual void draw( QPainter *, Qt::Orientation, + const QPointF& from, const QPointF& to ) const; + +private: + + class PrivateData; + PrivateData* d_data; +}; + +#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_knob.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_knob.cpp index 5af9ad3c5..a4036d479 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_knob.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_knob.cpp @@ -7,15 +7,24 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ +#include "qwt_knob.h" +#include "qwt_round_scale_draw.h" +#include "qwt_math.h" +#include "qwt_painter.h" #include #include #include +#include #include -#include "qwt_round_scale_draw.h" -#include "qwt_knob.h" -#include "qwt_math.h" -#include "qwt_painter.h" -#include "qwt_paint_buffer.h" +#include +#include + +#if QT_VERSION < 0x040601 +#define qAtan2(y, x) ::atan2(y, x) +#define qFabs(x) ::fabs(x) +#define qFastCos(x) ::cos(x) +#define qFastSin(x) ::sin(x) +#endif class QwtKnob::PrivateData { @@ -28,68 +37,53 @@ public: borderDist = 4; totalAngle = 270.0; scaleDist = 4; - symbol = Line; + markerStyle = QwtKnob::Notch; maxScaleTicks = 11; + knobStyle = QwtKnob::Raised; knobWidth = 50; - dotWidth = 8; + markerSize = 8; } + QwtKnob::KnobStyle knobStyle; + QwtKnob::MarkerStyle markerStyle; + int borderWidth; int borderDist; int scaleDist; int maxScaleTicks; int knobWidth; - int dotWidth; + int markerSize; - Symbol symbol; double angle; double totalAngle; double nTurns; - QRect knobRect; // bounding rect of the knob without scale + mutable QRectF knobRect; // bounding rect of the knob without scale }; /*! Constructor \param parent Parent widget */ -QwtKnob::QwtKnob(QWidget* parent): - QwtAbstractSlider(Qt::Horizontal, parent) +QwtKnob::QwtKnob( QWidget* parent ): + QwtAbstractSlider( Qt::Horizontal, parent ) { initKnob(); } -#if QT_VERSION < 0x040000 -/*! - Constructor - \param parent Parent widget - \param name Object name -*/ -QwtKnob::QwtKnob(QWidget* parent, const char *name): - QwtAbstractSlider(Qt::Horizontal, parent) -{ - setName(name); - initKnob(); -} -#endif - void QwtKnob::initKnob() { -#if QT_VERSION < 0x040000 - setWFlags(Qt::WNoAutoErase); -#endif - d_data = new PrivateData; - setScaleDraw(new QwtRoundScaleDraw()); + setScaleDraw( new QwtRoundScaleDraw() ); - setUpdateTime(50); + setUpdateTime( 50 ); setTotalAngle( 270.0 ); recalcAngle(); - setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); + setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); - setRange(0.0, 10.0, 1.0); - setValue(0.0); + setRange( 0.0, 10.0, 1.0 ); + setValue( 0.0 ); } //! Destructor @@ -99,25 +93,51 @@ QwtKnob::~QwtKnob() } /*! - \brief Set the symbol of the knob - \sa symbol() + \brief Set the knob type + + \param knobStyle Knob type + \sa knobStyle(), setBorderWidth() */ -void QwtKnob::setSymbol(QwtKnob::Symbol s) +void QwtKnob::setKnobStyle( KnobStyle knobStyle ) { - if ( d_data->symbol != s ) + if ( d_data->knobStyle != knobStyle ) { - d_data->symbol = s; + d_data->knobStyle = knobStyle; update(); } } -/*! - \return symbol of the knob - \sa setSymbol() +/*! + \return Marker type of the knob + \sa setKnobStyle(), setBorderWidth() */ -QwtKnob::Symbol QwtKnob::symbol() const +QwtKnob::KnobStyle QwtKnob::knobStyle() const { - return d_data->symbol; + return d_data->knobStyle; +} + +/*! + \brief Set the marker type of the knob + + \param markerStyle Marker type + \sa markerStyle(), setMarkerSize() +*/ +void QwtKnob::setMarkerStyle( MarkerStyle markerStyle ) +{ + if ( d_data->markerStyle != markerStyle ) + { + d_data->markerStyle = markerStyle; + update(); + } +} + +/*! + \return Marker type of the knob + \sa setMarkerStyle(), setMarkerSize() +*/ +QwtKnob::MarkerStyle QwtKnob::markerStyle() const +{ + return d_data->markerStyle; } /*! @@ -128,20 +148,20 @@ QwtKnob::Symbol QwtKnob::symbol() const an angle of more than 360 degrees so that the knob can be turned several times around its axis. */ -void QwtKnob::setTotalAngle (double angle) +void QwtKnob::setTotalAngle ( double angle ) { - if (angle < 10.0) - d_data->totalAngle = 10.0; + if ( angle < 10.0 ) + d_data->totalAngle = 10.0; else - d_data->totalAngle = angle; + d_data->totalAngle = angle; - scaleDraw()->setAngleRange( -0.5 * d_data->totalAngle, - 0.5 * d_data->totalAngle); - layoutKnob(); + scaleDraw()->setAngleRange( -0.5 * d_data->totalAngle, + 0.5 * d_data->totalAngle ); + layoutKnob( true ); } //! Return the total angle -double QwtKnob::totalAngle() const +double QwtKnob::totalAngle() const { return d_data->totalAngle; } @@ -151,86 +171,32 @@ double QwtKnob::totalAngle() const For changing the labels of the scales, it is necessary to derive from QwtRoundScaleDraw and - overload QwtRoundScaleDraw::label(). + overload QwtRoundScaleDraw::label(). \sa scaleDraw() */ -void QwtKnob::setScaleDraw(QwtRoundScaleDraw *scaleDraw) +void QwtKnob::setScaleDraw( QwtRoundScaleDraw *scaleDraw ) { - setAbstractScaleDraw(scaleDraw); - setTotalAngle(d_data->totalAngle); + setAbstractScaleDraw( scaleDraw ); + setTotalAngle( d_data->totalAngle ); } -/*! +/*! \return the scale draw of the knob \sa setScaleDraw() */ const QwtRoundScaleDraw *QwtKnob::scaleDraw() const { - return (QwtRoundScaleDraw *)abstractScaleDraw(); + return static_cast( abstractScaleDraw() ); } -/*! +/*! \return the scale draw of the knob \sa setScaleDraw() */ QwtRoundScaleDraw *QwtKnob::scaleDraw() { - return (QwtRoundScaleDraw *)abstractScaleDraw(); -} - -/*! - \brief Draw the knob - \param painter painter - \param r Bounding rectangle of the knob (without scale) -*/ -void QwtKnob::drawKnob(QPainter *painter, const QRect &r) -{ -#if QT_VERSION < 0x040000 - const QBrush buttonBrush = colorGroup().brush(QColorGroup::Button); - const QColor buttonTextColor = colorGroup().buttonText(); - const QColor lightColor = colorGroup().light(); - const QColor darkColor = colorGroup().dark(); -#else - const QBrush buttonBrush = palette().brush(QPalette::Button); - const QColor buttonTextColor = palette().color(QPalette::ButtonText); - const QColor lightColor = palette().color(QPalette::Light); - const QColor darkColor = palette().color(QPalette::Dark); -#endif - - const int bw2 = d_data->borderWidth / 2; - - const int radius = (qwtMin(r.width(), r.height()) - bw2) / 2; - - const QRect aRect( - r.center().x() - radius, r.center().y() - radius, - 2 * radius, 2 * radius); - - // - // draw button face - // - painter->setBrush(buttonBrush); - painter->drawEllipse(aRect); - - // - // draw button shades - // - QPen pn; - pn.setWidth(d_data->borderWidth); - - pn.setColor(lightColor); - painter->setPen(pn); - painter->drawArc(aRect, 45*16, 180*16); - - pn.setColor(darkColor); - painter->setPen(pn); - painter->drawArc(aRect, 225*16, 180*16); - - // - // draw marker - // - if ( isValid() ) - drawMarker(painter, d_data->angle, buttonTextColor); + return static_cast( abstractScaleDraw() ); } /*! @@ -250,65 +216,67 @@ void QwtKnob::valueChange() \brief Determine the value corresponding to a specified position Called by QwtAbstractSlider - \param p point + \param pos point */ -double QwtKnob::getValue(const QPoint &p) +double QwtKnob::getValue( const QPoint &pos ) { - const double dx = double((rect().x() + rect().width() / 2) - p.x() ); - const double dy = double((rect().y() + rect().height() / 2) - p.y() ); + const double dx = rect().center().x() - pos.x(); + const double dy = rect().center().y() - pos.y(); - const double arc = atan2(-dx,dy) * 180.0 / M_PI; + const double arc = qAtan2( -dx, dy ) * 180.0 / M_PI; - double newValue = 0.5 * (minValue() + maxValue()) - + (arc + d_data->nTurns * 360.0) * (maxValue() - minValue()) - / d_data->totalAngle; + double newValue = 0.5 * ( minValue() + maxValue() ) + + ( arc + d_data->nTurns * 360.0 ) * ( maxValue() - minValue() ) + / d_data->totalAngle; - const double oneTurn = fabs(maxValue() - minValue()) * 360.0 / d_data->totalAngle; + const double oneTurn = qFabs( maxValue() - minValue() ) * 360.0 / d_data->totalAngle; const double eqValue = value() + mouseOffset(); - if (fabs(newValue - eqValue) > 0.5 * oneTurn) + if ( qFabs( newValue - eqValue ) > 0.5 * oneTurn ) { - if (newValue < eqValue) - newValue += oneTurn; + if ( newValue < eqValue ) + newValue += oneTurn; else - newValue -= oneTurn; + newValue -= oneTurn; } - return newValue; + return newValue; } /*! \brief Set the scrolling mode and direction Called by QwtAbstractSlider - \param p Point in question + \param pos Point in question + \param scrollMode Scrolling mode + \param direction Direction */ -void QwtKnob::getScrollMode(const QPoint &p, int &scrollMode, int &direction) +void QwtKnob::getScrollMode( const QPoint &pos, + QwtAbstractSlider::ScrollMode &scrollMode, int &direction ) const { const int r = d_data->knobRect.width() / 2; - const int dx = d_data->knobRect.x() + r - p.x(); - const int dy = d_data->knobRect.y() + r - p.y(); + const int dx = d_data->knobRect.x() + r - pos.x(); + const int dy = d_data->knobRect.y() + r - pos.y(); - if ( (dx * dx) + (dy * dy) <= (r * r)) // point is inside the knob + if ( ( dx * dx ) + ( dy * dy ) <= ( r * r ) ) // point is inside the knob { - scrollMode = ScrMouse; + scrollMode = QwtAbstractSlider::ScrMouse; direction = 0; } else // point lies outside { - scrollMode = ScrTimer; - double arc = atan2(double(-dx),double(dy)) * 180.0 / M_PI; - if ( arc < d_data->angle) - direction = -1; - else if (arc > d_data->angle) - direction = 1; + scrollMode = QwtAbstractSlider::ScrTimer; + double arc = qAtan2( double( -dx ), double( dy ) ) * 180.0 / M_PI; + if ( arc < d_data->angle ) + direction = -1; + else if ( arc > d_data->angle ) + direction = 1; else - direction = 0; + direction = 0; } } - /*! \brief Notify a change of the range @@ -316,22 +284,41 @@ void QwtKnob::getScrollMode(const QPoint &p, int &scrollMode, int &direction) */ void QwtKnob::rangeChange() { - if (autoScale()) - rescale(minValue(), maxValue()); + if ( autoScale() ) + rescale( minValue(), maxValue() ); - layoutKnob(); + layoutKnob( true ); recalcAngle(); } /*! Qt Resize Event + \param event Resize event */ -void QwtKnob::resizeEvent(QResizeEvent *) +void QwtKnob::resizeEvent( QResizeEvent *event ) { + Q_UNUSED( event ); layoutKnob( false ); } /*! + Handle QEvent::StyleChange and QEvent::FontChange; + \param event Change event +*/ +void QwtKnob::changeEvent( QEvent *event ) +{ + switch( event->type() ) + { + case QEvent::StyleChange: + case QEvent::FontChange: + layoutKnob( true ); + break; + default: + break; + } +} + +/*! Recalculate the knob's geometry and layout based on the current rect and fonts. @@ -340,15 +327,14 @@ void QwtKnob::resizeEvent(QResizeEvent *) */ void QwtKnob::layoutKnob( bool update_geometry ) { - const QRect r = rect(); - const int radius = d_data->knobWidth / 2; + const double d = d_data->knobWidth; - d_data->knobRect.setWidth(2 * radius); - d_data->knobRect.setHeight(2 * radius); - d_data->knobRect.moveCenter(r.center()); + d_data->knobRect.setWidth( d ); + d_data->knobRect.setHeight( d ); + d_data->knobRect.moveCenter( rect().center() ); - scaleDraw()->setRadius(radius + d_data->scaleDist); - scaleDraw()->moveCenter(r.center()); + scaleDraw()->setRadius( 0.5 * d + d_data->scaleDist ); + scaleDraw()->moveCenter( rect().center() ); if ( update_geometry ) { @@ -359,92 +345,214 @@ void QwtKnob::layoutKnob( bool update_geometry ) /*! Repaint the knob - - \param e Paint event + \param event Paint event */ -void QwtKnob::paintEvent(QPaintEvent *e) +void QwtKnob::paintEvent( QPaintEvent *event ) { - const QRect &ur = e->rect(); - if ( ur.isValid() ) - { -#if QT_VERSION < 0x040000 - QwtPaintBuffer paintBuffer(this, ur); - draw(paintBuffer.painter(), ur); -#else - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); - draw(&painter, ur); -#endif - } + QPainter painter( this ); + painter.setClipRegion( event->region() ); + + QStyleOption opt; + opt.init(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); + + painter.setRenderHint( QPainter::Antialiasing, true ); + + if ( !d_data->knobRect.contains( event->region().boundingRect() ) ) + scaleDraw()->draw( &painter, palette() ); + + drawKnob( &painter, d_data->knobRect ); + drawMarker( &painter, d_data->knobRect, d_data->angle ); + + painter.setRenderHint( QPainter::Antialiasing, false ); + + if ( hasFocus() ) + QwtPainter::drawFocusRect( &painter, this ); } /*! - Repaint the knob - - \param painter Painter - \param rect Update rectangle + \brief Draw the knob + \param painter painter + \param knobRect Bounding rectangle of the knob (without scale) */ -void QwtKnob::draw(QPainter *painter, const QRect& rect) +void QwtKnob::drawKnob( QPainter *painter, + const QRectF &knobRect ) const { - if ( !d_data->knobRect.contains( rect ) ) // event from valueChange() + double dim = qMin( knobRect.width(), knobRect.height() ); + dim -= d_data->borderWidth * 0.5; + + QRectF aRect( 0, 0, dim, dim ); + aRect.moveCenter( knobRect.center() ); + + QPen pen( Qt::NoPen ); + if ( d_data->borderWidth > 0 ) { -#if QT_VERSION < 0x040000 - scaleDraw()->draw( painter, colorGroup() ); -#else - scaleDraw()->draw( painter, palette() ); -#endif + QColor c1 = palette().color( QPalette::Light ); + QColor c2 = palette().color( QPalette::Dark ); + + QLinearGradient gradient( aRect.topLeft(), aRect.bottomRight() ); + gradient.setColorAt( 0.0, c1 ); + gradient.setColorAt( 0.3, c1 ); + gradient.setColorAt( 0.7, c2 ); + gradient.setColorAt( 1.0, c2 ); + + pen = QPen( gradient, d_data->borderWidth ); } - drawKnob( painter, d_data->knobRect ); + QBrush brush; + switch( d_data->knobStyle ) + { + case QwtKnob::Raised: + { + double off = 0.3 * knobRect.width(); + QRadialGradient gradient( knobRect.center(), + knobRect.width(), knobRect.topLeft() + QPoint( off, off ) ); + + gradient.setColorAt( 0.0, palette().color( QPalette::Midlight ) ); + gradient.setColorAt( 1.0, palette().color( QPalette::Button ) ); - if ( hasFocus() ) - QwtPainter::drawFocusRect(painter, this); + brush = QBrush( gradient ); + + break; + } + case QwtKnob::Sunken: + { + QLinearGradient gradient( + knobRect.topLeft(), knobRect.bottomRight() ); + gradient.setColorAt( 0.0, palette().color( QPalette::Mid ) ); + gradient.setColorAt( 0.5, palette().color( QPalette::Button ) ); + gradient.setColorAt( 1.0, palette().color( QPalette::Midlight ) ); + brush = QBrush( gradient ); + + break; + } + default: + brush = palette().brush( QPalette::Button ); + } + + painter->setPen( pen ); + painter->setBrush( brush ); + painter->drawEllipse( aRect ); } + /*! \brief Draw the marker at the knob's front - \param p Painter - \param arc Angle of the marker - \param c Marker color + \param painter Painter + \param rect Bounding rectangle of the knob without scale + \param angle Angle of the marker in degrees */ -void QwtKnob::drawMarker(QPainter *p, double arc, const QColor &c) +void QwtKnob::drawMarker( QPainter *painter, + const QRectF &rect, double angle ) const { - const double rarc = arc * M_PI / 180.0; - const double ca = cos(rarc); - const double sa = - sin(rarc); + if ( d_data->markerStyle == NoMarker || !isValid() ) + return; - int radius = d_data->knobRect.width() / 2 - d_data->borderWidth; - if (radius < 3) - radius = 3; + const double radians = angle * M_PI / 180.0; + const double sinA = -qFastSin( radians ); + const double cosA = qFastCos( radians ); - const int ym = d_data->knobRect.y() + radius + d_data->borderWidth; - const int xm = d_data->knobRect.x() + radius + d_data->borderWidth; + const double xm = rect.center().x(); + const double ym = rect.center().y(); + const double margin = 4.0; - switch (d_data->symbol) + double radius = 0.5 * ( rect.width() - d_data->borderWidth ) - margin; + if ( radius < 1.0 ) + radius = 1.0; + + switch ( d_data->markerStyle ) { + case Notch: + case Nub: + { + const double dotWidth = + qMin( double( d_data->markerSize ), radius); + + const double dotCenterDist = radius - 0.5 * dotWidth; + if ( dotCenterDist > 0.0 ) + { + const QPointF center( xm - sinA * dotCenterDist, + ym - cosA * dotCenterDist ); + + QRectF ellipse( 0.0, 0.0, dotWidth, dotWidth ); + ellipse.moveCenter( center ); + + QColor c1 = palette().color( QPalette::Light ); + QColor c2 = palette().color( QPalette::Mid ); + + if ( d_data->markerStyle == Notch ) + qSwap( c1, c2 ); + + QLinearGradient gradient( + ellipse.topLeft(), ellipse.bottomRight() ); + gradient.setColorAt( 0.0, c1 ); + gradient.setColorAt( 1.0, c2 ); + + painter->setPen( Qt::NoPen ); + painter->setBrush( gradient ); + + painter->drawEllipse( ellipse ); + } + break; + } case Dot: { - p->setBrush(c); - p->setPen(Qt::NoPen); + const double dotWidth = + qMin( double( d_data->markerSize ), radius); + + const double dotCenterDist = radius - 0.5 * dotWidth; + if ( dotCenterDist > 0.0 ) + { + const QPointF center( xm - sinA * dotCenterDist, + ym - cosA * dotCenterDist ); + + QRectF ellipse( 0.0, 0.0, dotWidth, dotWidth ); + ellipse.moveCenter( center ); + + painter->setPen( Qt::NoPen ); + painter->setBrush( palette().color( QPalette::ButtonText ) ); + painter->drawEllipse( ellipse ); + } - const double rb = double(qwtMax(radius - 4 - d_data->dotWidth / 2, 0)); - p->drawEllipse(xm - qRound(sa * rb) - d_data->dotWidth / 2, - ym - qRound(ca * rb) - d_data->dotWidth / 2, - d_data->dotWidth, d_data->dotWidth); break; } - case Line: + case Tick: { - p->setPen(QPen(c, 2)); + const double rb = qMax( radius - d_data->markerSize, 1.0 ); + const double re = radius; + + const QLine line( xm - sinA * rb, ym - cosA * rb, + xm - sinA * re, ym - cosA * re ); + + QPen pen( palette().color( QPalette::ButtonText ), 0 ); + pen.setCapStyle( Qt::FlatCap ); + painter->setPen( pen ); + painter->drawLine ( line ); - const double rb = qwtMax(double((radius - 4) / 3.0), 0.0); - const double re = qwtMax(double(radius - 4), 0.0); - - p->drawLine ( xm - qRound(sa * rb), ym - qRound(ca * rb), - xm - qRound(sa * re), ym - qRound(ca * re)); - break; } +#if 0 + case Triangle: + { + const double rb = qMax( radius - d_data->markerSize, 1.0 ); + const double re = radius; + + painter->translate( rect.center() ); + painter->rotate( angle - 90.0 ); + + QPolygonF polygon; + polygon += QPointF( re, 0.0 ); + polygon += QPointF( rb, 0.5 * ( re - rb ) ); + polygon += QPointF( rb, -0.5 * ( re - rb ) ); + + painter->setPen( Qt::NoPen ); + painter->setBrush( palette().color( QPalette::Text ) ); + painter->drawPolygon( polygon ); + break; + } +#endif + default: + break; } } @@ -452,36 +560,55 @@ void QwtKnob::drawMarker(QPainter *p, double arc, const QColor &c) \brief Change the knob's width. The specified width must be >= 5, or it will be clipped. - \param w New width + \param width New width */ -void QwtKnob::setKnobWidth(int w) +void QwtKnob::setKnobWidth( int width ) { - d_data->knobWidth = qwtMax(w,5); - layoutKnob(); + d_data->knobWidth = qMax( width, 5 ); + layoutKnob( true ); } //! Return the width of the knob -int QwtKnob::knobWidth() const +int QwtKnob::knobWidth() const { return d_data->knobWidth; } /*! \brief Set the knob's border width - \param bw new border width + \param borderWidth new border width */ -void QwtKnob::setBorderWidth(int bw) +void QwtKnob::setBorderWidth( int borderWidth ) { - d_data->borderWidth = qwtMax(bw, 0); - layoutKnob(); + d_data->borderWidth = qMax( borderWidth, 0 ); + layoutKnob( true ); } //! Return the border width -int QwtKnob::borderWidth() const +int QwtKnob::borderWidth() const { return d_data->borderWidth; } +/*! + \brief Set the size of the marker + \sa markerSize(), markerStyle() +*/ +void QwtKnob::setMarkerSize( int size ) +{ + if ( d_data->markerSize != size ) + { + d_data->markerSize = size; + update(); + } +} + +//! Return the marker size +int QwtKnob::markerSize() const +{ + return d_data->markerSize; +} + /*! \brief Recalculate the marker angle corresponding to the current value @@ -491,16 +618,16 @@ void QwtKnob::recalcAngle() // // calculate the angle corresponding to the value // - if (maxValue() == minValue()) + if ( maxValue() == minValue() ) { d_data->angle = 0; d_data->nTurns = 0; } else { - d_data->angle = (value() - 0.5 * (minValue() + maxValue())) - / (maxValue() - minValue()) * d_data->totalAngle; - d_data->nTurns = floor((d_data->angle + 180.0) / 360.0); + d_data->angle = ( value() - 0.5 * ( minValue() + maxValue() ) ) + / ( maxValue() - minValue() ) * d_data->totalAngle; + d_data->nTurns = qFloor( ( d_data->angle + 180.0 ) / 360.0 ); d_data->angle = d_data->angle - d_data->nTurns * 360.0; } } @@ -512,17 +639,7 @@ void QwtKnob::recalcAngle() */ void QwtKnob::scaleChange() { - layoutKnob(); -} - -/*! - Recalculates the layout - \sa layoutKnob() -*/ -void QwtKnob::fontChange(const QFont &f) -{ - QwtAbstractSlider::fontChange( f ); - layoutKnob(); + layoutKnob( true ); } /*! @@ -530,18 +647,19 @@ void QwtKnob::fontChange(const QFont &f) */ QSize QwtKnob::sizeHint() const { - return minimumSizeHint(); + const QSize hint = minimumSizeHint(); + return hint.expandedTo( QApplication::globalStrut() ); } /*! \brief Return a minimum size hint - \warning The return value of QwtKnob::minimumSizeHint() depends on the + \warning The return value of QwtKnob::minimumSizeHint() depends on the font and the scale. */ QSize QwtKnob::minimumSizeHint() const { // Add the scale radial thickness to the knobWidth - const int sh = scaleDraw()->extent( QPen(), font() ); + const int sh = qCeil( scaleDraw()->extent( font() ) ); const int d = 2 * sh + 2 * d_data->scaleDist + d_data->knobWidth; return QSize( d, d ); diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_knob.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_knob.h index b20de8dd0..c820128c5 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_knob.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_knob.h @@ -33,65 +33,124 @@ class QwtRoundScaleDraw; class QWT_EXPORT QwtKnob : public QwtAbstractSlider, public QwtAbstractScale { - Q_OBJECT - Q_ENUMS (Symbol) + Q_OBJECT + + Q_ENUMS ( KnobStyle ) + Q_ENUMS ( MarkerStyle ) + + Q_PROPERTY( KnobStyle knobStyle READ knobStyle WRITE setKnobStyle ) + Q_PROPERTY( MarkerStyle markerStyle READ markerStyle WRITE setMarkerStyle ) Q_PROPERTY( int knobWidth READ knobWidth WRITE setKnobWidth ) Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth ) Q_PROPERTY( double totalAngle READ totalAngle WRITE setTotalAngle ) - Q_PROPERTY( Symbol symbol READ symbol WRITE setSymbol ) + Q_PROPERTY( int markerSize READ markerSize WRITE setMarkerSize ) + Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth ) public: + /*! + \brief Style of the knob surface + + Depending on the KnobStyle the surface of the knob is + filled from the brushes of the widget palette(). + + \sa setKnobStyle(), knobStyle() + */ + enum KnobStyle + { + //! Fill the knob with a brush from QPalette::Button. + NoStyle = -1, + + //! Build a gradient from QPalette::Midlight and QPalette::Button + Raised, + + /*! + Build a gradient from QPalette::Midlight, QPalette::Button + and QPalette::Midlight + */ + Sunken + }; + /*! - Symbol - \sa QwtKnob::QwtKnob() + \brief Marker type + + The marker indicates the current value on the knob + The default setting is a Notch marker. + + \sa setMarkerStyle(), setMarkerSize() */ + enum MarkerStyle + { + //! Don't paint any marker + NoMarker = -1, - enum Symbol { Line, Dot }; + //! Paint a single tick in QPalette::ButtonText color + Tick, - explicit QwtKnob(QWidget* parent = NULL); -#if QT_VERSION < 0x040000 - explicit QwtKnob(QWidget* parent, const char *name); -#endif + //! Paint a circle in QPalette::ButtonText color + Dot, + + /*! + Draw a raised ellipse with a gradient build from + QPalette::Light and QPalette::Mid + */ + Nub, + + /*! + Draw a sunken ellipse with a gradient build from + QPalette::Light and QPalette::Mid + */ + Notch + }; + + explicit QwtKnob( QWidget* parent = NULL ); virtual ~QwtKnob(); - void setKnobWidth(int w); + void setKnobWidth( int w ); int knobWidth() const; - void setTotalAngle (double angle); + void setTotalAngle ( double angle ); double totalAngle() const; - void setBorderWidth(int bw); + void setKnobStyle( KnobStyle ); + KnobStyle knobStyle() const; + + void setBorderWidth( int bw ); int borderWidth() const; - void setSymbol(Symbol); - Symbol symbol() const; + void setMarkerStyle( MarkerStyle ); + MarkerStyle markerStyle() const; + + void setMarkerSize( int ); + int markerSize() const; virtual QSize sizeHint() const; virtual QSize minimumSizeHint() const; - - void setScaleDraw(QwtRoundScaleDraw *); + + void setScaleDraw( QwtRoundScaleDraw * ); const QwtRoundScaleDraw *scaleDraw() const; QwtRoundScaleDraw *scaleDraw(); protected: - virtual void paintEvent(QPaintEvent *e); - virtual void resizeEvent(QResizeEvent *e); + virtual void paintEvent( QPaintEvent * ); + virtual void resizeEvent( QResizeEvent * ); + virtual void changeEvent( QEvent * ); - void draw(QPainter *p, const QRect& ur); - void drawKnob(QPainter *p, const QRect &r); - void drawMarker(QPainter *p, double arc, const QColor &c); + virtual void drawKnob( QPainter *, const QRectF & ) const; + virtual void drawMarker( QPainter *, + const QRectF &, double arc ) const; + + virtual double getValue( const QPoint &p ); + virtual void getScrollMode( const QPoint &, + QwtAbstractSlider::ScrollMode &, int &direction ) const; private: void initKnob(); - void layoutKnob( bool update = true ); - double getValue(const QPoint &p); - void getScrollMode( const QPoint &p, int &scrollMode, int &direction ); + void layoutKnob( bool update ); void recalcAngle(); - + virtual void valueChange(); virtual void rangeChange(); virtual void scaleChange(); - virtual void fontChange(const QFont &oldFont); class PrivateData; PrivateData *d_data; diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_layout_metrics.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_layout_metrics.cpp deleted file mode 100644 index f3d4c7177..000000000 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_layout_metrics.cpp +++ /dev/null @@ -1,339 +0,0 @@ -/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** - * Qwt Widget Library - * Copyright (C) 1997 Josef Wilgen - * Copyright (C) 2002 Uwe Rathmann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the Qwt License, Version 1.0 - *****************************************************************************/ - -#include -#include -#if QT_VERSION < 0x040000 -#include -#include -#define QwtMatrix QWMatrix -#else -#include -#define QwtMatrix QMatrix -#endif -#include -#include -#include "qwt_math.h" -#include "qwt_polygon.h" -#include "qwt_layout_metrics.h" - -static QSize deviceDpi(const QPaintDevice *device) -{ - QSize dpi; -#if QT_VERSION < 0x040000 - const QPaintDeviceMetrics metrics(device); - dpi.setWidth(metrics.logicalDpiX()); - dpi.setHeight(metrics.logicalDpiY()); -#else - dpi.setWidth(device->logicalDpiX()); - dpi.setHeight(device->logicalDpiY()); -#endif - - return dpi; -} - -#if QT_VERSION < 0x040000 - -inline static const QWMatrix &matrix(const QPainter *painter) -{ - return painter->worldMatrix(); -} -inline static QWMatrix invMatrix(const QPainter *painter) -{ - return painter->worldMatrix().invert(); -} - -#else // QT_VERSION >= 0x040000 - -inline static const QMatrix &matrix(const QPainter *painter) -{ - return painter->matrix(); -} -inline static QMatrix invMatrix(const QPainter *painter) -{ - return painter->matrix().inverted(); -} - -#endif - -QwtMetricsMap::QwtMetricsMap() -{ - d_screenToLayoutX = d_screenToLayoutY = - d_deviceToLayoutX = d_deviceToLayoutY = 1.0; -} - -void QwtMetricsMap::setMetrics(const QPaintDevice *layoutDevice, - const QPaintDevice *paintDevice) -{ - const QSize screenDpi = deviceDpi(QApplication::desktop()); - const QSize layoutDpi = deviceDpi(layoutDevice); - const QSize paintDpi = deviceDpi(paintDevice); - - d_screenToLayoutX = double(layoutDpi.width()) / - double(screenDpi.width()); - d_screenToLayoutY = double(layoutDpi.height()) / - double(screenDpi.height()); - - d_deviceToLayoutX = double(layoutDpi.width()) / - double(paintDpi.width()); - d_deviceToLayoutY = double(layoutDpi.height()) / - double(paintDpi.height()); -} - -#ifndef QT_NO_TRANSFORMATIONS -QPoint QwtMetricsMap::layoutToDevice(const QPoint &point, - const QPainter *painter) const -#else -QPoint QwtMetricsMap::layoutToDevice(const QPoint &point, - const QPainter *) const -#endif -{ - if ( isIdentity() ) - return point; - - QPoint mappedPoint(point); - -#ifndef QT_NO_TRANSFORMATIONS - if ( painter ) - mappedPoint = matrix(painter).map(mappedPoint); -#endif - - mappedPoint.setX(layoutToDeviceX(mappedPoint.x())); - mappedPoint.setY(layoutToDeviceY(mappedPoint.y())); - -#ifndef QT_NO_TRANSFORMATIONS - if ( painter ) - mappedPoint = invMatrix(painter).map(mappedPoint); -#endif - - return mappedPoint; -} - -#ifndef QT_NO_TRANSFORMATIONS -QPoint QwtMetricsMap::deviceToLayout(const QPoint &point, - const QPainter *painter) const -#else -QPoint QwtMetricsMap::deviceToLayout(const QPoint &point, - const QPainter *) const -#endif -{ - if ( isIdentity() ) - return point; - - QPoint mappedPoint(point); - -#ifndef QT_NO_TRANSFORMATIONS - if ( painter ) - mappedPoint = matrix(painter).map(mappedPoint); -#endif - - mappedPoint.setX(deviceToLayoutX(mappedPoint.x())); - mappedPoint.setY(deviceToLayoutY(mappedPoint.y())); - -#ifndef QT_NO_TRANSFORMATIONS - if ( painter ) - mappedPoint = invMatrix(painter).map(mappedPoint); -#endif - - return mappedPoint; -} - -QPoint QwtMetricsMap::screenToLayout(const QPoint &point) const -{ - if ( d_screenToLayoutX == 1.0 && d_screenToLayoutY == 1.0 ) - return point; - - return QPoint(screenToLayoutX(point.x()), screenToLayoutY(point.y())); -} - -QPoint QwtMetricsMap::layoutToScreen(const QPoint &point) const -{ - if ( d_screenToLayoutX == 1.0 && d_screenToLayoutY == 1.0 ) - return point; - - return QPoint(layoutToScreenX(point.x()), layoutToScreenY(point.y())); -} - -#ifndef QT_NO_TRANSFORMATIONS -QRect QwtMetricsMap::layoutToDevice(const QRect &rect, - const QPainter *painter) const -#else -QRect QwtMetricsMap::layoutToDevice(const QRect &rect, - const QPainter *) const -#endif -{ - if ( isIdentity() ) - return rect; - - int dx = 0; - int dy = 0; - - QRect mappedRect(rect); -#ifndef QT_NO_TRANSFORMATIONS - if ( painter ) - { - // only translations, but this code doesn't need to be perfect - // as it used for printing of stuff only, that is not on the canvas. - // Here we know we have translations only. - // As soon as Qt3 support is dropped, Qwt will use a floating point - // based layout and this class can die completely. - - dx = qRound(matrix(painter).dx()); - dy = qRound(matrix(painter).dy()); - - mappedRect = QRect(mappedRect.x() + dx, mappedRect.y() + dy, - mappedRect.width(), mappedRect.height() ); - } -#endif - - mappedRect = QRect( - layoutToDevice(mappedRect.topLeft()), - layoutToDevice(mappedRect.bottomRight()) - ); - - mappedRect = QRect(mappedRect.x() - dx, mappedRect.y() - dy, - mappedRect.width(), mappedRect.height() ); - - return mappedRect; -} - -#ifndef QT_NO_TRANSFORMATIONS -QRect QwtMetricsMap::deviceToLayout(const QRect &rect, - const QPainter *painter) const -#else -QRect QwtMetricsMap::deviceToLayout(const QRect &rect, - const QPainter *) const -#endif -{ - if ( isIdentity() ) - return rect; - - QRect mappedRect(rect); -#ifndef QT_NO_TRANSFORMATIONS - if ( painter ) - mappedRect = translate(matrix(painter), mappedRect); -#endif - - mappedRect = QRect( - deviceToLayout(mappedRect.topLeft()), - deviceToLayout(mappedRect.bottomRight()) - ); - -#ifndef QT_NO_TRANSFORMATIONS - if ( painter ) - mappedRect = translate(invMatrix(painter), mappedRect); -#endif - - return mappedRect; -} - -QRect QwtMetricsMap::screenToLayout(const QRect &rect) const -{ - if ( d_screenToLayoutX == 1.0 && d_screenToLayoutY == 1.0 ) - return rect; - - return QRect(screenToLayoutX(rect.x()), screenToLayoutY(rect.y()), - screenToLayoutX(rect.width()), screenToLayoutY(rect.height())); -} - -QRect QwtMetricsMap::layoutToScreen(const QRect &rect) const -{ - if ( d_screenToLayoutX == 1.0 && d_screenToLayoutY == 1.0 ) - return rect; - - return QRect(layoutToScreenX(rect.x()), layoutToScreenY(rect.y()), - layoutToScreenX(rect.width()), layoutToScreenY(rect.height())); -} - -#ifndef QT_NO_TRANSFORMATIONS -QwtPolygon QwtMetricsMap::layoutToDevice(const QwtPolygon &pa, - const QPainter *painter) const -#else -QwtPolygon QwtMetricsMap::layoutToDevice(const QwtPolygon &pa, - const QPainter *) const -#endif -{ - if ( isIdentity() ) - return pa; - - QwtPolygon mappedPa(pa); - -#ifndef QT_NO_TRANSFORMATIONS - if ( painter ) - mappedPa = translate(matrix(painter), mappedPa); -#endif - - QwtMatrix m; - m.scale(1.0 / d_deviceToLayoutX, 1.0 / d_deviceToLayoutY); - mappedPa = translate(m, mappedPa); - -#ifndef QT_NO_TRANSFORMATIONS - if ( painter ) - mappedPa = translate(invMatrix(painter), mappedPa); -#endif - - return mappedPa; -} - -#ifndef QT_NO_TRANSFORMATIONS -QwtPolygon QwtMetricsMap::deviceToLayout(const QwtPolygon &pa, - const QPainter *painter) const -#else -QwtPolygon QwtMetricsMap::deviceToLayout(const QwtPolygon &pa, - const QPainter *) const -#endif -{ - if ( isIdentity() ) - return pa; - - QwtPolygon mappedPa(pa); - -#ifndef QT_NO_TRANSFORMATIONS - if ( painter ) - mappedPa = translate(matrix(painter), mappedPa); -#endif - - QwtMatrix m; - m.scale(d_deviceToLayoutX, d_deviceToLayoutY); - mappedPa = translate(m, mappedPa); - -#ifndef QT_NO_TRANSFORMATIONS - if ( painter ) - mappedPa = translate(invMatrix(painter), mappedPa); -#endif - - return mappedPa; -} - -/*! - Wrapper for QMatrix::mapRect. - - \param m Matrix - \param rect Rectangle to translate - \return Translated rectangle -*/ - -QRect QwtMetricsMap::translate( - const QwtMatrix &m, const QRect &rect) -{ - return m.mapRect(rect); -} - -/*! - Wrapper for QMatrix::map. - - \param m Matrix - \param pa Polygon to translate - \return Translated polygon -*/ -QwtPolygon QwtMetricsMap::translate( - const QwtMatrix &m, const QwtPolygon &pa) -{ - return m.map(pa); -} diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_layout_metrics.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_layout_metrics.h deleted file mode 100644 index 643198d3f..000000000 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_layout_metrics.h +++ /dev/null @@ -1,169 +0,0 @@ -/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** - * Qwt Widget Library - * Copyright (C) 1997 Josef Wilgen - * Copyright (C) 2002 Uwe Rathmann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the Qwt License, Version 1.0 - *****************************************************************************/ - -#ifndef QWT_LAYOUT_METRICS_H -#define QWT_LAYOUT_METRICS_H - -#include -#include -#include "qwt_polygon.h" -#include "qwt_global.h" - -class QPainter; -class QString; -class QFontMetrics; -#if QT_VERSION < 0x040000 -class QWMatrix; -#else -class QMatrix; -#endif -class QPaintDevice; - -/*! - \brief A Map to translate between layout, screen and paint device metrics - - Qt3 supports painting in integer coordinates only. Therefore it is not - possible to scale the layout in screen coordinates to layouts in higher - resolutions ( f.e printing ) without losing the higher precision. - QwtMetricsMap is used to incorporate the various widget attributes - ( always in screen resolution ) into the layout/printing code of QwtPlot. - - Qt4 is able to paint floating point based coordinates, what makes it - possible always to render in screen coordinates - ( with a common scale factor ). - QwtMetricsMap will be obsolete as soon as Qt3 support has been - dropped ( Qwt 6.x ). -*/ -class QWT_EXPORT QwtMetricsMap -{ -public: - QwtMetricsMap(); - - bool isIdentity() const; - - void setMetrics(const QPaintDevice *layoutMetrics, - const QPaintDevice *deviceMetrics); - - int layoutToDeviceX(int x) const; - int deviceToLayoutX(int x) const; - int screenToLayoutX(int x) const; - int layoutToScreenX(int x) const; - - int layoutToDeviceY(int y) const; - int deviceToLayoutY(int y) const; - int screenToLayoutY(int y) const; - int layoutToScreenY(int y) const; - - QPoint layoutToDevice(const QPoint &, const QPainter * = NULL) const; - QPoint deviceToLayout(const QPoint &, const QPainter * = NULL) const; - QPoint screenToLayout(const QPoint &) const; - QPoint layoutToScreen(const QPoint &point) const; - - - QSize layoutToDevice(const QSize &) const; - QSize deviceToLayout(const QSize &) const; - QSize screenToLayout(const QSize &) const; - QSize layoutToScreen(const QSize &) const; - - QRect layoutToDevice(const QRect &, const QPainter * = NULL) const; - QRect deviceToLayout(const QRect &, const QPainter * = NULL) const; - QRect screenToLayout(const QRect &) const; - QRect layoutToScreen(const QRect &) const; - - QwtPolygon layoutToDevice(const QwtPolygon &, - const QPainter * = NULL) const; - QwtPolygon deviceToLayout(const QwtPolygon &, - const QPainter * = NULL) const; - -#if QT_VERSION < 0x040000 - static QwtPolygon translate(const QWMatrix &, const QwtPolygon &); - static QRect translate(const QWMatrix &, const QRect &); -#else - static QwtPolygon translate(const QMatrix &, const QwtPolygon &); - static QRect translate(const QMatrix &, const QRect &); -#endif - -private: - double d_screenToLayoutX; - double d_screenToLayoutY; - - double d_deviceToLayoutX; - double d_deviceToLayoutY; -}; - -inline bool QwtMetricsMap::isIdentity() const -{ - return d_deviceToLayoutX == 1.0 && d_deviceToLayoutY == 1.0; -} - -inline int QwtMetricsMap::layoutToDeviceX(int x) const -{ - return qRound(x / d_deviceToLayoutX); -} - -inline int QwtMetricsMap::deviceToLayoutX(int x) const -{ - return qRound(x * d_deviceToLayoutX); -} - -inline int QwtMetricsMap::screenToLayoutX(int x) const -{ - return qRound(x * d_screenToLayoutX); -} - -inline int QwtMetricsMap::layoutToScreenX(int x) const -{ - return qRound(x / d_screenToLayoutX); -} - -inline int QwtMetricsMap::layoutToDeviceY(int y) const -{ - return qRound(y / d_deviceToLayoutY); -} - -inline int QwtMetricsMap::deviceToLayoutY(int y) const -{ - return qRound(y * d_deviceToLayoutY); -} - -inline int QwtMetricsMap::screenToLayoutY(int y) const -{ - return qRound(y * d_screenToLayoutY); -} - -inline int QwtMetricsMap::layoutToScreenY(int y) const -{ - return qRound(y / d_screenToLayoutY); -} - -inline QSize QwtMetricsMap::layoutToDevice(const QSize &size) const -{ - return QSize(layoutToDeviceX(size.width()), - layoutToDeviceY(size.height())); -} - -inline QSize QwtMetricsMap::deviceToLayout(const QSize &size) const -{ - return QSize(deviceToLayoutX(size.width()), - deviceToLayoutY(size.height())); -} - -inline QSize QwtMetricsMap::screenToLayout(const QSize &size) const -{ - return QSize(screenToLayoutX(size.width()), - screenToLayoutY(size.height())); -} - -inline QSize QwtMetricsMap::layoutToScreen(const QSize &size) const -{ - return QSize(layoutToScreenX(size.width()), - layoutToScreenY(size.height())); -} - -#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_legend.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_legend.cpp index 4e4bc10ae..1e73accd0 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_legend.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_legend.cpp @@ -2,23 +2,20 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - -#include -#include -#if QT_VERSION >= 0x040000 -#include -#endif -#include "qwt_math.h" -#include "qwt_dyngrid_layout.h" +#include "qwt_legend.h" #include "qwt_legend_itemmanager.h" #include "qwt_legend_item.h" -#include "qwt_legend.h" +#include "qwt_dyngrid_layout.h" +#include "qwt_math.h" +#include +#include +#include +#include class QwtLegend::PrivateData { @@ -26,20 +23,20 @@ public: class LegendMap { public: - void insert(const QwtLegendItemManager *, QWidget *); + void insert( const QwtLegendItemManager *, QWidget * ); - void remove(const QwtLegendItemManager *); - void remove(QWidget *); + void remove( const QwtLegendItemManager * ); + void remove( QWidget * ); void clear(); uint count() const; - inline const QWidget *find(const QwtLegendItemManager *) const; - inline QWidget *find(const QwtLegendItemManager *); + inline const QWidget *find( const QwtLegendItemManager * ) const; + inline QWidget *find( const QwtLegendItemManager * ); - inline const QwtLegendItemManager *find(const QWidget *) const; - inline QwtLegendItemManager *find(const QWidget *); + inline const QwtLegendItemManager *find( const QWidget * ) const; + inline QwtLegendItemManager *find( const QWidget * ); const QMap &widgetMap() const; QMap &widgetMap(); @@ -50,8 +47,6 @@ public: }; QwtLegend::LegendItemMode itemMode; - QwtLegend::LegendDisplayPolicy displayPolicy; - int identifierMode; LegendMap map; @@ -59,73 +54,45 @@ public: LegendView *view; }; -#if QT_VERSION < 0x040000 -#include - -class QwtLegend::PrivateData::LegendView: public QScrollView -{ -public: - LegendView(QWidget *parent): - QScrollView(parent) - { - setResizePolicy(Manual); - - viewport()->setBackgroundMode(Qt::NoBackground); // Avoid flicker - - contentsWidget = new QWidget(viewport()); - - addChild(contentsWidget); - } - - void viewportResizeEvent(QResizeEvent *e) - { - QScrollView::viewportResizeEvent(e); - - // It's not safe to update the layout now, because - // we are in an internal update of the scrollview framework. - // So we delay the update by posting a LayoutHint. - - QApplication::postEvent(contentsWidget, - new QEvent(QEvent::LayoutHint)); - } - - QWidget *contentsWidget; -}; - -#else // QT_VERSION >= 0x040000 - -#include - class QwtLegend::PrivateData::LegendView: public QScrollArea { public: - LegendView(QWidget *parent): - QScrollArea(parent) + LegendView( QWidget *parent ): + QScrollArea( parent ) { - contentsWidget = new QWidget(this); + setFocusPolicy( Qt::NoFocus ); - setWidget(contentsWidget); - setWidgetResizable(false); - setFocusPolicy(Qt::NoFocus); + contentsWidget = new QWidget( this ); + contentsWidget->setObjectName( "QwtLegendViewContents" ); + + setWidget( contentsWidget ); + setWidgetResizable( false ); + + viewport()->setObjectName( "QwtLegendViewport" ); + + // QScrollArea::setWidget internally sets autoFillBackground to true + // But we don't want a background. + contentsWidget->setAutoFillBackground( false ); + viewport()->setAutoFillBackground( false ); } - virtual bool viewportEvent(QEvent *e) + virtual bool viewportEvent( QEvent *e ) { - bool ok = QScrollArea::viewportEvent(e); + bool ok = QScrollArea::viewportEvent( e ); if ( e->type() == QEvent::Resize ) { - QEvent event(QEvent::LayoutRequest); - QApplication::sendEvent(contentsWidget, &event); + QEvent event( QEvent::LayoutRequest ); + QApplication::sendEvent( contentsWidget, &event ); } return ok; } - QSize viewportSize(int w, int h) const + QSize viewportSize( int w, int h ) const { const int sbHeight = horizontalScrollBar()->sizeHint().height(); const int sbWidth = verticalScrollBar()->sizeHint().width(); - + const int cw = contentsRect().width(); const int ch = contentsRect().height(); @@ -141,63 +108,52 @@ public: if ( w > vw && vh == ch ) vh -= sbHeight; } - return QSize(vw, vh); + return QSize( vw, vh ); } QWidget *contentsWidget; }; -#endif - - void QwtLegend::PrivateData::LegendMap::insert( - const QwtLegendItemManager *item, QWidget *widget) + const QwtLegendItemManager *item, QWidget *widget ) { - d_itemMap.insert(item, widget); - d_widgetMap.insert(widget, item); + d_itemMap.insert( item, widget ); + d_widgetMap.insert( widget, item ); } -void QwtLegend::PrivateData::LegendMap::remove(const QwtLegendItemManager *item) +void QwtLegend::PrivateData::LegendMap::remove( const QwtLegendItemManager *item ) { QWidget *widget = d_itemMap[item]; - d_itemMap.remove(item); - d_widgetMap.remove(widget); + d_itemMap.remove( item ); + d_widgetMap.remove( widget ); } -void QwtLegend::PrivateData::LegendMap::remove(QWidget *widget) +void QwtLegend::PrivateData::LegendMap::remove( QWidget *widget ) { const QwtLegendItemManager *item = d_widgetMap[widget]; - d_itemMap.remove(item); - d_widgetMap.remove(widget); + d_itemMap.remove( item ); + d_widgetMap.remove( widget ); } void QwtLegend::PrivateData::LegendMap::clear() { - + /* We can't delete the widgets in the following loop, because we would get ChildRemoved events, changing d_itemMap, while we are iterating. */ -#if QT_VERSION < 0x040000 - QValueList widgets; + QList widgets; QMap::const_iterator it; - for ( it = d_itemMap.begin(); it != d_itemMap.end(); ++it ) - widgets.append(it.data()); -#else - QList widgets; - - QMap::const_iterator it; - for ( it = d_itemMap.begin(); it != d_itemMap.end(); ++it ) - widgets.append(it.value()); -#endif + for ( it = d_itemMap.begin(); it != d_itemMap.end(); ++it ) + widgets.append( it.value() ); d_itemMap.clear(); d_widgetMap.clear(); - for ( int i = 0; i < (int)widgets.size(); i++ ) + for ( int i = 0; i < widgets.size(); i++ ) delete widgets[i]; } @@ -206,79 +162,82 @@ uint QwtLegend::PrivateData::LegendMap::count() const return d_itemMap.count(); } -inline const QWidget *QwtLegend::PrivateData::LegendMap::find(const QwtLegendItemManager *item) const +inline const QWidget *QwtLegend::PrivateData::LegendMap::find( + const QwtLegendItemManager *item ) const { - if ( !d_itemMap.contains((QwtLegendItemManager *)item) ) + if ( !d_itemMap.contains( item ) ) return NULL; - return d_itemMap[(QwtLegendItemManager *)item]; + return d_itemMap[item]; } -inline QWidget *QwtLegend::PrivateData::LegendMap::find(const QwtLegendItemManager *item) +inline QWidget *QwtLegend::PrivateData::LegendMap::find( + const QwtLegendItemManager *item ) { - if ( !d_itemMap.contains((QwtLegendItemManager *)item) ) + if ( !d_itemMap.contains( item ) ) return NULL; - return d_itemMap[(QwtLegendItemManager *)item]; + return d_itemMap[item]; } inline const QwtLegendItemManager *QwtLegend::PrivateData::LegendMap::find( - const QWidget *widget) const + const QWidget *widget ) const { - if ( !d_widgetMap.contains((QWidget *)widget) ) + QWidget *w = const_cast( widget ); + if ( !d_widgetMap.contains( w ) ) return NULL; - return d_widgetMap[(QWidget *)widget]; + return d_widgetMap[w]; } inline QwtLegendItemManager *QwtLegend::PrivateData::LegendMap::find( - const QWidget *widget) + const QWidget *widget ) { - if ( !d_widgetMap.contains((QWidget *)widget) ) + QWidget *w = const_cast( widget ); + if ( !d_widgetMap.contains( w ) ) return NULL; - return (QwtLegendItemManager *)d_widgetMap[(QWidget *)widget]; + return const_cast( d_widgetMap[w] ); } inline const QMap & - QwtLegend::PrivateData::LegendMap::widgetMap() const +QwtLegend::PrivateData::LegendMap::widgetMap() const { return d_widgetMap; -} +} inline QMap & - QwtLegend::PrivateData::LegendMap::widgetMap() +QwtLegend::PrivateData::LegendMap::widgetMap() { return d_widgetMap; -} +} /*! Constructor \param parent Parent widget */ -QwtLegend::QwtLegend(QWidget *parent): - QFrame(parent) +QwtLegend::QwtLegend( QWidget *parent ): + QFrame( parent ) { - setFrameStyle(NoFrame); + setFrameStyle( NoFrame ); d_data = new QwtLegend::PrivateData; d_data->itemMode = QwtLegend::ReadOnlyItem; - d_data->displayPolicy = QwtLegend::AutoIdentifier; - d_data->identifierMode = QwtLegendItem::ShowLine | - QwtLegendItem::ShowSymbol | QwtLegendItem::ShowText; - d_data->view = new QwtLegend::PrivateData::LegendView(this); - d_data->view->setFrameStyle(NoFrame); + d_data->view = new QwtLegend::PrivateData::LegendView( this ); + d_data->view->setObjectName( "QwtLegendView" ); + d_data->view->setFrameStyle( NoFrame ); - QwtDynGridLayout *layout = new QwtDynGridLayout( - d_data->view->contentsWidget); -#if QT_VERSION < 0x040000 - layout->setAutoAdd(true); -#endif - layout->setAlignment(Qt::AlignHCenter | Qt::AlignTop); + QwtDynGridLayout *gridLayout = new QwtDynGridLayout( + d_data->view->contentsWidget ); + gridLayout->setAlignment( Qt::AlignHCenter | Qt::AlignTop ); - d_data->view->contentsWidget->installEventFilter(this); + d_data->view->contentsWidget->installEventFilter( this ); + + QVBoxLayout *layout = new QVBoxLayout( this ); + layout->setContentsMargins( 0, 0, 0, 0 ); + layout->addWidget( d_data->view ); } //! Destructor @@ -287,49 +246,8 @@ QwtLegend::~QwtLegend() delete d_data; } -/*! - Set the legend display policy to: - - \param policy Legend display policy - \param mode Identifier mode (or'd ShowLine, ShowSymbol, ShowText) - - \sa displayPolicy(), LegendDisplayPolicy -*/ -void QwtLegend::setDisplayPolicy(LegendDisplayPolicy policy, int mode) -{ - d_data->displayPolicy = policy; - if (-1 != mode) - d_data->identifierMode = mode; - - QMap &map = - d_data->map.widgetMap(); - - QMap::iterator it; - for ( it = map.begin(); it != map.end(); ++it ) - { -#if QT_VERSION < 0x040000 - QwtLegendItemManager *item = (QwtLegendItemManager *)it.data(); -#else - QwtLegendItemManager *item = (QwtLegendItemManager *)it.value(); -#endif - if ( item ) - item->updateLegend(this); - } -} - -/*! - \return the legend display policy. - Default is LegendDisplayPolicy::Auto. - \sa setDisplayPolicy(), LegendDisplayPolicy -*/ - -QwtLegend::LegendDisplayPolicy QwtLegend::displayPolicy() const -{ - return d_data->displayPolicy; -} - //! \sa LegendItemMode -void QwtLegend::setItemMode(LegendItemMode mode) +void QwtLegend::setItemMode( LegendItemMode mode ) { d_data->itemMode = mode; } @@ -341,26 +259,17 @@ QwtLegend::LegendItemMode QwtLegend::itemMode() const } /*! - \return the IdentifierMode to be used in combination with - LegendDisplayPolicy::Fixed. + The contents widget is the only child of the viewport of + the internal QScrollArea and the parent widget of all legend items. - Default is ShowLine | ShowSymbol | ShowText. + \return Container widget of the legend items */ -int QwtLegend::identifierMode() const +QWidget *QwtLegend::contentsWidget() { - return d_data->identifierMode; + return d_data->view->contentsWidget; } -/*! - The contents widget is the only child of the viewport() and - the parent widget of all legend items. -*/ -QWidget *QwtLegend::contentsWidget() -{ - return d_data->view->contentsWidget; -} - -/*! +/*! \return Horizontal scrollbar \sa verticalScrollBar() */ @@ -369,7 +278,7 @@ QScrollBar *QwtLegend::horizontalScrollBar() const return d_data->view->horizontalScrollBar(); } -/*! +/*! \return Vertical scrollbar \sa horizontalScrollBar() */ @@ -378,22 +287,25 @@ QScrollBar *QwtLegend::verticalScrollBar() const return d_data->view->verticalScrollBar(); } -/*! - The contents widget is the only child of the viewport() and - the parent widget of all legend items. +/*! + The contents widget is the only child of the viewport of + the internal QScrollArea and the parent widget of all legend items. + + \return Container widget of the legend items + */ -const QWidget *QwtLegend::contentsWidget() const -{ - return d_data->view->contentsWidget; +const QWidget *QwtLegend::contentsWidget() const +{ + return d_data->view->contentsWidget; } /*! Insert a new item for a plot item \param plotItem Plot item \param legendItem New legend item - \note The parent of item will be changed to QwtLegend::contentsWidget() + \note The parent of item will be changed to contentsWidget() */ -void QwtLegend::insert(const QwtLegendItemManager *plotItem, QWidget *legendItem) +void QwtLegend::insert( const QwtLegendItemManager *plotItem, QWidget *legendItem ) { if ( legendItem == NULL || plotItem == NULL ) return; @@ -401,63 +313,41 @@ void QwtLegend::insert(const QwtLegendItemManager *plotItem, QWidget *legendItem QWidget *contentsWidget = d_data->view->contentsWidget; if ( legendItem->parent() != contentsWidget ) - { -#if QT_VERSION >= 0x040000 - legendItem->setParent(contentsWidget); -#else - legendItem->reparent(contentsWidget, QPoint(0, 0)); -#endif - } + legendItem->setParent( contentsWidget ); legendItem->show(); - d_data->map.insert(plotItem, legendItem); + d_data->map.insert( plotItem, legendItem ); layoutContents(); if ( contentsWidget->layout() ) { -#if QT_VERSION >= 0x040000 - contentsWidget->layout()->addWidget(legendItem); -#endif + contentsWidget->layout()->addWidget( legendItem ); // set tab focus chain QWidget *w = NULL; -#if QT_VERSION < 0x040000 - QLayoutIterator layoutIterator = - contentsWidget->layout()->iterator(); - for ( QLayoutItem *item = layoutIterator.current(); - item != 0; item = ++layoutIterator) + for ( int i = 0; i < contentsWidget->layout()->count(); i++ ) { -#else - for (int i = 0; i < contentsWidget->layout()->count(); i++) - { - QLayoutItem *item = contentsWidget->layout()->itemAt(i); -#endif + QLayoutItem *item = contentsWidget->layout()->itemAt( i ); if ( w && item->widget() ) - { - QWidget::setTabOrder(w, item->widget()); - w = item->widget(); - } + QWidget::setTabOrder( w, item->widget() ); + + w = item->widget(); } } if ( parentWidget() && parentWidget()->layout() == NULL ) { - /* - updateGeometry() doesn't post LayoutRequest in certain - situations, like when we are hidden. But we want the - parent widget notified, so it can show/hide the legend - depending on its items. - */ -#if QT_VERSION < 0x040000 - QApplication::postEvent(parentWidget(), - new QEvent(QEvent::LayoutHint)); -#else - QApplication::postEvent(parentWidget(), - new QEvent(QEvent::LayoutRequest)); -#endif + /* + updateGeometry() doesn't post LayoutRequest in certain + situations, like when we are hidden. But we want the + parent widget notified, so it can show/hide the legend + depending on its items. + */ + QApplication::postEvent( parentWidget(), + new QEvent( QEvent::LayoutRequest ) ); } } @@ -467,9 +357,9 @@ void QwtLegend::insert(const QwtLegendItemManager *plotItem, QWidget *legendItem \param plotItem Plot item \return Widget on the legend, or NULL */ -QWidget *QwtLegend::find(const QwtLegendItemManager *plotItem) const +QWidget *QwtLegend::find( const QwtLegendItemManager *plotItem ) const { - return d_data->map.find(plotItem); + return d_data->map.find( plotItem ); } /*! @@ -478,37 +368,36 @@ QWidget *QwtLegend::find(const QwtLegendItemManager *plotItem) const \param legendItem Legend item \return Widget on the legend, or NULL */ -QwtLegendItemManager *QwtLegend::find(const QWidget *legendItem) const +QwtLegendItemManager *QwtLegend::find( const QWidget *legendItem ) const { - return d_data->map.find(legendItem); + return d_data->map.find( legendItem ); } -/*! - Find the corresponding item for a plotItem and remove it +/*! + Find the corresponding item for a plotItem and remove it from the item list. \param plotItem Plot item */ -void QwtLegend::remove(const QwtLegendItemManager *plotItem) -{ - QWidget *legendItem = d_data->map.find(plotItem); - d_data->map.remove(legendItem); +void QwtLegend::remove( const QwtLegendItemManager *plotItem ) +{ + QWidget *legendItem = d_data->map.find( plotItem ); + d_data->map.remove( legendItem ); delete legendItem; } //! Remove all items. void QwtLegend::clear() { -#if QT_VERSION < 0x040000 - bool doUpdate = isUpdatesEnabled(); -#else bool doUpdate = updatesEnabled(); -#endif - setUpdatesEnabled(false); + if ( doUpdate ) + setUpdatesEnabled( false ); d_data->map.clear(); - setUpdatesEnabled(doUpdate); + if ( doUpdate ) + setUpdatesEnabled( true ); + update(); } @@ -516,7 +405,7 @@ void QwtLegend::clear() QSize QwtLegend::sizeHint() const { QSize hint = d_data->view->contentsWidget->sizeHint(); - hint += QSize(2 * frameWidth(), 2 * frameWidth()); + hint += QSize( 2 * frameWidth(), 2 * frameWidth() ); return hint; } @@ -525,22 +414,11 @@ QSize QwtLegend::sizeHint() const \return The preferred height, for the width w. \param width Width */ -int QwtLegend::heightForWidth(int width) const +int QwtLegend::heightForWidth( int width ) const { width -= 2 * frameWidth(); - int h = d_data->view->contentsWidget->heightForWidth(width); -#if QT_VERSION < 0x040000 - - // Asking the layout is the default implementation in Qt4 - - if ( h <= 0 ) - { - QLayout *l = d_data->view->contentsWidget->layout(); - if ( l && l->hasHeightForWidth() ) - h = l->heightForWidth(width); - } -#endif + int h = d_data->view->contentsWidget->heightForWidth( width ); if ( h >= 0 ) h += 2 * frameWidth(); @@ -552,73 +430,64 @@ int QwtLegend::heightForWidth(int width) const */ void QwtLegend::layoutContents() { - const QSize visibleSize = d_data->view->viewport()->size(); + const QSize visibleSize = + d_data->view->viewport()->contentsRect().size(); - const QLayout *l = d_data->view->contentsWidget->layout(); - if ( l && l->inherits("QwtDynGridLayout") ) + const QwtDynGridLayout *tl = qobject_cast( + d_data->view->contentsWidget->layout() ); + if ( tl ) { - const QwtDynGridLayout *tl = (const QwtDynGridLayout *)l; + const int minW = int( tl->maxItemWidth() ) + 2 * tl->margin(); - const int minW = int(tl->maxItemWidth()) + 2 * tl->margin(); + int w = qMax( visibleSize.width(), minW ); + int h = qMax( tl->heightForWidth( w ), visibleSize.height() ); - int w = qwtMax(visibleSize.width(), minW); - int h = qwtMax(tl->heightForWidth(w), visibleSize.height()); - - const int vpWidth = d_data->view->viewportSize(w, h).width(); + const int vpWidth = d_data->view->viewportSize( w, h ).width(); if ( w > vpWidth ) { - w = qwtMax(vpWidth, minW); - h = qwtMax(tl->heightForWidth(w), visibleSize.height()); + w = qMax( vpWidth, minW ); + h = qMax( tl->heightForWidth( w ), visibleSize.height() ); } - d_data->view->contentsWidget->resize(w, h); -#if QT_VERSION < 0x040000 - d_data->view->resizeContents(w, h); -#endif + d_data->view->contentsWidget->resize( w, h ); } } /*! - Filter layout related events of QwtLegend::contentsWidget(). + Handle QEvent::ChildRemoved andQEvent::LayoutRequest events + for the contentsWidget(). - \param o Object to be filtered - \param e Event + \param object Object to be filtered + \param event Event */ -bool QwtLegend::eventFilter(QObject *o, QEvent *e) +bool QwtLegend::eventFilter( QObject *object, QEvent *event ) { - if ( o == d_data->view->contentsWidget ) + if ( object == d_data->view->contentsWidget ) { - switch(e->type()) + switch ( event->type() ) { case QEvent::ChildRemoved: - { - const QChildEvent *ce = (const QChildEvent *)e; + { + const QChildEvent *ce = + static_cast(event); if ( ce->child()->isWidgetType() ) - d_data->map.remove((QWidget *)ce->child()); + { + QWidget *w = static_cast< QWidget * >( ce->child() ); + d_data->map.remove( w ); + } break; } -#if QT_VERSION < 0x040000 - case QEvent::LayoutHint: -#else case QEvent::LayoutRequest: -#endif { layoutContents(); break; } -#if QT_VERSION < 0x040000 - case QEvent::Resize: - { - updateGeometry(); - break; - } -#endif default: break; } } - - return QFrame::eventFilter(o, e); + + return QFrame::eventFilter( object, event ); } @@ -635,34 +504,16 @@ uint QwtLegend::itemCount() const } //! Return a list of all legend items -#if QT_VERSION < 0x040000 -QValueList QwtLegend::legendItems() const -#else QList QwtLegend::legendItems() const -#endif { - const QMap &map = + const QMap &map = d_data->map.widgetMap(); -#if QT_VERSION < 0x040000 - QValueList list; -#else QList list; -#endif QMap::const_iterator it; - for ( it = map.begin(); it != map.end(); ++it ) + for ( it = map.begin(); it != map.end(); ++it ) list += it.key(); return list; -} - -/*! - Resize event - \param e Resize event -*/ -void QwtLegend::resizeEvent(QResizeEvent *e) -{ - QFrame::resizeEvent(e); - d_data->view->setGeometry(contentsRect()); -} +} \ No newline at end of file diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_legend.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_legend.h index e2711870e..03cdb4b57 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_legend.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_legend.h @@ -7,18 +7,12 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - #ifndef QWT_LEGEND_H #define QWT_LEGEND_H -#include #include "qwt_global.h" -#if QT_VERSION < 0x040000 -#include -#else +#include #include -#endif class QScrollBar; class QwtLegendItemManager; @@ -38,47 +32,11 @@ class QWT_EXPORT QwtLegend : public QFrame Q_OBJECT public: - /*! - \brief Display policy - - - NoIdentifier\n - The client code is responsible how to display of each legend item. - The Qwt library will not interfere. - - - FixedIdentifier\n - All legend items are displayed with the QwtLegendItem::IdentifierMode - to be passed in 'mode'. - - - AutoIdentifier\n - Each legend item is displayed with a mode that is a bitwise or of - - QwtLegendItem::ShowLine (if its curve is drawn with a line) and - - QwtLegendItem::ShowSymbol (if its curve is drawn with symbols) and - - QwtLegendItem::ShowText (if the has a title). - - Default is AutoIdentifier. - \sa setDisplayPolicy(), displayPolicy(), QwtLegendItem::IdentifierMode - */ - - enum LegendDisplayPolicy - { - NoIdentifier = 0, - FixedIdentifier = 1, - AutoIdentifier = 2 - }; - /*! \brief Interaction mode for the legend items - - ReadOnlyItem\n - The legend item is not interactive, like a label + The default is QwtLegend::ReadOnlyItem. - - ClickableItem\n - The legend item is clickable, like a push button - - - CheckableItem\n - The legend item is checkable, like a checkable button - - Default is ReadOnlyItem. \sa setItemMode(), itemMode(), QwtLegendItem::IdentifierMode QwtLegendItem::clicked(), QwtLegendItem::checked(), QwtPlot::legendClicked(), QwtPlot::legendChecked() @@ -86,52 +44,47 @@ public: enum LegendItemMode { + //! The legend item is not interactive, like a label ReadOnlyItem, + + //! The legend item is clickable, like a push button ClickableItem, + + //! The legend item is checkable, like a checkable button CheckableItem }; - explicit QwtLegend(QWidget *parent = NULL); + explicit QwtLegend( QWidget *parent = NULL ); virtual ~QwtLegend(); - - void setDisplayPolicy(LegendDisplayPolicy policy, int mode); - LegendDisplayPolicy displayPolicy() const; - void setItemMode(LegendItemMode); + void setItemMode( LegendItemMode ); LegendItemMode itemMode() const; - int identifierMode() const; - QWidget *contentsWidget(); const QWidget *contentsWidget() const; - void insert(const QwtLegendItemManager *, QWidget *); - void remove(const QwtLegendItemManager *); + void insert( const QwtLegendItemManager *, QWidget * ); + void remove( const QwtLegendItemManager * ); - QWidget *find(const QwtLegendItemManager *) const; - QwtLegendItemManager *find(const QWidget *) const; + QWidget *find( const QwtLegendItemManager * ) const; + QwtLegendItemManager *find( const QWidget * ) const; -#if QT_VERSION < 0x040000 - virtual QValueList legendItems() const; -#else virtual QList legendItems() const; -#endif void clear(); - + bool isEmpty() const; uint itemCount() const; - virtual bool eventFilter(QObject *, QEvent *); + virtual bool eventFilter( QObject *, QEvent * ); virtual QSize sizeHint() const; - virtual int heightForWidth(int w) const; + virtual int heightForWidth( int w ) const; QScrollBar *horizontalScrollBar() const; QScrollBar *verticalScrollBar() const; protected: - virtual void resizeEvent(QResizeEvent *); virtual void layoutContents(); private: @@ -139,4 +92,4 @@ private: PrivateData *d_data; }; -#endif // QWT_LEGEND_H +#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_legend_item.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_legend_item.cpp index 8aa82ec93..67cc7b012 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_legend_item.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_legend_item.cpp @@ -2,74 +2,54 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - +#include "qwt_legend_item.h" +#include "qwt_math.h" +#include "qwt_painter.h" +#include "qwt_symbol.h" #include #include #include #include -#if QT_VERSION >= 0x040000 #include #include -#endif -#include "qwt_math.h" -#include "qwt_painter.h" -#include "qwt_symbol.h" -#include "qwt_legend_item.h" +#include static const int ButtonFrame = 2; static const int Margin = 2; -static QSize buttonShift(const QwtLegendItem *w) +static QSize buttonShift( const QwtLegendItem *w ) { -#if QT_VERSION < 0x040000 - const int ph = w->style().pixelMetric( - QStyle::PM_ButtonShiftHorizontal, w); - const int pv = w->style().pixelMetric( - QStyle::PM_ButtonShiftVertical, w); -#else QStyleOption option; - option.init(w); + option.init( w ); const int ph = w->style()->pixelMetric( - QStyle::PM_ButtonShiftHorizontal, &option, w); + QStyle::PM_ButtonShiftHorizontal, &option, w ); const int pv = w->style()->pixelMetric( - QStyle::PM_ButtonShiftVertical, &option, w); -#endif - return QSize(ph, pv); + QStyle::PM_ButtonShiftVertical, &option, w ); + return QSize( ph, pv ); } class QwtLegendItem::PrivateData { public: PrivateData(): - itemMode(QwtLegend::ReadOnlyItem), - isDown(false), - identifierWidth(8), - identifierMode(QwtLegendItem::ShowLine | QwtLegendItem::ShowText), - curvePen(Qt::NoPen), - spacing(Margin) + itemMode( QwtLegend::ReadOnlyItem ), + isDown( false ), + identifierSize( 8, 8 ), + spacing( Margin ) { - symbol = new QwtSymbol(); - } - - ~PrivateData() - { - delete symbol; } QwtLegend::LegendItemMode itemMode; bool isDown; - int identifierWidth; - int identifierMode; - QwtSymbol *symbol; - QPen curvePen; + QSize identifierSize; + QPixmap identifier; int spacing; }; @@ -77,39 +57,12 @@ public: /*! \param parent Parent widget */ -QwtLegendItem::QwtLegendItem(QWidget *parent): - QwtTextLabel(parent) +QwtLegendItem::QwtLegendItem( QWidget *parent ): + QwtTextLabel( parent ) { d_data = new PrivateData; - init(QwtText()); -} - -/*! - \param symbol Curve symbol - \param curvePen Curve pen - \param text Label text - \param parent Parent widget -*/ -QwtLegendItem::QwtLegendItem(const QwtSymbol &symbol, - const QPen &curvePen, const QwtText &text, - QWidget *parent): - QwtTextLabel(parent) -{ - d_data = new PrivateData; - - delete d_data->symbol; - d_data->symbol = symbol.clone(); - - d_data->curvePen = curvePen; - - init(text); -} - -void QwtLegendItem::init(const QwtText &text) -{ - setMargin(Margin); - setIndent(margin() + d_data->identifierWidth + 2 * d_data->spacing); - setText(text); + setMargin( Margin ); + setIndent( Margin + d_data->identifierSize.width() + 2 * d_data->spacing ); } //! Destructor @@ -125,19 +78,15 @@ QwtLegendItem::~QwtLegendItem() \param text Text label \sa QwtTextLabel::text() */ -void QwtLegendItem::setText(const QwtText &text) +void QwtLegendItem::setText( const QwtText &text ) { const int flags = Qt::AlignLeft | Qt::AlignVCenter -#if QT_VERSION < 0x040000 - | Qt::WordBreak | Qt::ExpandTabs; -#else | Qt::TextExpandTabs | Qt::TextWordWrap; -#endif QwtText txt = text; - txt.setRenderFlags(flags); + txt.setRenderFlags( flags ); - QwtTextLabel::setText(txt); + QwtTextLabel::setText( txt ); } /*! @@ -147,81 +96,80 @@ void QwtLegendItem::setText(const QwtText &text) \param mode Item mode \sa itemMode() */ -void QwtLegendItem::setItemMode(QwtLegend::LegendItemMode mode) -{ - d_data->itemMode = mode; - d_data->isDown = false; - -#if QT_VERSION >= 0x040000 - using namespace Qt; -#endif - setFocusPolicy(mode != QwtLegend::ReadOnlyItem ? TabFocus : NoFocus); - setMargin(ButtonFrame + Margin); - - updateGeometry(); -} - -/*! - Return the item mode - - \sa setItemMode() -*/ -QwtLegend::LegendItemMode QwtLegendItem::itemMode() const -{ - return d_data->itemMode; -} - -/*! - Set identifier mode. - Default is ShowLine | ShowText. - \param mode Or'd values of IdentifierMode - - \sa identifierMode() -*/ -void QwtLegendItem::setIdentifierMode(int mode) +void QwtLegendItem::setItemMode( QwtLegend::LegendItemMode mode ) { - if ( mode != d_data->identifierMode ) + if ( mode != d_data->itemMode ) { - d_data->identifierMode = mode; - update(); + d_data->itemMode = mode; + d_data->isDown = false; + + setFocusPolicy( mode != QwtLegend::ReadOnlyItem ? Qt::TabFocus : Qt::NoFocus ); + setMargin( ButtonFrame + Margin ); + + updateGeometry(); } } /*! - Or'd values of IdentifierMode. - \sa setIdentifierMode(), IdentifierMode + Return the item mode + + \sa setItemMode() */ -int QwtLegendItem::identifierMode() const -{ - return d_data->identifierMode; +QwtLegend::LegendItemMode QwtLegendItem::itemMode() const +{ + return d_data->itemMode; } /*! - Set the width for the identifier - Default is 8 pixels + Assign the identifier + The identifier needs to be created according to the identifierWidth() - \param width New width + \param identifier Pixmap representing a plot item - \sa identifierMode(), identifierWidth() + \sa identifier(), identifierWidth() */ -void QwtLegendItem::setIdentifierWidth(int width) +void QwtLegendItem::setIdentifier( const QPixmap &identifier ) { - width = qwtMax(width, 0); - if ( width != d_data->identifierWidth ) + d_data->identifier = identifier; + update(); +} + +/*! + \return pixmap representing a plot item + \sa setIdentifier() +*/ +QPixmap QwtLegendItem::identifier() const +{ + return d_data->identifier; +} + +/*! + Set the size for the identifier + Default is 8x8 pixels + + \param size New size + + \sa identifierSize() +*/ +void QwtLegendItem::setIdentifierSize( const QSize &size ) +{ + QSize sz = size.expandedTo( QSize( 0, 0 ) ); + if ( sz != d_data->identifierSize ) { - d_data->identifierWidth = width; - setIndent(margin() + d_data->identifierWidth - + 2 * d_data->spacing); + d_data->identifierSize = sz; + setIndent( margin() + d_data->identifierSize.width() + + 2 * d_data->spacing ); + updateGeometry(); } } /*! Return the width of the identifier - \sa setIdentifierWidth() + \sa setIdentifierSize() */ -int QwtLegendItem::identifierWidth() const +QSize QwtLegendItem::identifierSize() const { - return d_data->identifierWidth; + return d_data->identifierSize; } /*! @@ -229,14 +177,14 @@ int QwtLegendItem::identifierWidth() const \param spacing Spacing \sa spacing(), identifierWidth(), QwtTextLabel::margin() */ -void QwtLegendItem::setSpacing(int spacing) +void QwtLegendItem::setSpacing( int spacing ) { - spacing = qwtMax(spacing, 0); + spacing = qMax( spacing, 0 ); if ( spacing != d_data->spacing ) { d_data->spacing = spacing; - setIndent(margin() + d_data->identifierWidth - + 2 * d_data->spacing); + setIndent( margin() + d_data->identifierSize.width() + + 2 * d_data->spacing ); } } @@ -249,292 +197,22 @@ int QwtLegendItem::spacing() const return d_data->spacing; } -/*! - Set curve symbol. - \param symbol Symbol - - \sa symbol() -*/ -void QwtLegendItem::setSymbol(const QwtSymbol &symbol) -{ - delete d_data->symbol; - d_data->symbol = symbol.clone(); - update(); -} - -/*! - \return The curve symbol. - \sa setSymbol() -*/ -const QwtSymbol& QwtLegendItem::symbol() const -{ - return *d_data->symbol; -} - - -/*! - Set curve pen. - \param pen Curve pen - - \sa curvePen() -*/ -void QwtLegendItem::setCurvePen(const QPen &pen) -{ - if ( pen != d_data->curvePen ) - { - d_data->curvePen = pen; - update(); - } -} - -/*! - \return The curve pen. - \sa setCurvePen() -*/ -const QPen& QwtLegendItem::curvePen() const -{ - return d_data->curvePen; -} - -/*! - Paint the identifier to a given rect. - \param painter Painter - \param rect Rect where to paint -*/ -void QwtLegendItem::drawIdentifier( - QPainter *painter, const QRect &rect) const -{ - if ( rect.isEmpty() ) - return; - - if ( (d_data->identifierMode & ShowLine ) && (d_data->curvePen.style() != Qt::NoPen) ) - { - painter->save(); - painter->setPen(QwtPainter::scaledPen(d_data->curvePen)); - QwtPainter::drawLine(painter, rect.left(), rect.center().y(), - rect.right(), rect.center().y()); - painter->restore(); - } - - if ( (d_data->identifierMode & ShowSymbol) - && (d_data->symbol->style() != QwtSymbol::NoSymbol) ) - { - QSize symbolSize = - QwtPainter::metricsMap().screenToLayout(d_data->symbol->size()); - - // scale the symbol size down if it doesn't fit into rect. - - if ( rect.width() < symbolSize.width() ) - { - const double ratio = - double(symbolSize.width()) / double(rect.width()); - symbolSize.setWidth(rect.width()); - symbolSize.setHeight(qRound(symbolSize.height() / ratio)); - } - if ( rect.height() < symbolSize.height() ) - { - const double ratio = - double(symbolSize.width()) / double(rect.width()); - symbolSize.setHeight(rect.height()); - symbolSize.setWidth(qRound(symbolSize.width() / ratio)); - } - - QRect symbolRect; - symbolRect.setSize(symbolSize); - symbolRect.moveCenter(rect.center()); - - painter->save(); - painter->setBrush(d_data->symbol->brush()); - painter->setPen(QwtPainter::scaledPen(d_data->symbol->pen())); - d_data->symbol->draw(painter, symbolRect); - painter->restore(); - } -} - -/*! - Draw the legend item to a given rect. - \param painter Painter - \param rect Rect where to paint the button -*/ - -void QwtLegendItem::drawItem(QPainter *painter, const QRect &rect) const -{ - painter->save(); - - const QwtMetricsMap &map = QwtPainter::metricsMap(); - - const int m = map.screenToLayoutX(margin()); - const int spacing = map.screenToLayoutX(d_data->spacing); - const int identifierWidth = map.screenToLayoutX(d_data->identifierWidth); - - const QRect identifierRect(rect.x() + m, rect.y(), - identifierWidth, rect.height()); - drawIdentifier(painter, identifierRect); - - // Label - - QRect titleRect = rect; - titleRect.setX(identifierRect.right() + 2 * spacing); - - text().draw(painter, titleRect); - - painter->restore(); -} - -//! Paint event -void QwtLegendItem::paintEvent(QPaintEvent *e) -{ - const QRect cr = contentsRect(); - - QPainter painter(this); - painter.setClipRegion(e->region()); - - if ( d_data->isDown ) - { - qDrawWinButton(&painter, 0, 0, width(), height(), -#if QT_VERSION < 0x040000 - colorGroup(), -#else - palette(), -#endif - true); - } - - painter.save(); - - if ( d_data->isDown ) - { - const QSize shiftSize = buttonShift(this); - painter.translate(shiftSize.width(), shiftSize.height()); - } - - painter.setClipRect(cr); - - drawContents(&painter); - - QRect rect = cr; - rect.setX(rect.x() + margin()); - if ( d_data->itemMode != QwtLegend::ReadOnlyItem ) - rect.setX(rect.x() + ButtonFrame); - - rect.setWidth(d_data->identifierWidth); - - drawIdentifier(&painter, rect); - - painter.restore(); -} - -//! Handle mouse press events -void QwtLegendItem::mousePressEvent(QMouseEvent *e) -{ - if ( e->button() == Qt::LeftButton ) - { - switch(d_data->itemMode) - { - case QwtLegend::ClickableItem: - { - setDown(true); - return; - } - case QwtLegend::CheckableItem: - { - setDown(!isDown()); - return; - } - default:; - } - } - QwtTextLabel::mousePressEvent(e); -} - -//! Handle mouse release events -void QwtLegendItem::mouseReleaseEvent(QMouseEvent *e) -{ - if ( e->button() == Qt::LeftButton ) - { - switch(d_data->itemMode) - { - case QwtLegend::ClickableItem: - { - setDown(false); - return; - } - case QwtLegend::CheckableItem: - { - return; // do nothing, but accept - } - default:; - } - } - QwtTextLabel::mouseReleaseEvent(e); -} - -//! Handle key press events -void QwtLegendItem::keyPressEvent(QKeyEvent *e) -{ - if ( e->key() == Qt::Key_Space ) - { - switch(d_data->itemMode) - { - case QwtLegend::ClickableItem: - { - if ( !e->isAutoRepeat() ) - setDown(true); - return; - } - case QwtLegend::CheckableItem: - { - if ( !e->isAutoRepeat() ) - setDown(!isDown()); - return; - } - default:; - } - } - - QwtTextLabel::keyPressEvent(e); -} - -//! Handle key release events -void QwtLegendItem::keyReleaseEvent(QKeyEvent *e) -{ - if ( e->key() == Qt::Key_Space ) - { - switch(d_data->itemMode) - { - case QwtLegend::ClickableItem: - { - if ( !e->isAutoRepeat() ) - setDown(false); - return; - } - case QwtLegend::CheckableItem: - { - return; // do nothing, but accept - } - default:; - } - } - - QwtTextLabel::keyReleaseEvent(e); -} - /*! Check/Uncheck a the item \param on check/uncheck \sa setItemMode() */ -void QwtLegendItem::setChecked(bool on) +void QwtLegendItem::setChecked( bool on ) { if ( d_data->itemMode == QwtLegend::CheckableItem ) { const bool isBlocked = signalsBlocked(); - blockSignals(true); + blockSignals( true ); - setDown(on); + setDown( on ); - blockSignals(isBlocked); + blockSignals( isBlocked ); } } @@ -545,7 +223,7 @@ bool QwtLegendItem::isChecked() const } //! Set the item being down -void QwtLegendItem::setDown(bool down) +void QwtLegendItem::setDown( bool down ) { if ( down == d_data->isDown ) return; @@ -556,16 +234,16 @@ void QwtLegendItem::setDown(bool down) if ( d_data->itemMode == QwtLegend::ClickableItem ) { if ( d_data->isDown ) - emit pressed(); + Q_EMIT pressed(); else { - emit released(); - emit clicked(); + Q_EMIT released(); + Q_EMIT clicked(); } } if ( d_data->itemMode == QwtLegend::CheckableItem ) - emit checked(d_data->isDown); + Q_EMIT checked( d_data->isDown ); } //! Return true, if the item is down @@ -578,13 +256,150 @@ bool QwtLegendItem::isDown() const QSize QwtLegendItem::sizeHint() const { QSize sz = QwtTextLabel::sizeHint(); + sz.setHeight( qMax( sz.height(), d_data->identifier.height() + 4 ) ); + if ( d_data->itemMode != QwtLegend::ReadOnlyItem ) - sz += buttonShift(this); + { + sz += buttonShift( this ); + sz = sz.expandedTo( QApplication::globalStrut() ); + } return sz; } -void QwtLegendItem::drawText(QPainter *painter, const QRect &rect) +//! Paint event +void QwtLegendItem::paintEvent( QPaintEvent *e ) { - QwtTextLabel::drawText(painter, rect); + const QRect cr = contentsRect(); + + QPainter painter( this ); + painter.setClipRegion( e->region() ); + + if ( d_data->isDown ) + { + qDrawWinButton( &painter, 0, 0, width(), height(), + palette(), true ); + } + + painter.save(); + + if ( d_data->isDown ) + { + const QSize shiftSize = buttonShift( this ); + painter.translate( shiftSize.width(), shiftSize.height() ); + } + + painter.setClipRect( cr ); + + drawContents( &painter ); + + if ( !d_data->identifier.isNull() ) + { + QRect identRect = cr; + identRect.setX( identRect.x() + margin() ); + if ( d_data->itemMode != QwtLegend::ReadOnlyItem ) + identRect.setX( identRect.x() + ButtonFrame ); + + identRect.setSize( d_data->identifier.size() ); + identRect.moveCenter( QPoint( identRect.center().x(), cr.center().y() ) ); + + painter.drawPixmap( identRect, d_data->identifier ); + } + + painter.restore(); } + +//! Handle mouse press events +void QwtLegendItem::mousePressEvent( QMouseEvent *e ) +{ + if ( e->button() == Qt::LeftButton ) + { + switch ( d_data->itemMode ) + { + case QwtLegend::ClickableItem: + { + setDown( true ); + return; + } + case QwtLegend::CheckableItem: + { + setDown( !isDown() ); + return; + } + default:; + } + } + QwtTextLabel::mousePressEvent( e ); +} + +//! Handle mouse release events +void QwtLegendItem::mouseReleaseEvent( QMouseEvent *e ) +{ + if ( e->button() == Qt::LeftButton ) + { + switch ( d_data->itemMode ) + { + case QwtLegend::ClickableItem: + { + setDown( false ); + return; + } + case QwtLegend::CheckableItem: + { + return; // do nothing, but accept + } + default:; + } + } + QwtTextLabel::mouseReleaseEvent( e ); +} + +//! Handle key press events +void QwtLegendItem::keyPressEvent( QKeyEvent *e ) +{ + if ( e->key() == Qt::Key_Space ) + { + switch ( d_data->itemMode ) + { + case QwtLegend::ClickableItem: + { + if ( !e->isAutoRepeat() ) + setDown( true ); + return; + } + case QwtLegend::CheckableItem: + { + if ( !e->isAutoRepeat() ) + setDown( !isDown() ); + return; + } + default:; + } + } + + QwtTextLabel::keyPressEvent( e ); +} + +//! Handle key release events +void QwtLegendItem::keyReleaseEvent( QKeyEvent *e ) +{ + if ( e->key() == Qt::Key_Space ) + { + switch ( d_data->itemMode ) + { + case QwtLegend::ClickableItem: + { + if ( !e->isAutoRepeat() ) + setDown( false ); + return; + } + case QwtLegend::CheckableItem: + { + return; // do nothing, but accept + } + default:; + } + } + + QwtTextLabel::keyReleaseEvent( e ); +} \ No newline at end of file diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_legend_item.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_legend_item.h index 2f3bcd416..5a2b0dee5 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_legend_item.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_legend_item.h @@ -7,8 +7,6 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - #ifndef QWT_LEGEND_ITEM_H #define QWT_LEGEND_ITEM_H @@ -16,78 +14,40 @@ #include "qwt_legend.h" #include "qwt_text.h" #include "qwt_text_label.h" - -class QPainter; -class QPen; -class QwtSymbol; +#include /*! - \brief A legend label - - QwtLegendItem represents a curve on a legend. - It displays an curve identifier with an explaining text. - The identifier might be a combination of curve symbol and line. - In readonly mode it behaves like a label, otherwise like - an unstylish push button. - - \sa QwtLegend, QwtPlotCurve + \brief A widget representing something on a QwtLegend(). */ class QWT_EXPORT QwtLegendItem: public QwtTextLabel { Q_OBJECT public: - - /*! - \brief Identifier mode - - Default is ShowLine | ShowText - \sa identifierMode(), setIdentifierMode() - */ - - enum IdentifierMode - { - NoIdentifier = 0, - ShowLine = 1, - ShowSymbol = 2, - ShowText = 4 - }; - - explicit QwtLegendItem(QWidget *parent = 0); - explicit QwtLegendItem(const QwtSymbol &, const QPen &, - const QwtText &, QWidget *parent = 0); + explicit QwtLegendItem( QWidget *parent = 0 ); virtual ~QwtLegendItem(); - virtual void setText(const QwtText &); - - void setItemMode(QwtLegend::LegendItemMode); + void setItemMode( QwtLegend::LegendItemMode ); QwtLegend::LegendItemMode itemMode() const; - void setIdentifierMode(int); - int identifierMode() const; - - void setIdentifierWidth(int width); - int identifierWidth() const; - - void setSpacing(int spacing); + void setSpacing( int spacing ); int spacing() const; - void setSymbol(const QwtSymbol &); - const QwtSymbol& symbol() const; + virtual void setText( const QwtText & ); - void setCurvePen(const QPen &); - const QPen& curvePen() const; + void setIdentifier( const QPixmap & ); + QPixmap identifier() const; - virtual void drawIdentifier(QPainter *, const QRect &) const; - virtual void drawItem(QPainter *p, const QRect &) const; + void setIdentifierSize( const QSize & ); + QSize identifierSize() const; virtual QSize sizeHint() const; bool isChecked() const; -public slots: - void setChecked(bool on); +public Q_SLOTS: + void setChecked( bool on ); -signals: +Q_SIGNALS: //! Signal, when the legend item has been clicked void clicked(); @@ -98,25 +58,21 @@ signals: void released(); //! Signal, when the legend item has been toggled - void checked(bool); + void checked( bool ); protected: - void setDown(bool); + void setDown( bool ); bool isDown() const; - virtual void paintEvent(QPaintEvent *); - virtual void mousePressEvent(QMouseEvent *); - virtual void mouseReleaseEvent(QMouseEvent *); - virtual void keyPressEvent(QKeyEvent *); - virtual void keyReleaseEvent(QKeyEvent *); - - virtual void drawText(QPainter *, const QRect &); + virtual void paintEvent( QPaintEvent * ); + virtual void mousePressEvent( QMouseEvent * ); + virtual void mouseReleaseEvent( QMouseEvent * ); + virtual void keyPressEvent( QKeyEvent * ); + virtual void keyReleaseEvent( QKeyEvent * ); private: - void init(const QwtText &); - class PrivateData; PrivateData *d_data; }; -#endif // QWT_LEGEND_ITEM_H +#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_legend_itemmanager.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_legend_itemmanager.h index eb94d777e..f87515e32 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_legend_itemmanager.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_legend_itemmanager.h @@ -7,8 +7,6 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - #ifndef QWT_LEGEND_ITEM_MANAGER_H #define QWT_LEGEND_ITEM_MANAGER_H @@ -16,6 +14,8 @@ class QwtLegend; class QWidget; +class QRectF; +class QPainter; /*! \brief Abstract API to bind plot items to the legend @@ -25,12 +25,12 @@ class QWT_EXPORT QwtLegendItemManager { public: //! Constructor - QwtLegendItemManager() + QwtLegendItemManager() { } //! Destructor - virtual ~QwtLegendItemManager() + virtual ~QwtLegendItemManager() { } @@ -39,7 +39,7 @@ public: \param legend Legend \sa legendItem() */ - virtual void updateLegend(QwtLegend *legend) const = 0; + virtual void updateLegend( QwtLegend *legend ) const = 0; /*! Allocate the widget that represents the item on the legend @@ -48,6 +48,18 @@ public: */ virtual QWidget *legendItem() const = 0; + + /*! + QwtLegendItem can display an icon-identifier followed + by a text. The icon helps to identify a plot item on + the plot canvas and depends on the type of information, + that is displayed. + + The default implementation paints nothing. + */ + virtual void drawLegendIdentifier( QPainter *, const QRectF & ) const + { + } }; #endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_magnifier.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_magnifier.cpp index f11f934bc..6179bc50b 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_magnifier.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_magnifier.cpp @@ -7,35 +7,27 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - -#include +#include "qwt_magnifier.h" +#include "qwt_math.h" #include #include -#include "qwt_math.h" -#include "qwt_magnifier.h" class QwtMagnifier::PrivateData { public: PrivateData(): - isEnabled(false), - wheelFactor(0.9), - wheelButtonState(Qt::NoButton), - mouseFactor(0.95), - mouseButton(Qt::RightButton), - mouseButtonState(Qt::NoButton), - keyFactor(0.9), - zoomInKey(Qt::Key_Plus), - zoomOutKey(Qt::Key_Minus), -#if QT_VERSION < 0x040000 - zoomInKeyModifiers(Qt::NoButton), - zoomOutKeyModifiers(Qt::NoButton), -#else - zoomInKeyModifiers(Qt::NoModifier), - zoomOutKeyModifiers(Qt::NoModifier), -#endif - mousePressed(false) + isEnabled( false ), + wheelFactor( 0.9 ), + wheelButtonState( Qt::NoButton ), + mouseFactor( 0.95 ), + mouseButton( Qt::RightButton ), + mouseButtonState( Qt::NoButton ), + keyFactor( 0.9 ), + zoomInKey( Qt::Key_Plus ), + zoomOutKey( Qt::Key_Minus ), + zoomInKeyModifiers( Qt::NoModifier ), + zoomOutKeyModifiers( Qt::NoModifier ), + mousePressed( false ) { } @@ -59,15 +51,15 @@ public: QPoint mousePos; }; -/*! +/*! Constructor \param parent Widget to be magnified */ -QwtMagnifier::QwtMagnifier(QWidget *parent): - QObject(parent) +QwtMagnifier::QwtMagnifier( QWidget *parent ): + QObject( parent ) { d_data = new PrivateData(); - setEnabled(true); + setEnabled( true ); } //! Destructor @@ -85,7 +77,7 @@ QwtMagnifier::~QwtMagnifier() \param on true or false \sa isEnabled(), eventFilter() */ -void QwtMagnifier::setEnabled(bool on) +void QwtMagnifier::setEnabled( bool on ) { if ( d_data->isEnabled != on ) { @@ -95,9 +87,9 @@ void QwtMagnifier::setEnabled(bool on) if ( o ) { if ( d_data->isEnabled ) - o->installEventFilter(this); + o->installEventFilter( this ); else - o->removeEventFilter(this); + o->removeEventFilter( this ); } } } @@ -117,12 +109,12 @@ bool QwtMagnifier::isEnabled() const The wheel factor defines the ratio between the current range on the parent widget and the zoomed range for each step of the wheel. The default value is 0.9. - + \param factor Wheel factor - \sa wheelFactor(), setWheelButtonState(), + \sa wheelFactor(), setWheelButtonState(), setMouseFactor(), setKeyFactor() */ -void QwtMagnifier::setWheelFactor(double factor) +void QwtMagnifier::setWheelFactor( double factor ) { d_data->wheelFactor = factor; } @@ -143,7 +135,7 @@ double QwtMagnifier::wheelFactor() const \param buttonState Button state \sa wheelButtonState() */ -void QwtMagnifier::setWheelButtonState(int buttonState) +void QwtMagnifier::setWheelButtonState( int buttonState ) { d_data->wheelButtonState = buttonState; } @@ -157,17 +149,17 @@ int QwtMagnifier::wheelButtonState() const return d_data->wheelButtonState; } -/*! +/*! \brief Change the mouse factor The mouse factor defines the ratio between the current range on the parent widget and the zoomed range for each vertical mouse movement. The default value is 0.95. - + \param factor Wheel factor \sa mouseFactor(), setMouseButton(), setWheelFactor(), setKeyFactor() -*/ -void QwtMagnifier::setMouseFactor(double factor) +*/ +void QwtMagnifier::setMouseFactor( double factor ) { d_data->mouseFactor = factor; } @@ -189,7 +181,7 @@ double QwtMagnifier::mouseFactor() const \param buttonState Button state \sa getMouseButton() */ -void QwtMagnifier::setMouseButton(int button, int buttonState) +void QwtMagnifier::setMouseButton( int button, int buttonState ) { d_data->mouseButton = button; d_data->mouseButtonState = buttonState; @@ -197,7 +189,7 @@ void QwtMagnifier::setMouseButton(int button, int buttonState) //! \sa setMouseButton() void QwtMagnifier::getMouseButton( - int &button, int &buttonState) const + int &button, int &buttonState ) const { button = d_data->mouseButton; buttonState = d_data->mouseButtonState; @@ -209,12 +201,12 @@ void QwtMagnifier::getMouseButton( The key factor defines the ratio between the current range on the parent widget and the zoomed range for each key press of the zoom in/out keys. The default value is 0.9. - + \param factor Key factor \sa keyFactor(), setZoomInKey(), setZoomOutKey(), setWheelFactor, setMouseFactor() */ -void QwtMagnifier::setKeyFactor(double factor) +void QwtMagnifier::setKeyFactor( double factor ) { d_data->keyFactor = factor; } @@ -236,14 +228,14 @@ double QwtMagnifier::keyFactor() const \param modifiers \sa getZoomInKey(), setZoomOutKey() */ -void QwtMagnifier::setZoomInKey(int key, int modifiers) +void QwtMagnifier::setZoomInKey( int key, int modifiers ) { d_data->zoomInKey = key; d_data->zoomInKeyModifiers = modifiers; } //! \sa setZoomInKey() -void QwtMagnifier::getZoomInKey(int &key, int &modifiers) const +void QwtMagnifier::getZoomInKey( int &key, int &modifiers ) const { key = d_data->zoomInKey; modifiers = d_data->zoomInKeyModifiers; @@ -257,14 +249,14 @@ void QwtMagnifier::getZoomInKey(int &key, int &modifiers) const \param modifiers \sa getZoomOutKey(), setZoomOutKey() */ -void QwtMagnifier::setZoomOutKey(int key, int modifiers) +void QwtMagnifier::setZoomOutKey( int key, int modifiers ) { d_data->zoomOutKey = key; d_data->zoomOutKeyModifiers = modifiers; } //! \sa setZoomOutKey() -void QwtMagnifier::getZoomOutKey(int &key, int &modifiers) const +void QwtMagnifier::getZoomOutKey( int &key, int &modifiers ) const { key = d_data->zoomOutKey; modifiers = d_data->zoomOutKeyModifiers; @@ -275,198 +267,197 @@ void QwtMagnifier::getZoomOutKey(int &key, int &modifiers) const When isEnabled() the mouse events of the observed widget are filtered. + \param object Object to be filtered + \param event Event + \sa widgetMousePressEvent(), widgetMouseReleaseEvent(), widgetMouseMoveEvent(), widgetWheelEvent(), widgetKeyPressEvent() widgetKeyReleaseEvent() */ -bool QwtMagnifier::eventFilter(QObject *o, QEvent *e) +bool QwtMagnifier::eventFilter( QObject *object, QEvent *event ) { - if ( o && o == parent() ) + if ( object && object == parent() ) { - switch(e->type() ) + switch ( event->type() ) { case QEvent::MouseButtonPress: { - widgetMousePressEvent((QMouseEvent *)e); + widgetMousePressEvent( ( QMouseEvent * )event ); break; } case QEvent::MouseMove: { - widgetMouseMoveEvent((QMouseEvent *)e); + widgetMouseMoveEvent( ( QMouseEvent * )event ); break; } case QEvent::MouseButtonRelease: { - widgetMouseReleaseEvent((QMouseEvent *)e); + widgetMouseReleaseEvent( ( QMouseEvent * )event ); break; } case QEvent::Wheel: { - widgetWheelEvent((QWheelEvent *)e); + widgetWheelEvent( ( QWheelEvent * )event ); break; } case QEvent::KeyPress: { - widgetKeyPressEvent((QKeyEvent *)e); + widgetKeyPressEvent( ( QKeyEvent * )event ); break; } case QEvent::KeyRelease: { - widgetKeyReleaseEvent((QKeyEvent *)e); + widgetKeyReleaseEvent( ( QKeyEvent * )event ); break; } default:; } } - return QObject::eventFilter(o, e); + return QObject::eventFilter( object, event ); } /*! Handle a mouse press event for the observed widget. - \param me Mouse event - \sa eventFilter(), widgetMouseReleaseEvent(), widgetMouseMoveEvent() + \param mouseEvent Mouse event + \sa eventFilter(), widgetMouseReleaseEvent(), widgetMouseMoveEvent() */ -void QwtMagnifier::widgetMousePressEvent(QMouseEvent *me) +void QwtMagnifier::widgetMousePressEvent( QMouseEvent *mouseEvent ) { - if ( me->button() != d_data->mouseButton || parentWidget() == NULL ) + if ( ( mouseEvent->button() != d_data->mouseButton) + || parentWidget() == NULL ) + { return; + } -#if QT_VERSION < 0x040000 - if ( (me->state() & Qt::KeyButtonMask) != - (d_data->mouseButtonState & Qt::KeyButtonMask) ) -#else - if ( (me->modifiers() & Qt::KeyboardModifierMask) != - (int)(d_data->mouseButtonState & Qt::KeyboardModifierMask) ) -#endif + if ( ( mouseEvent->modifiers() & Qt::KeyboardModifierMask ) != + ( int )( d_data->mouseButtonState & Qt::KeyboardModifierMask ) ) { return; } d_data->hasMouseTracking = parentWidget()->hasMouseTracking(); - parentWidget()->setMouseTracking(true); - d_data->mousePos = me->pos(); + parentWidget()->setMouseTracking( true ); + d_data->mousePos = mouseEvent->pos(); d_data->mousePressed = true; } /*! Handle a mouse release event for the observed widget. + + \param mouseEvent Mouse event + \sa eventFilter(), widgetMousePressEvent(), widgetMouseMoveEvent(), */ -void QwtMagnifier::widgetMouseReleaseEvent(QMouseEvent *) +void QwtMagnifier::widgetMouseReleaseEvent( QMouseEvent *mouseEvent ) { + Q_UNUSED( mouseEvent ); + if ( d_data->mousePressed && parentWidget() ) { d_data->mousePressed = false; - parentWidget()->setMouseTracking(d_data->hasMouseTracking); + parentWidget()->setMouseTracking( d_data->hasMouseTracking ); } } /*! Handle a mouse move event for the observed widget. - - \param me Mouse event + + \param mouseEvent Mouse event \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), -*/ -void QwtMagnifier::widgetMouseMoveEvent(QMouseEvent *me) +*/ +void QwtMagnifier::widgetMouseMoveEvent( QMouseEvent *mouseEvent ) { if ( !d_data->mousePressed ) return; - const int dy = me->pos().y() - d_data->mousePos.y(); + const int dy = mouseEvent->pos().y() - d_data->mousePos.y(); if ( dy != 0 ) { double f = d_data->mouseFactor; if ( dy < 0 ) f = 1 / f; - rescale(f); + rescale( f ); } - d_data->mousePos = me->pos(); + d_data->mousePos = mouseEvent->pos(); } /*! Handle a wheel event for the observed widget. - \param we Wheel event + \param wheelEvent Wheel event \sa eventFilter() */ -void QwtMagnifier::widgetWheelEvent(QWheelEvent *we) +void QwtMagnifier::widgetWheelEvent( QWheelEvent *wheelEvent ) { -#if QT_VERSION < 0x040000 - if ( (we->state() & Qt::KeyButtonMask) != - (d_data->wheelButtonState & Qt::KeyButtonMask) ) -#else - if ( (we->modifiers() & Qt::KeyboardModifierMask) != - (int)(d_data->wheelButtonState & Qt::KeyboardModifierMask) ) -#endif + if ( ( wheelEvent->modifiers() & Qt::KeyboardModifierMask ) != + ( int )( d_data->wheelButtonState & Qt::KeyboardModifierMask ) ) { return; } if ( d_data->wheelFactor != 0.0 ) { - /* - A positive delta indicates that the wheel was - rotated forwards away from the user; a negative - value indicates that the wheel was rotated - backwards toward the user. - Most mouse types work in steps of 15 degrees, - in which case the delta value is a multiple - of 120 (== 15 * 8). - */ - double f = ::pow(d_data->wheelFactor, - qwtAbs(we->delta() / 120)); - if ( we->delta() > 0 ) + /* + A positive delta indicates that the wheel was + rotated forwards away from the user; a negative + value indicates that the wheel was rotated + backwards toward the user. + Most mouse types work in steps of 15 degrees, + in which case the delta value is a multiple + of 120 (== 15 * 8). + */ + double f = qPow( d_data->wheelFactor, + qAbs( wheelEvent->delta() / 120 ) ); + + if ( wheelEvent->delta() > 0 ) f = 1 / f; - rescale(f); + rescale( f ); } } /*! Handle a key press event for the observed widget. - \param ke Key event + \param keyEvent Key event \sa eventFilter(), widgetKeyReleaseEvent() */ -void QwtMagnifier::widgetKeyPressEvent(QKeyEvent *ke) +void QwtMagnifier::widgetKeyPressEvent( QKeyEvent *keyEvent ) { - const int key = ke->key(); -#if QT_VERSION < 0x040000 - const int state = ke->state(); -#else - const int state = ke->modifiers(); -#endif + const int key = keyEvent->key(); + const int state = keyEvent->modifiers(); - if ( key == d_data->zoomInKey && + if ( key == d_data->zoomInKey && state == d_data->zoomInKeyModifiers ) { - rescale(d_data->keyFactor); + rescale( d_data->keyFactor ); } - else if ( key == d_data->zoomOutKey && + else if ( key == d_data->zoomOutKey && state == d_data->zoomOutKeyModifiers ) { - rescale(1.0 / d_data->keyFactor); + rescale( 1.0 / d_data->keyFactor ); } } /*! Handle a key release event for the observed widget. - \param ke Key event + \param keyEvent Key event \sa eventFilter(), widgetKeyReleaseEvent() */ -void QwtMagnifier::widgetKeyReleaseEvent(QKeyEvent *) +void QwtMagnifier::widgetKeyReleaseEvent( QKeyEvent *keyEvent ) { + Q_UNUSED( keyEvent ); } //! \return Parent widget, where the rescaling happens QWidget *QwtMagnifier::parentWidget() { - if ( parent()->inherits("QWidget") ) - return (QWidget *)parent(); + if ( parent()->inherits( "QWidget" ) ) + return ( QWidget * )parent(); return NULL; } @@ -474,8 +465,8 @@ QWidget *QwtMagnifier::parentWidget() //! \return Parent widget, where the rescaling happens const QWidget *QwtMagnifier::parentWidget() const { - if ( parent()->inherits("QWidget") ) - return (const QWidget *)parent(); + if ( parent()->inherits( "QWidget" ) ) + return ( const QWidget * )parent(); return NULL; } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_magnifier.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_magnifier.h index 16391346b..e41ae8bf1 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_magnifier.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_magnifier.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -29,54 +29,54 @@ class QWT_EXPORT QwtMagnifier: public QObject Q_OBJECT public: - explicit QwtMagnifier(QWidget *); + explicit QwtMagnifier( QWidget * ); virtual ~QwtMagnifier(); QWidget *parentWidget(); const QWidget *parentWidget() const; - void setEnabled(bool); + void setEnabled( bool ); bool isEnabled() const; // mouse - void setMouseFactor(double); + void setMouseFactor( double ); double mouseFactor() const; - void setMouseButton(int button, int buttonState = Qt::NoButton); - void getMouseButton(int &button, int &buttonState) const; + void setMouseButton( int button, int buttonState = Qt::NoButton ); + void getMouseButton( int &button, int &buttonState ) const; // mouse wheel - void setWheelFactor(double); + void setWheelFactor( double ); double wheelFactor() const; - void setWheelButtonState(int buttonState); + void setWheelButtonState( int buttonState ); int wheelButtonState() const; // keyboard - void setKeyFactor(double); + void setKeyFactor( double ); double keyFactor() const; - void setZoomInKey(int key, int modifiers); - void getZoomInKey(int &key, int &modifiers) const; + void setZoomInKey( int key, int modifiers ); + void getZoomInKey( int &key, int &modifiers ) const; - void setZoomOutKey(int key, int modifiers); - void getZoomOutKey(int &key, int &modifiers) const; + void setZoomOutKey( int key, int modifiers ); + void getZoomOutKey( int &key, int &modifiers ) const; - virtual bool eventFilter(QObject *, QEvent *); + virtual bool eventFilter( QObject *, QEvent * ); protected: /*! Rescale the parent widget \param factor Scale factor */ - virtual void rescale(double factor) = 0; + virtual void rescale( double factor ) = 0; - virtual void widgetMousePressEvent(QMouseEvent *); - virtual void widgetMouseReleaseEvent(QMouseEvent *); - virtual void widgetMouseMoveEvent(QMouseEvent *); - virtual void widgetWheelEvent(QWheelEvent *); - virtual void widgetKeyPressEvent(QKeyEvent *); - virtual void widgetKeyReleaseEvent(QKeyEvent *); + virtual void widgetMousePressEvent( QMouseEvent * ); + virtual void widgetMouseReleaseEvent( QMouseEvent * ); + virtual void widgetMouseMoveEvent( QMouseEvent * ); + virtual void widgetWheelEvent( QWheelEvent * ); + virtual void widgetKeyPressEvent( QKeyEvent * ); + virtual void widgetKeyReleaseEvent( QKeyEvent * ); private: class PrivateData; diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_math.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_math.cpp index 63099be58..ee5dfff37 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_math.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_math.cpp @@ -2,13 +2,11 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - #include "qwt_math.h" /*! @@ -16,14 +14,14 @@ \param array Pointer to an array \param size Array size */ -double qwtGetMin(const double *array, int size) +double qwtGetMin( const double *array, int size ) { - if (size <= 0) - return 0.0; + if ( size <= 0 ) + return 0.0; double rv = array[0]; - for (int i = 1; i < size; i++) - rv = qwtMin(rv, array[i]); + for ( int i = 1; i < size; i++ ) + rv = qMin( rv, array[i] ); return rv; } @@ -34,14 +32,14 @@ double qwtGetMin(const double *array, int size) \param array Pointer to an array \param size Array size */ -double qwtGetMax(const double *array, int size) +double qwtGetMax( const double *array, int size ) { - if (size <= 0) - return 0.0; - + if ( size <= 0 ) + return 0.0; + double rv = array[0]; - for (int i = 1; i < size; i++) - rv = qwtMax(rv, array[i]); + for ( int i = 1; i < size; i++ ) + rv = qMax( rv, array[i] ); return rv; } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_math.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_math.h index fc0dc4896..a45603fb2 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_math.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_math.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -10,25 +10,23 @@ #ifndef QWT_MATH_H #define QWT_MATH_H -#include -#include #include "qwt_global.h" -#include "qwt_double_rect.h" -#if QT_VERSION < 0x040000 - -#define qwtMax QMAX -#define qwtMin QMIN -#define qwtAbs QABS - -#else // QT_VERSION >= 0x040000 - -#define qwtMax qMax -#define qwtMin qMin -#define qwtAbs qAbs +#if defined(_MSC_VER) +/* + Microsoft says: + Define _USE_MATH_DEFINES before including math.h to expose these macro + definitions for common math constants. These are placed under an #ifdef + since these commonly-defined names are not part of the C/C++ standards. +*/ +#define _USE_MATH_DEFINES 1 #endif +#include +#include +#include "qwt_global.h" + #ifndef LOG10_2 #define LOG10_2 0.30102999566398119802 /* log10(2) */ #endif @@ -107,86 +105,78 @@ #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ #endif -QWT_EXPORT double qwtGetMin(const double *array, int size); -QWT_EXPORT double qwtGetMax(const double *array, int size); - - -//! Return the sign -inline int qwtSign(double x) -{ - if (x > 0.0) - return 1; - else if (x < 0.0) - return (-1); - else - return 0; -} - -//! Return the square of a number -inline double qwtSqr(const double x) -{ - return x*x; -} +QWT_EXPORT double qwtGetMin( const double *array, int size ); +QWT_EXPORT double qwtGetMax( const double *array, int size ); /*! - \brief Limit a value to fit into a specified interval - \param x Input value - \param x1 First interval boundary - \param x2 Second interval boundary + \brief Compare 2 values, relative to an interval + + Values are "equal", when : + \f$\cdot value2 - value1 <= abs(intervalSize * 10e^{-6})\f$ + + \param value1 First value to compare + \param value2 Second value to compare + \param intervalSize interval size + + \return 0: if equal, -1: if value2 > value1, 1: if value1 > value2 */ -template -T qwtLim(const T& x, const T& x1, const T& x2) +inline int qwtFuzzyCompare( double value1, double value2, double intervalSize ) { - T rv; - T xmin, xmax; - - xmin = qwtMin(x1, x2); - xmax = qwtMax(x1, x2); + const double eps = qAbs( 1.0e-6 * intervalSize ); - if ( x < xmin ) - rv = xmin; - else if ( x > xmax ) - rv = xmax; + if ( value2 - value1 > eps ) + return -1; + + if ( value1 - value2 > eps ) + return 1; + + return 0; +} + + +inline bool qwtFuzzyGreaterOrEqual( double d1, double d2 ) +{ + return ( d1 >= d2 ) || qFuzzyCompare( d1, d2 ); +} + +inline bool qwtFuzzyLessOrEqual( double d1, double d2 ) +{ + return ( d1 <= d2 ) || qFuzzyCompare( d1, d2 ); +} + +//! Return the sign +inline int qwtSign( double x ) +{ + if ( x > 0.0 ) + return 1; + else if ( x < 0.0 ) + return ( -1 ); else - rv = x; - - return rv; + return 0; } -inline QPoint qwtPolar2Pos(const QPoint &pole, - double radius, double angle) +//! Return the square of a number +inline double qwtSqr( double x ) { - const double x = pole.x() + radius * ::cos(angle); - const double y = pole.y() - radius * ::sin(angle); - - return QPoint(qRound(x), qRound(y)); + return x * x; } -inline QPoint qwtDegree2Pos(const QPoint &pole, - double radius, double angle) -{ - return qwtPolar2Pos(pole, radius, angle / 180.0 * M_PI); +//! Like qRound, but without converting the result to an int +inline double qwtRoundF(double d) +{ + return ::floor( d + 0.5 ); } -inline QwtDoublePoint qwtPolar2Pos(const QwtDoublePoint &pole, - double radius, double angle) -{ - const double x = pole.x() + radius * ::cos(angle); - const double y = pole.y() - radius * ::sin(angle); - - return QPoint(qRound(x), qRound(y)); +//! Like qFloor, but without converting the result to an int +inline double qwtFloorF(double d) +{ + return ::floor( d ); } -inline QwtDoublePoint qwtDegree2Pos(const QwtDoublePoint &pole, - double radius, double angle) -{ - return qwtPolar2Pos(pole, radius, angle / 180.0 * M_PI); -} - -//! Rounding of doubles, like qRound for integers -inline double qwtRound(double value) -{ - return ::floor(value + 0.5); // MSVC has no ::round(). +//! Like qCeil, but without converting the result to an int +inline double qwtCeilF(double d) +{ + return ::ceil( d ); } #endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_matrix_raster_data.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_matrix_raster_data.cpp new file mode 100644 index 000000000..7f537e7a0 --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_matrix_raster_data.cpp @@ -0,0 +1,270 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#include "qwt_matrix_raster_data.h" +#include +#include + +class QwtMatrixRasterData::PrivateData +{ +public: + PrivateData(): + resampleMode(QwtMatrixRasterData::NearestNeighbour), + numColumns(0) + { + } + + inline double value(size_t row, size_t col) const + { + return values.data()[ row * numColumns + col ]; + } + + QwtMatrixRasterData::ResampleMode resampleMode; + + QVector values; + size_t numColumns; + size_t numRows; + + double dx; + double dy; +}; + +//! Constructor +QwtMatrixRasterData::QwtMatrixRasterData() +{ + d_data = new PrivateData(); + update(); +} + +//! Destructor +QwtMatrixRasterData::~QwtMatrixRasterData() +{ + delete d_data; +} + +/*! + \brief Set the resampling algorithm + + \param mode Resampling mode + \sa resampleMode(), value() +*/ +void QwtMatrixRasterData::setResampleMode(ResampleMode mode) +{ + d_data->resampleMode = mode; +} + +/*! + \return resampling algorithm + \sa setResampleMode(), value() +*/ +QwtMatrixRasterData::ResampleMode QwtMatrixRasterData::resampleMode() const +{ + return d_data->resampleMode; +} + +/*! + \brief Assign the bounding interval for an axis + + Setting the bounding intervals for the X/Y axis is mandatory + to define the positions for the values of the value matrix. + The interval in Z direction defines the possible range for + the values in the matrix, what is f.e used by QwtPlotSpectrogram + to map values to colors. The Z-interval might be the bounding + interval of the values in the matrix, but usually it isn't. + ( f.e a interval of 0.0-100.0 for values in percentage ) + + \param axis X, Y or Z axis + \param interval Interval + + \sa QwtRasterData::interval(), setValueMatrix() +*/ +void QwtMatrixRasterData::setInterval( + Qt::Axis axis, const QwtInterval &interval ) +{ + QwtRasterData::setInterval( axis, interval ); + update(); +} + +/*! + \brief Assign a value matrix + + The positions of the values are calculated by dividing + the bounding rectangle of the X/Y intervals into equidistant + rectangles ( pixels ). Each value corresponds to the center of + a pixel. + + \param values Vector of values + \param numColumns Number of columns + + \sa valueMatrix(), numColumns(), numRows(), setInterval()() +*/ +void QwtMatrixRasterData::setValueMatrix( + const QVector &values, size_t numColumns ) +{ + d_data->values = values; + d_data->numColumns = numColumns; + update(); +} + +/*! + \return Value matrix + \sa setValueMatrix(), numColumns(), numRows(), setInterval() +*/ +const QVector QwtMatrixRasterData::valueMatrix() const +{ + return d_data->values; +} + +/*! + \return Number of columns of the value matrix + \sa valueMatrix(), numRows(), setValueMatrix() +*/ +size_t QwtMatrixRasterData::numColumns() const +{ + return d_data->numColumns; +} + +/*! + \return Number of rows of the value matrix + \sa valueMatrix(), numColumns(), setValueMatrix() +*/ +size_t QwtMatrixRasterData::numRows() const +{ + return d_data->numRows; +} + +/*! + \brief Pixel hint + + - NearestNeighbour\n + pixelHint() returns the surrounding pixel of the top left value + in the matrix. + + - BilinearInterpolation\n + Returns an empty rectangle recommending + to render in target device ( f.e. screen ) resolution. + + \sa ResampleMode, setMatrix(), setInterval() +*/ +QRectF QwtMatrixRasterData::pixelHint( const QRectF & ) const +{ + QRectF rect; + if ( d_data->resampleMode == NearestNeighbour ) + { + const QwtInterval intervalX = interval( Qt::XAxis ); + const QwtInterval intervalY = interval( Qt::YAxis ); + if ( intervalX.isValid() && intervalY.isValid() ) + { + rect = QRectF( intervalX.minValue(), intervalY.minValue(), + d_data->dx, d_data->dy ); + } + } + + return rect; +} + +/*! + \return the value at a raster position + + \param x X value in plot coordinates + \param y Y value in plot coordinates + + \sa ResampleMode +*/ +double QwtMatrixRasterData::value( double x, double y ) const +{ + const QwtInterval xInterval = interval( Qt::XAxis ); + const QwtInterval yInterval = interval( Qt::YAxis ); + + if ( !( xInterval.contains(x) && yInterval.contains(y) ) ) + return qQNaN(); + + double value; + + switch( d_data->resampleMode ) + { + case BilinearInterpolation: + { + int col1 = qRound( (x - xInterval.minValue() ) / d_data->dx ) - 1; + int row1 = qRound( (y - yInterval.minValue() ) / d_data->dy ) - 1; + int col2 = col1 + 1; + int row2 = row1 + 1; + + if ( col1 < 0 ) + col1 = col2; + else if ( col2 >= (int)d_data->numColumns ) + col2 = col1; + + if ( row1 < 0 ) + row1 = row2; + else if ( row2 >= (int)d_data->numRows ) + row2 = row1; + + const double v11 = d_data->value( row1, col1 ); + const double v21 = d_data->value( row1, col2 ); + const double v12 = d_data->value( row2, col1 ); + const double v22 = d_data->value( row2, col2 ); + + const double x2 = xInterval.minValue() + + ( col2 + 0.5 ) * d_data->dx; + const double y2 = yInterval.minValue() + + ( row2 + 0.5 ) * d_data->dy; + + const double rx = ( x2 - x ) / d_data->dx; + const double ry = ( y2 - y ) / d_data->dy; + + const double vr1 = rx * v11 + ( 1.0 - rx ) * v21; + const double vr2 = rx * v12 + ( 1.0 - rx ) * v22; + + value = ry * vr1 + ( 1.0 - ry ) * vr2; + + break; + } + case NearestNeighbour: + default: + { + uint row = uint( (y - yInterval.minValue() ) / d_data->dy ); + uint col = uint( (x - xInterval.minValue() ) / d_data->dx ); + + // In case of intervals, where the maximum is included + // we get out of bound for row/col, when the value for the + // maximum is requested. Instead we return the value + // from the last row/col + + if ( row >= d_data->numRows ) + row = d_data->numRows - 1; + + if ( col >= d_data->numColumns ) + col = d_data->numColumns - 1; + + value = d_data->value( row, col ); + } + } + + return value; +} + +void QwtMatrixRasterData::update() +{ + d_data->numRows = 0; + d_data->dx = 0.0; + d_data->dy = 0.0; + + if ( d_data->numColumns > 0 ) + { + d_data->numRows = d_data->values.size() / d_data->numColumns; + + const QwtInterval xInterval = interval( Qt::XAxis ); + const QwtInterval yInterval = interval( Qt::YAxis ); + if ( xInterval.isValid() ) + d_data->dx = xInterval.width() / d_data->numColumns; + if ( yInterval.isValid() ) + d_data->dy = yInterval.width() / d_data->numRows; + } +} diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_matrix_raster_data.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_matrix_raster_data.h new file mode 100644 index 000000000..b5b181bb4 --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_matrix_raster_data.h @@ -0,0 +1,71 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#ifndef QWT_MATRIX_RASTER_DATA_H +#define QWT_MATRIX_RASTER_DATA_H 1 + +#include "qwt_global.h" +#include "qwt_raster_data.h" +#include + +/*! + \brief A class representing a matrix of values as raster data + + QwtMatrixRasterData implements an interface for a matrix of + equidistant values, that can be used by a QwtPlotRasterItem. + It implements a couple of resampling algorithms, to provide + values for positions, that or not on the value matrix. +*/ +class QWT_EXPORT QwtMatrixRasterData: public QwtRasterData +{ +public: + /*! + \brief Resampling algorithm + The default setting is NearestNeighbour; + */ + enum ResampleMode + { + /*! + Return the value from the matrix, that is nearest to the + the requested position. + */ + NearestNeighbour, + + /*! + Interpolate the value from the distances and values of the + 4 surrounding values in the matrix, + */ + BilinearInterpolation + }; + + QwtMatrixRasterData(); + virtual ~QwtMatrixRasterData(); + + void setResampleMode(ResampleMode mode); + ResampleMode resampleMode() const; + + virtual void setInterval( Qt::Axis, const QwtInterval & ); + void setValueMatrix( const QVector &values, size_t numColumns ); + + const QVector valueMatrix() const; + size_t numColumns() const; + size_t numRows() const; + + virtual QRectF pixelHint( const QRectF & ) const; + + virtual double value( double x, double y ) const; + +private: + void update(); + + class PrivateData; + PrivateData *d_data; +}; + +#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_null_paintdevice.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_null_paintdevice.cpp new file mode 100644 index 000000000..1edf2e571 --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_null_paintdevice.cpp @@ -0,0 +1,428 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#include "qwt_null_paintdevice.h" +#include +#include + +class QwtNullPaintDevice::PrivateData +{ +public: + PrivateData(): + size( 0, 0 ) + { + } + + QSize size; +}; + +class QwtNullPaintDevice::PaintEngine: public QPaintEngine +{ +public: + PaintEngine( QPaintEngine::PaintEngineFeatures ); + + virtual bool begin( QPaintDevice * ); + virtual bool end(); + + virtual Type type () const; + virtual void updateState(const QPaintEngineState &); + + virtual void drawRects(const QRect *, int ); + virtual void drawRects(const QRectF *, int ); + + virtual void drawLines(const QLine *, int ); + virtual void drawLines(const QLineF *, int ); + + virtual void drawEllipse(const QRectF &); + virtual void drawEllipse(const QRect &); + + virtual void drawPath(const QPainterPath &); + + virtual void drawPoints(const QPointF *, int ); + virtual void drawPoints(const QPoint *, int ); + + virtual void drawPolygon(const QPointF *, int , PolygonDrawMode ); + virtual void drawPolygon(const QPoint *, int , PolygonDrawMode ); + + virtual void drawPixmap(const QRectF &, + const QPixmap &, const QRectF &); + + virtual void drawTextItem(const QPointF &, const QTextItem &); + virtual void drawTiledPixmap(const QRectF &, + const QPixmap &, const QPointF &s); + virtual void drawImage(const QRectF &, + const QImage &, const QRectF &, Qt::ImageConversionFlags ); + +private: + QwtNullPaintDevice *d_device; +}; + +QwtNullPaintDevice::PaintEngine::PaintEngine( + QPaintEngine::PaintEngineFeatures features ): + QPaintEngine( features ), + d_device(NULL) +{ +} + +bool QwtNullPaintDevice::PaintEngine::begin( + QPaintDevice *device ) +{ + d_device = static_cast( device ); + return true; +} + +bool QwtNullPaintDevice::PaintEngine::end() +{ + d_device = NULL; + return true; +} + +QPaintEngine::Type +QwtNullPaintDevice::PaintEngine::type () const +{ + return QPaintEngine::User; +} + +void QwtNullPaintDevice::PaintEngine::drawRects( + const QRect *rects, int rectCount) +{ + if ( d_device ) + d_device->drawRects( rects, rectCount ); +} + +void QwtNullPaintDevice::PaintEngine::drawRects( + const QRectF *rects, int rectCount) +{ + if ( d_device ) + d_device->drawRects( rects, rectCount ); +} + +void QwtNullPaintDevice::PaintEngine::drawLines( + const QLine *lines, int lineCount) +{ + if ( d_device ) + d_device->drawLines( lines, lineCount ); +} + +void QwtNullPaintDevice::PaintEngine::drawLines( + const QLineF *lines, int lineCount) +{ + if ( d_device ) + d_device->drawLines( lines, lineCount ); +} + +void QwtNullPaintDevice::PaintEngine::drawEllipse( + const QRectF &rect) +{ + if ( d_device ) + d_device->drawEllipse( rect ); +} + +void QwtNullPaintDevice::PaintEngine::drawEllipse( + const QRect &rect) +{ + if ( d_device ) + d_device->drawEllipse( rect ); +} + + +void QwtNullPaintDevice::PaintEngine::drawPath( + const QPainterPath &path) +{ + if ( d_device ) + d_device->drawPath( path ); +} + +void QwtNullPaintDevice::PaintEngine::drawPoints( + const QPointF *points, int pointCount) +{ + if ( d_device ) + d_device->drawPoints( points, pointCount ); +} + +void QwtNullPaintDevice::PaintEngine::drawPoints( + const QPoint *points, int pointCount) +{ + if ( d_device ) + d_device->drawPoints( points, pointCount ); +} + +void QwtNullPaintDevice::PaintEngine::drawPolygon( + const QPointF *points, int pointCount, PolygonDrawMode mode) +{ + if ( d_device ) + d_device->drawPolygon( points, pointCount, mode ); +} + +void QwtNullPaintDevice::PaintEngine::drawPolygon( + const QPoint *points, int pointCount, PolygonDrawMode mode) +{ + if ( d_device ) + d_device->drawPolygon( points, pointCount, mode ); +} + +void QwtNullPaintDevice::PaintEngine::drawPixmap( + const QRectF &rect, const QPixmap &pm, const QRectF &subRect ) +{ + if ( d_device ) + d_device->drawPixmap( rect, pm, subRect ); +} + +void QwtNullPaintDevice::PaintEngine::drawTextItem( + const QPointF &pos, const QTextItem &textItem) +{ + if ( d_device ) + d_device->drawTextItem( pos, textItem ); +} + +void QwtNullPaintDevice::PaintEngine::drawTiledPixmap( + const QRectF &rect, const QPixmap &pixmap, + const QPointF &subRect) +{ + if ( d_device ) + d_device->drawTiledPixmap( rect, pixmap, subRect ); +} + +void QwtNullPaintDevice::PaintEngine::drawImage( + const QRectF &rect, const QImage &image, + const QRectF &subRect, Qt::ImageConversionFlags flags) +{ + if ( d_device ) + d_device->drawImage( rect, image, subRect, flags ); +} + +void QwtNullPaintDevice::PaintEngine::updateState( + const QPaintEngineState &state) +{ + if ( d_device ) + d_device->updateState( state ); +} + +//! Constructor +QwtNullPaintDevice::QwtNullPaintDevice( + QPaintEngine::PaintEngineFeatures features ) +{ + init( features ); +} + +//! Constructor +QwtNullPaintDevice::QwtNullPaintDevice( const QSize &size, + QPaintEngine::PaintEngineFeatures features ) +{ + init( features ); + d_data->size = size; +} + +void QwtNullPaintDevice::init( + QPaintEngine::PaintEngineFeatures features ) +{ + d_engine = new PaintEngine( features ); + d_data = new PrivateData; +} + +//! Destructor +QwtNullPaintDevice::~QwtNullPaintDevice() +{ + delete d_engine; + delete d_data; +} + +/*! + Set the size of the paint device + + \param size Size + \sa size() +*/ +void QwtNullPaintDevice::setSize( const QSize & size ) +{ + d_data->size = size; +} + +/*! + \return Size of the paint device + \sa setSize() +*/ +QSize QwtNullPaintDevice::size() const +{ + return d_data->size; +} + +//! See QPaintDevice::paintEngine() +QPaintEngine *QwtNullPaintDevice::paintEngine() const +{ + return d_engine; +} + +/*! + See QPaintDevice::metric() + \sa setSize() +*/ +int QwtNullPaintDevice::metric( PaintDeviceMetric metric ) const +{ + static QPixmap pm; + + int value; + + switch ( metric ) + { + case PdmWidth: + value = qMax( d_data->size.width(), 0 ); + break; + case PdmHeight: + value = qMax( d_data->size.height(), 0 ); + break; + case PdmNumColors: + value = 16777216; + break; + case PdmDepth: + value = 24; + break; + case PdmPhysicalDpiX: + case PdmDpiY: + case PdmPhysicalDpiY: + case PdmWidthMM: + case PdmHeightMM: + case PdmDpiX: + default: + value = 0; + } + return value; + +} + +//! See QPaintEngine::drawRects() +void QwtNullPaintDevice::drawRects( + const QRect *rects, int rectCount) +{ + Q_UNUSED(rects); + Q_UNUSED(rectCount); +} + +//! See QPaintEngine::drawRects() +void QwtNullPaintDevice::drawRects( + const QRectF *rects, int rectCount) +{ + Q_UNUSED(rects); + Q_UNUSED(rectCount); +} + +//! See QPaintEngine::drawLines() +void QwtNullPaintDevice::drawLines( + const QLine *lines, int lineCount) +{ + Q_UNUSED(lines); + Q_UNUSED(lineCount); +} + +//! See QPaintEngine::drawLines() +void QwtNullPaintDevice::drawLines( + const QLineF *lines, int lineCount) +{ + Q_UNUSED(lines); + Q_UNUSED(lineCount); +} + +//! See QPaintEngine::drawEllipse() +void QwtNullPaintDevice::drawEllipse( const QRectF &rect ) +{ + Q_UNUSED(rect); +} + +//! See QPaintEngine::drawEllipse() +void QwtNullPaintDevice::drawEllipse( const QRect &rect ) +{ + Q_UNUSED(rect); +} + +//! See QPaintEngine::drawPath() +void QwtNullPaintDevice::drawPath( const QPainterPath &path ) +{ + Q_UNUSED(path); +} + +//! See QPaintEngine::drawPoints() +void QwtNullPaintDevice::drawPoints( + const QPointF *points, int pointCount) +{ + Q_UNUSED(points); + Q_UNUSED(pointCount); +} + +//! See QPaintEngine::drawPoints() +void QwtNullPaintDevice::drawPoints( + const QPoint *points, int pointCount) +{ + Q_UNUSED(points); + Q_UNUSED(pointCount); +} + +//! See QPaintEngine::drawPolygon() +void QwtNullPaintDevice::drawPolygon( + const QPointF *points, int pointCount, + QPaintEngine::PolygonDrawMode mode) +{ + Q_UNUSED(points); + Q_UNUSED(pointCount); + Q_UNUSED(mode); +} + +//! See QPaintEngine::drawPolygon() +void QwtNullPaintDevice::drawPolygon( + const QPoint *points, int pointCount, + QPaintEngine::PolygonDrawMode mode) +{ + Q_UNUSED(points); + Q_UNUSED(pointCount); + Q_UNUSED(mode); +} + +//! See QPaintEngine::drawPixmap() +void QwtNullPaintDevice::drawPixmap( const QRectF &rect, + const QPixmap &pm, const QRectF &subRect ) +{ + Q_UNUSED(rect); + Q_UNUSED(pm); + Q_UNUSED(subRect); +} + +//! See QPaintEngine::drawTextItem() +void QwtNullPaintDevice::drawTextItem( + const QPointF &pos, const QTextItem &textItem) +{ + Q_UNUSED(pos); + Q_UNUSED(textItem); +} + +//! See QPaintEngine::drawTiledPixmap() +void QwtNullPaintDevice::drawTiledPixmap( + const QRectF &rect, const QPixmap &pixmap, + const QPointF &subRect) +{ + Q_UNUSED(rect); + Q_UNUSED(pixmap); + Q_UNUSED(subRect); +} + +//! See QPaintEngine::drawImage() +void QwtNullPaintDevice::drawImage( + const QRectF &rect, const QImage &image, + const QRectF &subRect, Qt::ImageConversionFlags flags) +{ + Q_UNUSED(rect); + Q_UNUSED(image); + Q_UNUSED(subRect); + Q_UNUSED(flags); +} + +//! See QPaintEngine::updateState() +void QwtNullPaintDevice::updateState( + const QPaintEngineState &state ) +{ + Q_UNUSED(state); +} diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_null_paintdevice.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_null_paintdevice.h new file mode 100644 index 000000000..a67da16a7 --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_null_paintdevice.h @@ -0,0 +1,89 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#ifndef QWT_NULL_PAINT_DEVICE_H +#define QWT_NULL_PAINT_DEVICE_H 1 + +#include "qwt_global.h" +#include +#include + +/*! + \brief A null paint device doing nothing + + Sometimes important layout/rendering geometries are not + available or changable from the public Qt class interface. + ( f.e hidden in the style implementation ). + + QwtNullPaintDevice can be used to manipulate or filter out + these informations by analyzing the stream of paint primitives. + + F.e. QwtNullPaintDevice is used by QwtPlotCanvas to identify + styled backgrounds with rounded corners. +*/ + +class QWT_EXPORT QwtNullPaintDevice: public QPaintDevice +{ +public: + QwtNullPaintDevice( QPaintEngine::PaintEngineFeatures ); + QwtNullPaintDevice( const QSize &size, + QPaintEngine::PaintEngineFeatures ); + + virtual ~QwtNullPaintDevice(); + + void setSize( const QSize &); + QSize size() const; + + virtual QPaintEngine *paintEngine() const; + virtual int metric( PaintDeviceMetric metric ) const; + + virtual void drawRects(const QRect *, int ); + virtual void drawRects(const QRectF *, int ); + + virtual void drawLines(const QLine *, int ); + virtual void drawLines(const QLineF *, int ); + + virtual void drawEllipse(const QRectF &); + virtual void drawEllipse(const QRect &); + + virtual void drawPath(const QPainterPath &); + + virtual void drawPoints(const QPointF *, int ); + virtual void drawPoints(const QPoint *, int ); + + virtual void drawPolygon( + const QPointF *, int , QPaintEngine::PolygonDrawMode ); + + virtual void drawPolygon( + const QPoint *, int , QPaintEngine::PolygonDrawMode ); + + virtual void drawPixmap(const QRectF &, + const QPixmap &, const QRectF &); + + virtual void drawTextItem(const QPointF &, const QTextItem &); + + virtual void drawTiledPixmap(const QRectF &, + const QPixmap &, const QPointF &s); + + virtual void drawImage(const QRectF &, + const QImage &, const QRectF &, Qt::ImageConversionFlags ); + + virtual void updateState( const QPaintEngineState &state ); + +private: + void init( QPaintEngine::PaintEngineFeatures ); + + class PaintEngine; + PaintEngine *d_engine; + + class PrivateData; + PrivateData *d_data; +}; + +#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_paint_buffer.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_paint_buffer.cpp deleted file mode 100644 index 65cd83ec5..000000000 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_paint_buffer.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** - * Qwt Widget Library - * Copyright (C) 1997 Josef Wilgen - * Copyright (C) 2002 Uwe Rathmann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the Qwt License, Version 1.0 - *****************************************************************************/ - - -#include -#if QT_VERSION < 0x040000 - -#include -#include -#include "qwt_paint_buffer.h" - -bool QwtPaintBuffer::d_enabled = true; - -//! Default constructor -QwtPaintBuffer::QwtPaintBuffer(): - d_device(0), - d_painter(0), - d_devicePainter(0) -{ -} - -/*! - Create an open paint buffer - \param device Device to paint on - \param rect Rect to paint on - \param painter Painter to paint on device. In case of 0 - QwtPaintBuffer uses an internal painter - - \sa open() -*/ - -QwtPaintBuffer::QwtPaintBuffer(QPaintDevice *device, - const QRect &rect, QPainter *painter): - d_device(0), - d_painter(0), - d_devicePainter(0) -{ - open(device, rect, painter); -} - -/*! - Closes the buffer - \sa close() -*/ -QwtPaintBuffer::~QwtPaintBuffer() -{ - close(); -} - -/*! - \return Depending on isEnabled() the painter - connected to an internal pixmap buffer - otherwise the painter connected to the device. -*/ - -QPainter *QwtPaintBuffer::painter() -{ - return d_painter; -} - -/*! - \return Device to paint on -*/ -const QPaintDevice *QwtPaintBuffer::device() -{ - return d_device; -} - -/*! - Enable/Disable double buffering. Please note that - this is a global switch for all QwtPaintBuffers, but - won't change opened buffers. -*/ -void QwtPaintBuffer::setEnabled(bool enable) -{ - d_enabled = enable; -} - -/*! - \return true if double buffering is enabled, false otherwise. -*/ -bool QwtPaintBuffer::isEnabled() -{ - return d_enabled; -} - -/*! - Open the buffer - \param device Device to paint on - \param rect Rect to paint on - \param painter Painter to paint on device. In case of 0 - QwtPaintBuffer uses an internal painter -*/ - -void QwtPaintBuffer::open(QPaintDevice *device, - const QRect &rect, QPainter *painter) -{ - close(); - - if ( device == 0 || !rect.isValid() ) - return; - - d_device = device; - d_devicePainter = painter; - d_rect = rect; - - if ( isEnabled() ) - { -#ifdef Q_WS_X11 - if ( d_pixBuffer.x11Screen() != d_device->x11Screen() ) - d_pixBuffer.x11SetScreen(d_device->x11Screen()); -#endif - d_pixBuffer.resize(d_rect.size()); - - d_painter = new QPainter(); - if ( d_device->devType() == QInternal::Widget ) - { - QWidget *w = (QWidget *)d_device; - d_pixBuffer.fill(w, d_rect.topLeft()); - d_painter->begin(&d_pixBuffer, w); - d_painter->translate(-d_rect.x(), -d_rect.y()); - } - else - { - d_painter->begin(&d_pixBuffer); - } - } - else - { - if ( d_devicePainter ) - d_painter = d_devicePainter; - else - d_painter = new QPainter(d_device); - - if ( d_device->devType() == QInternal::Widget ) - { - QWidget *w = (QWidget *)d_device; - if ( w->testWFlags( Qt::WNoAutoErase ) ) - d_painter->eraseRect(d_rect); - } - } -} - -/*! - Flush the internal pixmap buffer to the device. -*/ -void QwtPaintBuffer::flush() -{ - if ( d_enabled && d_device != 0 && d_rect.isValid()) - { - // We need a painter to find out if - // there is a painter redirection for d_device. - - QPainter *p; - if ( d_devicePainter == 0 ) - p = new QPainter(d_device); - else - p = d_devicePainter; - - QPaintDevice *device = p->device(); - if ( device->isExtDev() ) - d_devicePainter->drawPixmap(d_rect.topLeft(), d_pixBuffer); - else - bitBlt(device, d_rect.topLeft(), &d_pixBuffer ); - - if ( d_devicePainter == 0 ) - delete p; - } -} - -/*! - Flush the internal pixmap buffer to the device and close the buffer. -*/ -void QwtPaintBuffer::close() -{ - flush(); - - if ( d_painter ) - { - if ( d_painter->isActive() ) - d_painter->end(); - - if ( d_painter != d_devicePainter ) - delete d_painter; - } - - if ( !d_pixBuffer.isNull() ) - d_pixBuffer = QPixmap(); - - d_device = 0; - d_painter = 0; - d_devicePainter = 0; -} - -#endif // QT_VERSION < 0x040000 diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_paint_buffer.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_paint_buffer.h deleted file mode 100644 index d1285028f..000000000 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_paint_buffer.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** - * Qwt Widget Library - * Copyright (C) 1997 Josef Wilgen - * Copyright (C) 2002 Uwe Rathmann - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the Qwt License, Version 1.0 - *****************************************************************************/ - -#ifndef QWT_PAINT_BUFFER_H -#define QWT_PAINT_BUFFER_H 1 - -#include -#if QT_VERSION < 0x040000 - -#include -#include "qwt_global.h" - -class QPainter; - -/*! - \brief Paint buffer for Qwt widgets - - QwtPaintBuffer offers a simple way to en/disable double buffering. - Double buffering is enabled as default and in general there will be - no reason to change this. -*/ - -class QWT_EXPORT QwtPaintBuffer -{ -public: - explicit QwtPaintBuffer(); - explicit QwtPaintBuffer(QPaintDevice *, const QRect &, QPainter *p = NULL); - - virtual ~QwtPaintBuffer(); - - void open(QPaintDevice *, const QRect &, QPainter *p = NULL); - void close(); - - QPainter *painter(); - const QPaintDevice *device(); - - static void setEnabled(bool enable); - static bool isEnabled(); - - //! Return Buffer used for double buffering - const QPixmap &buffer() const { return d_pixBuffer; } - -protected: - void flush(); - -private: - QPixmap d_pixBuffer; - QRect d_rect; - - QPaintDevice *d_device; // use QGuardedPtr - QPainter *d_painter; // use QGuardedPtr - QPainter *d_devicePainter; // use QGuardedPtr - - static bool d_enabled; -}; - -#endif // QT_VERSION < 0x040000 - -#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_painter.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_painter.cpp index 1d9018c60..dc28cfe6a 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_painter.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_painter.cpp @@ -7,52 +7,35 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - +#include "qwt_painter.h" +#include "qwt_math.h" +#include "qwt_clipper.h" +#include "qwt_color_map.h" +#include "qwt_scale_map.h" #include #include +#include #include #include #include #include #include #include -#if QT_VERSION < 0x040000 -#include -#else #include #include #include #include -#endif +#include +#include -#include "qwt_math.h" -#include "qwt_clipper.h" -#include "qwt_color_map.h" -#include "qwt_scale_map.h" -#include "qwt_painter.h" +bool QwtPainter::d_polylineSplitting = true; +bool QwtPainter::d_roundingAlignment = true; -QwtMetricsMap QwtPainter::d_metricsMap; - -#if defined(Q_WS_X11) -bool QwtPainter::d_deviceClipping = true; -#else -bool QwtPainter::d_deviceClipping = false; -#endif - -#if QT_VERSION < 0x040000 -bool QwtPainter::d_SVGMode = false; -#endif - -static inline bool isClippingNeeded(const QPainter *painter, QRect &clipRect) +static inline bool isClippingNeeded( const QPainter *painter, QRectF &clipRect ) { bool doClipping = false; -#if QT_VERSION >= 0x040000 const QPaintEngine *pe = painter->paintEngine(); if ( pe && pe->type() == QPaintEngine::SVG ) -#else - if ( painter->device()->devType() == QInternal::Picture ) -#endif { // The SVG paint engine ignores any clipping, @@ -63,189 +46,175 @@ static inline bool isClippingNeeded(const QPainter *painter, QRect &clipRect) } } - if ( QwtPainter::deviceClipping() ) - { - if (painter->device()->devType() == QInternal::Widget || - painter->device()->devType() == QInternal::Pixmap ) - { - if ( doClipping ) - { - clipRect &= QwtPainter::deviceClipRect(); - } - else - { - doClipping = true; - clipRect = QwtPainter::deviceClipRect(); - } - } - } - return doClipping; } -/*! - \brief En/Disable device clipping. - - On X11 the default for device clipping is enabled, - otherwise it is disabled. - \sa QwtPainter::deviceClipping() -*/ -void QwtPainter::setDeviceClipping(bool enable) +static inline void drawPolyline( QPainter *painter, + const QPointF *points, int pointCount, bool polylineSplitting ) { - d_deviceClipping = enable; -} - -/*! - Returns rect for device clipping - \sa QwtPainter::setDeviceClipping() -*/ -const QRect &QwtPainter::deviceClipRect() -{ - static QRect clip; - - if ( !clip.isValid() ) + bool doSplit = false; + if ( polylineSplitting ) { - clip.setCoords(QWT_COORD_MIN, QWT_COORD_MIN, - QWT_COORD_MAX, QWT_COORD_MAX); + const QPaintEngine *pe = painter->paintEngine(); + if ( pe && pe->type() == QPaintEngine::Raster ) + { + /* + The raster paint engine seems to use some algo with O(n*n). + ( Qt 4.3 is better than Qt 4.2, but remains unacceptable) + To work around this problem, we have to split the polygon into + smaller pieces. + */ + doSplit = true; + } } - return clip; + + if ( doSplit ) + { + const int splitSize = 20; + for ( int i = 0; i < pointCount; i += splitSize ) + { + const int n = qMin( splitSize + 1, pointCount - i ); + painter->drawPolyline( points + i, n ); + } + } + else + painter->drawPolyline( points, pointCount ); } -#if QT_VERSION < 0x040000 - -/*! - \brief En/Disable SVG mode. - - When saving a QPicture to a SVG some texts are misaligned. - In SVGMode QwtPainter tries to fix them. - - \sa QwtPainter::isSVGMode() - \note A QPicture that is created in SVG mode and saved to the - native format, will be misaligned. Also it is not possible to - reload and play a SVG document, that was created in SVG mode. -*/ -void QwtPainter::setSVGMode(bool on) +static inline void unscaleFont( QPainter *painter ) { - d_SVGMode = on; -} + if ( painter->font().pixelSize() >= 0 ) + return; -bool QwtPainter::isSVGMode() -{ - return d_SVGMode; -} + static QSize screenResolution; + if ( !screenResolution.isValid() ) + { + QDesktopWidget *desktop = QApplication::desktop(); + if ( desktop ) + { + screenResolution.setWidth( desktop->logicalDpiX() ); + screenResolution.setHeight( desktop->logicalDpiY() ); + } + } -#endif // QT_VERSION < 0x040000 + const QPaintDevice *pd = painter->device(); + if ( pd->logicalDpiX() != screenResolution.width() || + pd->logicalDpiY() != screenResolution.height() ) + { + QFont pixelFont( painter->font(), QApplication::desktop() ); + pixelFont.setPixelSize( QFontInfo( pixelFont ).pixelSize() ); -/*! - Scale all QwtPainter drawing operations using the ratio - QwtPaintMetrics(from).logicalDpiX() / QwtPaintMetrics(to).logicalDpiX() - and QwtPaintMetrics(from).logicalDpiY() / QwtPaintMetrics(to).logicalDpiY() - - \sa QwtPainter::resetScaleMetrics(), QwtPainter::scaleMetricsX(), - QwtPainter::scaleMetricsY() -*/ -void QwtPainter::setMetricsMap(const QPaintDevice *layout, - const QPaintDevice *device) -{ - d_metricsMap.setMetrics(layout, device); -} - -/*! - Change the metrics map - \sa QwtPainter::resetMetricsMap(), QwtPainter::metricsMap() -*/ -void QwtPainter::setMetricsMap(const QwtMetricsMap &map) -{ - d_metricsMap = map; -} - -/*! - Reset the metrics map to the ratio 1:1 - \sa QwtPainter::setMetricsMap(), QwtPainter::resetMetricsMap() -*/ -void QwtPainter::resetMetricsMap() -{ - d_metricsMap = QwtMetricsMap(); + painter->setFont( pixelFont ); + } } /*! - \return Metrics map + Check if the painter is using a paint engine, that aligns + coordinates to integers. Today these are all paint engines + beside QPaintEngine::Pdf and QPaintEngine::SVG. + + \param painter Painter + \return true, when the paint engine is aligning + + \sa setRoundingAlignment() */ -const QwtMetricsMap &QwtPainter::metricsMap() +bool QwtPainter::isAligning( QPainter *painter ) { - return d_metricsMap; + if ( painter && painter->isActive() ) + { + switch ( painter->paintEngine()->type() ) + { + case QPaintEngine::Pdf: + case QPaintEngine::SVG: + return false; + + default:; + } + } + + return true; } /*! - Wrapper for QPainter::setClipRect() + Enable whether coordinates should be rounded, before they are painted + to a paint engine that floors to integer values. For other paint engines + this ( Pdf, SVG ), this flag has no effect. + QwtPainter stores this flag only, the rounding itsself is done in + the painting code ( f.e the plot items ). + + The default setting is true. + + \sa roundingAlignment(), isAligning() */ -void QwtPainter::setClipRect(QPainter *painter, const QRect &rect) +void QwtPainter::setRoundingAlignment( bool enable ) { - painter->setClipRect(d_metricsMap.layoutToDevice(rect, painter)); + d_roundingAlignment = enable; } /*! - Wrapper for QPainter::drawRect() + \brief En/Disable line splitting for the raster paint engine + + The raster paint engine paints polylines of many points + much faster when they are splitted in smaller chunks. + + \sa polylineSplitting() */ -void QwtPainter::drawRect(QPainter *painter, int x, int y, int w, int h) +void QwtPainter::setPolylineSplitting( bool enable ) { - drawRect(painter, QRect(x, y, w, h)); + d_polylineSplitting = enable; } -/*! - Wrapper for QPainter::drawRect() -*/ -void QwtPainter::drawRect(QPainter *painter, const QRect &rect) +//! Wrapper for QPainter::drawPath() +void QwtPainter::drawPath( QPainter *painter, const QPainterPath &path ) { - const QRect r = d_metricsMap.layoutToDevice(rect, painter); + painter->drawPath( path ); +} - QRect clipRect; - const bool deviceClipping = isClippingNeeded(painter, clipRect); +//! Wrapper for QPainter::drawRect() +void QwtPainter::drawRect( QPainter *painter, double x, double y, double w, double h ) +{ + drawRect( painter, QRectF( x, y, w, h ) ); +} + +//! Wrapper for QPainter::drawRect() +void QwtPainter::drawRect( QPainter *painter, const QRectF &rect ) +{ + const QRectF r = rect; + + QRectF clipRect; + const bool deviceClipping = isClippingNeeded( painter, clipRect ); if ( deviceClipping ) { - if ( !clipRect.intersects(r) ) + if ( !clipRect.intersects( r ) ) return; - if ( !clipRect.contains(r) ) + if ( !clipRect.contains( r ) ) { - fillRect(painter, r & clipRect, painter->brush()); - - int pw = painter->pen().width(); - pw = pw % 2 + pw / 2; - - QwtPolygon pa(5); - pa.setPoint(0, r.left(), r.top()); - pa.setPoint(1, r.right() - pw, r.top()); - pa.setPoint(2, r.right() - pw, r.bottom() - pw); - pa.setPoint(3, r.left(), r.bottom() - pw); - pa.setPoint(4, r.left(), r.top()); + fillRect( painter, r & clipRect, painter->brush() ); painter->save(); - painter->setBrush(Qt::NoBrush); - drawPolyline(painter, pa); + painter->setBrush( Qt::NoBrush ); + drawPolyline( painter, QPolygonF( r ) ); painter->restore(); return; } } - painter->drawRect(r); + painter->drawRect( r ); } -/*! - Wrapper for QPainter::fillRect() -*/ -void QwtPainter::fillRect(QPainter *painter, - const QRect &rect, const QBrush &brush) +//! Wrapper for QPainter::fillRect() +void QwtPainter::fillRect( QPainter *painter, + const QRectF &rect, const QBrush &brush ) { if ( !rect.isValid() ) return; - QRect clipRect; - const bool deviceClipping = isClippingNeeded(painter, clipRect); + QRectF clipRect; + const bool deviceClipping = isClippingNeeded( painter, clipRect ); -#if QT_VERSION >= 0x040000 /* Performance of Qt4 is horrible for non trivial brushs. Without clipping expect minutes or hours for repainting large rects @@ -259,509 +228,477 @@ void QwtPainter::fillRect(QPainter *painter, if ( painter->hasClipping() ) clipRect &= painter->clipRegion().boundingRect(); -#endif - QRect r = d_metricsMap.layoutToDevice(rect, painter); + QRectF r = rect; if ( deviceClipping ) - r = r.intersect(clipRect); + r = r.intersect( clipRect ); if ( r.isValid() ) - painter->fillRect(r, brush); + painter->fillRect( r, brush ); } -/*! - Wrapper for QPainter::drawPie() -*/ -void QwtPainter::drawPie(QPainter *painter, const QRect &rect, - int a, int alen) +//! Wrapper for QPainter::drawPie() +void QwtPainter::drawPie( QPainter *painter, const QRectF &rect, + int a, int alen ) { - const QRect r = d_metricsMap.layoutToDevice(rect, painter); - - QRect clipRect; - const bool deviceClipping = isClippingNeeded(painter, clipRect); - if ( deviceClipping && !clipRect.contains(r) ) + QRectF clipRect; + const bool deviceClipping = isClippingNeeded( painter, clipRect ); + if ( deviceClipping && !clipRect.contains( rect ) ) return; - painter->drawPie(r, a, alen); + painter->drawPie( rect, a, alen ); } -/*! - Wrapper for QPainter::drawEllipse() -*/ -void QwtPainter::drawEllipse(QPainter *painter, const QRect &rect) +//! Wrapper for QPainter::drawEllipse() +void QwtPainter::drawEllipse( QPainter *painter, const QRectF &rect ) { - QRect r = d_metricsMap.layoutToDevice(rect, painter); + QRectF clipRect; + const bool deviceClipping = isClippingNeeded( painter, clipRect ); - QRect clipRect; - const bool deviceClipping = isClippingNeeded(painter, clipRect); - - if ( deviceClipping && !clipRect.contains(r) ) + if ( deviceClipping && !clipRect.contains( rect ) ) return; -#if QT_VERSION >= 0x040000 - if ( painter->pen().style() != Qt::NoPen && - painter->pen().color().isValid() ) - { - // Qt4 adds the pen to the rect, Qt3 not. - int pw = painter->pen().width(); - if ( pw == 0 ) - pw = 1; - - r.setWidth(r.width() - pw); - r.setHeight(r.height() - pw); - } -#endif - - painter->drawEllipse(r); + painter->drawEllipse( rect ); } -/*! - Wrapper for QPainter::drawText() -*/ -void QwtPainter::drawText(QPainter *painter, int x, int y, - const QString &text) +//! Wrapper for QPainter::drawText() +void QwtPainter::drawText( QPainter *painter, double x, double y, + const QString &text ) { - drawText(painter, QPoint(x, y), text); + drawText( painter, QPointF( x, y ), text ); } -/*! - Wrapper for QPainter::drawText() -*/ -void QwtPainter::drawText(QPainter *painter, const QPoint &pos, - const QString &text) +//! Wrapper for QPainter::drawText() +void QwtPainter::drawText( QPainter *painter, const QPointF &pos, + const QString &text ) { - const QPoint p = d_metricsMap.layoutToDevice(pos, painter); + QRectF clipRect; + const bool deviceClipping = isClippingNeeded( painter, clipRect ); - QRect clipRect; - const bool deviceClipping = isClippingNeeded(painter, clipRect); - - if ( deviceClipping && !clipRect.contains(p) ) + if ( deviceClipping && !clipRect.contains( pos ) ) return; - painter->drawText(p, text); + + painter->save(); + unscaleFont( painter ); + painter->drawText( pos, text ); + painter->restore(); } -/*! - Wrapper for QPainter::drawText() -*/ -void QwtPainter::drawText(QPainter *painter, int x, int y, int w, int h, - int flags, const QString &text) +//! Wrapper for QPainter::drawText() +void QwtPainter::drawText( QPainter *painter, + double x, double y, double w, double h, + int flags, const QString &text ) { - drawText(painter, QRect(x, y, w, h), flags, text); + drawText( painter, QRectF( x, y, w, h ), flags, text ); } -/*! - Wrapper for QPainter::drawText() -*/ -void QwtPainter::drawText(QPainter *painter, const QRect &rect, - int flags, const QString &text) +//! Wrapper for QPainter::drawText() +void QwtPainter::drawText( QPainter *painter, const QRectF &rect, + int flags, const QString &text ) { - QRect textRect = d_metricsMap.layoutToDevice(rect, painter); -#if QT_VERSION < 0x040000 - if ( d_SVGMode && - ( flags == 0 || flags & Qt::AlignVCenter ) - && painter->device()->devType() == QInternal::Picture ) - { - /* - Qt3 misalignes texts, when saving a text - to a SVG image. - */ - textRect.setY(textRect.y() - painter->fontMetrics().height() / 4); - } -#endif - painter->drawText(textRect, flags, text); + painter->save(); + unscaleFont( painter ); + painter->drawText( rect, flags, text ); + painter->restore(); } #ifndef QT_NO_RICHTEXT /*! - Wrapper for QSimpleRichText::draw() + Draw a text document into a rectangle + + \param painter Painter + \param rect Traget rectangle + \param flags Alignments/Text flags, see QPainter::drawText() + \param text Text document */ -#if QT_VERSION < 0x040000 - -void QwtPainter::drawSimpleRichText(QPainter *painter, const QRect &rect, - int flags, QSimpleRichText &text) +void QwtPainter::drawSimpleRichText( QPainter *painter, const QRectF &rect, + int flags, const QTextDocument &text ) { - QColorGroup cg; - cg.setColor(QColorGroup::Text, painter->pen().color()); - - const QRect scaledRect = d_metricsMap.layoutToDevice(rect, painter); - - text.setWidth(painter, scaledRect.width()); - - // QSimpleRichText is Qt::AlignTop by default - - int y = scaledRect.y(); - if (flags & Qt::AlignBottom) - y += (scaledRect.height() - text.height()); - else if (flags & Qt::AlignVCenter) - y += (scaledRect.height() - text.height())/2; - - text.draw(painter, scaledRect.x(), y, scaledRect, cg); -} -#else -void QwtPainter::drawSimpleRichText(QPainter *painter, const QRect &rect, - int flags, QTextDocument &text) -{ - const QRect scaledRect = d_metricsMap.layoutToDevice(rect, painter); - text.setPageSize(QSize(scaledRect.width(), QWIDGETSIZE_MAX)); - - QAbstractTextDocumentLayout* layout = text.documentLayout(); - - const int height = qRound(layout->documentSize().height()); - int y = scaledRect.y(); - if (flags & Qt::AlignBottom) - y += (scaledRect.height() - height); - else if (flags & Qt::AlignVCenter) - y += (scaledRect.height() - height)/2; - - QAbstractTextDocumentLayout::PaintContext context; - context.palette.setColor(QPalette::Text, painter->pen().color()); + QTextDocument *txt = text.clone(); painter->save(); - painter->translate(scaledRect.x(), y); - layout->draw(painter, context); + painter->setFont( txt->defaultFont() ); + unscaleFont( painter ); + + txt->setDefaultFont( painter->font() ); + txt->setPageSize( QSizeF( rect.width(), QWIDGETSIZE_MAX ) ); + + QAbstractTextDocumentLayout* layout = txt->documentLayout(); + + const double height = layout->documentSize().height(); + double y = rect.y(); + if ( flags & Qt::AlignBottom ) + y += ( rect.height() - height ); + else if ( flags & Qt::AlignVCenter ) + y += ( rect.height() - height ) / 2; + + QAbstractTextDocumentLayout::PaintContext context; + context.palette.setColor( QPalette::Text, painter->pen().color() ); + + painter->translate( rect.x(), y ); + layout->draw( painter, context ); painter->restore(); + delete txt; } -#endif #endif // !QT_NO_RICHTEXT -/*! - Wrapper for QPainter::drawLine() -*/ -void QwtPainter::drawLine(QPainter *painter, int x1, int y1, int x2, int y2) +//! Wrapper for QPainter::drawLine() +void QwtPainter::drawLine( QPainter *painter, + const QPointF &p1, const QPointF &p2 ) { - QRect clipRect; - const bool deviceClipping = isClippingNeeded(painter, clipRect); + QRectF clipRect; + const bool deviceClipping = isClippingNeeded( painter, clipRect ); - if ( deviceClipping && - !(clipRect.contains(x1, y1) && clipRect.contains(x2, y2)) ) + if ( deviceClipping && + !( clipRect.contains( p1 ) && clipRect.contains( p2 ) ) ) { - QwtPolygon pa(2); - pa.setPoint(0, x1, y1); - pa.setPoint(1, x2, y2); - drawPolyline(painter, pa); + QPolygonF polygon; + polygon += p1; + polygon += p2; + drawPolyline( painter, polygon ); return; } - if ( d_metricsMap.isIdentity() ) - { -#if QT_VERSION >= 0x030200 && QT_VERSION < 0x040000 - if ( !painter->device()->isExtDev() ) -#endif - { - painter->drawLine(x1, y1, x2, y2); - return; - } - } - - const QPoint p1 = d_metricsMap.layoutToDevice(QPoint(x1, y1)); - const QPoint p2 = d_metricsMap.layoutToDevice(QPoint(x2, y2)); - -#if QT_VERSION >= 0x030200 && QT_VERSION < 0x040000 - if ( painter->device()->isExtDev() ) - { - // Strange: the postscript driver of QPrinter adds an offset - // of 0.5 to the start/endpoint when using drawLine, but not - // for lines painted with drawLineSegments. - - QwtPolygon pa(2); - pa.setPoint(0, p1); - pa.setPoint(1, p2); - painter->drawLineSegments(pa); - } - else - painter->drawLine(p1, p2); -#else - painter->drawLine(p1, p2); -#endif + painter->drawLine( p1, p2 ); } -/*! - Wrapper for QPainter::drawPolygon() -*/ -void QwtPainter::drawPolygon(QPainter *painter, const QwtPolygon &pa) +//! Wrapper for QPainter::drawPolygon() +void QwtPainter::drawPolygon( QPainter *painter, const QPolygonF &polygon ) { - QRect clipRect; - const bool deviceClipping = isClippingNeeded(painter, clipRect); + QRectF clipRect; + const bool deviceClipping = isClippingNeeded( painter, clipRect ); + + QPolygonF cpa = polygon; + if ( deviceClipping ) + cpa = QwtClipper::clipPolygonF( clipRect, polygon ); + + painter->drawPolygon( cpa ); +} + +//! Wrapper for QPainter::drawPolyline() +void QwtPainter::drawPolyline( QPainter *painter, const QPolygonF &polygon ) +{ + QRectF clipRect; + const bool deviceClipping = isClippingNeeded( painter, clipRect ); + + QPolygonF cpa = polygon; + if ( deviceClipping ) + cpa = QwtClipper::clipPolygonF( clipRect, cpa ); + + ::drawPolyline( painter, + cpa.constData(), cpa.size(), d_polylineSplitting ); +} + +//! Wrapper for QPainter::drawPolyline() +void QwtPainter::drawPolyline( QPainter *painter, + const QPointF *points, int pointCount ) +{ + QRectF clipRect; + const bool deviceClipping = isClippingNeeded( painter, clipRect ); - QwtPolygon cpa = d_metricsMap.layoutToDevice(pa); if ( deviceClipping ) { -#ifdef __GNUC__ -#endif - cpa = QwtClipper::clipPolygon(clipRect, cpa); - } - painter->drawPolygon(cpa); -} + QPolygonF polygon( pointCount ); + qMemCopy( polygon.data(), points, pointCount * sizeof( QPointF ) ); -/*! - Wrapper for QPainter::drawPolyline() -*/ -void QwtPainter::drawPolyline(QPainter *painter, const QwtPolygon &pa) -{ - QRect clipRect; - const bool deviceClipping = isClippingNeeded(painter, clipRect); - - QwtPolygon cpa = d_metricsMap.layoutToDevice(pa); - if ( deviceClipping ) - cpa = QwtClipper::clipPolygon(clipRect, cpa); - -#if QT_VERSION >= 0x040000 && QT_VERSION < 0x040400 - bool doSplit = false; - - const QPaintEngine *pe = painter->paintEngine(); - if ( pe && pe->type() == QPaintEngine::Raster && - painter->pen().width() >= 2 ) - { - /* - The raster paint engine seems to use some algo with O(n*n). - ( Qt 4.3 is better than Qt 4.2, but remains unacceptable) - To work around this problem, we have to split the polygon into - smaller pieces. - */ - doSplit = true; - } - - if ( doSplit ) - { - const int numPoints = cpa.size(); - const QPoint *points = cpa.data(); - - const int splitSize = 20; - for ( int i = 0; i < numPoints; i += splitSize ) - { - const int n = qwtMin(splitSize + 1, cpa.size() - i); - painter->drawPolyline(points + i, n); - } + polygon = QwtClipper::clipPolygonF( clipRect, polygon ); + ::drawPolyline( painter, + polygon.constData(), polygon.size(), d_polylineSplitting ); } else -#endif - painter->drawPolyline(cpa); + ::drawPolyline( painter, points, pointCount, d_polylineSplitting ); } -/*! - Wrapper for QPainter::drawPoint() -*/ - -void QwtPainter::drawPoint(QPainter *painter, int x, int y) +//! Wrapper for QPainter::drawPoint() +void QwtPainter::drawPoint( QPainter *painter, const QPointF &pos ) { - QRect clipRect; - const bool deviceClipping = isClippingNeeded(painter, clipRect); + QRectF clipRect; + const bool deviceClipping = isClippingNeeded( painter, clipRect ); - const QPoint pos = d_metricsMap.layoutToDevice(QPoint(x, y)); - - if ( deviceClipping && !clipRect.contains(pos) ) + if ( deviceClipping && !clipRect.contains( pos ) ) return; - painter->drawPoint(pos); + painter->drawPoint( pos ); } -void QwtPainter::drawColoredArc(QPainter *painter, const QRect &rect, - int peak, int arc, int interval, const QColor &c1, const QColor &c2) +//! Wrapper for QPainter::drawImage() +void QwtPainter::drawImage( QPainter *painter, + const QRectF &rect, const QImage &image ) { - int h1, s1, v1; - int h2, s2, v2; + const QRect alignedRect = rect.toAlignedRect(); -#if QT_VERSION < 0x040000 - c1.hsv(&h1, &s1, &v1); - c2.hsv(&h2, &s2, &v2); -#else - c1.getHsv(&h1, &s1, &v1); - c2.getHsv(&h2, &s2, &v2); -#endif - - arc /= 2; - for ( int angle = -arc; angle < arc; angle += interval) + if ( alignedRect != rect ) { - double ratio; - if ( angle >= 0 ) - ratio = 1.0 - angle / double(arc); - else - ratio = 1.0 + angle / double(arc); + const QRectF clipRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 ); + + painter->save(); + painter->setClipRect( clipRect, Qt::IntersectClip ); + painter->drawImage( alignedRect, image ); + painter->restore(); + } + else + { + painter->drawImage( alignedRect, image ); + } +} + +//! Wrapper for QPainter::drawPixmap() +void QwtPainter::drawPixmap( QPainter *painter, + const QRectF &rect, const QPixmap &pixmap ) +{ + const QRect alignedRect = rect.toAlignedRect(); + + if ( alignedRect != rect ) + { + const QRectF clipRect = rect.adjusted( 0.0, 0.0, -1.0, -1.0 ); + + painter->save(); + painter->setClipRect( clipRect, Qt::IntersectClip ); + painter->drawPixmap( alignedRect, pixmap ); + painter->restore(); + } + else + { + painter->drawPixmap( alignedRect, pixmap ); + } +} + +//! Draw a focus rectangle on a widget using its style. +void QwtPainter::drawFocusRect( QPainter *painter, QWidget *widget ) +{ + drawFocusRect( painter, widget, widget->rect() ); +} + +//! Draw a focus rectangle on a widget using its style. +void QwtPainter::drawFocusRect( QPainter *painter, QWidget *widget, + const QRect &rect ) +{ + QStyleOptionFocusRect opt; + opt.init( widget ); + opt.rect = rect; + opt.state |= QStyle::State_HasFocus; + + widget->style()->drawPrimitive( QStyle::PE_FrameFocusRect, + &opt, painter, widget ); +} + +/*! + Draw a frame with rounded borders + + \param painter Painter + \param rect Frame rectangle + \param xRadius x-radius of the ellipses defining the corners + \param yRadius y-radius of the ellipses defining the corners + \param palette QPalette::WindowText is used for plain borders + QPalette::Dark and QPalette::Light for raised + or sunken borders + \param lineWidth Line width + \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow +*/ + +void QwtPainter::drawRoundedFrame( QPainter *painter, + const QRectF &rect, double xRadius, double yRadius, + const QPalette &palette, int lineWidth, int frameStyle ) +{ + painter->save(); + painter->setRenderHint( QPainter::Antialiasing, true ); + painter->setBrush( Qt::NoBrush ); + + double lw2 = lineWidth * 0.5; + QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 ); + + QPainterPath path; + path.addRoundedRect( r, xRadius, yRadius ); + + enum Style + { + Plain, + Sunken, + Raised + }; + + Style style = Plain; + if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken ) + style = Sunken; + else if ( (frameStyle & QFrame::Raised) == QFrame::Raised ) + style = Raised; + + if ( style != Plain && path.elementCount() == 17 ) + { + // move + 4 * ( cubicTo + lineTo ) + QPainterPath pathList[8]; + + for ( int i = 0; i < 4; i++ ) + { + const int j = i * 4 + 1; + pathList[ 2 * i ].moveTo( + path.elementAt(j - 1).x, path.elementAt( j - 1 ).y + ); + + pathList[ 2 * i ].cubicTo( + path.elementAt(j + 0).x, path.elementAt(j + 0).y, + path.elementAt(j + 1).x, path.elementAt(j + 1).y, + path.elementAt(j + 2).x, path.elementAt(j + 2).y ); + + pathList[ 2 * i + 1 ].moveTo( + path.elementAt(j + 2).x, path.elementAt(j + 2).y + ); + pathList[ 2 * i + 1 ].lineTo( + path.elementAt(j + 3).x, path.elementAt(j + 3).y + ); + } - QColor c; - c.setHsv( h1 + qRound(ratio * (h2 - h1)), - s1 + qRound(ratio * (s2 - s1)), - v1 + qRound(ratio * (v2 - v1)) ); + QColor c1( palette.color( QPalette::Dark ) ); + QColor c2( palette.color( QPalette::Light ) ); - painter->setPen(QPen(c, painter->pen().width())); - painter->drawArc(rect, (peak + angle) * 16, interval * 16); - } -} + if ( style == Raised ) + qSwap( c1, c2 ); -void QwtPainter::drawFocusRect(QPainter *painter, QWidget *widget) -{ - drawFocusRect(painter, widget, widget->rect()); -} + for ( int i = 0; i < 4; i++ ) + { + QRectF r = pathList[2 * i].controlPointRect(); -void QwtPainter::drawFocusRect(QPainter *painter, QWidget *widget, - const QRect &rect) -{ -#if QT_VERSION < 0x040000 - widget->style().drawPrimitive(QStyle::PE_FocusRect, painter, - rect, widget->colorGroup()); -#else - QStyleOptionFocusRect opt; - opt.init(widget); - opt.rect = rect; - opt.state |= QStyle::State_HasFocus; + QPen arcPen; + arcPen.setWidth( lineWidth ); - widget->style()->drawPrimitive(QStyle::PE_FrameFocusRect, - &opt, painter, widget); -#endif + QPen linePen; + linePen.setWidth( lineWidth ); -} + switch( i ) + { + case 0: + { + arcPen.setColor( c1 ); + linePen.setColor( c1 ); + break; + } + case 1: + { + QLinearGradient gradient; + gradient.setStart( r.topLeft() ); + gradient.setFinalStop( r.bottomRight() ); + gradient.setColorAt( 0.0, c1 ); + gradient.setColorAt( 1.0, c2 ); -//! Draw a round frame -#if QT_VERSION < 0x040000 -void QwtPainter::drawRoundFrame(QPainter *painter, const QRect &rect, - int width, const QColorGroup &cg, bool sunken) -#else -void QwtPainter::drawRoundFrame(QPainter *painter, const QRect &rect, - int width, const QPalette &palette, bool sunken) -#endif -{ + arcPen.setBrush( gradient ); + linePen.setColor( c2 ); + break; + } + case 2: + { + arcPen.setColor( c2 ); + linePen.setColor( c2 ); + break; + } + case 3: + { + QLinearGradient gradient; -#if QT_VERSION < 0x040000 - QColor c0 = cg.mid(); - QColor c1, c2; - if ( sunken ) - { - c1 = cg.dark(); - c2 = cg.light(); + gradient.setStart( r.bottomRight() ); + gradient.setFinalStop( r.topLeft() ); + gradient.setColorAt( 0.0, c2 ); + gradient.setColorAt( 1.0, c1 ); + + arcPen.setBrush( gradient ); + linePen.setColor( c1 ); + break; + } + } + + + painter->setPen( arcPen ); + painter->drawPath( pathList[ 2 * i] ); + + painter->setPen( linePen ); + painter->drawPath( pathList[ 2 * i + 1] ); + } } else { - c1 = cg.light(); - c2 = cg.dark(); + QPen pen( palette.color( QPalette::WindowText ), lineWidth ); + painter->setPen( pen ); + painter->drawPath( path ); } -#else - QColor c0 = palette.color(QPalette::Mid); - QColor c1, c2; - if ( sunken ) - { - c1 = palette.color(QPalette::Dark); - c2 = palette.color(QPalette::Light); - } - else - { - c1 = palette.color(QPalette::Light); - c2 = palette.color(QPalette::Dark); - } -#endif - painter->setPen(QPen(c0, width)); - painter->drawArc(rect, 0, 360 * 16); // full - - const int peak = 150; - const int interval = 2; - - if ( c0 != c1 ) - drawColoredArc(painter, rect, peak, 160, interval, c0, c1); - if ( c0 != c2 ) - drawColoredArc(painter, rect, peak + 180, 120, interval, c0, c2); + painter->restore(); } -void QwtPainter::drawColorBar(QPainter *painter, - const QwtColorMap &colorMap, const QwtDoubleInterval &interval, +/*! + Draw a color bar into a rectangle + + \param painter Painter + \param colorMap Color map + \param interval Value range + \param scaleMap Scale map + \param orientation Orientation + \param rect Traget rectangle +*/ +void QwtPainter::drawColorBar( QPainter *painter, + const QwtColorMap &colorMap, const QwtInterval &interval, const QwtScaleMap &scaleMap, Qt::Orientation orientation, - const QRect &rect) + const QRectF &rect ) { -#if QT_VERSION < 0x040000 - QValueVector colorTable; -#else QVector colorTable; -#endif if ( colorMap.format() == QwtColorMap::Indexed ) - colorTable = colorMap.colorTable(interval); + colorTable = colorMap.colorTable( interval ); QColor c; - const QRect devRect = d_metricsMap.layoutToDevice(rect); + const QRect devRect = rect.toAlignedRect(); /* We paint to a pixmap first to have something scalable for printing ( f.e. in a Pdf document ) */ - - QPixmap pixmap(devRect.size()); - QPainter pmPainter(&pixmap); - pmPainter.translate(-devRect.x(), -devRect.y()); + + QPixmap pixmap( devRect.size() ); + QPainter pmPainter( &pixmap ); + pmPainter.translate( -devRect.x(), -devRect.y() ); if ( orientation == Qt::Horizontal ) { QwtScaleMap sMap = scaleMap; - sMap.setPaintInterval(devRect.left(), devRect.right()); + sMap.setPaintInterval( rect.left(), rect.right() ); for ( int x = devRect.left(); x <= devRect.right(); x++ ) { - const double value = sMap.invTransform(x); + const double value = sMap.invTransform( x ); if ( colorMap.format() == QwtColorMap::RGB ) - c.setRgb(colorMap.rgb(interval, value)); + c.setRgb( colorMap.rgb( interval, value ) ); else - c = colorTable[colorMap.colorIndex(interval, value)]; + c = colorTable[colorMap.colorIndex( interval, value )]; - pmPainter.setPen(c); - pmPainter.drawLine(x, devRect.top(), x, devRect.bottom()); + pmPainter.setPen( c ); + pmPainter.drawLine( x, devRect.top(), x, devRect.bottom() ); } } else // Vertical { QwtScaleMap sMap = scaleMap; - sMap.setPaintInterval(devRect.bottom(), devRect.top()); + sMap.setPaintInterval( rect.bottom(), rect.top() ); for ( int y = devRect.top(); y <= devRect.bottom(); y++ ) { - const double value = sMap.invTransform(y); + const double value = sMap.invTransform( y ); if ( colorMap.format() == QwtColorMap::RGB ) - c.setRgb(colorMap.rgb(interval, value)); + c.setRgb( colorMap.rgb( interval, value ) ); else - c = colorTable[colorMap.colorIndex(interval, value)]; + c = colorTable[colorMap.colorIndex( interval, value )]; - pmPainter.setPen(c); - pmPainter.drawLine(devRect.left(), y, devRect.right(), y); + pmPainter.setPen( c ); + pmPainter.drawLine( devRect.left(), y, devRect.right(), y ); } } pmPainter.end(); - painter->drawPixmap(devRect, pixmap); + + drawPixmap( painter, rect, pixmap ); } - -/*! - \brief Scale a pen according to the layout metrics - - The width of non cosmetic pens is scaled from screen to layout metrics, - so that they look similar on paint devices with different resolutions. - - \param pen Unscaled pen - \return Scaled pen -*/ - -QPen QwtPainter::scaledPen(const QPen &pen) -{ -#if QT_VERSION < 0x040000 - return pen; -#else - QPen sPen = pen; - - if ( !pen.isCosmetic() ) - { - int pw = pen.width(); - if ( pw == 0 ) - pw = 1; - - sPen.setWidth(QwtPainter::metricsMap().screenToLayoutX(pw)); - sPen.setCosmetic(true); - } - - return sPen; -#endif -} - diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_painter.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_painter.h index 814aa0e54..4393fd410 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_painter.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_painter.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -10,150 +10,140 @@ #ifndef QWT_PAINTER_H #define QWT_PAINTER_H +#include "qwt_global.h" + #include #include #include -#include "qwt_global.h" -#include "qwt_layout_metrics.h" -#include "qwt_polygon.h" +#include class QPainter; class QBrush; class QColor; class QWidget; +class QPolygonF; +class QRectF; +class QImage; +class QPixmap; class QwtScaleMap; class QwtColorMap; -class QwtDoubleInterval; +class QwtInterval; -#if QT_VERSION < 0x040000 -class QColorGroup; -class QSimpleRichText; -#else class QPalette; class QTextDocument; -#endif - -#if defined(Q_WS_X11) -// Warning: QCOORD_MIN, QCOORD_MAX are wrong on X11. -#define QWT_COORD_MAX 16384 -#define QWT_COORD_MIN (-QWT_COORD_MAX - 1) -#else -#define QWT_COORD_MAX 2147483647 -#define QWT_COORD_MIN -QWT_COORD_MAX - 1 -#endif +class QPainterPath; /*! \brief A collection of QPainter workarounds - - 1) Clipping to coordinate system limits (Qt3 only) - - On X11 pixel coordinates are stored in shorts. Qt - produces overruns when mapping QCOORDS to shorts. - - 2) Scaling to device metrics - - QPainter scales fonts, line and fill patterns to the metrics - of the paint device. Other values like the geometries of rects, points - remain device independend. To enable a device independent widget - implementation, QwtPainter adds scaling of these geometries. - (Unfortunately QPainter::scale scales both types of paintings, - so the objects of the first type would be scaled twice). */ - class QWT_EXPORT QwtPainter { public: - static void setMetricsMap(const QPaintDevice *layout, - const QPaintDevice *device); - static void setMetricsMap(const QwtMetricsMap &); - static void resetMetricsMap(); - static const QwtMetricsMap &metricsMap(); + static void setPolylineSplitting( bool ); + static bool polylineSplitting(); - static void setDeviceClipping(bool); - static bool deviceClipping(); - static const QRect &deviceClipRect(); + static void setRoundingAlignment( bool ); + static bool roundingAlignment(); + static bool roundingAlignment(QPainter *); - static void setClipRect(QPainter *, const QRect &); - - static void drawText(QPainter *, int x, int y, - const QString &); - static void drawText(QPainter *, const QPoint &, - const QString &); - static void drawText(QPainter *, int x, int y, int w, int h, - int flags, const QString &); - static void drawText(QPainter *, const QRect &, - int flags, const QString &); + static void drawText( QPainter *, double x, double y, const QString & ); + static void drawText( QPainter *, const QPointF &, const QString & ); + static void drawText( QPainter *, double x, double y, double w, double h, + int flags, const QString & ); + static void drawText( QPainter *, const QRectF &, + int flags, const QString & ); #ifndef QT_NO_RICHTEXT -#if QT_VERSION < 0x040000 - static void drawSimpleRichText(QPainter *, const QRect &, - int flags, QSimpleRichText &); -#else - static void drawSimpleRichText(QPainter *, const QRect &, - int flags, QTextDocument &); -#endif + static void drawSimpleRichText( QPainter *, const QRectF &, + int flags, const QTextDocument & ); #endif - static void drawRect(QPainter *, int x, int y, int w, int h); - static void drawRect(QPainter *, const QRect &rect); - static void fillRect(QPainter *, const QRect &, const QBrush &); + static void drawRect( QPainter *, double x, double y, double w, double h ); + static void drawRect( QPainter *, const QRectF &rect ); + static void fillRect( QPainter *, const QRectF &, const QBrush & ); - static void drawEllipse(QPainter *, const QRect &); - static void drawPie(QPainter *, const QRect & r, int a, int alen); + static void drawEllipse( QPainter *, const QRectF & ); + static void drawPie( QPainter *, const QRectF & r, int a, int alen ); - static void drawLine(QPainter *, int x1, int y1, int x2, int y2); - static void drawLine(QPainter *, const QPoint &p1, const QPoint &p2); - static void drawPolygon(QPainter *, const QwtPolygon &pa); - static void drawPolyline(QPainter *, const QwtPolygon &pa); - static void drawPoint(QPainter *, int x, int y); + static void drawLine( QPainter *, double x1, double y1, double x2, double y2 ); + static void drawLine( QPainter *, const QPointF &p1, const QPointF &p2 ); + static void drawLine( QPainter *, const QLineF & ); -#if QT_VERSION < 0x040000 - static void drawRoundFrame(QPainter *, const QRect &, - int width, const QColorGroup &cg, bool sunken); -#else - static void drawRoundFrame(QPainter *, const QRect &, - int width, const QPalette &, bool sunken); -#endif - static void drawFocusRect(QPainter *, QWidget *); - static void drawFocusRect(QPainter *, QWidget *, const QRect &); + static void drawPolygon( QPainter *, const QPolygonF &pa ); + static void drawPolyline( QPainter *, const QPolygonF &pa ); + static void drawPolyline( QPainter *, const QPointF *, int pointCount ); - static void drawColorBar(QPainter *painter, - const QwtColorMap &, const QwtDoubleInterval &, - const QwtScaleMap &, Qt::Orientation, const QRect &); + static void drawPoint( QPainter *, double x, double y ); + static void drawPoint( QPainter *, const QPointF & ); -#if QT_VERSION < 0x040000 - static void setSVGMode(bool on); - static bool isSVGMode(); -#endif + static void drawPath( QPainter *, const QPainterPath & ); + static void drawImage( QPainter *, const QRectF &, const QImage & ); + static void drawPixmap( QPainter *, const QRectF &, const QPixmap & ); - static QPen scaledPen(const QPen &); + static void drawRoundedFrame( QPainter *, + const QRectF &, double xRadius, double yRadius, + const QPalette &, int lineWidth, int frameStyle ); + + static void drawFocusRect( QPainter *, QWidget * ); + static void drawFocusRect( QPainter *, QWidget *, const QRect & ); + + static void drawColorBar( QPainter *painter, + const QwtColorMap &, const QwtInterval &, + const QwtScaleMap &, Qt::Orientation, const QRectF & ); + + static bool isAligning( QPainter *painter ); private: - static void drawColoredArc(QPainter *, const QRect &, - int peak, int arc, int intervall, const QColor &c1, const QColor &c2); - - static bool d_deviceClipping; - static QwtMetricsMap d_metricsMap; -#if QT_VERSION < 0x040000 - static bool d_SVGMode; -#endif + static bool d_polylineSplitting; + static bool d_roundingAlignment; }; -//! Wrapper for QPainter::drawLine() -inline void QwtPainter::drawLine(QPainter *painter, - const QPoint &p1, const QPoint &p2) +//! Wrapper for QPainter::drawPoint() +inline void QwtPainter::drawPoint( QPainter *painter, double x, double y ) { - drawLine(painter, p1.x(), p1.y(), p2.x(), p2.y()); + QwtPainter::drawPoint( painter, QPointF( x, y ) ); +} + +//! Wrapper for QPainter::drawLine() +inline void QwtPainter::drawLine( QPainter *painter, + double x1, double y1, double x2, double y2 ) +{ + QwtPainter::drawLine( painter, QPointF( x1, y1 ), QPointF( x2, y2 ) ); +} + +//! Wrapper for QPainter::drawLine() +inline void QwtPainter::drawLine( QPainter *painter, const QLineF &line ) +{ + QwtPainter::drawLine( painter, line.p1(), line.p2() ); } /*! - Returns whether device clipping is enabled. On X11 the default - is enabled, otherwise it is disabled. - \sa QwtPainter::setDeviceClipping() + Returns whether line splitting for the raster paint engine is enabled. + \sa setPolylineSplitting() */ -inline bool QwtPainter::deviceClipping() +inline bool QwtPainter::polylineSplitting() { - return d_deviceClipping; + return d_polylineSplitting; } +/*! + Returns whether coordinates should be rounded, before they are painted + to a paint engine that floors to integer values. For other paint engines + this ( Pdf, SVG ), this flag has no effect. + + \sa setRoundingAlignment(), isAligning() +*/ +inline bool QwtPainter::roundingAlignment() +{ + return d_roundingAlignment; +} + +/*! + \return roundingAlignment() && isAligning(painter); + \param painter Painter +*/ +inline bool QwtPainter::roundingAlignment(QPainter *painter) +{ + return d_roundingAlignment && isAligning(painter); +} #endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_panner.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_panner.cpp index 7424639a6..ff0b6a735 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_panner.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_panner.cpp @@ -7,55 +7,29 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - +#include "qwt_panner.h" +#include "qwt_picker.h" #include #include #include -#include #include -#if QT_VERSION < 0x040000 -#include -#endif -#include "qwt_picker.h" -#include "qwt_array.h" -#include "qwt_panner.h" +#include -static QwtArray activePickers(QWidget *w) +static QVector qwtActivePickers( QWidget *w ) { - QwtArray pickers; + QVector pickers; -#if QT_VERSION >= 0x040000 QObjectList children = w->children(); for ( int i = 0; i < children.size(); i++ ) { QObject *obj = children[i]; - if ( obj->inherits("QwtPicker") ) + if ( obj->inherits( "QwtPicker" ) ) { - QwtPicker *picker = (QwtPicker *)obj; + QwtPicker *picker = ( QwtPicker * )obj; if ( picker->isEnabled() ) pickers += picker; } } -#else - QObjectList *children = (QObjectList *)w->children(); - if ( children ) - { - for ( QObjectListIterator it(*children); it.current(); ++it ) - { - QObject *obj = (QObject *)it.current(); - if ( obj->inherits("QwtPicker") ) - { - QwtPicker *picker = (QwtPicker *)obj; - if ( picker->isEnabled() ) - { - pickers.resize(pickers.size() + 1); - pickers[int(pickers.size()) - 1] = picker; - } - } - } - } -#endif return pickers; } @@ -64,23 +38,18 @@ class QwtPanner::PrivateData { public: PrivateData(): - button(Qt::LeftButton), - buttonState(Qt::NoButton), - abortKey(Qt::Key_Escape), - abortKeyState(Qt::NoButton), + button( Qt::LeftButton ), + buttonState( Qt::NoButton ), + abortKey( Qt::Key_Escape ), + abortKeyState( Qt::NoButton ), #ifndef QT_NO_CURSOR - cursor(NULL), - restoreCursor(NULL), - hasCursor(false), + cursor( NULL ), + restoreCursor( NULL ), + hasCursor( false ), #endif - isEnabled(false) + isEnabled( false ) { -#if QT_VERSION >= 0x040000 orientations = Qt::Vertical | Qt::Horizontal; -#else - orientations[Qt::Vertical] = true; - orientations[Qt::Horizontal] = true; -#endif } ~PrivateData() @@ -90,7 +59,7 @@ public: delete restoreCursor; #endif } - + int button; int buttonState; int abortKey; @@ -100,17 +69,15 @@ public: QPoint pos; QPixmap pixmap; + QBitmap contentsMask; + #ifndef QT_NO_CURSOR QCursor *cursor; QCursor *restoreCursor; bool hasCursor; #endif bool isEnabled; -#if QT_VERSION >= 0x040000 Qt::Orientations orientations; -#else - bool orientations[2]; -#endif }; /*! @@ -118,22 +85,17 @@ public: \param parent Parent widget to be panned */ -QwtPanner::QwtPanner(QWidget *parent): - QWidget(parent) +QwtPanner::QwtPanner( QWidget *parent ): + QWidget( parent ) { d_data = new PrivateData(); -#if QT_VERSION >= 0x040000 - setAttribute(Qt::WA_TransparentForMouseEvents); - setAttribute(Qt::WA_NoSystemBackground); - setFocusPolicy(Qt::NoFocus); -#else - setBackgroundMode(Qt::NoBackground); - setFocusPolicy(QWidget::NoFocus); -#endif + setAttribute( Qt::WA_TransparentForMouseEvents ); + setAttribute( Qt::WA_NoSystemBackground ); + setFocusPolicy( Qt::NoFocus ); hide(); - setEnabled(true); + setEnabled( true ); } //! Destructor @@ -146,14 +108,14 @@ QwtPanner::~QwtPanner() Change the mouse button The defaults are Qt::LeftButton and Qt::NoButton */ -void QwtPanner::setMouseButton(int button, int buttonState) +void QwtPanner::setMouseButton( int button, int buttonState ) { d_data->button = button; d_data->buttonState = buttonState; } //! Get the mouse button -void QwtPanner::getMouseButton(int &button, int &buttonState) const +void QwtPanner::getMouseButton( int &button, int &buttonState ) const { button = d_data->button; buttonState = d_data->buttonState; @@ -166,14 +128,14 @@ void QwtPanner::getMouseButton(int &button, int &buttonState) const \param key Key ( See Qt::Keycode ) \param state State */ -void QwtPanner::setAbortKey(int key, int state) +void QwtPanner::setAbortKey( int key, int state ) { d_data->abortKey = key; d_data->abortKeyState = state; } //! Get the abort key -void QwtPanner::getAbortKey(int &key, int &state) const +void QwtPanner::getAbortKey( int &key, int &state ) const { key = d_data->abortKey; state = d_data->abortKeyState; @@ -188,9 +150,9 @@ void QwtPanner::getAbortKey(int &key, int &state) const \sa setCursor() */ #ifndef QT_NO_CURSOR -void QwtPanner::setCursor(const QCursor &cursor) +void QwtPanner::setCursor( const QCursor &cursor ) { - d_data->cursor = new QCursor(cursor); + d_data->cursor = new QCursor( cursor ); } #endif @@ -211,16 +173,16 @@ const QCursor QwtPanner::cursor() const } #endif -/*! +/*! \brief En/disable the panner - + When enabled is true an event filter is installed for the observed widget, otherwise the event filter is removed. \param on true or false \sa isEnabled(), eventFilter() */ -void QwtPanner::setEnabled(bool on) +void QwtPanner::setEnabled( bool on ) { if ( d_data->isEnabled != on ) { @@ -231,25 +193,24 @@ void QwtPanner::setEnabled(bool on) { if ( d_data->isEnabled ) { - w->installEventFilter(this); + w->installEventFilter( this ); } else { - w->removeEventFilter(this); + w->removeEventFilter( this ); hide(); } } } } -#if QT_VERSION >= 0x040000 /*! Set the orientations, where panning is enabled The default value is in both directions: Qt::Horizontal | Qt::Vertical /param o Orientation */ -void QwtPanner::setOrientations(Qt::Orientations o) +void QwtPanner::setOrientations( Qt::Orientations o ) { d_data->orientations = o; } @@ -260,27 +221,13 @@ Qt::Orientations QwtPanner::orientations() const return d_data->orientations; } -#else -void QwtPanner::enableOrientation(Qt::Orientation o, bool enable) -{ - if ( o == Qt::Vertical || o == Qt::Horizontal ) - d_data->orientations[o] = enable; -} -#endif - -/*! +/*! Return true if a orientatio is enabled \sa orientations(), setOrientations() */ -bool QwtPanner::isOrientationEnabled(Qt::Orientation o) const +bool QwtPanner::isOrientationEnabled( Qt::Orientation o ) const { -#if QT_VERSION >= 0x040000 return d_data->orientations & o; -#else - if ( o == Qt::Vertical || o == Qt::Horizontal ) - return d_data->orientations[o]; - return false; -#endif } /*! @@ -300,77 +247,103 @@ bool QwtPanner::isEnabled() const \param pe Paint event */ -void QwtPanner::paintEvent(QPaintEvent *pe) +void QwtPanner::paintEvent( QPaintEvent *pe ) { - QPixmap pm(size()); - - QPainter painter(&pm); - - const QColor bg = -#if QT_VERSION < 0x040000 - parentWidget()->palette().color( - QPalette::Normal, QColorGroup::Background); -#else - parentWidget()->palette().color( - QPalette::Normal, QPalette::Background); -#endif - - painter.setPen(Qt::NoPen); - painter.setBrush(QBrush(bg)); - painter.drawRect(0, 0, pm.width(), pm.height()); - int dx = d_data->pos.x() - d_data->initialPos.x(); int dy = d_data->pos.y() - d_data->initialPos.y(); - QRect r(0, 0, d_data->pixmap.width(), d_data->pixmap.height()); - r.moveCenter(QPoint(r.center().x() + dx, r.center().y() + dy)); + QRect r( 0, 0, d_data->pixmap.width(), d_data->pixmap.height() ); + r.moveCenter( QPoint( r.center().x() + dx, r.center().y() + dy ) ); + + QPixmap pm( size() ); + pm.fill( parentWidget(), 0, 0 ); + + QPainter painter( &pm ); + + if ( !d_data->contentsMask.isNull() ) + { + QPixmap masked = d_data->pixmap; + masked.setMask( d_data->contentsMask ); + painter.drawPixmap( r, masked ); + } + else + { + painter.drawPixmap( r, d_data->pixmap ); + } - painter.drawPixmap(r, d_data->pixmap); painter.end(); - painter.begin(this); - painter.setClipRegion(pe->region()); - painter.drawPixmap(0, 0, pm); + if ( !d_data->contentsMask.isNull() ) + pm.setMask( d_data->contentsMask ); + + painter.begin( this ); + painter.setClipRegion( pe->region() ); + painter.drawPixmap( 0, 0, pm ); } -/*! +/*! + \brief Calculate a mask for the contents of the panned widget + + Sometimes only parts of the contents of a widget should be + panned. F.e. for a widget with a styled background with rounded borders + only the area inside of the border should be panned. + + \return An empty bitmap, indicating no mask +*/ +QBitmap QwtPanner::contentsMask() const +{ + return QBitmap(); +} + +/*! + Grab the widget into a pixmap. +*/ +QPixmap QwtPanner::grab() const +{ + return QPixmap::grabWidget( parentWidget() ); +} + +/*! \brief Event filter When isEnabled() the mouse events of the observed widget are filtered. + \param object Object to be filtered + \param event Event + \sa widgetMousePressEvent(), widgetMouseReleaseEvent(), widgetMouseMoveEvent() */ -bool QwtPanner::eventFilter(QObject *o, QEvent *e) +bool QwtPanner::eventFilter( QObject *object, QEvent *event ) { - if ( o == NULL || o != parentWidget() ) + if ( object == NULL || object != parentWidget() ) return false; - switch(e->type()) + switch ( event->type() ) { case QEvent::MouseButtonPress: { - widgetMousePressEvent((QMouseEvent *)e); + widgetMousePressEvent( ( QMouseEvent * )event ); break; } case QEvent::MouseMove: { - widgetMouseMoveEvent((QMouseEvent *)e); + widgetMouseMoveEvent( ( QMouseEvent * )event ); break; } case QEvent::MouseButtonRelease: { - widgetMouseReleaseEvent((QMouseEvent *)e); + widgetMouseReleaseEvent( ( QMouseEvent * )event ); break; } case QEvent::KeyPress: { - widgetKeyPressEvent((QKeyEvent *)e); + widgetKeyPressEvent( ( QKeyEvent * )event ); break; } case QEvent::KeyRelease: { - widgetKeyReleaseEvent((QKeyEvent *)e); + widgetKeyReleaseEvent( ( QKeyEvent * )event ); break; } case QEvent::Paint: @@ -388,54 +361,43 @@ bool QwtPanner::eventFilter(QObject *o, QEvent *e) /*! Handle a mouse press event for the observed widget. - \param me Mouse event + \param mouseEvent Mouse event \sa eventFilter(), widgetMouseReleaseEvent(), widgetMouseMoveEvent(), */ -void QwtPanner::widgetMousePressEvent(QMouseEvent *me) +void QwtPanner::widgetMousePressEvent( QMouseEvent *mouseEvent ) { - if ( me->button() != d_data->button ) + if ( mouseEvent->button() != d_data->button ) return; QWidget *w = parentWidget(); if ( w == NULL ) return; -#if QT_VERSION < 0x040000 - if ( (me->state() & Qt::KeyButtonMask) != - (d_data->buttonState & Qt::KeyButtonMask) ) -#else - if ( (me->modifiers() & Qt::KeyboardModifierMask) != - (int)(d_data->buttonState & Qt::KeyboardModifierMask) ) -#endif + if ( ( mouseEvent->modifiers() & Qt::KeyboardModifierMask ) != + ( int )( d_data->buttonState & Qt::KeyboardModifierMask ) ) { return; } #ifndef QT_NO_CURSOR - showCursor(true); + showCursor( true ); #endif - d_data->initialPos = d_data->pos = me->pos(); + d_data->initialPos = d_data->pos = mouseEvent->pos(); - QRect cr = parentWidget()->rect(); - if ( parentWidget()->inherits("QFrame") ) - { - const QFrame* frame = (QFrame*)parentWidget(); - cr = frame->contentsRect(); - } - setGeometry(cr); + setGeometry( parentWidget()->rect() ); // We don't want to grab the picker ! - QwtArray pickers = activePickers(parentWidget()); - for ( int i = 0; i < (int)pickers.size(); i++ ) - pickers[i]->setEnabled(false); + QVector pickers = qwtActivePickers( parentWidget() ); + for ( int i = 0; i < ( int )pickers.size(); i++ ) + pickers[i]->setEnabled( false ); - d_data->pixmap = QPixmap::grabWidget(parentWidget(), - cr.x(), cr.y(), cr.width(), cr.height()); + d_data->pixmap = grab(); + d_data->contentsMask = contentsMask(); - for ( int i = 0; i < (int)pickers.size(); i++ ) - pickers[i]->setEnabled(true); + for ( int i = 0; i < ( int )pickers.size(); i++ ) + pickers[i]->setEnabled( true ); show(); } @@ -443,59 +405,60 @@ void QwtPanner::widgetMousePressEvent(QMouseEvent *me) /*! Handle a mouse move event for the observed widget. - \param me Mouse event + \param mouseEvent Mouse event \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent() */ -void QwtPanner::widgetMouseMoveEvent(QMouseEvent *me) +void QwtPanner::widgetMouseMoveEvent( QMouseEvent *mouseEvent ) { if ( !isVisible() ) return; - QPoint pos = me->pos(); - if ( !isOrientationEnabled(Qt::Horizontal) ) - pos.setX(d_data->initialPos.x()); - if ( !isOrientationEnabled(Qt::Vertical) ) - pos.setY(d_data->initialPos.y()); + QPoint pos = mouseEvent->pos(); + if ( !isOrientationEnabled( Qt::Horizontal ) ) + pos.setX( d_data->initialPos.x() ); + if ( !isOrientationEnabled( Qt::Vertical ) ) + pos.setY( d_data->initialPos.y() ); - if ( pos != d_data->pos && rect().contains(pos) ) + if ( pos != d_data->pos && rect().contains( pos ) ) { d_data->pos = pos; update(); - emit moved(d_data->pos.x() - d_data->initialPos.x(), - d_data->pos.y() - d_data->initialPos.y()); + Q_EMIT moved( d_data->pos.x() - d_data->initialPos.x(), + d_data->pos.y() - d_data->initialPos.y() ); } } /*! Handle a mouse release event for the observed widget. - \param me Mouse event + \param mouseEvent Mouse event \sa eventFilter(), widgetMousePressEvent(), widgetMouseMoveEvent(), */ -void QwtPanner::widgetMouseReleaseEvent(QMouseEvent *me) +void QwtPanner::widgetMouseReleaseEvent( QMouseEvent *mouseEvent ) { if ( isVisible() ) { hide(); #ifndef QT_NO_CURSOR - showCursor(false); + showCursor( false ); #endif - QPoint pos = me->pos(); - if ( !isOrientationEnabled(Qt::Horizontal) ) - pos.setX(d_data->initialPos.x()); - if ( !isOrientationEnabled(Qt::Vertical) ) - pos.setY(d_data->initialPos.y()); + QPoint pos = mouseEvent->pos(); + if ( !isOrientationEnabled( Qt::Horizontal ) ) + pos.setX( d_data->initialPos.x() ); + if ( !isOrientationEnabled( Qt::Vertical ) ) + pos.setY( d_data->initialPos.y() ); d_data->pixmap = QPixmap(); + d_data->contentsMask = QBitmap(); d_data->pos = pos; if ( d_data->pos != d_data->initialPos ) { - emit panned(d_data->pos.x() - d_data->initialPos.x(), - d_data->pos.y() - d_data->initialPos.y()); + Q_EMIT panned( d_data->pos.x() - d_data->initialPos.x(), + d_data->pos.y() - d_data->initialPos.y() ); } } } @@ -503,26 +466,21 @@ void QwtPanner::widgetMouseReleaseEvent(QMouseEvent *me) /*! Handle a key press event for the observed widget. - \param ke Key event + \param keyEvent Key event \sa eventFilter(), widgetKeyReleaseEvent() */ -void QwtPanner::widgetKeyPressEvent(QKeyEvent *ke) +void QwtPanner::widgetKeyPressEvent( QKeyEvent *keyEvent ) { - if ( ke->key() == d_data->abortKey ) + if ( keyEvent->key() == d_data->abortKey ) { const bool matched = -#if QT_VERSION < 0x040000 - (ke->state() & Qt::KeyButtonMask) == - (d_data->abortKeyState & Qt::KeyButtonMask); -#else - (ke->modifiers() & Qt::KeyboardModifierMask) == - (int)(d_data->abortKeyState & Qt::KeyboardModifierMask); -#endif + ( keyEvent->modifiers() & Qt::KeyboardModifierMask ) == + ( int )( d_data->abortKeyState & Qt::KeyboardModifierMask ); if ( matched ) { hide(); #ifndef QT_NO_CURSOR - showCursor(false); + showCursor( false ); #endif d_data->pixmap = QPixmap(); } @@ -531,14 +489,17 @@ void QwtPanner::widgetKeyPressEvent(QKeyEvent *ke) /*! Handle a key release event for the observed widget. + + \param keyEvent Key event \sa eventFilter(), widgetKeyReleaseEvent() */ -void QwtPanner::widgetKeyReleaseEvent(QKeyEvent *) +void QwtPanner::widgetKeyReleaseEvent( QKeyEvent *keyEvent ) { + Q_UNUSED( keyEvent ); } #ifndef QT_NO_CURSOR -void QwtPanner::showCursor(bool on) +void QwtPanner::showCursor( bool on ) { if ( on == d_data->hasCursor ) return; @@ -551,22 +512,18 @@ void QwtPanner::showCursor(bool on) if ( on ) { -#if QT_VERSION < 0x040000 - if ( w->testWState(WState_OwnCursor) ) -#else - if ( w->testAttribute(Qt::WA_SetCursor) ) -#endif + if ( w->testAttribute( Qt::WA_SetCursor ) ) { delete d_data->restoreCursor; - d_data->restoreCursor = new QCursor(w->cursor()); + d_data->restoreCursor = new QCursor( w->cursor() ); } - w->setCursor(*d_data->cursor); + w->setCursor( *d_data->cursor ); } else { - if ( d_data->restoreCursor ) + if ( d_data->restoreCursor ) { - w->setCursor(*d_data->restoreCursor); + w->setCursor( *d_data->restoreCursor ); delete d_data->restoreCursor; d_data->restoreCursor = NULL; } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_panner.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_panner.h index d01df690f..166873614 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_panner.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_panner.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -10,9 +10,9 @@ #ifndef QWT_PANNER_H #define QWT_PANNER_H 1 -#include -#include #include "qwt_global.h" +#include +#include class QCursor; @@ -22,12 +22,12 @@ class QCursor; QwtPanner grabs the contents of a widget, that can be dragged in all directions. The offset between the start and the end position is emitted by the panned signal. - + QwtPanner grabs the content of the widget into a pixmap and moves the pixmap around, without initiating any repaint events for the widget. - Areas, that are not part of content are not painted while panning - in in process. This makes panning fast enough for widgets, where - repaints are too slow for mouse movements. + Areas, that are not part of content are not painted while panning. + This makes panning fast enough for widgets, where + repaints are too slow for mouse movements. For widgets, where repaints are very fast it might be better to implement panning manually by mapping mouse events into paint events. @@ -37,39 +37,35 @@ class QWT_EXPORT QwtPanner: public QWidget Q_OBJECT public: - QwtPanner(QWidget* parent); + QwtPanner( QWidget* parent ); virtual ~QwtPanner(); - void setEnabled(bool); + void setEnabled( bool ); bool isEnabled() const; - void setMouseButton(int button, int buttonState = Qt::NoButton); - void getMouseButton(int &button, int &buttonState) const; - void setAbortKey(int key, int state = Qt::NoButton); - void getAbortKey(int &key, int &state) const; + void setMouseButton( int button, int buttonState = Qt::NoButton ); + void getMouseButton( int &button, int &buttonState ) const; + void setAbortKey( int key, int state = Qt::NoButton ); + void getAbortKey( int &key, int &state ) const; - void setCursor(const QCursor &); + void setCursor( const QCursor & ); const QCursor cursor() const; -#if QT_VERSION >= 0x040000 - void setOrientations(Qt::Orientations); + void setOrientations( Qt::Orientations ); Qt::Orientations orientations() const; -#else - void enableOrientation(Qt::Orientation, bool enable); -#endif - bool isOrientationEnabled(Qt::Orientation) const; + bool isOrientationEnabled( Qt::Orientation ) const; - virtual bool eventFilter(QObject *, QEvent *); + virtual bool eventFilter( QObject *, QEvent * ); -signals: +Q_SIGNALS: /*! Signal emitted, when panning is done \param dx Offset in horizontal direction \param dy Offset in vertical direction */ - void panned(int dx, int dy); + void panned( int dx, int dy ); /*! Signal emitted, while the widget moved, but panning @@ -78,20 +74,23 @@ signals: \param dx Offset in horizontal direction \param dy Offset in vertical direction */ - void moved(int dx, int dy); + void moved( int dx, int dy ); protected: - virtual void widgetMousePressEvent(QMouseEvent *); - virtual void widgetMouseReleaseEvent(QMouseEvent *); - virtual void widgetMouseMoveEvent(QMouseEvent *); - virtual void widgetKeyPressEvent(QKeyEvent *); - virtual void widgetKeyReleaseEvent(QKeyEvent *); + virtual void widgetMousePressEvent( QMouseEvent * ); + virtual void widgetMouseReleaseEvent( QMouseEvent * ); + virtual void widgetMouseMoveEvent( QMouseEvent * ); + virtual void widgetKeyPressEvent( QKeyEvent * ); + virtual void widgetKeyReleaseEvent( QKeyEvent * ); - virtual void paintEvent(QPaintEvent *); + virtual void paintEvent( QPaintEvent * ); + + virtual QBitmap contentsMask() const; + virtual QPixmap grab() const; private: #ifndef QT_NO_CURSOR - void showCursor(bool); + void showCursor( bool ); #endif class PrivateData; diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_picker.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_picker.cpp index fae7789c6..ddca36b43 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_picker.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_picker.cpp @@ -7,22 +7,19 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ +#include "qwt_picker.h" +#include "qwt_picker_machine.h" +#include "qwt_painter.h" +#include "qwt_math.h" #include #include #include #include #include #include -#include "qwt_math.h" -#include "qwt_painter.h" -#include "qwt_picker_machine.h" -#include "qwt_picker.h" -#if QT_VERSION < 0x040000 -#include -#else #include #include -#endif +#include class QwtPicker::PickerWidget: public QWidget { @@ -33,18 +30,18 @@ public: Text }; - PickerWidget(QwtPicker *, QWidget *, Type); - virtual void updateMask(); + PickerWidget( QwtPicker *, QWidget *, Type ); + void updateMask(); /* - For a tracker text with a background we can use the background + For a tracker text with a background we can use the background rect as mask. Also for "regular" Qt widgets >= 4.3.0 we don't need to mask the text anymore. */ bool d_hasTextMask; protected: - virtual void paintEvent(QPaintEvent *); + virtual void paintEvent( QPaintEvent * ); QwtPicker *d_picker; Type d_type; @@ -57,7 +54,6 @@ public: QwtPickerMachine *stateMachine; - int selectionFlags; QwtPicker::ResizeMode resizeMode; QwtPicker::RubberBand rubberBand; @@ -67,7 +63,7 @@ public: QPen trackerPen; QFont trackerFont; - QwtPolygon selection; + QPolygon pickedPoints; bool isActive; QPoint trackerPosition; @@ -79,33 +75,21 @@ public: In case of (f.e) a CrossRubberBand and a text this creates complete repaints of the widget. So we better use two different widgets. */ - -#if QT_VERSION < 0x040000 - QGuardedPtr rubberBandWidget; - QGuardedPtr trackerWidget; -#else + QPointer rubberBandWidget; QPointer trackerWidget; -#endif }; QwtPicker::PickerWidget::PickerWidget( - QwtPicker *picker, QWidget *parent, Type type): - QWidget(parent), - d_hasTextMask(false), - d_picker(picker), - d_type(type) + QwtPicker *picker, QWidget *parent, Type type ): + QWidget( parent ), + d_hasTextMask( false ), + d_picker( picker ), + d_type( type ) { -#if QT_VERSION >= 0x040000 - setAttribute(Qt::WA_TransparentForMouseEvents); - setAttribute(Qt::WA_NoSystemBackground); - setFocusPolicy(Qt::NoFocus); -#else - setBackgroundMode(Qt::NoBackground); - setFocusPolicy(QWidget::NoFocus); - setMouseTracking(true); -#endif - hide(); + setAttribute( Qt::WA_TransparentForMouseEvents ); + setAttribute( Qt::WA_NoSystemBackground ); + setFocusPolicy( Qt::NoFocus ); } void QwtPicker::PickerWidget::updateMask() @@ -114,103 +98,83 @@ void QwtPicker::PickerWidget::updateMask() if ( d_type == RubberBand ) { - QBitmap bm(width(), height()); - bm.fill(Qt::color0); + QBitmap bm( width(), height() ); + bm.fill( Qt::color0 ); - QPainter painter(&bm); + QPainter painter( &bm ); QPen pen = d_picker->rubberBandPen(); - pen.setColor(Qt::color1); - painter.setPen(pen); + pen.setColor( Qt::color1 ); + painter.setPen( pen ); - d_picker->drawRubberBand(&painter); + d_picker->drawRubberBand( &painter ); - mask = QRegion(bm); + mask = QRegion( bm ); } if ( d_type == Text ) { - d_hasTextMask = true; -#if QT_VERSION >= 0x040300 - if ( !parentWidget()->testAttribute(Qt::WA_PaintOnScreen) ) - { -#if 0 - if ( parentWidget()->paintEngine()->type() != QPaintEngine::OpenGL ) -#endif - { - // With Qt >= 4.3 drawing of the tracker can be implemented in an - // easier way, using the textRect as mask. + d_hasTextMask = parentWidget()->testAttribute( Qt::WA_PaintOnScreen ); - d_hasTextMask = false; - } - } -#endif - if ( d_hasTextMask ) { const QwtText label = d_picker->trackerText( - d_picker->trackerPosition()); - if ( label.testPaintAttribute(QwtText::PaintBackground) + d_picker->trackerPosition() ); + + if ( label.testPaintAttribute( QwtText::PaintBackground ) && label.backgroundBrush().style() != Qt::NoBrush ) { -#if QT_VERSION >= 0x040300 if ( label.backgroundBrush().color().alpha() > 0 ) -#endif - // We don't need a text mask, when we have a background - d_hasTextMask = false; + { + // We don't need a text mask, when we have a background + d_hasTextMask = false; + } } } if ( d_hasTextMask ) { - QBitmap bm(width(), height()); - bm.fill(Qt::color0); + QBitmap bm( width(), height() ); + bm.fill( Qt::color0 ); - QPainter painter(&bm); - painter.setFont(font()); + QPainter painter( &bm ); + painter.setFont( font() ); QPen pen = d_picker->trackerPen(); - pen.setColor(Qt::color1); - painter.setPen(pen); + pen.setColor( Qt::color1 ); + painter.setPen( pen ); - d_picker->drawTracker(&painter); + d_picker->drawTracker( &painter ); - mask = QRegion(bm); + mask = QRegion( bm ); } else { - mask = d_picker->trackerRect(font()); + mask = d_picker->trackerRect( font() ); } } -#if QT_VERSION < 0x040000 QWidget *w = parentWidget(); - const bool doUpdate = w->isUpdatesEnabled(); - const Qt::BackgroundMode bgMode = w->backgroundMode(); - w->setUpdatesEnabled(false); - if ( bgMode != Qt::NoBackground ) - w->setBackgroundMode(Qt::NoBackground); -#endif + if ( w && !w->testAttribute( Qt::WA_PaintOnScreen ) ) + { + // The parent widget gets an update for its complete rectangle + // when the mask is changed in visible state. + // With this hide/show we only get an update for the + // previous mask. - setMask(mask); - -#if QT_VERSION < 0x040000 - if ( bgMode != Qt::NoBackground ) - w->setBackgroundMode(bgMode); - - w->setUpdatesEnabled(doUpdate); -#endif - - setShown(!mask.isEmpty()); + hide(); + } + setMask( mask ); + setVisible( !mask.isEmpty() ); } -void QwtPicker::PickerWidget::paintEvent(QPaintEvent *e) +void QwtPicker::PickerWidget::paintEvent( QPaintEvent *e ) { - QPainter painter(this); - painter.setClipRegion(e->region()); + QPainter painter( this ); + painter.setClipRegion( e->region() ); if ( d_type == RubberBand ) { - painter.setPen(d_picker->rubberBandPen()); - d_picker->drawRubberBand(&painter); + painter.setPen( d_picker->rubberBandPen() ); + d_picker->drawRubberBand( &painter ); } if ( d_type == Text ) @@ -219,59 +183,52 @@ void QwtPicker::PickerWidget::paintEvent(QPaintEvent *e) If we have a text mask we simply fill the region of the mask. This gives better results for antialiased fonts. */ - bool doDrawTracker = !d_hasTextMask; -#if QT_VERSION < 0x040000 - if ( !doDrawTracker && QPainter::redirect(this) ) + if ( d_hasTextMask ) { - // setMask + painter redirection doesn't work - doDrawTracker = true; - } -#endif - if ( doDrawTracker ) - { - painter.setPen(d_picker->trackerPen()); - d_picker->drawTracker(&painter); + painter.fillRect( e->rect(), + QBrush( d_picker->trackerPen().color() ) ); } else - painter.fillRect(e->rect(), QBrush(d_picker->trackerPen().color())); + { + painter.setPen( d_picker->trackerPen() ); + d_picker->drawTracker( &painter ); + } } } /*! Constructor - Creates an picker that is enabled, but where selection flag - is set to NoSelection, rubberband and tracker are disabled. - + Creates an picker that is enabled, but without a state machine. + rubberband and tracker are disabled. + \param parent Parent widget, that will be observed */ -QwtPicker::QwtPicker(QWidget *parent): - QObject(parent) +QwtPicker::QwtPicker( QWidget *parent ): + QObject( parent ) { - init(parent, NoSelection, NoRubberBand, AlwaysOff); + init( parent, NoRubberBand, AlwaysOff ); } /*! Constructor - \param selectionFlags Or'd value of SelectionType, RectSelectionType and - SelectionMode \param rubberBand Rubberband style \param trackerMode Tracker mode \param parent Parent widget, that will be observed */ -QwtPicker::QwtPicker(int selectionFlags, RubberBand rubberBand, - DisplayMode trackerMode, QWidget *parent): - QObject(parent) +QwtPicker::QwtPicker( RubberBand rubberBand, + DisplayMode trackerMode, QWidget *parent ): + QObject( parent ) { - init(parent, selectionFlags, rubberBand, trackerMode); + init( parent, rubberBand, trackerMode ); } //! Destructor QwtPicker::~QwtPicker() { - setMouseTracking(false); + setMouseTracking( false ); delete d_data->stateMachine; delete d_data->rubberBandWidget; delete d_data->trackerWidget; @@ -279,8 +236,8 @@ QwtPicker::~QwtPicker() } //! Init the picker, used by the constructors -void QwtPicker::init(QWidget *parent, int selectionFlags, - RubberBand rubberBand, DisplayMode trackerMode) +void QwtPicker::init( QWidget *parent, + RubberBand rubberBand, DisplayMode trackerMode ) { d_data = new PrivateData; @@ -292,33 +249,30 @@ void QwtPicker::init(QWidget *parent, int selectionFlags, d_data->resizeMode = Stretch; d_data->trackerMode = AlwaysOff; d_data->isActive = false; - d_data->trackerPosition = QPoint(-1, -1); + d_data->trackerPosition = QPoint( -1, -1 ); d_data->mouseTracking = false; d_data->stateMachine = NULL; - setSelectionFlags(selectionFlags); if ( parent ) { -#if QT_VERSION >= 0x040000 if ( parent->focusPolicy() == Qt::NoFocus ) - parent->setFocusPolicy(Qt::WheelFocus); -#else - if ( parent->focusPolicy() == QWidget::NoFocus ) - parent->setFocusPolicy(QWidget::WheelFocus); -#endif + parent->setFocusPolicy( Qt::WheelFocus ); d_data->trackerFont = parent->font(); d_data->mouseTracking = parent->hasMouseTracking(); - setEnabled(true); + setEnabled( true ); } - setTrackerMode(trackerMode); + setTrackerMode( trackerMode ); } /*! - Set a state machine and delete the previous one + Set a state machine and delete the previous one + + \param stateMachine State machine + \sa stateMachine() */ -void QwtPicker::setStateMachine(QwtPickerMachine *stateMachine) +void QwtPicker::setStateMachine( QwtPickerMachine *stateMachine ) { if ( d_data->stateMachine != stateMachine ) { @@ -333,42 +287,21 @@ void QwtPicker::setStateMachine(QwtPickerMachine *stateMachine) } /*! - Create a state machine depending on the selection flags. - - - PointSelection | ClickSelection\n - QwtPickerClickPointMachine() - - PointSelection | DragSelection\n - QwtPickerDragPointMachine() - - RectSelection | ClickSelection\n - QwtPickerClickRectMachine() - - RectSelection | DragSelection\n - QwtPickerDragRectMachine() - - PolygonSelection\n - QwtPickerPolygonMachine() - - \sa setSelectionFlags() + \return Assigned state machine + \sa setStateMachine() */ -QwtPickerMachine *QwtPicker::stateMachine(int flags) const +QwtPickerMachine *QwtPicker::stateMachine() { - if ( flags & PointSelection ) - { - if ( flags & ClickSelection ) - return new QwtPickerClickPointMachine; - else - return new QwtPickerDragPointMachine; - } - if ( flags & RectSelection ) - { - if ( flags & ClickSelection ) - return new QwtPickerClickRectMachine; - else - return new QwtPickerDragRectMachine; - } - if ( flags & PolygonSelection ) - { - return new QwtPickerPolygonMachine(); - } - return NULL; + return d_data->stateMachine; +} + +/*! + \return Assigned state machine + \sa setStateMachine() +*/ +const QwtPickerMachine *QwtPicker::stateMachine() const +{ + return d_data->stateMachine; } //! Return the parent widget, where the selection happens @@ -376,7 +309,7 @@ QWidget *QwtPicker::parentWidget() { QObject *obj = parent(); if ( obj && obj->isWidgetType() ) - return (QWidget *)obj; + return static_cast( obj ); return NULL; } @@ -386,45 +319,20 @@ const QWidget *QwtPicker::parentWidget() const { QObject *obj = parent(); if ( obj && obj->isWidgetType() ) - return (QWidget *)obj; + return static_cast< const QWidget *>( obj ); return NULL; } /*! - Set the selection flags - - \param flags Or'd value of SelectionType, RectSelectionType and - SelectionMode. The default value is NoSelection. - - \sa selectionFlags(), SelectionType, RectSelectionType, SelectionMode -*/ - -void QwtPicker::setSelectionFlags(int flags) -{ - d_data->selectionFlags = flags; - setStateMachine(stateMachine(flags)); -} - -/*! - \return Selection flags, an Or'd value of SelectionType, RectSelectionType and - SelectionMode. - \sa setSelectionFlags(), SelectionType, RectSelectionType, SelectionMode -*/ -int QwtPicker::selectionFlags() const -{ - return d_data->selectionFlags; -} - -/*! - Set the rubberband style + Set the rubberband style \param rubberBand Rubberband style The default value is NoRubberBand. \sa rubberBand(), RubberBand, setRubberBandPen() */ -void QwtPicker::setRubberBand(RubberBand rubberBand) +void QwtPicker::setRubberBand( RubberBand rubberBand ) { d_data->rubberBand = rubberBand; } @@ -446,7 +354,7 @@ QwtPicker::RubberBand QwtPicker::rubberBand() const if the tracker has to be displayed whenever the observed widget has focus and cursor (AlwaysOn), never (AlwaysOff), or only when the selection is active (ActiveOnly). - + \param mode Tracker display mode \warning In case of AlwaysOn, mouseTracking will be enabled @@ -454,23 +362,23 @@ QwtPicker::RubberBand QwtPicker::rubberBand() const \sa trackerMode(), DisplayMode */ -void QwtPicker::setTrackerMode(DisplayMode mode) -{ +void QwtPicker::setTrackerMode( DisplayMode mode ) +{ if ( d_data->trackerMode != mode ) { d_data->trackerMode = mode; - setMouseTracking(d_data->trackerMode == AlwaysOn); + setMouseTracking( d_data->trackerMode == AlwaysOn ); } -} +} /*! \return Tracker display mode \sa setTrackerMode(), DisplayMode */ QwtPicker::DisplayMode QwtPicker::trackerMode() const -{ +{ return d_data->trackerMode; -} +} /*! \brief Set the resize mode. @@ -486,10 +394,10 @@ QwtPicker::DisplayMode QwtPicker::trackerMode() const \param mode Resize mode \sa resizeMode(), ResizeMode */ -void QwtPicker::setResizeMode(ResizeMode mode) +void QwtPicker::setResizeMode( ResizeMode mode ) { d_data->resizeMode = mode; -} +} /*! \return Resize mode @@ -497,7 +405,7 @@ void QwtPicker::setResizeMode(ResizeMode mode) */ QwtPicker::ResizeMode QwtPicker::resizeMode() const -{ +{ return d_data->resizeMode; } @@ -510,7 +418,7 @@ QwtPicker::ResizeMode QwtPicker::resizeMode() const \param enabled true or false \sa isEnabled(), eventFilter() */ -void QwtPicker::setEnabled(bool enabled) +void QwtPicker::setEnabled( bool enabled ) { if ( d_data->enabled != enabled ) { @@ -520,9 +428,9 @@ void QwtPicker::setEnabled(bool enabled) if ( w ) { if ( enabled ) - w->installEventFilter(this); + w->installEventFilter( this ); else - w->removeEventFilter(this); + w->removeEventFilter( this ); } updateDisplay(); @@ -545,7 +453,7 @@ bool QwtPicker::isEnabled() const \param font Tracker font \sa trackerFont(), setTrackerMode(), setTrackerPen() */ -void QwtPicker::setTrackerFont(const QFont &font) +void QwtPicker::setTrackerFont( const QFont &font ) { if ( font != d_data->trackerFont ) { @@ -570,7 +478,7 @@ QFont QwtPicker::trackerFont() const \param pen Tracker pen \sa trackerPen(), setTrackerMode(), setTrackerFont() */ -void QwtPicker::setTrackerPen(const QPen &pen) +void QwtPicker::setTrackerPen( const QPen &pen ) { if ( pen != d_data->trackerPen ) { @@ -594,7 +502,7 @@ QPen QwtPicker::trackerPen() const \param pen Rubberband pen \sa rubberBandPen(), setRubberBand() */ -void QwtPicker::setRubberBandPen(const QPen &pen) +void QwtPicker::setRubberBandPen( const QPen &pen ) { if ( pen != d_data->rubberBandPen ) { @@ -625,117 +533,112 @@ QPen QwtPicker::rubberBandPen() const \return Converted position as string */ -QwtText QwtPicker::trackerText(const QPoint &pos) const +QwtText QwtPicker::trackerText( const QPoint &pos ) const { QString label; - switch(rubberBand()) + switch ( rubberBand() ) { case HLineRubberBand: - label.sprintf("%d", pos.y()); + label.sprintf( "%d", pos.y() ); break; case VLineRubberBand: - label.sprintf("%d", pos.x()); + label.sprintf( "%d", pos.x() ); break; default: - label.sprintf("%d, %d", pos.x(), pos.y()); + label.sprintf( "%d, %d", pos.x(), pos.y() ); } return label; } /*! - Draw a rubberband , depending on rubberBand() and selectionFlags() + Draw a rubberband, depending on rubberBand() - \param painter Painter, initialized with clip rect + \param painter Painter, initialized with clip rect - \sa rubberBand(), RubberBand, selectionFlags() + \sa rubberBand(), RubberBand */ -void QwtPicker::drawRubberBand(QPainter *painter) const +void QwtPicker::drawRubberBand( QPainter *painter ) const { - if ( !isActive() || rubberBand() == NoRubberBand || + if ( !isActive() || rubberBand() == NoRubberBand || rubberBandPen().style() == Qt::NoPen ) { return; } const QRect &pRect = pickRect(); - const QwtPolygon &pa = d_data->selection; + const QPolygon pa = adjustedPoints( d_data->pickedPoints ); - if ( selectionFlags() & PointSelection ) + QwtPickerMachine::SelectionType selectionType = + QwtPickerMachine::NoSelection; + + if ( d_data->stateMachine ) + selectionType = d_data->stateMachine->selectionType(); + + switch ( selectionType ) { - if ( pa.count() < 1 ) - return; - - const QPoint pos = pa[0]; - - switch(rubberBand()) + case QwtPickerMachine::NoSelection: + case QwtPickerMachine::PointSelection: { - case VLineRubberBand: - QwtPainter::drawLine(painter, pos.x(), - pRect.top(), pos.x(), pRect.bottom()); - break; + if ( pa.count() < 1 ) + return; - case HLineRubberBand: - QwtPainter::drawLine(painter, pRect.left(), - pos.y(), pRect.right(), pos.y()); - break; + const QPoint pos = pa[0]; - case CrossRubberBand: - QwtPainter::drawLine(painter, pos.x(), - pRect.top(), pos.x(), pRect.bottom()); - QwtPainter::drawLine(painter, pRect.left(), - pos.y(), pRect.right(), pos.y()); - break; - default: - break; + switch ( rubberBand() ) + { + case VLineRubberBand: + QwtPainter::drawLine( painter, pos.x(), + pRect.top(), pos.x(), pRect.bottom() ); + break; + + case HLineRubberBand: + QwtPainter::drawLine( painter, pRect.left(), + pos.y(), pRect.right(), pos.y() ); + break; + + case CrossRubberBand: + QwtPainter::drawLine( painter, pos.x(), + pRect.top(), pos.x(), pRect.bottom() ); + QwtPainter::drawLine( painter, pRect.left(), + pos.y(), pRect.right(), pos.y() ); + break; + default: + break; + } + break; } - } - - else if ( selectionFlags() & RectSelection ) - { - if ( pa.count() < 2 ) - return; - - QPoint p1 = pa[0]; - QPoint p2 = pa[int(pa.count() - 1)]; - - if ( selectionFlags() & CenterToCorner ) + case QwtPickerMachine::RectSelection: { - p1.setX(p1.x() - (p2.x() - p1.x())); - p1.setY(p1.y() - (p2.y() - p1.y())); - } - else if ( selectionFlags() & CenterToRadius ) - { - const int radius = qwtMax(qwtAbs(p2.x() - p1.x()), - qwtAbs(p2.y() - p1.y())); - p2.setX(p1.x() + radius); - p2.setY(p1.y() + radius); - p1.setX(p1.x() - radius); - p1.setY(p1.y() - radius); - } + if ( pa.count() < 2 ) + return; -#if QT_VERSION < 0x040000 - const QRect rect = QRect(p1, p2).normalize(); -#else - const QRect rect = QRect(p1, p2).normalized(); -#endif - switch(rubberBand()) - { - case EllipseRubberBand: - QwtPainter::drawEllipse(painter, rect); - break; - case RectRubberBand: - QwtPainter::drawRect(painter, rect); - break; - default: - break; + const QPoint p1 = pa[0]; + const QPoint p2 = pa[int( pa.count() - 1 )]; + + const QRect rect = QRect( p1, p2 ).normalized(); + switch ( rubberBand() ) + { + case EllipseRubberBand: + QwtPainter::drawEllipse( painter, rect ); + break; + case RectRubberBand: + QwtPainter::drawRect( painter, rect ); + break; + default: + break; + } + break; } - } - else if ( selectionFlags() & PolygonSelection ) - { - if ( rubberBand() == PolygonRubberBand ) - painter->drawPolyline(pa); + case QwtPickerMachine::PolygonSelection: + { + if ( rubberBand() == PolygonRubberBand ) + painter->drawPolyline( pa ); + break; + } + default: + break; } } @@ -746,35 +649,67 @@ void QwtPicker::drawRubberBand(QPainter *painter) const \sa trackerRect(), trackerText() */ -void QwtPicker::drawTracker(QPainter *painter) const +void QwtPicker::drawTracker( QPainter *painter ) const { - const QRect textRect = trackerRect(painter->font()); + const QRect textRect = trackerRect( painter->font() ); if ( !textRect.isEmpty() ) { - QwtText label = trackerText(d_data->trackerPosition); + const QwtText label = trackerText( d_data->trackerPosition ); if ( !label.isEmpty() ) - { - painter->save(); - -#if defined(Q_WS_MAC) - // Antialiased fonts are broken on the Mac. -#if QT_VERSION >= 0x040000 - painter->setRenderHint(QPainter::TextAntialiasing, false); -#else - QFont fnt = label.usedFont(painter->font()); - fnt.setStyleStrategy(QFont::NoAntialias); - label.setFont(fnt); -#endif -#endif - label.draw(painter, textRect); - - painter->restore(); - } + label.draw( painter, textRect ); } } +/*! + \brief Map the pickedPoints() into a selection() + + adjustedPoints() maps the points, that have been collected on + the parentWidget() into a selection(). The default implementation + simply returns the points unmodified. + + The reason, why a selection() differs from the picked points + depends on the application requirements. F.e. : + + - A rectangular selection might need to have a specific aspect ratio only.\n + - A selection could accept non intersecting polygons only.\n + - ...\n + + The example below is for a rectangular selection, where the first + point is the center of the selected rectangle. + \par Example + \verbatim QPolygon MyPicker::adjustedPoints(const QPolygon &points) const +{ + QPolygon adjusted; + if ( points.size() == 2 ) + { + const int width = qAbs(points[1].x() - points[0].x()); + const int height = qAbs(points[1].y() - points[0].y()); + + QRect rect(0, 0, 2 * width, 2 * height); + rect.moveCenter(points[0]); + + adjusted += rect.topLeft(); + adjusted += rect.bottomRight(); + } + return adjusted; +}\endverbatim\n +*/ +QPolygon QwtPicker::adjustedPoints( const QPolygon &points ) const +{ + return points; +} + +/*! + \return Selected points + \sa pickedPoints(), adjustedPoints() +*/ +QPolygon QwtPicker::selection() const +{ + return adjustedPoints( d_data->pickedPoints ); +} + //! \return Current position of the tracker -QPoint QwtPicker::trackerPosition() const +QPoint QwtPicker::trackerPosition() const { return d_data->trackerPosition; } @@ -788,10 +723,10 @@ QPoint QwtPicker::trackerPosition() const \sa trackerPosition() */ -QRect QwtPicker::trackerRect(const QFont &font) const +QRect QwtPicker::trackerRect( const QFont &font ) const { - if ( trackerMode() == AlwaysOff || - (trackerMode() == ActiveOnly && !isActive() ) ) + if ( trackerMode() == AlwaysOff || + ( trackerMode() == ActiveOnly && !isActive() ) ) { return QRect(); } @@ -799,23 +734,24 @@ QRect QwtPicker::trackerRect(const QFont &font) const if ( d_data->trackerPosition.x() < 0 || d_data->trackerPosition.y() < 0 ) return QRect(); - QwtText text = trackerText(d_data->trackerPosition); + QwtText text = trackerText( d_data->trackerPosition ); if ( text.isEmpty() ) return QRect(); - QRect textRect(QPoint(0, 0), text.textSize(font)); + const QSizeF textSize = text.textSize( font ); + QRect textRect( 0, 0, qCeil( textSize.width() ), qCeil( textSize.height() ) ); const QPoint &pos = d_data->trackerPosition; int alignment = 0; - if ( isActive() && d_data->selection.count() > 1 + if ( isActive() && d_data->pickedPoints.count() > 1 && rubberBand() != NoRubberBand ) { - const QPoint last = - d_data->selection[int(d_data->selection.count()) - 2]; + const QPoint last = + d_data->pickedPoints[int( d_data->pickedPoints.count() ) - 2]; - alignment |= (pos.x() >= last.x()) ? Qt::AlignRight : Qt::AlignLeft; - alignment |= (pos.y() > last.y()) ? Qt::AlignBottom : Qt::AlignTop; + alignment |= ( pos.x() >= last.x() ) ? Qt::AlignRight : Qt::AlignLeft; + alignment |= ( pos.y() > last.y() ) ? Qt::AlignBottom : Qt::AlignTop; } else alignment = Qt::AlignTop | Qt::AlignRight; @@ -833,16 +769,16 @@ QRect QwtPicker::trackerRect(const QFont &font) const y += margin; else if ( alignment & Qt::AlignTop ) y -= textRect.height() + margin; - - textRect.moveTopLeft(QPoint(x, y)); - int right = qwtMin(textRect.right(), pickRect().right() - margin); - int bottom = qwtMin(textRect.bottom(), pickRect().bottom() - margin); - textRect.moveBottomRight(QPoint(right, bottom)); + textRect.moveTopLeft( QPoint( x, y ) ); - int left = qwtMax(textRect.left(), pickRect().left() + margin); - int top = qwtMax(textRect.top(), pickRect().top() + margin); - textRect.moveTopLeft(QPoint(left, top)); + int right = qMin( textRect.right(), pickRect().right() - margin ); + int bottom = qMin( textRect.bottom(), pickRect().bottom() - margin ); + textRect.moveBottomRight( QPoint( right, bottom ) ); + + int left = qMax( textRect.left(), pickRect().left() + margin ); + int top = qMax( textRect.top(), pickRect().top() + margin ); + textRect.moveTopLeft( QPoint( left, top ) ); return textRect; } @@ -852,55 +788,63 @@ QRect QwtPicker::trackerRect(const QFont &font) const When isEnabled() == true all events of the observed widget are filtered. Mouse and keyboard events are translated into widgetMouse- and widgetKey- - and widgetWheel-events. Paint and Resize events are handled to keep + and widgetWheel-events. Paint and Resize events are handled to keep rubberband and tracker up to date. - \sa event(), widgetMousePressEvent(), widgetMouseReleaseEvent(), + \param object Object to be filtered + \param event Event + + \sa widgetEnterEvent(), widgetLeaveEvent(), + widgetMousePressEvent(), widgetMouseReleaseEvent(), widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(), - widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent() + widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent(), + QObject::installEventFilter(), QObject::event() */ -bool QwtPicker::eventFilter(QObject *o, QEvent *e) +bool QwtPicker::eventFilter( QObject *object, QEvent *event ) { - if ( o && o == parentWidget() ) + if ( object && object == parentWidget() ) { - switch(e->type()) + switch ( event->type() ) { case QEvent::Resize: { - const QResizeEvent *re = (QResizeEvent *)e; + const QResizeEvent *re = ( QResizeEvent * )event; if ( d_data->resizeMode == Stretch ) - stretchSelection(re->oldSize(), re->size()); + stretchSelection( re->oldSize(), re->size() ); if ( d_data->rubberBandWidget ) - d_data->rubberBandWidget->resize(re->size()); - + d_data->rubberBandWidget->resize( re->size() ); + if ( d_data->trackerWidget ) - d_data->trackerWidget->resize(re->size()); + d_data->trackerWidget->resize( re->size() ); break; } + case QEvent::Enter: + widgetEnterEvent( event ); + break; case QEvent::Leave: - widgetLeaveEvent(e); + widgetLeaveEvent( event ); break; case QEvent::MouseButtonPress: - widgetMousePressEvent((QMouseEvent *)e); + widgetMousePressEvent( ( QMouseEvent * )event ); break; case QEvent::MouseButtonRelease: - widgetMouseReleaseEvent((QMouseEvent *)e); + widgetMouseReleaseEvent( ( QMouseEvent * )event ); break; case QEvent::MouseButtonDblClick: - widgetMouseDoubleClickEvent((QMouseEvent *)e); + widgetMouseDoubleClickEvent( ( QMouseEvent * )event ); break; case QEvent::MouseMove: - widgetMouseMoveEvent((QMouseEvent *)e); + widgetMouseMoveEvent( ( QMouseEvent * )event ); break; case QEvent::KeyPress: - widgetKeyPressEvent((QKeyEvent *)e); + widgetKeyPressEvent( ( QKeyEvent * )event ); break; case QEvent::KeyRelease: - widgetKeyReleaseEvent((QKeyEvent *)e); + widgetKeyReleaseEvent( ( QKeyEvent * )event ); break; case QEvent::Wheel: - widgetWheelEvent((QWheelEvent *)e); + widgetWheelEvent( ( QWheelEvent * )event ); break; default: break; @@ -912,50 +856,67 @@ bool QwtPicker::eventFilter(QObject *o, QEvent *e) /*! Handle a mouse press event for the observed widget. - Begin and/or end a selection depending on the selection flags. + \param mouseEvent Mouse event - \sa QwtPicker, selectionFlags() \sa eventFilter(), widgetMouseReleaseEvent(), widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(), widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent() */ -void QwtPicker::widgetMousePressEvent(QMouseEvent *e) +void QwtPicker::widgetMousePressEvent( QMouseEvent *mouseEvent ) { - transition(e); + transition( mouseEvent ); } /*! Handle a mouse move event for the observed widget. - Move the last point of the selection in case of isActive() == true + \param mouseEvent Mouse event \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), widgetMouseDoubleClickEvent(), widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent() */ -void QwtPicker::widgetMouseMoveEvent(QMouseEvent *e) +void QwtPicker::widgetMouseMoveEvent( QMouseEvent *mouseEvent ) { - if ( pickRect().contains(e->pos()) ) - d_data->trackerPosition = e->pos(); + if ( pickRect().contains( mouseEvent->pos() ) ) + d_data->trackerPosition = mouseEvent->pos(); else - d_data->trackerPosition = QPoint(-1, -1); + d_data->trackerPosition = QPoint( -1, -1 ); if ( !isActive() ) updateDisplay(); - transition(e); + transition( mouseEvent ); +} + +/*! + Handle a enter event for the observed widget. + + \param event Qt event + + \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), + widgetMouseDoubleClickEvent(), + widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent() +*/ +void QwtPicker::widgetEnterEvent( QEvent *event ) +{ + transition( event ); } /*! Handle a leave event for the observed widget. + \param event Qt event + \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), widgetMouseDoubleClickEvent(), widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent() */ -void QwtPicker::widgetLeaveEvent(QEvent *) +void QwtPicker::widgetLeaveEvent( QEvent *event ) { - d_data->trackerPosition = QPoint(-1, -1); + transition( event ); + + d_data->trackerPosition = QPoint( -1, -1 ); if ( !isActive() ) updateDisplay(); } @@ -963,52 +924,53 @@ void QwtPicker::widgetLeaveEvent(QEvent *) /*! Handle a mouse relase event for the observed widget. - End a selection depending on the selection flags. + \param mouseEvent Mouse event - \sa QwtPicker, selectionFlags() - \sa eventFilter(), widgetMousePressEvent(), + \sa eventFilter(), widgetMousePressEvent(), widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(), widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent() */ -void QwtPicker::widgetMouseReleaseEvent(QMouseEvent *e) +void QwtPicker::widgetMouseReleaseEvent( QMouseEvent *mouseEvent ) { - transition(e); + transition( mouseEvent ); } /*! Handle mouse double click event for the observed widget. - Empty implementation, does nothing. + \param mouseEvent Mouse event \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), widgetMouseMoveEvent(), widgetWheelEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent() */ -void QwtPicker::widgetMouseDoubleClickEvent(QMouseEvent *me) +void QwtPicker::widgetMouseDoubleClickEvent( QMouseEvent *mouseEvent ) { - transition(me); + transition( mouseEvent ); } - + /*! Handle a wheel event for the observed widget. Move the last point of the selection in case of isActive() == true + \param wheelEvent Wheel event + \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(), widgetKeyPressEvent(), widgetKeyReleaseEvent() */ -void QwtPicker::widgetWheelEvent(QWheelEvent *e) +void QwtPicker::widgetWheelEvent( QWheelEvent *wheelEvent ) { - if ( pickRect().contains(e->pos()) ) - d_data->trackerPosition = e->pos(); + if ( pickRect().contains( wheelEvent->pos() ) ) + d_data->trackerPosition = wheelEvent->pos(); else - d_data->trackerPosition = QPoint(-1, -1); + d_data->trackerPosition = QPoint( -1, -1 ); updateDisplay(); - transition(e); + transition( wheelEvent ); } /*! @@ -1018,101 +980,105 @@ void QwtPicker::widgetWheelEvent(QWheelEvent *e) move the cursor, the abort key aborts a selection. All other keys are handled by the current state machine. - \sa QwtPicker, selectionFlags() + \param keyEvent Key event + \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(), widgetWheelEvent(), widgetKeyReleaseEvent(), stateMachine(), QwtEventPattern::KeyPatternCode */ -void QwtPicker::widgetKeyPressEvent(QKeyEvent *ke) +void QwtPicker::widgetKeyPressEvent( QKeyEvent *keyEvent ) { int dx = 0; int dy = 0; int offset = 1; - if ( ke->isAutoRepeat() ) + if ( keyEvent->isAutoRepeat() ) offset = 5; - if ( keyMatch(KeyLeft, ke) ) + if ( keyMatch( KeyLeft, keyEvent ) ) dx = -offset; - else if ( keyMatch(KeyRight, ke) ) + else if ( keyMatch( KeyRight, keyEvent ) ) dx = offset; - else if ( keyMatch(KeyUp, ke) ) + else if ( keyMatch( KeyUp, keyEvent ) ) dy = -offset; - else if ( keyMatch(KeyDown, ke) ) + else if ( keyMatch( KeyDown, keyEvent ) ) dy = offset; - else if ( keyMatch(KeyAbort, ke) ) + else if ( keyMatch( KeyAbort, keyEvent ) ) { reset(); } else - transition(ke); + transition( keyEvent ); if ( dx != 0 || dy != 0 ) { const QRect rect = pickRect(); - const QPoint pos = parentWidget()->mapFromGlobal(QCursor::pos()); + const QPoint pos = parentWidget()->mapFromGlobal( QCursor::pos() ); int x = pos.x() + dx; - x = qwtMax(rect.left(), x); - x = qwtMin(rect.right(), x); + x = qMax( rect.left(), x ); + x = qMin( rect.right(), x ); int y = pos.y() + dy; - y = qwtMax(rect.top(), y); - y = qwtMin(rect.bottom(), y); + y = qMax( rect.top(), y ); + y = qMin( rect.bottom(), y ); - QCursor::setPos(parentWidget()->mapToGlobal(QPoint(x, y))); + QCursor::setPos( parentWidget()->mapToGlobal( QPoint( x, y ) ) ); } } - + /*! Handle a key release event for the observed widget. Passes the event to the state machine. + \param keyEvent Key event + \sa eventFilter(), widgetMousePressEvent(), widgetMouseReleaseEvent(), widgetMouseDoubleClickEvent(), widgetMouseMoveEvent(), widgetWheelEvent(), widgetKeyPressEvent(), stateMachine() */ -void QwtPicker::widgetKeyReleaseEvent(QKeyEvent *ke) +void QwtPicker::widgetKeyReleaseEvent( QKeyEvent *keyEvent ) { - transition(ke); + transition( keyEvent ); } /*! - Passes an event to the state machine and executes the resulting + Passes an event to the state machine and executes the resulting commands. Append and Move commands use the current position of the cursor (QCursor::pos()). - \param e Event + \param event Event */ -void QwtPicker::transition(const QEvent *e) +void QwtPicker::transition( const QEvent *event ) { if ( !d_data->stateMachine ) return; - QwtPickerMachine::CommandList commandList = - d_data->stateMachine->transition(*this, e); + const QList commandList = + d_data->stateMachine->transition( *this, event ); QPoint pos; - switch(e->type()) + switch ( event->type() ) { case QEvent::MouseButtonDblClick: case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseMove: { - const QMouseEvent *me = (QMouseEvent *)e; + const QMouseEvent *me = + static_cast< const QMouseEvent * >( event ); pos = me->pos(); break; } default: - pos = parentWidget()->mapFromGlobal(QCursor::pos()); + pos = parentWidget()->mapFromGlobal( QCursor::pos() ); } - for ( uint i = 0; i < (uint)commandList.count(); i++ ) + for ( int i = 0; i < commandList.count(); i++ ) { - switch(commandList[i]) + switch ( commandList[i] ) { case QwtPickerMachine::Begin: { @@ -1121,12 +1087,17 @@ void QwtPicker::transition(const QEvent *e) } case QwtPickerMachine::Append: { - append(pos); + append( pos ); break; } case QwtPickerMachine::Move: { - move(pos); + move( pos ); + break; + } + case QwtPickerMachine::Remove: + { + remove(); break; } case QwtPickerMachine::End: @@ -1148,51 +1119,53 @@ void QwtPicker::begin() if ( d_data->isActive ) return; - d_data->selection.resize(0); + d_data->pickedPoints.resize( 0 ); d_data->isActive = true; + Q_EMIT activated( true ); if ( trackerMode() != AlwaysOff ) { - if ( d_data->trackerPosition.x() < 0 || d_data->trackerPosition.y() < 0 ) + if ( d_data->trackerPosition.x() < 0 || d_data->trackerPosition.y() < 0 ) { QWidget *w = parentWidget(); if ( w ) - d_data->trackerPosition = w->mapFromGlobal(QCursor::pos()); + d_data->trackerPosition = w->mapFromGlobal( QCursor::pos() ); } } updateDisplay(); - setMouseTracking(true); + setMouseTracking( true ); } /*! \brief Close a selection setting the state to inactive. - The selection is validated and maybe fixed by QwtPicker::accept(). + The selection is validated and maybe fixed by accept(). \param ok If true, complete the selection and emit a selected signal otherwise discard the selection. \return true if the selection is accepted, false otherwise \sa isActive(), begin(), append(), move(), selected(), accept() */ -bool QwtPicker::end(bool ok) +bool QwtPicker::end( bool ok ) { if ( d_data->isActive ) { - setMouseTracking(false); + setMouseTracking( false ); d_data->isActive = false; + Q_EMIT activated( false ); if ( trackerMode() == ActiveOnly ) - d_data->trackerPosition = QPoint(-1, -1); + d_data->trackerPosition = QPoint( -1, -1 ); if ( ok ) - ok = accept(d_data->selection); + ok = accept( d_data->pickedPoints ); if ( ok ) - emit selected(d_data->selection); + Q_EMIT selected( d_data->pickedPoints ); else - d_data->selection.resize(0); + d_data->pickedPoints.resize( 0 ); updateDisplay(); } @@ -1210,8 +1183,8 @@ void QwtPicker::reset() if ( d_data->stateMachine ) d_data->stateMachine->reset(); - if (isActive()) - end(false); + if ( isActive() ) + end( false ); } /*! @@ -1222,17 +1195,16 @@ void QwtPicker::reset() \sa isActive(), begin(), end(), move(), appended() */ -void QwtPicker::append(const QPoint &pos) +void QwtPicker::append( const QPoint &pos ) { if ( d_data->isActive ) { - const int idx = d_data->selection.count(); - d_data->selection.resize(idx + 1); - d_data->selection[idx] = pos; + const int idx = d_data->pickedPoints.count(); + d_data->pickedPoints.resize( idx + 1 ); + d_data->pickedPoints[idx] = pos; updateDisplay(); - - emit appended(pos); + Q_EMIT appended( pos ); } } @@ -1242,29 +1214,60 @@ void QwtPicker::append(const QPoint &pos) \param pos New position \sa isActive(), begin(), end(), append() - */ -void QwtPicker::move(const QPoint &pos) +void QwtPicker::move( const QPoint &pos ) { if ( d_data->isActive ) { - const int idx = d_data->selection.count() - 1; + const int idx = d_data->pickedPoints.count() - 1; if ( idx >= 0 ) { - if ( d_data->selection[idx] != pos ) + if ( d_data->pickedPoints[idx] != pos ) { - d_data->selection[idx] = pos; + d_data->pickedPoints[idx] = pos; updateDisplay(); - - emit moved(pos); + Q_EMIT moved( pos ); } } } } -bool QwtPicker::accept(QwtPolygon &) const +/*! + Remove the last point of the selection + The removed() signal is emitted. + + \sa isActive(), begin(), end(), append(), move() +*/ +void QwtPicker::remove() { + if ( d_data->isActive ) + { + const int idx = d_data->pickedPoints.count() - 1; + if ( idx > 0 ) + { + const int idx = d_data->pickedPoints.count(); + + const QPoint pos = d_data->pickedPoints[idx - 1]; + d_data->pickedPoints.resize( idx - 1 ); + + updateDisplay(); + Q_EMIT removed( pos ); + } + } +} + +/*! + \brief Validate and fixup the selection + + Accepts all selections unmodified + + \param selection Selection to validate and fixup + \return true, when accepted, false otherwise +*/ +bool QwtPicker::accept( QPolygon &selection ) const +{ + Q_UNUSED( selection ); return true; } @@ -1272,15 +1275,19 @@ bool QwtPicker::accept(QwtPolygon &) const A picker is active between begin() and end(). \return true if the selection is active. */ -bool QwtPicker::isActive() const +bool QwtPicker::isActive() const { return d_data->isActive; } -//! Return Selected points -const QwtPolygon &QwtPicker::selection() const +/*! + Return the points, that have been collected so far. The selection() + is calculated from the pickedPoints() in adjustedPoints(). + \return Picked points +*/ +const QPolygon &QwtPicker::pickedPoints() const { - return d_data->selection; + return d_data->pickedPoints; } /*! @@ -1292,27 +1299,27 @@ const QwtPolygon &QwtPicker::selection() const \sa ResizeMode, setResizeMode(), resizeMode() */ -void QwtPicker::stretchSelection(const QSize &oldSize, const QSize &newSize) +void QwtPicker::stretchSelection( const QSize &oldSize, const QSize &newSize ) { if ( oldSize.isEmpty() ) { - // avoid division by zero. But scaling for small sizes also + // avoid division by zero. But scaling for small sizes also // doesn't make much sense, because of rounding losses. TODO ... return; } const double xRatio = - double(newSize.width()) / double(oldSize.width()); + double( newSize.width() ) / double( oldSize.width() ); const double yRatio = - double(newSize.height()) / double(oldSize.height()); + double( newSize.height() ) / double( oldSize.height() ); - for ( int i = 0; i < int(d_data->selection.count()); i++ ) + for ( int i = 0; i < int( d_data->pickedPoints.count() ); i++ ) { - QPoint &p = d_data->selection[i]; - p.setX(qRound(p.x() * xRatio)); - p.setY(qRound(p.y() * yRatio)); + QPoint &p = d_data->pickedPoints[i]; + p.setX( qRound( p.x() * xRatio ) ); + p.setY( qRound( p.y() * yRatio ) ); - emit changed(d_data->selection); + Q_EMIT changed( d_data->pickedPoints ); } } @@ -1329,7 +1336,7 @@ void QwtPicker::stretchSelection(const QSize &oldSize, const QSize &newSize) be restored. */ -void QwtPicker::setMouseTracking(bool enable) +void QwtPicker::setMouseTracking( bool enable ) { QWidget *widget = parentWidget(); if ( !widget ) @@ -1338,33 +1345,26 @@ void QwtPicker::setMouseTracking(bool enable) if ( enable ) { d_data->mouseTracking = widget->hasMouseTracking(); - widget->setMouseTracking(true); + widget->setMouseTracking( true ); } else { - widget->setMouseTracking(d_data->mouseTracking); + widget->setMouseTracking( d_data->mouseTracking ); } } /*! Find the area of the observed widget, where selection might happen. - \return QFrame::contentsRect() if it is a QFrame, QWidget::rect() otherwise. + \return parentWidget()->contentsRect() */ QRect QwtPicker::pickRect() const { - QRect rect; - const QWidget *widget = parentWidget(); - if ( !widget ) - return rect; + if ( widget ) + return widget->contentsRect(); - if ( widget->inherits("QFrame") ) - rect = ((QFrame *)widget)->contentsRect(); - else - rect = widget->rect(); - - return rect; + return QRect(); } //! Update the state of rubberband and tracker label @@ -1383,24 +1383,20 @@ void QwtPicker::updateDisplay() } if ( trackerMode() == AlwaysOn || - (trackerMode() == ActiveOnly && isActive() ) ) + ( trackerMode() == ActiveOnly && isActive() ) ) { if ( trackerPen() != Qt::NoPen ) showTracker = true; } } -#if QT_VERSION < 0x040000 - QGuardedPtr &rw = d_data->rubberBandWidget; -#else QPointer &rw = d_data->rubberBandWidget; -#endif if ( showRubberband ) { if ( rw.isNull() ) { - rw = new PickerWidget( this, w, PickerWidget::RubberBand); - rw->resize(w->size()); + rw = new PickerWidget( this, w, PickerWidget::RubberBand ); + rw->resize( w->size() ); } rw->updateMask(); rw->update(); // Needed, when the mask doesn't change @@ -1408,18 +1404,15 @@ void QwtPicker::updateDisplay() else delete rw; -#if QT_VERSION < 0x040000 - QGuardedPtr &tw = d_data->trackerWidget; -#else QPointer &tw = d_data->trackerWidget; -#endif if ( showTracker ) { if ( tw.isNull() ) { - tw = new PickerWidget( this, w, PickerWidget::Text); - tw->resize(w->size()); + tw = new PickerWidget( this, w, PickerWidget::Text ); + tw->resize( w->size() ); } + tw->setFont( d_data->trackerFont ); tw->updateMask(); tw->update(); // Needed, when the mask doesn't change } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_picker.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_picker.h index f505e9bfc..5049f71e3 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_picker.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_picker.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -10,14 +10,13 @@ #ifndef QWT_PICKER #define QWT_PICKER 1 +#include "qwt_global.h" +#include "qwt_text.h" +#include "qwt_event_pattern.h" #include #include #include #include -#include "qwt_global.h" -#include "qwt_text.h" -#include "qwt_polygon.h" -#include "qwt_event_pattern.h" class QWidget; class QMouseEvent; @@ -28,41 +27,55 @@ class QwtPickerMachine; /*! \brief QwtPicker provides selections on a widget - QwtPicker filters all mouse and keyboard events of a widget - and translates them into an array of selected points. Depending - on the QwtPicker::SelectionType the selection might be a single point, - a rectangle or a polygon. The selection process is supported by - optional rubberbands (rubberband selection) and position trackers. + QwtPicker filters all enter, leave, mouse and keyboard events of a widget + and translates them into an array of selected points. - QwtPicker is useful for widgets where the event handlers - can't be overloaded, like for components of composite widgets. - It offers alternative handlers for mouse and key events. + The way how the points are collected depends on type of state machine + that is connected to the picker. Qwt offers a couple of predefined + state machines for selecting: - \par Example + - Nothing\n + QwtPickerTrackerMachine + - Single points\n + QwtPickerClickPointMachine, QwtPickerDragPointMachine + - Rectangles\n + QwtPickerClickRectMachine, QwtPickerDragRectMachine + - Polygons\n + QwtPickerPolygonMachine + + While these state machines cover the most common ways to collect points + it is also possible to implement individual machines as well. + + QwtPicker translates the picked points into a selection using the + adjustedPoints method. adjustedPoints is intended to be reimplemented + to fixup the selection according to application specific requirements. + (F.e. when an application accepts rectangles of a fixed aspect ratio only.) + + Optionally QwtPicker support the process of collecting points by a + rubberband and tracker displaying a text for the current mouse + position. + + \par Example \verbatim #include +#include QwtPicker *picker = new QwtPicker(widget); +picker->setStateMachine(new QwtPickerDragRectMachine); picker->setTrackerMode(QwtPicker::ActiveOnly); -connect(picker, SIGNAL(selected(const QwtPolygon &)), ...); - -// emit the position of clicks on widget -picker->setSelectionFlags(QwtPicker::PointSelection | QwtPicker::ClickSelection); - - ... - -// now select rectangles -picker->setSelectionFlags(QwtPicker::RectSelection | QwtPicker::DragSelection); picker->setRubberBand(QwtPicker::RectRubberBand); \endverbatim\n - The selection process uses the commands begin(), append(), move() and end(). - append() adds a new point to the selection, move() changes the position of - the latest point. + The state machine triggers the following commands: - The commands are initiated from a small state machine (QwtPickerMachine) - that translates mouse and key events. There are a couple of predefined - state machines for point, rect and polygon selections. The selectionFlags() - control which one should be used. It is possible to use other machines - by overloading stateMachine(). + - begin()\n + Activate/Initialize the selection. + - append()\n + Add a new point + - move() \n + Change the position of the last point. + - remove()\n + Remove the last point. + - end()\n + Terminate the selection and call accept to validate the picked points. The picker is active (isActive()), between begin() and end(). In active state the rubberband is displayed, and the tracker is visible @@ -73,7 +86,7 @@ picker->setRubberBand(QwtPicker::RectRubberBand); \endverbatim\n \warning In case of QWidget::NoFocus the focus policy of the observed widget is set to QWidget::WheelFocus and mouse tracking - will be manipulated for ClickSelection while the picker is active, + will be manipulated while the picker is active, or if trackerMode() is AlwayOn. */ @@ -81,220 +94,158 @@ class QWT_EXPORT QwtPicker: public QObject, public QwtEventPattern { Q_OBJECT - Q_ENUMS(RubberBand) - Q_ENUMS(DisplayMode) - Q_ENUMS(ResizeMode) + Q_ENUMS( RubberBand ) + Q_ENUMS( DisplayMode ) + Q_ENUMS( ResizeMode ) - Q_PROPERTY(int selectionFlags READ selectionFlags WRITE setSelectionFlags) - Q_PROPERTY(DisplayMode trackerMode READ trackerMode WRITE setTrackerMode) - Q_PROPERTY(QFont trackerFont READ trackerFont WRITE setTrackerFont) - Q_PROPERTY(RubberBand rubberBand READ rubberBand WRITE setRubberBand) - Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) - Q_PROPERTY(bool isEnabled READ isEnabled WRITE setEnabled) + Q_PROPERTY( bool isEnabled READ isEnabled WRITE setEnabled ) + Q_PROPERTY( ResizeMode resizeMode READ resizeMode WRITE setResizeMode ) - Q_PROPERTY(QPen trackerPen READ trackerPen WRITE setTrackerPen) - Q_PROPERTY(QPen rubberBandPen READ rubberBandPen WRITE setRubberBandPen) + Q_PROPERTY( DisplayMode trackerMode READ trackerMode WRITE setTrackerMode ) + Q_PROPERTY( QPen trackerPen READ trackerPen WRITE setTrackerPen ) + Q_PROPERTY( QFont trackerFont READ trackerFont WRITE setTrackerFont ) + + Q_PROPERTY( RubberBand rubberBand READ rubberBand WRITE setRubberBand ) + Q_PROPERTY( QPen rubberBandPen READ rubberBandPen WRITE setRubberBandPen ) public: - /*! - This enum type describes the type of a selection. It can be or'd - with QwtPicker::RectSelectionType and QwtPicker::SelectionMode - and passed to QwtPicker::setSelectionFlags() - - NoSelection\n - Selection is disabled. Note this is different to the disabled - state, as you might have a tracker. - - PointSelection\n - Select a single point. - - RectSelection\n - Select a rectangle. - - PolygonSelection\n - Select a polygon. - - The default value is NoSelection. - \sa QwtPicker::setSelectionFlags(), QwtPicker::selectionFlags() - */ - - enum SelectionType - { - NoSelection = 0, - PointSelection = 1, - RectSelection = 2, - PolygonSelection = 4 - }; - - /*! - \brief Selection subtype for RectSelection - This enum type describes the type of rectangle selections. - It can be or'd with QwtPicker::RectSelectionType and - QwtPicker::SelectionMode and passed to QwtPicker::setSelectionFlags(). - - CornerToCorner\n - The first and the second selected point are the corners - of the rectangle. - - CenterToCorner\n - The first point is the center, the second a corner of the - rectangle. - - CenterToRadius\n - The first point is the center of a quadrat, calculated by the maximum - of the x- and y-distance. - - The default value is CornerToCorner. - \sa QwtPicker::setSelectionFlags(), QwtPicker::selectionFlags() - */ - enum RectSelectionType - { - CornerToCorner = 64, - CenterToCorner = 128, - CenterToRadius = 256 - }; - - /*! - Values of this enum type or'd together with a SelectionType value - identifies which state machine should be used for the selection. - - The default value is ClickSelection. - \sa stateMachine() - */ - enum SelectionMode - { - ClickSelection = 1024, - DragSelection = 2048 - }; - - /*! + /*! Rubberband style - - NoRubberBand\n - No rubberband. - - HLineRubberBand & PointSelection\n - A horizontal line. - - VLineRubberBand & PointSelection\n - A vertical line. - - CrossRubberBand & PointSelection\n - A horizontal and a vertical line. - - RectRubberBand & RectSelection\n - A rectangle. - - EllipseRubberBand & RectSelection\n - An ellipse. - - PolygonRubberBand &PolygonSelection\n - A polygon. - - UserRubberBand\n - Values >= UserRubberBand can be used to define additional - rubber bands. - The default value is NoRubberBand. - \sa QwtPicker::setRubberBand(), QwtPicker::rubberBand() + The default value is QwtPicker::NoRubberBand. + \sa setRubberBand(), rubberBand() */ enum RubberBand { + //! No rubberband. NoRubberBand = 0, - // Point + //! A horizontal line ( only for QwtPicker::PointSelection ) HLineRubberBand, + + //! A vertical line ( only for QwtPicker::PointSelection ) VLineRubberBand, + + //! A crosshair ( only for QwtPicker::PointSelection ) CrossRubberBand, - // Rect + //! A rectangle ( only for QwtPicker::RectSelection ) RectRubberBand, + + //! An ellipse ( only for QwtPicker::RectSelection ) EllipseRubberBand, - // Polygon + //! A polygon ( only for QwtPicker::&PolygonSelection ) PolygonRubberBand, + /*! + Values >= UserRubberBand can be used to define additional + rubber bands. + */ UserRubberBand = 100 }; - /*! - - AlwaysOff\n - Display never. - - AlwaysOn\n - Display always. - - ActiveOnly\n - Display only when the selection is active. - - \sa QwtPicker::setTrackerMode(), QwtPicker::trackerMode(), - QwtPicker::isActive() + /*! + \brief Display mode + \sa setTrackerMode(), trackerMode(), isActive() */ enum DisplayMode { + //! Display never AlwaysOff, + + //! Display always AlwaysOn, + + //! Display only when the selection is active ActiveOnly }; - /*! + /*! Controls what to do with the selected points of an active selection when the observed widget is resized. - - Stretch\n - All points are scaled according to the new size, - - KeepSize\n - All points remain unchanged. - The default value is Stretch. - \sa QwtPicker::setResizeMode(), QwtPicker::resize() + The default value is QwtPicker::Stretch. + \sa setResizeMode() */ enum ResizeMode { + //! All points are scaled according to the new size, Stretch, + + //! All points remain unchanged. KeepSize }; - explicit QwtPicker(QWidget *parent); - explicit QwtPicker(int selectionFlags, RubberBand rubberBand, - DisplayMode trackerMode, QWidget *); + explicit QwtPicker( QWidget *parent ); + explicit QwtPicker( RubberBand rubberBand, + DisplayMode trackerMode, QWidget * ); virtual ~QwtPicker(); - virtual void setSelectionFlags(int); - int selectionFlags() const; + void setStateMachine( QwtPickerMachine * ); + const QwtPickerMachine *stateMachine() const; + QwtPickerMachine *stateMachine(); - virtual void setRubberBand(RubberBand); + void setRubberBand( RubberBand ); RubberBand rubberBand() const; - virtual void setTrackerMode(DisplayMode); + void setTrackerMode( DisplayMode ); DisplayMode trackerMode() const; - virtual void setResizeMode(ResizeMode); + void setResizeMode( ResizeMode ); ResizeMode resizeMode() const; - virtual void setRubberBandPen(const QPen &); + void setRubberBandPen( const QPen & ); QPen rubberBandPen() const; - virtual void setTrackerPen(const QPen &); + void setTrackerPen( const QPen & ); QPen trackerPen() const; - virtual void setTrackerFont(const QFont &); + void setTrackerFont( const QFont & ); QFont trackerFont() const; bool isEnabled() const; - virtual void setEnabled(bool); - bool isActive() const; - virtual bool eventFilter(QObject *, QEvent *); + virtual bool eventFilter( QObject *, QEvent * ); QWidget *parentWidget(); const QWidget *parentWidget() const; virtual QRect pickRect() const; - const QwtPolygon &selection() const; - virtual void drawRubberBand(QPainter *) const; - virtual void drawTracker(QPainter *) const; + virtual void drawRubberBand( QPainter * ) const; + virtual void drawTracker( QPainter * ) const; - virtual QwtText trackerText(const QPoint &pos) const; + virtual QwtText trackerText( const QPoint &pos ) const; QPoint trackerPosition() const; - QRect trackerRect(const QFont &) const; + virtual QRect trackerRect( const QFont & ) const; + QPolygon selection() const; -signals: +public Q_SLOTS: + void setEnabled( bool ); + +Q_SIGNALS: /*! - A signal emitting the selected points, + A signal indicating, when the picker has been activated. + Together with setEnabled() it can be used to implement + selections with more than one picker. + + \param on True, when the picker has been activated + */ + void activated( bool on ); + + /*! + A signal emitting the selected points, at the end of a selection. - \param pa Selected points + \param polygon Selected points */ - void selected(const QwtPolygon &pa); + void selected( const QPolygon &polygon ); /*! A signal emitted when a point has been appended to the selection @@ -302,75 +253,75 @@ signals: \param pos Position of the appended point. \sa append(). moved() */ - void appended(const QPoint &pos); + void appended( const QPoint &pos ); /*! - A signal emitted whenever the last appended point of the + A signal emitted whenever the last appended point of the selection has been moved. \param pos Position of the moved last point of the selection. \sa move(), appended() */ - void moved(const QPoint &pos); + void moved( const QPoint &pos ); + /*! + A signal emitted whenever the last appended point of the + selection has been removed. + + \sa remove(), appended() + */ + void removed( const QPoint &pos ); /*! A signal emitted when the active selection has been changed. This might happen when the observed widget is resized. - \param pa Changed selection + \param selection Changed selection \sa stretchSelection() */ - void changed(const QwtPolygon &pa); + void changed( const QPolygon &selection ); protected: - /*! - \brief Validate and fixup the selection + virtual QPolygon adjustedPoints( const QPolygon & ) const; - Accepts all selections unmodified - - \param selection Selection to validate and fixup - \return true, when accepted, false otherwise - */ - virtual bool accept(QwtPolygon &selection) const; - - virtual void transition(const QEvent *); + virtual void transition( const QEvent * ); virtual void begin(); - virtual void append(const QPoint &); - virtual void move(const QPoint &); - virtual bool end(bool ok = true); + virtual void append( const QPoint & ); + virtual void move( const QPoint & ); + virtual void remove(); + virtual bool end( bool ok = true ); + virtual bool accept( QPolygon & ) const; virtual void reset(); - virtual void widgetMousePressEvent(QMouseEvent *); - virtual void widgetMouseReleaseEvent(QMouseEvent *); - virtual void widgetMouseDoubleClickEvent(QMouseEvent *); - virtual void widgetMouseMoveEvent(QMouseEvent *); - virtual void widgetWheelEvent(QWheelEvent *); - virtual void widgetKeyPressEvent(QKeyEvent *); - virtual void widgetKeyReleaseEvent(QKeyEvent *); - virtual void widgetLeaveEvent(QEvent *); + virtual void widgetMousePressEvent( QMouseEvent * ); + virtual void widgetMouseReleaseEvent( QMouseEvent * ); + virtual void widgetMouseDoubleClickEvent( QMouseEvent * ); + virtual void widgetMouseMoveEvent( QMouseEvent * ); + virtual void widgetWheelEvent( QWheelEvent * ); + virtual void widgetKeyPressEvent( QKeyEvent * ); + virtual void widgetKeyReleaseEvent( QKeyEvent * ); + virtual void widgetEnterEvent( QEvent * ); + virtual void widgetLeaveEvent( QEvent * ); - virtual void stretchSelection(const QSize &oldSize, - const QSize &newSize); - - virtual QwtPickerMachine *stateMachine(int) const; + virtual void stretchSelection( const QSize &oldSize, + const QSize &newSize ); virtual void updateDisplay(); const QWidget *rubberBandWidget() const; const QWidget *trackerWidget() const; -private: - void init(QWidget *, int selectionFlags, RubberBand rubberBand, - DisplayMode trackerMode); + const QPolygon &pickedPoints() const; - void setStateMachine(QwtPickerMachine *); - void setMouseTracking(bool); +private: + void init( QWidget *, RubberBand rubberBand, DisplayMode trackerMode ); + + void setMouseTracking( bool ); class PickerWidget; class PrivateData; PrivateData *d_data; }; - + #endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_picker_machine.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_picker_machine.cpp index 301e29536..0ae245cdf 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_picker_machine.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_picker_machine.cpp @@ -7,13 +7,14 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -#include -#include "qwt_event_pattern.h" #include "qwt_picker_machine.h" +#include "qwt_event_pattern.h" +#include //! Constructor -QwtPickerMachine::QwtPickerMachine(): - d_state(0) +QwtPickerMachine::QwtPickerMachine( SelectionType type ): + d_selectionType( type ), + d_state( 0 ) { } @@ -22,6 +23,12 @@ QwtPickerMachine::~QwtPickerMachine() { } +//! Return the selection type +QwtPickerMachine::SelectionType QwtPickerMachine::selectionType() const +{ + return d_selectionType; +} + //! Return the current state int QwtPickerMachine::state() const { @@ -29,29 +36,77 @@ int QwtPickerMachine::state() const } //! Change the current state -void QwtPickerMachine::setState(int state) +void QwtPickerMachine::setState( int state ) { d_state = state; } //! Set the current state to 0. -void QwtPickerMachine::reset() +void QwtPickerMachine::reset() +{ + setState( 0 ); +} + +//! Constructor +QwtPickerTrackerMachine::QwtPickerTrackerMachine(): + QwtPickerMachine( NoSelection ) { - setState(0); } //! Transition -QwtPickerMachine::CommandList QwtPickerClickPointMachine::transition( - const QwtEventPattern &eventPattern, const QEvent *e) -{ - QwtPickerMachine::CommandList cmdList; +QList QwtPickerTrackerMachine::transition( + const QwtEventPattern &, const QEvent *e ) +{ + QList cmdList; - switch(e->type()) + switch ( e->type() ) + { + case QEvent::Enter: + case QEvent::MouseMove: + { + if ( state() == 0 ) + { + cmdList += Begin; + cmdList += Append; + setState( 1 ); + } + else + { + cmdList += Move; + } + break; + } + case QEvent::Leave: + { + cmdList += Remove; + cmdList += End; + setState( 0 ); + } + default: + break; + } + + return cmdList; +} + +//! Constructor +QwtPickerClickPointMachine::QwtPickerClickPointMachine(): + QwtPickerMachine( PointSelection ) +{ +} + +//! Transition +QList QwtPickerClickPointMachine::transition( + const QwtEventPattern &eventPattern, const QEvent *e ) +{ + QList cmdList; + + switch ( e->type() ) { case QEvent::MouseButtonPress: { if ( eventPattern.mouseMatch( - QwtEventPattern::MouseSelect1, (const QMouseEvent *)e) ) + QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) ) { cmdList += Begin; cmdList += Append; @@ -60,14 +115,14 @@ QwtPickerMachine::CommandList QwtPickerClickPointMachine::transition( break; } case QEvent::KeyPress: - { + { if ( eventPattern.keyMatch( - QwtEventPattern::KeySelect1, (const QKeyEvent *)e) ) + QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) ) { cmdList += Begin; cmdList += Append; cmdList += End; - } + } break; } default: @@ -77,24 +132,30 @@ QwtPickerMachine::CommandList QwtPickerClickPointMachine::transition( return cmdList; } -//! Transition -QwtPickerMachine::CommandList QwtPickerDragPointMachine::transition( - const QwtEventPattern &eventPattern, const QEvent *e) -{ - QwtPickerMachine::CommandList cmdList; +//! Constructor +QwtPickerDragPointMachine::QwtPickerDragPointMachine(): + QwtPickerMachine( PointSelection ) +{ +} - switch(e->type()) +//! Transition +QList QwtPickerDragPointMachine::transition( + const QwtEventPattern &eventPattern, const QEvent *e ) +{ + QList cmdList; + + switch ( e->type() ) { case QEvent::MouseButtonPress: { if ( eventPattern.mouseMatch( - QwtEventPattern::MouseSelect1, (const QMouseEvent *)e) ) + QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) ) { if ( state() == 0 ) { cmdList += Begin; cmdList += Append; - setState(1); + setState( 1 ); } } break; @@ -111,25 +172,25 @@ QwtPickerMachine::CommandList QwtPickerDragPointMachine::transition( if ( state() != 0 ) { cmdList += End; - setState(0); + setState( 0 ); } break; } case QEvent::KeyPress: { if ( eventPattern.keyMatch( - QwtEventPattern::KeySelect1, (const QKeyEvent *)e) ) + QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) ) { if ( state() == 0 ) { cmdList += Begin; cmdList += Append; - setState(1); + setState( 1 ); } else { cmdList += End; - setState(0); + setState( 0 ); } } break; @@ -141,37 +202,43 @@ QwtPickerMachine::CommandList QwtPickerDragPointMachine::transition( return cmdList; } -//! Transition -QwtPickerMachine::CommandList QwtPickerClickRectMachine::transition( - const QwtEventPattern &eventPattern, const QEvent *e) -{ - QwtPickerMachine::CommandList cmdList; +//! Constructor +QwtPickerClickRectMachine::QwtPickerClickRectMachine(): + QwtPickerMachine( RectSelection ) +{ +} - switch(e->type()) +//! Transition +QList QwtPickerClickRectMachine::transition( + const QwtEventPattern &eventPattern, const QEvent *e ) +{ + QList cmdList; + + switch ( e->type() ) { case QEvent::MouseButtonPress: { if ( eventPattern.mouseMatch( - QwtEventPattern::MouseSelect1, (const QMouseEvent *)e) ) + QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) ) { - switch(state()) + switch ( state() ) { case 0: - { + { cmdList += Begin; cmdList += Append; - setState(1); + setState( 1 ); break; } case 1: { // Uh, strange we missed the MouseButtonRelease - break; + break; } default: { cmdList += End; - setState(0); + setState( 0 ); } } } @@ -186,41 +253,41 @@ QwtPickerMachine::CommandList QwtPickerClickRectMachine::transition( case QEvent::MouseButtonRelease: { if ( eventPattern.mouseMatch( - QwtEventPattern::MouseSelect1, (const QMouseEvent *)e) ) + QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) ) { if ( state() == 1 ) { cmdList += Append; - setState(2); + setState( 2 ); } } break; } case QEvent::KeyPress: - { + { if ( eventPattern.keyMatch( - QwtEventPattern::KeySelect1, (const QKeyEvent *)e) ) + QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) ) { if ( state() == 0 ) { cmdList += Begin; cmdList += Append; - setState(1); + setState( 1 ); } else { if ( state() == 1 ) { cmdList += Append; - setState(2); + setState( 2 ); } else if ( state() == 2 ) { cmdList += End; - setState(0); + setState( 0 ); } } - } + } break; } default: @@ -230,25 +297,31 @@ QwtPickerMachine::CommandList QwtPickerClickRectMachine::transition( return cmdList; } -//! Transition -QwtPickerMachine::CommandList QwtPickerDragRectMachine::transition( - const QwtEventPattern &eventPattern, const QEvent *e) -{ - QwtPickerMachine::CommandList cmdList; +//! Constructor +QwtPickerDragRectMachine::QwtPickerDragRectMachine(): + QwtPickerMachine( RectSelection ) +{ +} - switch(e->type()) +//! Transition +QList QwtPickerDragRectMachine::transition( + const QwtEventPattern &eventPattern, const QEvent *e ) +{ + QList cmdList; + + switch ( e->type() ) { case QEvent::MouseButtonPress: { if ( eventPattern.mouseMatch( - QwtEventPattern::MouseSelect1, (const QMouseEvent *)e) ) + QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) ) { if ( state() == 0 ) { cmdList += Begin; cmdList += Append; cmdList += Append; - setState(2); + setState( 2 ); } } break; @@ -265,26 +338,26 @@ QwtPickerMachine::CommandList QwtPickerDragRectMachine::transition( if ( state() == 2 ) { cmdList += End; - setState(0); + setState( 0 ); } break; } case QEvent::KeyPress: { if ( eventPattern.keyMatch( - QwtEventPattern::KeySelect1, (const QKeyEvent *)e) ) + QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) ) { if ( state() == 0 ) { cmdList += Begin; cmdList += Append; cmdList += Append; - setState(2); + setState( 2 ); } else { cmdList += End; - setState(0); + setState( 0 ); } } break; @@ -296,36 +369,42 @@ QwtPickerMachine::CommandList QwtPickerDragRectMachine::transition( return cmdList; } -//! Transition -QwtPickerMachine::CommandList QwtPickerPolygonMachine::transition( - const QwtEventPattern &eventPattern, const QEvent *e) +//! Constructor +QwtPickerPolygonMachine::QwtPickerPolygonMachine(): + QwtPickerMachine( PolygonSelection ) { - QwtPickerMachine::CommandList cmdList; +} - switch(e->type()) +//! Transition +QList QwtPickerPolygonMachine::transition( + const QwtEventPattern &eventPattern, const QEvent *e ) +{ + QList cmdList; + + switch ( e->type() ) { case QEvent::MouseButtonPress: { if ( eventPattern.mouseMatch( - QwtEventPattern::MouseSelect1, (const QMouseEvent *)e) ) + QwtEventPattern::MouseSelect1, ( const QMouseEvent * )e ) ) { - if (state() == 0) + if ( state() == 0 ) { cmdList += Begin; cmdList += Append; cmdList += Append; - setState(1); + setState( 1 ); } else { cmdList += End; - setState(0); + setState( 0 ); } } if ( eventPattern.mouseMatch( - QwtEventPattern::MouseSelect2, (const QMouseEvent *)e) ) + QwtEventPattern::MouseSelect2, ( const QMouseEvent * )e ) ) { - if (state() == 1) + if ( state() == 1 ) cmdList += Append; } break; @@ -340,23 +419,23 @@ QwtPickerMachine::CommandList QwtPickerPolygonMachine::transition( case QEvent::KeyPress: { if ( eventPattern.keyMatch( - QwtEventPattern::KeySelect1, (const QKeyEvent *)e) ) + QwtEventPattern::KeySelect1, ( const QKeyEvent * )e ) ) { if ( state() == 0 ) { cmdList += Begin; cmdList += Append; cmdList += Append; - setState(1); + setState( 1 ); } else { cmdList += End; - setState(0); + setState( 0 ); } } else if ( eventPattern.keyMatch( - QwtEventPattern::KeySelect2, (const QKeyEvent *)e) ) + QwtEventPattern::KeySelect2, ( const QKeyEvent * )e ) ) { if ( state() == 1 ) cmdList += Append; diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_picker_machine.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_picker_machine.h index 3529b695e..99a1e744c 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_picker_machine.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_picker_machine.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -11,11 +11,7 @@ #define QWT_PICKER_MACHINE 1 #include "qwt_global.h" -#if QT_VERSION < 0x040000 -#include -#else #include -#endif class QEvent; class QwtEventPattern; @@ -24,7 +20,7 @@ class QwtEventPattern; \brief A state machine for QwtPicker selections QwtPickerMachine accepts key and mouse events and translates them - into selection commands. + into selection commands. \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode */ @@ -32,42 +28,73 @@ class QwtEventPattern; class QWT_EXPORT QwtPickerMachine { public: - //! Commands - the output of the state machine + /*! + Type of a selection. + \sa selectionType() + */ + enum SelectionType + { + //! The state machine not usable for any type of selection. + NoSelection = -1, + + //! The state machine is for selecting a single point. + PointSelection, + + //! The state machine is for selecting a rectangle (2 points). + RectSelection, + + //! The state machine is for selecting a polygon (many points). + PolygonSelection + }; + + //! Commands - the output of a state machine enum Command { Begin, Append, Move, + Remove, End }; -#if QT_VERSION < 0x040000 - typedef QValueList CommandList; -#else - typedef QList CommandList; -#endif - + QwtPickerMachine( SelectionType ); virtual ~QwtPickerMachine(); //! Transition - virtual CommandList transition( - const QwtEventPattern &, const QEvent *) = 0; - void reset(); + virtual QList transition( + const QwtEventPattern &, const QEvent * ) = 0; + void reset(); int state() const; - void setState(int); + void setState( int ); -protected: - QwtPickerMachine(); + SelectionType selectionType() const; private: + const SelectionType d_selectionType; int d_state; }; +/*! + \brief A state machine for indicating mouse movements + + QwtPickerTrackerMachine supports displaying information + corresponding to mouse movements, but is not intended for + selecting anything. Begin/End are related to Enter/Leave events. +*/ +class QWT_EXPORT QwtPickerTrackerMachine: public QwtPickerMachine +{ +public: + QwtPickerTrackerMachine(); + + virtual QList transition( + const QwtEventPattern &, const QEvent * ); +}; + /*! \brief A state machine for point selections - Pressing QwtEventPattern::MouseSelect1 or + Pressing QwtEventPattern::MouseSelect1 or QwtEventPattern::KeySelect1 selects a point. \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode @@ -75,22 +102,26 @@ private: class QWT_EXPORT QwtPickerClickPointMachine: public QwtPickerMachine { public: - virtual CommandList transition( - const QwtEventPattern &, const QEvent *); + QwtPickerClickPointMachine(); + + virtual QList transition( + const QwtEventPattern &, const QEvent * ); }; /*! \brief A state machine for point selections - Pressing QwtEventPattern::MouseSelect1 or QwtEventPattern::KeySelect1 - starts the selection, releasing QwtEventPattern::MouseSelect1 or + Pressing QwtEventPattern::MouseSelect1 or QwtEventPattern::KeySelect1 + starts the selection, releasing QwtEventPattern::MouseSelect1 or a second press of QwtEventPattern::KeySelect1 terminates it. */ class QWT_EXPORT QwtPickerDragPointMachine: public QwtPickerMachine { public: - virtual CommandList transition( - const QwtEventPattern &, const QEvent *); + QwtPickerDragPointMachine(); + + virtual QList transition( + const QwtEventPattern &, const QEvent * ); }; /*! @@ -99,9 +130,9 @@ public: Pressing QwtEventPattern::MouseSelect1 starts the selection, releasing it selects the first point. Pressing it again selects the second point and terminates the selection. - Pressing QwtEventPattern::KeySelect1 also starts the - selection, a second press selects the first point. A third one selects - the second point and terminates the selection. + Pressing QwtEventPattern::KeySelect1 also starts the + selection, a second press selects the first point. A third one selects + the second point and terminates the selection. \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode */ @@ -109,8 +140,10 @@ public: class QWT_EXPORT QwtPickerClickRectMachine: public QwtPickerMachine { public: - virtual CommandList transition( - const QwtEventPattern &, const QEvent *); + QwtPickerClickRectMachine(); + + virtual QList transition( + const QwtEventPattern &, const QEvent * ); }; /*! @@ -118,8 +151,8 @@ public: Pressing QwtEventPattern::MouseSelect1 selects the first point, releasing it the second point. - Pressing QwtEventPattern::KeySelect1 also selects the - first point, a second press selects the second point and terminates + Pressing QwtEventPattern::KeySelect1 also selects the + first point, a second press selects the second point and terminates the selection. \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode @@ -128,16 +161,18 @@ public: class QWT_EXPORT QwtPickerDragRectMachine: public QwtPickerMachine { public: - virtual CommandList transition( - const QwtEventPattern &, const QEvent *); + QwtPickerDragRectMachine(); + + virtual QList transition( + const QwtEventPattern &, const QEvent * ); }; /*! \brief A state machine for polygon selections - Pressing QwtEventPattern::MouseSelect1 or QwtEventPattern::KeySelect1 - starts the selection and selects the first point, or appends a point. - Pressing QwtEventPattern::MouseSelect2 or QwtEventPattern::KeySelect2 + Pressing QwtEventPattern::MouseSelect1 or QwtEventPattern::KeySelect1 + starts the selection and selects the first point, or appends a point. + Pressing QwtEventPattern::MouseSelect2 or QwtEventPattern::KeySelect2 appends the last point and terminates the selection. \sa QwtEventPattern::MousePatternCode, QwtEventPattern::KeyPatternCode @@ -146,8 +181,10 @@ public: class QWT_EXPORT QwtPickerPolygonMachine: public QwtPickerMachine { public: - virtual CommandList transition( - const QwtEventPattern &, const QEvent *); + QwtPickerPolygonMachine(); + + virtual QList transition( + const QwtEventPattern &, const QEvent * ); }; #endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot.cpp index 68f8f6c0e..60f10f3a4 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot.cpp @@ -7,16 +7,6 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -#include -#if QT_VERSION < 0x040000 -#include -#include -#else -#include -#include -#endif -#include -#include #include "qwt_plot.h" #include "qwt_plot_dict.h" #include "qwt_plot_layout.h" @@ -26,20 +16,18 @@ #include "qwt_legend.h" #include "qwt_dyngrid_layout.h" #include "qwt_plot_canvas.h" -#include "qwt_paint_buffer.h" +#include +#include +#include +#include +#include class QwtPlot::PrivateData { public: -#if QT_VERSION < 0x040000 - QGuardedPtr lblTitle; - QGuardedPtr canvas; - QGuardedPtr legend; -#else QPointer lblTitle; QPointer canvas; QPointer legend; -#endif QwtPlotLayout *layout; bool autoReplot; @@ -49,10 +37,10 @@ public: \brief Constructor \param parent Parent widget */ -QwtPlot::QwtPlot(QWidget *parent): - QFrame(parent) +QwtPlot::QwtPlot( QWidget *parent ): + QFrame( parent ) { - initPlot(QwtText()); + initPlot( QwtText() ); } /*! @@ -60,30 +48,16 @@ QwtPlot::QwtPlot(QWidget *parent): \param title Title text \param parent Parent widget */ -QwtPlot::QwtPlot(const QwtText &title, QWidget *parent): - QFrame(parent) +QwtPlot::QwtPlot( const QwtText &title, QWidget *parent ): + QFrame( parent ) { - initPlot(title); + initPlot( title ); } -#if QT_VERSION < 0x040000 -/*! - \brief Constructor - \param parent Parent widget - \param name Object name - */ -QwtPlot::QwtPlot(QWidget *parent, const char *name): - QFrame(parent, name) -{ - initPlot(QwtText()); -} -#endif - - //! Destructor QwtPlot::~QwtPlot() { - detachItems(QwtPlotItem::Rtti_PlotItem, autoDelete()); + detachItems( QwtPlotItem::Rtti_PlotItem, autoDelete() ); delete d_data->layout; deleteAxesData(); @@ -94,75 +68,63 @@ QwtPlot::~QwtPlot() \brief Initializes a QwtPlot instance \param title Title text */ -void QwtPlot::initPlot(const QwtText &title) +void QwtPlot::initPlot( const QwtText &title ) { d_data = new PrivateData; -#if QT_VERSION < 0x040000 - setWFlags(Qt::WNoAutoErase); -#endif - d_data->layout = new QwtPlotLayout; - d_data->autoReplot = false; - d_data->lblTitle = new QwtTextLabel(title, this); - d_data->lblTitle->setFont(QFont(fontInfo().family(), 14, QFont::Bold)); + d_data->lblTitle = new QwtTextLabel( title, this ); + d_data->lblTitle->setObjectName( "QwtPlotTitle" ); - QwtText text(title); - int flags = Qt::AlignCenter; -#if QT_VERSION < 0x040000 - flags |= Qt::WordBreak | Qt::ExpandTabs; -#else - flags |= Qt::TextWordWrap; -#endif - text.setRenderFlags(flags); - d_data->lblTitle->setText(text); + d_data->lblTitle->setFont( QFont( fontInfo().family(), 14, QFont::Bold ) ); + + QwtText text( title ); + text.setRenderFlags( Qt::AlignCenter | Qt::TextWordWrap ); + d_data->lblTitle->setText( text ); d_data->legend = NULL; initAxesData(); - d_data->canvas = new QwtPlotCanvas(this); - d_data->canvas->setFrameStyle(QFrame::Panel|QFrame::Sunken); - d_data->canvas->setLineWidth(2); - d_data->canvas->setMidLineWidth(0); + d_data->canvas = new QwtPlotCanvas( this ); + d_data->canvas->setObjectName( "QwtPlotCanvas" ); + d_data->canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken ); + d_data->canvas->setLineWidth( 2 ); updateTabOrder(); - setSizePolicy(QSizePolicy::MinimumExpanding, - QSizePolicy::MinimumExpanding); + setSizePolicy( QSizePolicy::MinimumExpanding, + QSizePolicy::MinimumExpanding ); + + resize( 200, 200 ); } /*! \brief Adds handling of layout requests + \param event Event */ -bool QwtPlot::event(QEvent *e) +bool QwtPlot::event( QEvent *event ) { - bool ok = QFrame::event(e); - switch(e->type()) + bool ok = QFrame::event( event ); + switch ( event->type() ) { -#if QT_VERSION < 0x040000 - case QEvent::LayoutHint: -#else case QEvent::LayoutRequest: -#endif updateLayout(); break; -#if QT_VERSION >= 0x040000 case QEvent::PolishRequest: - polish(); + replot(); break; -#endif default:; } return ok; } -//! Replots the plot if QwtPlot::autoReplot() is \c true. +//! Replots the plot if autoReplot() is \c true. void QwtPlot::autoRefresh() { - if (d_data->autoReplot) + if ( d_data->autoReplot ) replot(); } @@ -181,26 +143,29 @@ void QwtPlot::autoRefresh() \param tf \c true or \c false. Defaults to \c true. \sa replot() */ -void QwtPlot::setAutoReplot(bool tf) +void QwtPlot::setAutoReplot( bool tf ) { d_data->autoReplot = tf; } -//! \return true if the autoReplot option is set. +/*! + \return true if the autoReplot option is set. + \sa setAutoReplot() +*/ bool QwtPlot::autoReplot() const { - return d_data->autoReplot; + return d_data->autoReplot; } /*! Change the plot's title \param title New title */ -void QwtPlot::setTitle(const QString &title) +void QwtPlot::setTitle( const QString &title ) { if ( title != d_data->lblTitle->text().text() ) { - d_data->lblTitle->setText(title); + d_data->lblTitle->setText( title ); updateLayout(); } } @@ -209,11 +174,11 @@ void QwtPlot::setTitle(const QString &title) Change the plot's title \param title New title */ -void QwtPlot::setTitle(const QwtText &title) +void QwtPlot::setTitle( const QwtText &title ) { if ( title != d_data->lblTitle->text() ) { - d_data->lblTitle->setText(title); + d_data->lblTitle->setText( title ); updateLayout(); } } @@ -255,47 +220,37 @@ const QwtTextLabel *QwtPlot::titleLabel() const \sa insertLegend() */ QwtLegend *QwtPlot::legend() -{ +{ return d_data->legend; -} +} /*! \return the plot's legend \sa insertLegend() */ const QwtLegend *QwtPlot::legend() const -{ +{ return d_data->legend; -} +} /*! \return the plot's canvas */ QwtPlotCanvas *QwtPlot::canvas() -{ +{ return d_data->canvas; -} +} /*! \return the plot's canvas */ const QwtPlotCanvas *QwtPlot::canvas() const -{ +{ return d_data->canvas; } -//! Polish -void QwtPlot::polish() -{ - replot(); - -#if QT_VERSION < 0x040000 - QFrame::polish(); -#endif -} - -/*! +/*! Return sizeHint \sa minimumSizeHint() */ @@ -306,30 +261,30 @@ QSize QwtPlot::sizeHint() const int dh = 0; for ( int axisId = 0; axisId < axisCnt; axisId++ ) { - if ( axisEnabled(axisId) ) - { + if ( axisEnabled( axisId ) ) + { const int niceDist = 40; - const QwtScaleWidget *scaleWidget = axisWidget(axisId); + const QwtScaleWidget *scaleWidget = axisWidget( axisId ); const QwtScaleDiv &scaleDiv = scaleWidget->scaleDraw()->scaleDiv(); - const int majCnt = scaleDiv.ticks(QwtScaleDiv::MajorTick).count(); + const int majCnt = scaleDiv.ticks( QwtScaleDiv::MajorTick ).count(); if ( axisId == yLeft || axisId == yRight ) { - int hDiff = (majCnt - 1) * niceDist + int hDiff = ( majCnt - 1 ) * niceDist - scaleWidget->minimumSizeHint().height(); if ( hDiff > dh ) dh = hDiff; } else { - int wDiff = (majCnt - 1) * niceDist + int wDiff = ( majCnt - 1 ) * niceDist - scaleWidget->minimumSizeHint().width(); if ( wDiff > dw ) dw = wDiff; } } } - return minimumSizeHint() + QSize(dw, dh); + return minimumSizeHint() + QSize( dw, dh ); } /*! @@ -337,19 +292,19 @@ QSize QwtPlot::sizeHint() const */ QSize QwtPlot::minimumSizeHint() const { - QSize hint = d_data->layout->minimumSizeHint(this); - hint += QSize(2 * frameWidth(), 2 * frameWidth()); + QSize hint = d_data->layout->minimumSizeHint( this ); + hint += QSize( 2 * frameWidth(), 2 * frameWidth() ); return hint; } -/*! +/*! Resize and update internal layout \param e Resize event */ -void QwtPlot::resizeEvent(QResizeEvent *e) +void QwtPlot::resizeEvent( QResizeEvent *e ) { - QFrame::resizeEvent(e); + QFrame::resizeEvent( e ); updateLayout(); } @@ -366,7 +321,7 @@ void QwtPlot::resizeEvent(QResizeEvent *e) void QwtPlot::replot() { bool doAutoReplot = autoReplot(); - setAutoReplot(false); + setAutoReplot( false ); updateAxes(); @@ -375,15 +330,11 @@ void QwtPlot::replot() axes labels. We need to process them here before painting to avoid that scales and canvas get out of sync. */ -#if QT_VERSION >= 0x040000 - QApplication::sendPostedEvents(this, QEvent::LayoutRequest); -#else - QApplication::sendPostedEvents(this, QEvent::LayoutHint); -#endif + QApplication::sendPostedEvents( this, QEvent::LayoutRequest ); d_data->canvas->replot(); - setAutoReplot(doAutoReplot); + setAutoReplot( doAutoReplot ); } /*! @@ -392,61 +343,68 @@ void QwtPlot::replot() */ void QwtPlot::updateLayout() { - d_data->layout->activate(this, contentsRect()); + d_data->layout->activate( this, contentsRect() ); + + QRect titleRect = d_data->layout->titleRect().toRect(); + QRect scaleRect[QwtPlot::axisCnt]; + for ( int axisId = 0; axisId < axisCnt; axisId++ ) + scaleRect[axisId] = d_data->layout->scaleRect( axisId ).toRect(); + QRect legendRect = d_data->layout->legendRect().toRect(); + QRect canvasRect = d_data->layout->canvasRect().toRect(); // // resize and show the visible widgets // - if (!d_data->lblTitle->text().isEmpty()) + if ( !d_data->lblTitle->text().isEmpty() ) { - d_data->lblTitle->setGeometry(d_data->layout->titleRect()); - if (!d_data->lblTitle->isVisible()) + d_data->lblTitle->setGeometry( titleRect ); + if ( !d_data->lblTitle->isVisibleTo( this ) ) d_data->lblTitle->show(); } else d_data->lblTitle->hide(); - for (int axisId = 0; axisId < axisCnt; axisId++ ) + for ( int axisId = 0; axisId < axisCnt; axisId++ ) { - if (axisEnabled(axisId) ) + if ( axisEnabled( axisId ) ) { - axisWidget(axisId)->setGeometry(d_data->layout->scaleRect(axisId)); + axisWidget( axisId )->setGeometry( scaleRect[axisId] ); if ( axisId == xBottom || axisId == xTop ) { - QRegion r(d_data->layout->scaleRect(axisId)); - if ( axisEnabled(yLeft) ) - r = r.subtract(QRegion(d_data->layout->scaleRect(yLeft))); - if ( axisEnabled(yRight) ) - r = r.subtract(QRegion(d_data->layout->scaleRect(yRight))); - r.translate(-d_data->layout->scaleRect(axisId).x(), - -d_data->layout->scaleRect(axisId).y()); + QRegion r( scaleRect[axisId] ); + if ( axisEnabled( yLeft ) ) + r = r.subtract( QRegion( scaleRect[yLeft] ) ); + if ( axisEnabled( yRight ) ) + r = r.subtract( QRegion( scaleRect[yRight] ) ); + r.translate( -d_data->layout->scaleRect( axisId ).x(), + -scaleRect[axisId].y() ); - axisWidget(axisId)->setMask(r); + axisWidget( axisId )->setMask( r ); } - if (!axisWidget(axisId)->isVisible()) - axisWidget(axisId)->show(); + if ( !axisWidget( axisId )->isVisibleTo( this ) ) + axisWidget( axisId )->show(); } else - axisWidget(axisId)->hide(); + axisWidget( axisId )->hide(); } - if ( d_data->legend && + if ( d_data->legend && d_data->layout->legendPosition() != ExternalLegend ) { - if (d_data->legend->itemCount() > 0) + if ( d_data->legend->itemCount() > 0 ) { - d_data->legend->setGeometry(d_data->layout->legendRect()); + d_data->legend->setGeometry( legendRect ); d_data->legend->show(); } else d_data->legend->hide(); } - d_data->canvas->setGeometry(d_data->layout->canvasRect()); + d_data->canvas->setGeometry( canvasRect ); } -/*! +/*! Update the focus tab order The order is changed so that the canvas will be in front of the @@ -456,44 +414,31 @@ void QwtPlot::updateLayout() void QwtPlot::updateTabOrder() { -#if QT_VERSION >= 0x040000 - using namespace Qt; // QWidget::NoFocus/Qt::NoFocus -#else - if ( d_data->canvas->focusPolicy() == NoFocus ) + if ( d_data->canvas->focusPolicy() == Qt::NoFocus ) return; -#endif - if ( d_data->legend.isNull() + if ( d_data->legend.isNull() || d_data->layout->legendPosition() == ExternalLegend || d_data->legend->legendItems().count() == 0 ) { return; } - // Depending on the position of the legend the + // Depending on the position of the legend the // tab order will be changed that the canvas is // next to the last legend item, or before - // the first one. + // the first one. - const bool canvasFirst = + const bool canvasFirst = d_data->layout->legendPosition() == QwtPlot::BottomLegend || d_data->layout->legendPosition() == QwtPlot::RightLegend; - QWidget *previous = NULL; + QWidget *previous = NULL; - QWidget *w; -#if QT_VERSION >= 0x040000 - w = d_data->canvas; + QWidget *w = d_data->canvas; while ( ( w = w->nextInFocusChain() ) != d_data->canvas ) -#else - if ( focusData() == NULL ) - return; - - while ( focusData()->next() != d_data->canvas ); - while ( (w = focusData()->next()) != d_data->canvas ) -#endif { bool isLegendItem = false; - if ( w->focusPolicy() != NoFocus + if ( w->focusPolicy() != Qt::NoFocus && w->parent() && w->parent() == d_data->legend->contentsWidget() ) { isLegendItem = true; @@ -518,11 +463,11 @@ void QwtPlot::updateTabOrder() } } - if ( previous && previous != d_data->canvas) - setTabOrder(previous, d_data->canvas); + if ( previous && previous != d_data->canvas ) + setTabOrder( previous, d_data->canvas ); } -/*! +/*! Redraw the canvas. \param painter Painter used for drawing @@ -531,27 +476,24 @@ void QwtPlot::updateTabOrder() plot items better overload drawItems() \sa drawItems() */ -void QwtPlot::drawCanvas(QPainter *painter) +void QwtPlot::drawCanvas( QPainter *painter ) { QwtScaleMap maps[axisCnt]; for ( int axisId = 0; axisId < axisCnt; axisId++ ) - maps[axisId] = canvasMap(axisId); + maps[axisId] = canvasMap( axisId ); - drawItems(painter, - d_data->canvas->contentsRect(), maps, QwtPlotPrintFilter()); + drawItems( painter, d_data->canvas->contentsRect(), maps ); } -/*! +/*! Redraw the canvas items. \param painter Painter used for drawing - \param rect Bounding rectangle where to paint + \param canvasRect Bounding rectangle where to paint \param map QwtPlot::axisCnt maps, mapping between plot and paint device coordinates - \param pfilter Plot print filter */ -void QwtPlot::drawItems(QPainter *painter, const QRect &rect, - const QwtScaleMap map[axisCnt], - const QwtPlotPrintFilter &pfilter) const +void QwtPlot::drawItems( QPainter *painter, const QRectF &canvasRect, + const QwtScaleMap map[axisCnt] ) const { const QwtPlotItemList& itmList = itemList(); for ( QwtPlotItemIterator it = itmList.begin(); @@ -560,22 +502,14 @@ void QwtPlot::drawItems(QPainter *painter, const QRect &rect, QwtPlotItem *item = *it; if ( item && item->isVisible() ) { - if ( !(pfilter.options() & QwtPlotPrintFilter::PrintGrid) - && item->rtti() == QwtPlotItem::Rtti_PlotGrid ) - { - continue; - } - painter->save(); -#if QT_VERSION >= 0x040000 - painter->setRenderHint(QPainter::Antialiasing, - item->testRenderHint(QwtPlotItem::RenderAntialiased) ); -#endif + painter->setRenderHint( QPainter::Antialiasing, + item->testRenderHint( QwtPlotItem::RenderAntialiased ) ); - item->draw(painter, + item->draw( painter, map[item->xAxis()], map[item->yAxis()], - rect); + canvasRect ); painter->restore(); } @@ -587,142 +521,111 @@ void QwtPlot::drawItems(QPainter *painter, const QRect &rect, \return Map for the axis on the canvas. With this map pixel coordinates can translated to plot coordinates and vice versa. \sa QwtScaleMap, transform(), invTransform() - + */ -QwtScaleMap QwtPlot::canvasMap(int axisId) const +QwtScaleMap QwtPlot::canvasMap( int axisId ) const { QwtScaleMap map; if ( !d_data->canvas ) return map; - map.setTransformation(axisScaleEngine(axisId)->transformation()); + map.setTransformation( axisScaleEngine( axisId )->transformation() ); - const QwtScaleDiv *sd = axisScaleDiv(axisId); - map.setScaleInterval(sd->lowerBound(), sd->upperBound()); + const QwtScaleDiv *sd = axisScaleDiv( axisId ); + map.setScaleInterval( sd->lowerBound(), sd->upperBound() ); - if ( axisEnabled(axisId) ) + if ( axisEnabled( axisId ) ) { - const QwtScaleWidget *s = axisWidget(axisId); + const QwtScaleWidget *s = axisWidget( axisId ); if ( axisId == yLeft || axisId == yRight ) { - int y = s->y() + s->startBorderDist() - d_data->canvas->y(); - int h = s->height() - s->startBorderDist() - s->endBorderDist(); - map.setPaintInterval(y + h, y); + double y = s->y() + s->startBorderDist() - d_data->canvas->y(); + double h = s->height() - s->startBorderDist() - s->endBorderDist(); + map.setPaintInterval( y + h, y ); } else { - int x = s->x() + s->startBorderDist() - d_data->canvas->x(); - int w = s->width() - s->startBorderDist() - s->endBorderDist(); - map.setPaintInterval(x, x + w); + double x = s->x() + s->startBorderDist() - d_data->canvas->x(); + double w = s->width() - s->startBorderDist() - s->endBorderDist(); + map.setPaintInterval( x, x + w ); } } else { - const int margin = plotLayout()->canvasMargin(axisId); + int margin = 0; + if ( !plotLayout()->alignCanvasToScales() ) + margin = plotLayout()->canvasMargin( axisId ); const QRect &canvasRect = d_data->canvas->contentsRect(); if ( axisId == yLeft || axisId == yRight ) { - map.setPaintInterval(canvasRect.bottom() - margin, - canvasRect.top() + margin); + map.setPaintInterval( canvasRect.bottom() - margin, + canvasRect.top() + margin ); } else { - map.setPaintInterval(canvasRect.left() + margin, - canvasRect.right() - margin); + map.setPaintInterval( canvasRect.left() + margin, + canvasRect.right() - margin ); } } return map; } -/*! - Change the margin of the plot. The margin is the space - around all components. - - \param margin new margin - \sa QwtPlotLayout::setMargin(), margin(), plotLayout() -*/ -void QwtPlot::setMargin(int margin) -{ - if ( margin < 0 ) - margin = 0; - - if ( margin != d_data->layout->margin() ) - { - d_data->layout->setMargin(margin); - updateLayout(); - } -} - -/*! - \return margin - \sa setMargin(), QwtPlotLayout::margin(), plotLayout() -*/ -int QwtPlot::margin() const -{ - return d_data->layout->margin(); -} - /*! \brief Change the background of the plotting area - - Sets c to QColorGroup::Background of all colorgroups of + + Sets brush to QPalette::Window of all colorgroups of the palette of the canvas. Using canvas()->setPalette() is a more powerful way to set these colors. - \param c new background color + + \param brush New background brush + \sa canvasBackground() */ -void QwtPlot::setCanvasBackground(const QColor &c) +void QwtPlot::setCanvasBackground( const QBrush &brush ) { - QPalette p = d_data->canvas->palette(); + QPalette pal = d_data->canvas->palette(); for ( int i = 0; i < QPalette::NColorGroups; i++ ) - { -#if QT_VERSION < 0x040000 - p.setColor((QPalette::ColorGroup)i, QColorGroup::Background, c); -#else - p.setColor((QPalette::ColorGroup)i, QPalette::Background, c); -#endif - } + pal.setBrush( ( QPalette::ColorGroup )i, QPalette::Window, brush ); - canvas()->setPalette(p); + canvas()->setPalette( pal ); } /*! - Nothing else than: canvas()->palette().color( - QPalette::Normal, QColorGroup::Background); - - \return the background color of the plotting area. + Nothing else than: canvas()->palette().brush( + QPalette::Normal, QPalette::Window); + + \return Background brush of the plotting area. + \sa setCanvasBackground() */ -const QColor & QwtPlot::canvasBackground() const +QBrush QwtPlot::canvasBackground() const { -#if QT_VERSION < 0x040000 - return canvas()->palette().color( - QPalette::Normal, QColorGroup::Background); -#else - return canvas()->palette().color( - QPalette::Normal, QPalette::Background); -#endif + return canvas()->palette().brush( + QPalette::Normal, QPalette::Window ); } /*! \brief Change the border width of the plotting area - Nothing else than canvas()->setLineWidth(w), + + Nothing else than canvas()->setLineWidth(w), left for compatibility only. - \param w new border width + + \param width New border width */ -void QwtPlot::setCanvasLineWidth(int w) +void QwtPlot::setCanvasLineWidth( int width ) { - canvas()->setLineWidth(w); + canvas()->setLineWidth( width ); updateLayout(); } - -/*! - Nothing else than: canvas()->lineWidth(), + +/*! + Nothing else than: canvas()->lineWidth(), left for compatibility only. + \return the border width of the plotting area */ int QwtPlot::canvasLineWidth() const -{ +{ return canvas()->lineWidth(); } @@ -730,9 +633,9 @@ int QwtPlot::canvasLineWidth() const \return \c true if the specified axis exists, otherwise \c false \param axisId axis index */ -bool QwtPlot::axisValid(int axisId) +bool QwtPlot::axisValid( int axisId ) { - return ((axisId >= QwtPlot::yLeft) && (axisId < QwtPlot::axisCnt)); + return ( ( axisId >= QwtPlot::yLeft ) && ( axisId < QwtPlot::axisCnt ) ); } /*! @@ -743,10 +646,10 @@ void QwtPlot::legendItemClicked() { if ( d_data->legend && sender()->isWidgetType() ) { - QwtPlotItem *plotItem = - (QwtPlotItem*)d_data->legend->find((QWidget *)sender()); + QwtPlotItem *plotItem = + ( QwtPlotItem* )d_data->legend->find( ( QWidget * )sender() ); if ( plotItem ) - emit legendClicked(plotItem); + Q_EMIT legendClicked( plotItem ); } } @@ -754,43 +657,33 @@ void QwtPlot::legendItemClicked() Called internally when the legend has been checked Emits a legendClicked() signal. */ -void QwtPlot::legendItemChecked(bool on) +void QwtPlot::legendItemChecked( bool on ) { if ( d_data->legend && sender()->isWidgetType() ) { - QwtPlotItem *plotItem = - (QwtPlotItem*)d_data->legend->find((QWidget *)sender()); + QwtPlotItem *plotItem = + ( QwtPlotItem* )d_data->legend->find( ( QWidget * )sender() ); if ( plotItem ) - emit legendChecked(plotItem, on); + Q_EMIT legendChecked( plotItem, on ); } } -/*! - Remove all curves and markers - \deprecated Use QwtPlotDeict::detachItems instead -*/ -void QwtPlot::clear() -{ - detachItems(QwtPlotItem::Rtti_PlotCurve); - detachItems(QwtPlotItem::Rtti_PlotMarker); -} - /*! \brief Insert a legend If the position legend is \c QwtPlot::LeftLegend or \c QwtPlot::RightLegend - the legend will be organized in one column from top to down. - Otherwise the legend items will be placed in a table + the legend will be organized in one column from top to down. + Otherwise the legend items will be placed in a table with a best fit number of columns from left to right. - If pos != QwtPlot::ExternalLegend the plot widget will become - parent of the legend. It will be deleted when the plot is deleted, + If pos != QwtPlot::ExternalLegend the plot widget will become + parent of the legend. It will be deleted when the plot is deleted, or another legend is set with insertLegend(). - + \param legend Legend \param pos The legend's position. For top/left position the number of colums will be limited to 1, otherwise it will be set to - unlimited. + unlimited. \param ratio Ratio between legend and the bounding rect of title, canvas and axes. The legend will be shrinked @@ -799,13 +692,13 @@ void QwtPlot::clear() it will be reset to the default ratio. The default vertical/horizontal ratio is 0.33/0.5. - \sa legend(), QwtPlotLayout::legendPosition(), + \sa legend(), QwtPlotLayout::legendPosition(), QwtPlotLayout::setLegendPosition() */ -void QwtPlot::insertLegend(QwtLegend *legend, - QwtPlot::LegendPosition pos, double ratio) +void QwtPlot::insertLegend( QwtLegend *legend, + QwtPlot::LegendPosition pos, double ratio ) { - d_data->layout->setLegendPosition(pos, ratio); + d_data->layout->setLegendPosition( pos, ratio ); if ( legend != d_data->legend ) { @@ -819,35 +712,29 @@ void QwtPlot::insertLegend(QwtLegend *legend, if ( pos != ExternalLegend ) { if ( d_data->legend->parent() != this ) - { -#if QT_VERSION < 0x040000 - d_data->legend->reparent(this, QPoint(0, 0)); -#else - d_data->legend->setParent(this); -#endif - } + d_data->legend->setParent( this ); } const QwtPlotItemList& itmList = itemList(); for ( QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); ++it ) { - (*it)->updateLegend(d_data->legend); + ( *it )->updateLegend( d_data->legend ); } - QLayout *l = d_data->legend->contentsWidget()->layout(); - if ( l && l->inherits("QwtDynGridLayout") ) + QwtDynGridLayout *tl = qobject_cast( + d_data->legend->contentsWidget()->layout() ); + if ( tl ) { - QwtDynGridLayout *tl = (QwtDynGridLayout *)l; - switch(d_data->layout->legendPosition()) + switch ( d_data->layout->legendPosition() ) { case LeftLegend: case RightLegend: - tl->setMaxCols(1); // 1 column: align vertical + tl->setMaxCols( 1 ); // 1 column: align vertical break; case TopLegend: case BottomLegend: - tl->setMaxCols(0); // unlimited + tl->setMaxCols( 0 ); // unlimited break; case ExternalLegend: break; diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot.h index 5042ab5fd..0528849d8 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot.h @@ -10,13 +10,12 @@ #ifndef QWT_PLOT_H #define QWT_PLOT_H -#include #include "qwt_global.h" -#include "qwt_array.h" #include "qwt_text.h" #include "qwt_plot_dict.h" #include "qwt_scale_map.h" -#include "qwt_plot_printfilter.h" +#include "qwt_interval.h" +#include class QwtPlotLayout; class QwtLegend; @@ -26,20 +25,19 @@ class QwtScaleDiv; class QwtScaleDraw; class QwtTextLabel; class QwtPlotCanvas; -class QwtPlotPrintFilter; /*! \brief A 2-D plotting widget QwtPlot is a widget for plotting two-dimensional graphs. - An unlimited number of plot items can be displayed on - its canvas. Plot items might be curves (QwtPlotCurve), markers - (QwtPlotMarker), the grid (QwtPlotGrid), or anything else derived + An unlimited number of plot items can be displayed on + its canvas. Plot items might be curves (QwtPlotCurve), markers + (QwtPlotMarker), the grid (QwtPlotGrid), or anything else derived from QwtPlotItem. A plot can have up to four axes, with each plot item attached to an x- and a y axis. The scales at the axes can be explicitely set (QwtScaleDiv), or - are calculated from the plot items, using algorithms (QwtScaleEngine) which - can be configured separately for each axis. + are calculated from the plot items, using algorithms (QwtScaleEngine) which + can be configured separately for each axis. \image html plot.png @@ -72,91 +70,79 @@ myPlot->replot(); class QWT_EXPORT QwtPlot: public QFrame, public QwtPlotDict { Q_OBJECT - Q_PROPERTY( QString propertiesDocument + Q_PROPERTY( QString propertiesDocument READ grabProperties WRITE applyProperties ) public: - /*! - Axis index + //! \brief Axis index + enum Axis + { + //! Y axis left of the canvas + yLeft, - - yLeft\n - - yRight\n - - xBottom\n - - xTop\n - */ - enum Axis - { - yLeft, - yRight, - xBottom, - xTop, + //! Y axis right of the canvas + yRight, - axisCnt + //! X axis below the canvas + xBottom, + + //! X axis above the canvas + xTop, + + //! Number of axes + axisCnt }; - /*! + /*! Position of the legend, relative to the canvas. - - LeftLegend\n - The legend will be left from the yLeft axis. - - RightLegend\n - The legend will be right from the yLeft axis. - - BottomLegend\n - The legend will be right below the xBottom axis. - - TopLegend\n - The legend will be between xTop axis and the title. - - ExternalLegend\n - External means that only the content of the legend - will be handled by QwtPlot, but not its geometry. - This might be interesting if an application wants to - have a legend in an external window ( or on the canvas ). - - \note In case of ExternalLegend, the legend is not - printed by print(). - \sa insertLegend() + \note In case of ExternalLegend, the legend is not + handled by QwtPlotRenderer */ - enum LegendPosition + enum LegendPosition { + //! The legend will be left from the QwtPlot::yLeft axis. LeftLegend, + + //! The legend will be right from the QwtPlot::yRight axis. RightLegend, + + //! The legend will be below QwtPlot::xBottom axis. BottomLegend, + + //! The legend will be between QwtPlot::xTop axis and the title. TopLegend, - + + /*! + External means that only the content of the legend + will be handled by QwtPlot, but not its geometry. + This type can be used to have a legend in an + external window ( or on the canvas ). + */ ExternalLegend }; - explicit QwtPlot(QWidget * = NULL); - explicit QwtPlot(const QwtText &title, QWidget *p = NULL); -#if QT_VERSION < 0x040000 - explicit QwtPlot(QWidget *, const char* name); -#endif + explicit QwtPlot( QWidget * = NULL ); + explicit QwtPlot( const QwtText &title, QWidget *p = NULL ); virtual ~QwtPlot(); - void applyProperties(const QString &); + void applyProperties( const QString & ); QString grabProperties() const; - void setAutoReplot(bool tf = true); + void setAutoReplot( bool tf = true ); bool autoReplot() const; - void print(QPaintDevice &p, - const QwtPlotPrintFilter & = QwtPlotPrintFilter()) const; - virtual void print(QPainter *, const QRect &rect, - const QwtPlotPrintFilter & = QwtPlotPrintFilter()) const; - // Layout QwtPlotLayout *plotLayout(); const QwtPlotLayout *plotLayout() const; - void setMargin(int margin); - int margin() const; - // Title - void setTitle(const QString &); - void setTitle(const QwtText &t); + void setTitle( const QString & ); + void setTitle( const QwtText &t ); QwtText title() const; QwtTextLabel *titleLabel(); @@ -167,88 +153,88 @@ public: QwtPlotCanvas *canvas(); const QwtPlotCanvas *canvas() const; - void setCanvasBackground (const QColor &c); - const QColor& canvasBackground() const; + void setCanvasBackground( const QBrush & ); + QBrush canvasBackground() const; - void setCanvasLineWidth(int w); + void setCanvasLineWidth( int w ); int canvasLineWidth() const; - virtual QwtScaleMap canvasMap(int axisId) const; + virtual QwtScaleMap canvasMap( int axisId ) const; - double invTransform(int axisId, int pos) const; - int transform(int axisId, double value) const; + double invTransform( int axisId, int pos ) const; + double transform( int axisId, double value ) const; // Axes - QwtScaleEngine *axisScaleEngine(int axisId); - const QwtScaleEngine *axisScaleEngine(int axisId) const; - void setAxisScaleEngine(int axisId, QwtScaleEngine *); + QwtScaleEngine *axisScaleEngine( int axisId ); + const QwtScaleEngine *axisScaleEngine( int axisId ) const; + void setAxisScaleEngine( int axisId, QwtScaleEngine * ); - void setAxisAutoScale(int axisId); - bool axisAutoScale(int axisId) const; + void setAxisAutoScale( int axisId, bool on = true ); + bool axisAutoScale( int axisId ) const; - void enableAxis(int axisId, bool tf = true); - bool axisEnabled(int axisId) const; + void enableAxis( int axisId, bool tf = true ); + bool axisEnabled( int axisId ) const; - void setAxisFont(int axisId, const QFont &f); - QFont axisFont(int axisId) const; + void setAxisFont( int axisId, const QFont &f ); + QFont axisFont( int axisId ) const; - void setAxisScale(int axisId, double min, double max, double step = 0); - void setAxisScaleDiv(int axisId, const QwtScaleDiv &); - void setAxisScaleDraw(int axisId, QwtScaleDraw *); + void setAxisScale( int axisId, double min, double max, double step = 0 ); + void setAxisScaleDiv( int axisId, const QwtScaleDiv & ); + void setAxisScaleDraw( int axisId, QwtScaleDraw * ); - double axisStepSize(int axisId) const; + double axisStepSize( int axisId ) const; + QwtInterval axisInterval( int axisId ) const; - const QwtScaleDiv *axisScaleDiv(int axisId) const; - QwtScaleDiv *axisScaleDiv(int axisId); + const QwtScaleDiv *axisScaleDiv( int axisId ) const; + QwtScaleDiv *axisScaleDiv( int axisId ); - const QwtScaleDraw *axisScaleDraw(int axisId) const; - QwtScaleDraw *axisScaleDraw(int axisId); + const QwtScaleDraw *axisScaleDraw( int axisId ) const; + QwtScaleDraw *axisScaleDraw( int axisId ); - const QwtScaleWidget *axisWidget(int axisId) const; - QwtScaleWidget *axisWidget(int axisId); + const QwtScaleWidget *axisWidget( int axisId ) const; + QwtScaleWidget *axisWidget( int axisId ); -#if QT_VERSION < 0x040000 - void setAxisLabelAlignment(int axisId, int); -#else - void setAxisLabelAlignment(int axisId, Qt::Alignment); -#endif - void setAxisLabelRotation(int axisId, double rotation); + void setAxisLabelAlignment( int axisId, Qt::Alignment ); + void setAxisLabelRotation( int axisId, double rotation ); - void setAxisTitle(int axisId, const QString &); - void setAxisTitle(int axisId, const QwtText &); - QwtText axisTitle(int axisId) const; + void setAxisTitle( int axisId, const QString & ); + void setAxisTitle( int axisId, const QwtText & ); + QwtText axisTitle( int axisId ) const; - void setAxisMaxMinor(int axisId, int maxMinor); - int axisMaxMajor(int axisId) const; - void setAxisMaxMajor(int axisId, int maxMajor); - int axisMaxMinor(int axisId) const; + void setAxisMaxMinor( int axisId, int maxMinor ); + int axisMaxMinor( int axisId ) const; - // Legend + void setAxisMaxMajor( int axisId, int maxMajor ); + int axisMaxMajor( int axisId ) const; - void insertLegend(QwtLegend *, LegendPosition = QwtPlot::RightLegend, - double ratio = -1.0); + // Legend + + void insertLegend( QwtLegend *, LegendPosition = QwtPlot::RightLegend, + double ratio = -1.0 ); QwtLegend *legend(); const QwtLegend *legend() const; // Misc - virtual void polish(); virtual QSize sizeHint() const; virtual QSize minimumSizeHint() const; virtual void updateLayout(); - virtual void drawCanvas(QPainter *); + virtual void drawCanvas( QPainter * ); void updateAxes(); - virtual bool event(QEvent *); + virtual bool event( QEvent * ); -signals: + virtual void drawItems( QPainter *, const QRectF &, + const QwtScaleMap maps[axisCnt] ) const; + +Q_SIGNALS: /*! - A signal which is emitted when the user has clicked on - a legend item, which is in QwtLegend::ClickableItem mode. + A signal which is emitted when the user has clicked on + a legend item, which is in QwtLegend::ClickableItem mode. \param plotItem Corresponding plot item of the selected legend item @@ -256,10 +242,10 @@ signals: \note clicks are disabled as default \sa QwtLegend::setItemMode(), QwtLegend::itemMode() */ - void legendClicked(QwtPlotItem *plotItem); + void legendClicked( QwtPlotItem *plotItem ); /*! - A signal which is emitted when the user has clicked on + A signal which is emitted when the user has clicked on a legend item, which is in QwtLegend::CheckableItem mode \param plotItem Corresponding plot item of the @@ -270,49 +256,29 @@ signals: \sa QwtLegend::setItemMode(), QwtLegend::itemMode() */ - void legendChecked(QwtPlotItem *plotItem, bool on); - -public slots: - virtual void clear(); + void legendChecked( QwtPlotItem *plotItem, bool on ); +public Q_SLOTS: virtual void replot(); void autoRefresh(); -protected slots: +protected Q_SLOTS: virtual void legendItemClicked(); - virtual void legendItemChecked(bool); + virtual void legendItemChecked( bool ); protected: - static bool axisValid(int axisId); - - virtual void drawItems(QPainter *, const QRect &, - const QwtScaleMap maps[axisCnt], - const QwtPlotPrintFilter &) const; + static bool axisValid( int axisId ); virtual void updateTabOrder(); - virtual void resizeEvent(QResizeEvent *e); - - virtual void printLegendItem(QPainter *, - const QWidget *, const QRect &) const; - - virtual void printTitle(QPainter *, const QRect &) const; - - virtual void printScale(QPainter *, int axisId, int startDist, int endDist, - int baseDist, const QRect &) const; - - virtual void printCanvas(QPainter *, - const QRect &boundingRect, const QRect &canvasRect, - const QwtScaleMap maps[axisCnt], const QwtPlotPrintFilter &) const; - - virtual void printLegend(QPainter *, const QRect &) const; + virtual void resizeEvent( QResizeEvent *e ); private: void initAxesData(); void deleteAxesData(); void updateScaleDiv(); - void initPlot(const QwtText &title); + void initPlot( const QwtText &title ); class AxisData; AxisData *d_axisData[axisCnt]; diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_axis.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_axis.cpp index caf179952..cef5bd101 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_axis.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_axis.cpp @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -36,32 +36,36 @@ void QwtPlot::initAxesData() { int axisId; - for( axisId = 0; axisId < axisCnt; axisId++) + for ( axisId = 0; axisId < axisCnt; axisId++ ) d_axisData[axisId] = new AxisData; - d_axisData[yLeft]->scaleWidget = - new QwtScaleWidget(QwtScaleDraw::LeftScale, this); - d_axisData[yRight]->scaleWidget = - new QwtScaleWidget(QwtScaleDraw::RightScale, this); - d_axisData[xTop]->scaleWidget = - new QwtScaleWidget(QwtScaleDraw::TopScale, this); - d_axisData[xBottom]->scaleWidget = - new QwtScaleWidget(QwtScaleDraw::BottomScale, this); + d_axisData[yLeft]->scaleWidget = + new QwtScaleWidget( QwtScaleDraw::LeftScale, this ); + d_axisData[yRight]->scaleWidget = + new QwtScaleWidget( QwtScaleDraw::RightScale, this ); + d_axisData[xTop]->scaleWidget = + new QwtScaleWidget( QwtScaleDraw::TopScale, this ); + d_axisData[xBottom]->scaleWidget = + new QwtScaleWidget( QwtScaleDraw::BottomScale, this ); + d_axisData[yLeft]->scaleWidget->setObjectName( "QwtPlotAxisYLeft" ); + d_axisData[yRight]->scaleWidget->setObjectName( "QwtPlotAxisYRight" ); + d_axisData[xTop]->scaleWidget->setObjectName( "QwtPlotAxisXTop" ); + d_axisData[xBottom]->scaleWidget->setObjectName( "QwtPlotAxisXBottom" ); - QFont fscl(fontInfo().family(), 10); - QFont fttl(fontInfo().family(), 12, QFont::Bold); + QFont fscl( fontInfo().family(), 10 ); + QFont fttl( fontInfo().family(), 12, QFont::Bold ); - for(axisId = 0; axisId < axisCnt; axisId++) + for ( axisId = 0; axisId < axisCnt; axisId++ ) { AxisData &d = *d_axisData[axisId]; - d.scaleWidget->setFont(fscl); - d.scaleWidget->setMargin(2); + d.scaleWidget->setFont( fscl ); + d.scaleWidget->setMargin( 2 ); QwtText text = d.scaleWidget->title(); - text.setFont(fttl); - d.scaleWidget->setTitle(text); + text.setFont( fttl ); + d.scaleWidget->setTitle( text ); d.doAutoScale = true; @@ -85,7 +89,7 @@ void QwtPlot::initAxesData() void QwtPlot::deleteAxesData() { - for( int axisId = 0; axisId < axisCnt; axisId++) + for ( int axisId = 0; axisId < axisCnt; axisId++ ) { delete d_axisData[axisId]->scaleEngine; delete d_axisData[axisId]; @@ -97,9 +101,9 @@ void QwtPlot::deleteAxesData() \return specified axis, or NULL if axisId is invalid. \param axisId axis index */ -const QwtScaleWidget *QwtPlot::axisWidget(int axisId) const +const QwtScaleWidget *QwtPlot::axisWidget( int axisId ) const { - if (axisValid(axisId)) + if ( axisValid( axisId ) ) return d_axisData[axisId]->scaleWidget; return NULL; @@ -109,9 +113,9 @@ const QwtScaleWidget *QwtPlot::axisWidget(int axisId) const \return specified axis, or NULL if axisId is invalid. \param axisId axis index */ -QwtScaleWidget *QwtPlot::axisWidget(int axisId) +QwtScaleWidget *QwtPlot::axisWidget( int axisId ) { - if (axisValid(axisId)) + if ( axisValid( axisId ) ) return d_axisData[axisId]->scaleWidget; return NULL; @@ -125,9 +129,9 @@ QwtScaleWidget *QwtPlot::axisWidget(int axisId) \sa axisScaleEngine() */ -void QwtPlot::setAxisScaleEngine(int axisId, QwtScaleEngine *scaleEngine) +void QwtPlot::setAxisScaleEngine( int axisId, QwtScaleEngine *scaleEngine ) { - if (axisValid(axisId) && scaleEngine != NULL ) + if ( axisValid( axisId ) && scaleEngine != NULL ) { AxisData &d = *d_axisData[axisId]; @@ -140,25 +144,25 @@ void QwtPlot::setAxisScaleEngine(int axisId, QwtScaleEngine *scaleEngine) } } -/*! +/*! \param axisId axis index \return Scale engine for a specific axis */ -QwtScaleEngine *QwtPlot::axisScaleEngine(int axisId) +QwtScaleEngine *QwtPlot::axisScaleEngine( int axisId ) { - if (axisValid(axisId)) + if ( axisValid( axisId ) ) return d_axisData[axisId]->scaleEngine; else return NULL; } -/*! +/*! \param axisId axis index \return Scale engine for a specific axis */ -const QwtScaleEngine *QwtPlot::axisScaleEngine(int axisId) const +const QwtScaleEngine *QwtPlot::axisScaleEngine( int axisId ) const { - if (axisValid(axisId)) + if ( axisValid( axisId ) ) return d_axisData[axisId]->scaleEngine; else return NULL; @@ -167,22 +171,22 @@ const QwtScaleEngine *QwtPlot::axisScaleEngine(int axisId) const \return \c true if autoscaling is enabled \param axisId axis index */ -bool QwtPlot::axisAutoScale(int axisId) const +bool QwtPlot::axisAutoScale( int axisId ) const { - if (axisValid(axisId)) + if ( axisValid( axisId ) ) return d_axisData[axisId]->doAutoScale; else return false; - + } /*! \return \c true if a specified axis is enabled \param axisId axis index */ -bool QwtPlot::axisEnabled(int axisId) const +bool QwtPlot::axisEnabled( int axisId ) const { - if (axisValid(axisId)) + if ( axisValid( axisId ) ) return d_axisData[axisId]->isEnabled; else return false; @@ -192,23 +196,23 @@ bool QwtPlot::axisEnabled(int axisId) const \return the font of the scale labels for a specified axis \param axisId axis index */ -QFont QwtPlot::axisFont(int axisId) const +QFont QwtPlot::axisFont( int axisId ) const { - if (axisValid(axisId)) - return axisWidget(axisId)->font(); + if ( axisValid( axisId ) ) + return axisWidget( axisId )->font(); else return QFont(); - + } /*! \return the maximum number of major ticks for a specified axis \param axisId axis index - sa setAxisMaxMajor() + \sa setAxisMaxMajor() */ -int QwtPlot::axisMaxMajor(int axisId) const +int QwtPlot::axisMaxMajor( int axisId ) const { - if (axisValid(axisId)) + if ( axisValid( axisId ) ) return d_axisData[axisId]->maxMajor; else return 0; @@ -217,11 +221,11 @@ int QwtPlot::axisMaxMajor(int axisId) const /*! \return the maximum number of minor ticks for a specified axis \param axisId axis index - sa setAxisMaxMinor() + \sa setAxisMaxMinor() */ -int QwtPlot::axisMaxMinor(int axisId) const +int QwtPlot::axisMaxMinor( int axisId ) const { - if (axisValid(axisId)) + if ( axisValid( axisId ) ) return d_axisData[axisId]->maxMinor; else return 0; @@ -234,13 +238,13 @@ int QwtPlot::axisMaxMinor(int axisId) const are the current limits of the axis scale. \param axisId axis index - \return Scale division + \return Scale division \sa QwtScaleDiv, setAxisScaleDiv() */ -const QwtScaleDiv *QwtPlot::axisScaleDiv(int axisId) const +const QwtScaleDiv *QwtPlot::axisScaleDiv( int axisId ) const { - if (!axisValid(axisId)) + if ( !axisValid( axisId ) ) return NULL; return &d_axisData[axisId]->scaleDiv; @@ -253,13 +257,13 @@ const QwtScaleDiv *QwtPlot::axisScaleDiv(int axisId) const are the current limits of the axis scale. \param axisId axis index - \return Scale division + \return Scale division \sa QwtScaleDiv, setAxisScaleDiv() */ -QwtScaleDiv *QwtPlot::axisScaleDiv(int axisId) +QwtScaleDiv *QwtPlot::axisScaleDiv( int axisId ) { - if (!axisValid(axisId)) + if ( !axisValid( axisId ) ) return NULL; return &d_axisData[axisId]->scaleDiv; @@ -271,12 +275,12 @@ QwtScaleDiv *QwtPlot::axisScaleDiv(int axisId) \return specified scaleDraw for axis, or NULL if axis is invalid. \sa QwtScaleDraw */ -const QwtScaleDraw *QwtPlot::axisScaleDraw(int axisId) const +const QwtScaleDraw *QwtPlot::axisScaleDraw( int axisId ) const { - if (!axisValid(axisId)) + if ( !axisValid( axisId ) ) return NULL; - return axisWidget(axisId)->scaleDraw(); + return axisWidget( axisId )->scaleDraw(); } /*! @@ -285,40 +289,58 @@ const QwtScaleDraw *QwtPlot::axisScaleDraw(int axisId) const \return specified scaleDraw for axis, or NULL if axis is invalid. \sa QwtScaleDraw */ -QwtScaleDraw *QwtPlot::axisScaleDraw(int axisId) +QwtScaleDraw *QwtPlot::axisScaleDraw( int axisId ) { - if (!axisValid(axisId)) + if ( !axisValid( axisId ) ) return NULL; - return axisWidget(axisId)->scaleDraw(); + return axisWidget( axisId )->scaleDraw(); } /*! Return the step size parameter, that has been set - in setAxisScale. This doesn't need to be the step size + in setAxisScale. This doesn't need to be the step size of the current scale. \param axisId axis index \return step size parameter value \sa setAxisScale() -*/ -double QwtPlot::axisStepSize(int axisId) const +*/ +double QwtPlot::axisStepSize( int axisId ) const { - if (!axisValid(axisId)) + if ( !axisValid( axisId ) ) return 0; return d_axisData[axisId]->stepSize; } +/*! + \brief Return the current interval of the specified axis + + This is only a convenience function for axisScaleDiv( axisId )->interval(); + + \param axisId axis index + \return Scale interval + + \sa QwtScaleDiv, axisScaleDiv() +*/ +QwtInterval QwtPlot::axisInterval( int axisId ) const +{ + if ( !axisValid( axisId ) ) + return QwtInterval(); + + return d_axisData[axisId]->scaleDiv.interval(); +} + /*! \return the title of a specified axis \param axisId axis index */ -QwtText QwtPlot::axisTitle(int axisId) const +QwtText QwtPlot::axisTitle( int axisId ) const { - if (axisValid(axisId)) - return axisWidget(axisId)->title(); + if ( axisValid( axisId ) ) + return axisWidget( axisId )->title(); else return QwtText(); } @@ -335,9 +357,9 @@ QwtText QwtPlot::axisTitle(int axisId) const \param axisId axis index \param tf \c true (enabled) or \c false (disabled) */ -void QwtPlot::enableAxis(int axisId, bool tf) +void QwtPlot::enableAxis( int axisId, bool tf ) { - if (axisValid(axisId) && tf != d_axisData[axisId]->isEnabled) + if ( axisValid( axisId ) && tf != d_axisData[axisId]->isEnabled ) { d_axisData[axisId]->isEnabled = tf; updateLayout(); @@ -352,12 +374,12 @@ void QwtPlot::enableAxis(int axisId, bool tf) \warning The position can be an x or a y coordinate, depending on the specified axis. */ -double QwtPlot::invTransform(int axisId, int pos) const +double QwtPlot::invTransform( int axisId, int pos ) const { - if (axisValid(axisId)) - return(canvasMap(axisId).invTransform(pos)); + if ( axisValid( axisId ) ) + return( canvasMap( axisId ).invTransform( pos ) ); else - return 0.0; + return 0.0; } @@ -368,13 +390,12 @@ double QwtPlot::invTransform(int axisId, int pos) const \return X or y coordinate in the plotting region corresponding to the value. */ -int QwtPlot::transform(int axisId, double value) const +double QwtPlot::transform( int axisId, double value ) const { - if (axisValid(axisId)) - return(canvasMap(axisId).transform(value)); + if ( axisValid( axisId ) ) + return( canvasMap( axisId ).transform( value ) ); else - return 0; - + return 0.0; } /*! @@ -384,10 +405,10 @@ int QwtPlot::transform(int axisId, double value) const \warning This function changes the font of the tick labels, not of the axis title. */ -void QwtPlot::setAxisFont(int axisId, const QFont &f) +void QwtPlot::setAxisFont( int axisId, const QFont &f ) { - if (axisValid(axisId)) - axisWidget(axisId)->setFont(f); + if ( axisValid( axisId ) ) + axisWidget( axisId )->setFont( f ); } /*! @@ -397,13 +418,17 @@ void QwtPlot::setAxisFont(int axisId, const QFont &f) after a fixed scale has been set. Autoscaling is enabled by default. \param axisId axis index - \sa QwtPlot::setAxisScale(), QwtPlot::setAxisScaleDiv() + \param on On/Off + \sa setAxisScale(), setAxisScaleDiv(), updateAxes() + + \note The autoscaling flag has no effect until updateAxes() is executed + ( called by replot() ). */ -void QwtPlot::setAxisAutoScale(int axisId) +void QwtPlot::setAxisAutoScale( int axisId, bool on ) { - if (axisValid(axisId) && !d_axisData[axisId]->doAutoScale ) + if ( axisValid( axisId ) && ( d_axisData[axisId]->doAutoScale != on ) ) { - d_axisData[axisId]->doAutoScale = true; + d_axisData[axisId]->doAutoScale = on; autoRefresh(); } } @@ -415,11 +440,11 @@ void QwtPlot::setAxisAutoScale(int axisId) \param max minimum and maximum of the scale \param stepSize Major step size. If step == 0, the step size is calculated automatically using the maxMajor setting. - \sa setAxisMaxMajor(), setAxisAutoScale() + \sa setAxisMaxMajor(), setAxisAutoScale(), axisStepSize() */ -void QwtPlot::setAxisScale(int axisId, double min, double max, double stepSize) +void QwtPlot::setAxisScale( int axisId, double min, double max, double stepSize ) { - if (axisValid(axisId)) + if ( axisValid( axisId ) ) { AxisData &d = *d_axisData[axisId]; @@ -429,7 +454,7 @@ void QwtPlot::setAxisScale(int axisId, double min, double max, double stepSize) d.minValue = min; d.maxValue = max; d.stepSize = stepSize; - + autoRefresh(); } } @@ -440,9 +465,9 @@ void QwtPlot::setAxisScale(int axisId, double min, double max, double stepSize) \param scaleDiv Scale division \sa setAxisScale(), setAxisAutoScale() */ -void QwtPlot::setAxisScaleDiv(int axisId, const QwtScaleDiv &scaleDiv) +void QwtPlot::setAxisScaleDiv( int axisId, const QwtScaleDiv &scaleDiv ) { - if (axisValid(axisId)) + if ( axisValid( axisId ) ) { AxisData &d = *d_axisData[axisId]; @@ -464,15 +489,15 @@ void QwtPlot::setAxisScaleDiv(int axisId, const QwtScaleDiv &scaleDiv) by the corresponding QwtScale member ( like a child object ). \sa QwtScaleDraw, QwtScaleWidget - \warning The attributes of scaleDraw will be overwritten by those of the - previous QwtScaleDraw. + \warning The attributes of scaleDraw will be overwritten by those of the + previous QwtScaleDraw. */ -void QwtPlot::setAxisScaleDraw(int axisId, QwtScaleDraw *scaleDraw) +void QwtPlot::setAxisScaleDraw( int axisId, QwtScaleDraw *scaleDraw ) { - if (axisValid(axisId)) + if ( axisValid( axisId ) ) { - axisWidget(axisId)->setScaleDraw(scaleDraw); + axisWidget( axisId )->setScaleDraw( scaleDraw ); autoRefresh(); } } @@ -480,17 +505,13 @@ void QwtPlot::setAxisScaleDraw(int axisId, QwtScaleDraw *scaleDraw) /*! Change the alignment of the tick labels \param axisId axis index - \param alignment Or'd Qt::AlignmentFlags + \param alignment Or'd Qt::AlignmentFlags see \sa QwtScaleDraw::setLabelAlignment() */ -#if QT_VERSION < 0x040000 -void QwtPlot::setAxisLabelAlignment(int axisId, int alignment) -#else -void QwtPlot::setAxisLabelAlignment(int axisId, Qt::Alignment alignment) -#endif +void QwtPlot::setAxisLabelAlignment( int axisId, Qt::Alignment alignment ) { - if (axisValid(axisId)) - axisWidget(axisId)->setLabelAlignment(alignment); + if ( axisValid( axisId ) ) + axisWidget( axisId )->setLabelAlignment( alignment ); } /*! @@ -500,10 +521,10 @@ void QwtPlot::setAxisLabelAlignment(int axisId, Qt::Alignment alignment) the label alignment might be adjusted too. \sa QwtScaleDraw::setLabelRotation(), setAxisLabelAlignment() */ -void QwtPlot::setAxisLabelRotation(int axisId, double rotation) +void QwtPlot::setAxisLabelRotation( int axisId, double rotation ) { - if (axisValid(axisId)) - axisWidget(axisId)->setLabelRotation(rotation); + if ( axisValid( axisId ) ) + axisWidget( axisId )->setLabelRotation( rotation ); } /*! @@ -513,17 +534,13 @@ void QwtPlot::setAxisLabelRotation(int axisId, double rotation) \param maxMinor maximum number of minor steps \sa axisMaxMinor() */ -void QwtPlot::setAxisMaxMinor(int axisId, int maxMinor) +void QwtPlot::setAxisMaxMinor( int axisId, int maxMinor ) { - if (axisValid(axisId)) + if ( axisValid( axisId ) ) { - if ( maxMinor < 0 ) - maxMinor = 0; - if ( maxMinor > 100 ) - maxMinor = 100; - - AxisData &d = *d_axisData[axisId]; + maxMinor = qBound( 0, maxMinor, 100 ); + AxisData &d = *d_axisData[axisId]; if ( maxMinor != d.maxMinor ) { d.maxMinor = maxMinor; @@ -540,17 +557,14 @@ void QwtPlot::setAxisMaxMinor(int axisId, int maxMinor) \param maxMajor maximum number of major steps \sa axisMaxMajor() */ -void QwtPlot::setAxisMaxMajor(int axisId, int maxMajor) +void QwtPlot::setAxisMaxMajor( int axisId, int maxMajor ) { - if (axisValid(axisId)) + if ( axisValid( axisId ) ) { - if ( maxMajor < 1 ) - maxMajor = 1; - if ( maxMajor > 1000 ) - maxMajor = 10000; - + maxMajor = qBound( 1, maxMajor, 10000 ); + AxisData &d = *d_axisData[axisId]; - if ( maxMajor != d.maxMinor ) + if ( maxMajor != d.maxMajor ) { d.maxMajor = maxMajor; d.scaleDiv.invalidate(); @@ -564,10 +578,10 @@ void QwtPlot::setAxisMaxMajor(int axisId, int maxMajor) \param axisId axis index \param title axis title */ -void QwtPlot::setAxisTitle(int axisId, const QString &title) +void QwtPlot::setAxisTitle( int axisId, const QString &title ) { - if (axisValid(axisId)) - axisWidget(axisId)->setTitle(title); + if ( axisValid( axisId ) ) + axisWidget( axisId )->setTitle( title ); } /*! @@ -575,19 +589,19 @@ void QwtPlot::setAxisTitle(int axisId, const QString &title) \param axisId axis index \param title axis title */ -void QwtPlot::setAxisTitle(int axisId, const QwtText &title) +void QwtPlot::setAxisTitle( int axisId, const QwtText &title ) { - if (axisValid(axisId)) - axisWidget(axisId)->setTitle(title); + if ( axisValid( axisId ) ) + axisWidget( axisId )->setTitle( title ); } //! Rebuild the scales -void QwtPlot::updateAxes() +void QwtPlot::updateAxes() { // Find bounding interval of the item data // for all axes, where autoscaling is enabled - - QwtDoubleInterval intv[axisCnt]; + + QwtInterval intv[axisCnt]; const QwtPlotItemList& itmList = itemList(); @@ -596,20 +610,23 @@ void QwtPlot::updateAxes() { const QwtPlotItem *item = *it; - if ( !item->testItemAttribute(QwtPlotItem::AutoScale) ) + if ( !item->testItemAttribute( QwtPlotItem::AutoScale ) ) continue; - if ( axisAutoScale(item->xAxis()) || axisAutoScale(item->yAxis()) ) + if ( !item->isVisible() ) + continue; + + if ( axisAutoScale( item->xAxis() ) || axisAutoScale( item->yAxis() ) ) { - const QwtDoubleRect rect = item->boundingRect(); - intv[item->xAxis()] |= QwtDoubleInterval(rect.left(), rect.right()); - intv[item->yAxis()] |= QwtDoubleInterval(rect.top(), rect.bottom()); + const QRectF rect = item->boundingRect(); + intv[item->xAxis()] |= QwtInterval( rect.left(), rect.right() ); + intv[item->yAxis()] |= QwtInterval( rect.top(), rect.bottom() ); } } // Adjust scales - for (int axisId = 0; axisId < axisCnt; axisId++) + for ( int axisId = 0; axisId < axisCnt; axisId++ ) { AxisData &d = *d_axisData[axisId]; @@ -624,30 +641,30 @@ void QwtPlot::updateAxes() minValue = intv[axisId].minValue(); maxValue = intv[axisId].maxValue(); - d.scaleEngine->autoScale(d.maxMajor, - minValue, maxValue, stepSize); + d.scaleEngine->autoScale( d.maxMajor, + minValue, maxValue, stepSize ); } if ( !d.scaleDiv.isValid() ) { d.scaleDiv = d.scaleEngine->divideScale( - minValue, maxValue, - d.maxMajor, d.maxMinor, stepSize); + minValue, maxValue, + d.maxMajor, d.maxMinor, stepSize ); } - QwtScaleWidget *scaleWidget = axisWidget(axisId); + QwtScaleWidget *scaleWidget = axisWidget( axisId ); scaleWidget->setScaleDiv( - d.scaleEngine->transformation(), d.scaleDiv); + d.scaleEngine->transformation(), d.scaleDiv ); int startDist, endDist; - scaleWidget->getBorderDistHint(startDist, endDist); - scaleWidget->setBorderDist(startDist, endDist); + scaleWidget->getBorderDistHint( startDist, endDist ); + scaleWidget->setBorderDist( startDist, endDist ); } for ( it = itmList.begin(); it != itmList.end(); ++it ) { QwtPlotItem *item = *it; - item->updateScaleDiv( *axisScaleDiv(item->xAxis()), - *axisScaleDiv(item->yAxis())); + item->updateScaleDiv( *axisScaleDiv( item->xAxis() ), + *axisScaleDiv( item->yAxis() ) ); } } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_canvas.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_canvas.cpp index 22301991c..19903823e 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_canvas.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_canvas.cpp @@ -7,68 +7,532 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - +#include "qwt_plot_canvas.h" +#include "qwt_painter.h" +#include "qwt_null_paintdevice.h" +#include "qwt_math.h" +#include "qwt_plot.h" #include #include -#if QT_VERSION >= 0x040000 #include #include +#include +#include #ifdef Q_WS_X11 #include #endif + +class QwtStyleSheetRecorder: public QwtNullPaintDevice +{ +public: + QwtStyleSheetRecorder( const QSize &size ): + QwtNullPaintDevice( QPaintEngine::AllFeatures ) + { + setSize( size ); + } + + virtual void updateState( const QPaintEngineState &state ) + { + if ( state.state() & QPaintEngine::DirtyPen ) + { + d_pen = state.pen(); + } + if ( state.state() & QPaintEngine::DirtyBrush ) + { + d_brush = state.brush(); + } + if ( state.state() & QPaintEngine::DirtyBrushOrigin ) + { + d_origin = state.brushOrigin(); + } + } + + virtual void drawRects(const QRectF *rects, int count ) + { + for ( int i = 0; i < count; i++ ) + border.rectList += rects[i]; + } + + virtual void drawPath( const QPainterPath &path ) + { + const QRectF rect( QPointF( 0.0, 0.0 ) , size() ); + if ( path.controlPointRect().contains( rect.center() ) ) + { + setCornerRects( path ); + alignCornerRects( rect ); + + background.path = path; + background.brush = d_brush; + background.origin = d_origin; + } + else + { + border.pathList += path; + } + } + + void setCornerRects( const QPainterPath &path ) + { + QPointF pos( 0.0, 0.0 ); + + for ( int i = 0; i < path.elementCount(); i++ ) + { + QPainterPath::Element el = path.elementAt(i); + switch( el.type ) + { + case QPainterPath::MoveToElement: + case QPainterPath::LineToElement: + { + pos.setX( el.x ); + pos.setY( el.y ); + break; + } + case QPainterPath::CurveToElement: + { + QRectF r( pos, QPointF( el.x, el.y ) ); + clipRects += r.normalized(); + + pos.setX( el.x ); + pos.setY( el.y ); + + break; + } + case QPainterPath::CurveToDataElement: + { + if ( clipRects.size() > 0 ) + { + QRectF r = clipRects.last(); + r.setCoords( + qMin( r.left(), el.x ), + qMin( r.top(), el.y ), + qMax( r.right(), el.x ), + qMax( r.bottom(), el.y ) + ); + clipRects.last() = r.normalized(); + } + break; + } + } + } + } + +private: + void alignCornerRects( const QRectF &rect ) + { + for ( int i = 0; i < clipRects.size(); i++ ) + { + QRectF &r = clipRects[i]; + if ( r.center().x() < rect.center().x() ) + r.setLeft( rect.left() ); + else + r.setRight( rect.right() ); + + if ( r.center().y() < rect.center().y() ) + r.setTop( rect.top() ); + else + r.setBottom( rect.bottom() ); + } + } + + +public: + QVector clipRects; + + struct Border + { + QList pathList; + QList rectList; + QRegion clipRegion; + } border; + + struct Background + { + QPainterPath path; + QBrush brush; + QPointF origin; + } background; + +private: + QPen d_pen; + QBrush d_brush; + QPointF d_origin; +}; + +static void qwtDrawBackground( QPainter *painter, QWidget *widget ) +{ + const QBrush &brush = + widget->palette().brush( widget->backgroundRole() ); + + if ( brush.style() == Qt::TexturePattern ) + { + QPixmap pm( widget->size() ); + pm.fill( widget, 0, 0 ); + painter->drawPixmap( 0, 0, pm ); + } + else if ( brush.gradient() ) + { + QVector rects; + + if ( brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode ) + { + rects += widget->rect(); + } + else + { + rects = painter->clipRegion().rects(); + } + +#if 1 + bool useRaster = false; + + if ( painter->paintEngine()->type() == QPaintEngine::X11 ) + { + // Qt 4.7.1: gradients on X11 are broken ( subrects + + // QGradient::StretchToDeviceMode ) and horrible slow. + // As workaround we have to use the raster paintengine. + // Even if the QImage -> QPixmap translation is slow + // it is three times faster, than using X11 directly + + useRaster = true; + } #endif -#include -#include "qwt_painter.h" -#include "qwt_math.h" -#include "qwt_plot.h" -#include "qwt_paint_buffer.h" -#include "qwt_plot_canvas.h" + if ( useRaster ) + { + QImage::Format format = QImage::Format_RGB32; + + const QGradientStops stops = brush.gradient()->stops(); + for ( int i = 0; i < stops.size(); i++ ) + { + if ( stops[i].second.alpha() != 255 ) + { + // don't use Format_ARGB32_Premultiplied. It's + // recommended by the Qt docs, but QPainter::drawImage() + // is horrible slow on X11. + + format = QImage::Format_ARGB32; + break; + } + } + + QImage image( widget->size(), format ); + + QPainter p( &image ); + p.setPen( Qt::NoPen ); + p.setBrush( brush ); + + p.drawRects( rects ); + + p.end(); + + painter->drawImage( 0, 0, image ); + } + else + { + painter->save(); + + painter->setPen( Qt::NoPen ); + painter->setBrush( brush ); + + painter->drawRects( rects ); + + painter->restore(); + } + } + else + { + painter->save(); + + painter->setPen( Qt::NoPen ); + painter->setBrush( brush ); + + painter->drawRects( painter->clipRegion().rects() ); + + painter->restore(); + } +} + +static inline void qwtRevertPath( QPainterPath &path ) +{ + if ( path.elementCount() == 4 ) + { + QPainterPath::Element &el0 = + const_cast( path.elementAt(0) ); + QPainterPath::Element &el2 = + const_cast( path.elementAt(3) ); + + qSwap( el0.x, el2.x ); + qSwap( el0.y, el2.y ); + } +} + +static QPainterPath qwtCombinePathList( const QRectF &rect, + const QList &pathList ) +{ + if ( pathList.isEmpty() ) + return QPainterPath(); + + QPainterPath ordered[8]; // starting top left + + for ( int i = 0; i < pathList.size(); i++ ) + { + int index = -1; + QPainterPath subPath = pathList[i]; + + const QRectF br = pathList[i].controlPointRect(); + if ( br.center().x() < rect.center().x() ) + { + if ( br.center().y() < rect.center().y() ) + { + if ( qAbs( br.top() - rect.top() ) < + qAbs( br.left() - rect.left() ) ) + { + index = 1; + } + else + { + index = 0; + } + } + else + { + if ( qAbs( br.bottom() - rect.bottom() ) < + qAbs( br.left() - rect.left() ) ) + { + index = 6; + } + else + { + index = 7; + } + } + + if ( subPath.currentPosition().y() > br.center().y() ) + qwtRevertPath( subPath ); + } + else + { + if ( br.center().y() < rect.center().y() ) + { + if ( qAbs( br.top() - rect.top() ) < + qAbs( br.right() - rect.right() ) ) + { + index = 2; + } + else + { + index = 3; + } + } + else + { + if ( qAbs( br.bottom() - rect.bottom() ) < + qAbs( br.right() - rect.right() ) ) + { + index = 5; + } + else + { + index = 4; + } + } + if ( subPath.currentPosition().y() < br.center().y() ) + qwtRevertPath( subPath ); + } + ordered[index] = subPath; + } + + for ( int i = 0; i < 4; i++ ) + { + if ( ordered[ 2 * i].isEmpty() != ordered[2 * i + 1].isEmpty() ) + { + // we don't accept incomplete rounded borders + return QPainterPath(); + } + } + + + const QPolygonF corners( rect ); + + QPainterPath path; + //path.moveTo( rect.topLeft() ); + + for ( int i = 0; i < 4; i++ ) + { + if ( ordered[2 * i].isEmpty() ) + { + path.lineTo( corners[i] ); + } + else + { + path.connectPath( ordered[2 * i] ); + path.connectPath( ordered[2 * i + 1] ); + } + } + + path.closeSubpath(); + +#if 0 + return path.simplified(); +#else + return path; +#endif +} + +static inline void qwtDrawStyledBackground( + QWidget *w, QPainter *painter ) +{ + QStyleOption opt; + opt.initFrom(w); + w->style()->drawPrimitive( QStyle::PE_Widget, &opt, painter, w); +} + +static QWidget *qwtBackgroundWidget( QWidget *w ) +{ + if ( w->parentWidget() == NULL ) + return w; + + if ( w->autoFillBackground() ) + { + const QBrush brush = w->palette().brush( w->backgroundRole() ); + if ( brush.color().alpha() > 0 ) + return w; + } + + if ( w->testAttribute( Qt::WA_StyledBackground ) ) + { + QImage image( 1, 1, QImage::Format_ARGB32 ); + image.fill( Qt::transparent ); + + QPainter painter( &image ); + painter.translate( -w->rect().center() ); + qwtDrawStyledBackground( w, &painter ); + painter.end(); + + if ( qAlpha( image.pixel( 0, 0 ) ) != 0 ) + return w; + } + + return qwtBackgroundWidget( w->parentWidget() ); +} + +static void qwtFillBackground( QPainter *painter, + QWidget *widget, const QVector &fillRects ) +{ + if ( fillRects.isEmpty() ) + return; + + QRegion clipRegion; + if ( painter->hasClipping() ) + clipRegion = painter->transform().map( painter->clipRegion() ); + else + clipRegion = widget->contentsRect(); + + // Try to find out which widget fills + // the unfilled areas of the styled background + + QWidget *bgWidget = qwtBackgroundWidget( widget->parentWidget() ); + + for ( int i = 0; i < fillRects.size(); i++ ) + { + const QRect rect = fillRects[i].toAlignedRect(); + if ( clipRegion.intersects( rect ) ) + { + QPixmap pm( rect.size() ); + pm.fill( bgWidget, widget->mapTo( bgWidget, rect.topLeft() ) ); + painter->drawPixmap( rect, pm ); + } + } +} + +static void qwtFillBackground( QPainter *painter, QwtPlotCanvas *canvas ) +{ + QVector rects; + + if ( canvas->testAttribute( Qt::WA_StyledBackground ) ) + { + QwtStyleSheetRecorder recorder( canvas->size() ); + + QPainter p( &recorder ); + qwtDrawStyledBackground( canvas, &p ); + p.end(); + + if ( recorder.background.brush.isOpaque() ) + rects = recorder.clipRects; + else + rects += canvas->rect(); + } + else + { + const QRectF r = canvas->rect(); + const double radius = canvas->borderRadius(); + if ( radius > 0.0 ) + { + QSize sz( radius, radius ); + + rects += QRectF( r.topLeft(), sz ); + rects += QRectF( r.topRight() - QPointF( radius, 0 ), sz ); + rects += QRectF( r.bottomRight() - QPointF( radius, radius ), sz ); + rects += QRectF( r.bottomLeft() - QPointF( 0, radius ), sz ); + } + } + + qwtFillBackground( painter, canvas, rects); +} + class QwtPlotCanvas::PrivateData { public: PrivateData(): - focusIndicator(NoFocusIndicator), - paintAttributes(0), - cache(NULL) + focusIndicator( NoFocusIndicator ), + borderRadius( 0 ), + paintAttributes( 0 ), + backingStore( NULL ) { + styleSheet.hasBorder = false; } ~PrivateData() { - delete cache; + delete backingStore; } FocusIndicator focusIndicator; - int paintAttributes; - QPixmap *cache; + double borderRadius; + QwtPlotCanvas::PaintAttributes paintAttributes; + QPixmap *backingStore; + + struct StyleSheet + { + bool hasBorder; + QPainterPath borderPath; + QVector cornerRects; + + struct StyleSheetBackground + { + QBrush brush; + QPointF origin; + } background; + + } styleSheet; + }; -//! Sets a cross cursor, enables QwtPlotCanvas::PaintCached +//! Sets a cross cursor, enables QwtPlotCanvas::BackingStore -QwtPlotCanvas::QwtPlotCanvas(QwtPlot *plot): - QFrame(plot) +QwtPlotCanvas::QwtPlotCanvas( QwtPlot *plot ): + QFrame( plot ) { d_data = new PrivateData; -#if QT_VERSION >= 0x040100 - setAutoFillBackground(true); +#ifndef QT_NO_CURSOR + setCursor( Qt::CrossCursor ); #endif -#if QT_VERSION < 0x040000 - setWFlags(Qt::WNoAutoErase); -#ifndef QT_NO_CURSOR - setCursor(Qt::crossCursor); -#endif -#else -#ifndef QT_NO_CURSOR - setCursor(Qt::CrossCursor); -#endif -#endif // >= 0x040000 - - setPaintAttribute(PaintCached, true); - setPaintAttribute(PaintPacked, true); + setAutoFillBackground( true ); + setPaintAttribute( QwtPlotCanvas::BackingStore, true ); + setPaintAttribute( QwtPlotCanvas::Opaque, true ); + setPaintAttribute( QwtPlotCanvas::HackStyledBackground, true ); } //! Destructor @@ -80,21 +544,13 @@ QwtPlotCanvas::~QwtPlotCanvas() //! Return parent plot widget QwtPlot *QwtPlotCanvas::plot() { - QWidget *w = parentWidget(); - if ( w && w->inherits("QwtPlot") ) - return (QwtPlot *)w; - - return NULL; + return qobject_cast( parentWidget() ); } //! Return parent plot widget const QwtPlot *QwtPlotCanvas::plot() const { - const QWidget *w = parentWidget(); - if ( w && w->inherits("QwtPlot") ) - return (QwtPlot *)w; - - return NULL; + return qobject_cast( parentWidget() ); } /*! @@ -103,13 +559,11 @@ const QwtPlot *QwtPlotCanvas::plot() const \param attribute Paint attribute \param on On/Off - The default setting enables PaintCached and PaintPacked - - \sa testPaintAttribute(), drawCanvas(), drawContents(), paintCache() + \sa testPaintAttribute(), backingStore() */ -void QwtPlotCanvas::setPaintAttribute(PaintAttribute attribute, bool on) +void QwtPlotCanvas::setPaintAttribute( PaintAttribute attribute, bool on ) { - if ( bool(d_data->paintAttributes & attribute) == on ) + if ( bool( d_data->paintAttributes & attribute ) == on ) return; if ( on ) @@ -117,43 +571,40 @@ void QwtPlotCanvas::setPaintAttribute(PaintAttribute attribute, bool on) else d_data->paintAttributes &= ~attribute; - switch(attribute) + switch ( attribute ) { - case PaintCached: + case BackingStore: { if ( on ) { - if ( d_data->cache == NULL ) - d_data->cache = new QPixmap(); + if ( d_data->backingStore == NULL ) + d_data->backingStore = new QPixmap(); if ( isVisible() ) { - const QRect cr = contentsRect(); - *d_data->cache = QPixmap::grabWidget(this, - cr.x(), cr.y(), cr.width(), cr.height() ); + *d_data->backingStore = + QPixmap::grabWidget( this, rect() ); } } else { - delete d_data->cache; - d_data->cache = NULL; + delete d_data->backingStore; + d_data->backingStore = NULL; } break; } - case PaintPacked: + case Opaque: { - /* - If not visible, changing of the background mode - is delayed until it becomes visible. This tries to avoid - looking through the canvas when the canvas is shown the first - time. - */ - - if ( on == false || isVisible() ) - QwtPlotCanvas::setSystemBackground(!on); + if ( on ) + setAttribute( Qt::WA_OpaquePaintEvent, true ); break; } + case HackStyledBackground: + case ImmediatePaint: + { + break; + } } } @@ -164,28 +615,22 @@ void QwtPlotCanvas::setPaintAttribute(PaintAttribute attribute, bool on) \return true if the attribute is enabled \sa setPaintAttribute() */ -bool QwtPlotCanvas::testPaintAttribute(PaintAttribute attribute) const +bool QwtPlotCanvas::testPaintAttribute( PaintAttribute attribute ) const { - return (d_data->paintAttributes & attribute) != 0; + return d_data->paintAttributes & attribute; } -//! Return the paint cache, might be null -QPixmap *QwtPlotCanvas::paintCache() +//! \return Backing store, might be null +const QPixmap *QwtPlotCanvas::backingStore() const { - return d_data->cache; + return d_data->backingStore; } -//! Return the paint cache, might be null -const QPixmap *QwtPlotCanvas::paintCache() const +//! Invalidate the internal backing store +void QwtPlotCanvas::invalidateBackingStore() { - return d_data->cache; -} - -//! Invalidate the internal paint cache -void QwtPlotCanvas::invalidatePaintCache() -{ - if ( d_data->cache ) - *d_data->cache = QPixmap(); + if ( d_data->backingStore ) + *d_data->backingStore = QPixmap(); } /*! @@ -193,14 +638,14 @@ void QwtPlotCanvas::invalidatePaintCache() \sa FocusIndicator, focusIndicator() */ -void QwtPlotCanvas::setFocusIndicator(FocusIndicator focusIndicator) +void QwtPlotCanvas::setFocusIndicator( FocusIndicator focusIndicator ) { d_data->focusIndicator = focusIndicator; } /*! \return Focus indicator - + \sa FocusIndicator, setFocusIndicator() */ QwtPlotCanvas::FocusIndicator QwtPlotCanvas::focusIndicator() const @@ -209,186 +654,285 @@ QwtPlotCanvas::FocusIndicator QwtPlotCanvas::focusIndicator() const } /*! - Hide event - \param event Hide event + Set the radius for the corners of the border frame + + \param radius Radius of a rounded corner + \sa borderRadius() */ -void QwtPlotCanvas::hideEvent(QHideEvent *event) +void QwtPlotCanvas::setBorderRadius( double radius ) { - QFrame::hideEvent(event); + d_data->borderRadius = qMax( 0.0, radius ); +} - if ( d_data->paintAttributes & PaintPacked ) +/*! + \return Radius for the corners of the border frame + \sa setBorderRadius() +*/ +double QwtPlotCanvas::borderRadius() const +{ + return d_data->borderRadius; +} + +/*! + Qt event handler for QEvent::PolishRequest and QEvent::StyleChange + \param event Qt Event +*/ +bool QwtPlotCanvas::event( QEvent *event ) +{ + if ( event->type() == QEvent::PolishRequest ) { - // enable system background to avoid the "looking through - // the canvas" effect, for the next show - - setSystemBackground(true); + if ( testPaintAttribute( QwtPlotCanvas::Opaque ) ) + { + // Setting a style sheet changes the + // Qt::WA_OpaquePaintEvent attribute, but we insist + // on painting the background. + + setAttribute( Qt::WA_OpaquePaintEvent, true ); + } } + + if ( event->type() == QEvent::PolishRequest || + event->type() == QEvent::StyleChange ) + { + updateStyleSheetInfo(); + } + + return QFrame::event( event ); } /*! Paint event \param event Paint event */ -void QwtPlotCanvas::paintEvent(QPaintEvent *event) +void QwtPlotCanvas::paintEvent( QPaintEvent *event ) { -#if QT_VERSION >= 0x040000 - QPainter painter(this); - - if ( !contentsRect().contains( event->rect() ) ) + QPainter painter( this ); + painter.setClipRegion( event->region() ); + + if ( testPaintAttribute( QwtPlotCanvas::BackingStore ) && + d_data->backingStore != NULL ) { - painter.save(); - painter.setClipRegion( event->region() & frameRect() ); - drawFrame( &painter ); - painter.restore(); - } + QPixmap &bs = *d_data->backingStore; + if ( bs.size() != size() ) + { + bs = QPixmap( size() ); - painter.setClipRegion(event->region() & contentsRect()); - - drawContents( &painter ); -#else // QT_VERSION < 0x040000 - QFrame::paintEvent(event); +#ifdef Q_WS_X11 + if ( bs.x11Info().screen() != x11Info().screen() ) + bs.x11SetScreen( x11Info().screen() ); #endif - if ( d_data->paintAttributes & PaintPacked ) - setSystemBackground(false); -} + if ( testAttribute(Qt::WA_StyledBackground) ) + { + QPainter p( &bs ); + qwtFillBackground( &p, this ); + drawCanvas( &p, true ); + } + else + { + QPainter p; + if ( d_data->borderRadius <= 0.0 ) + { + bs.fill( this, 0, 0 ); + p.begin( &bs ); + drawCanvas( &p, false ); + } + else + { + p.begin( &bs ); + qwtFillBackground( &p, this ); + drawCanvas( &p, true ); + } -/*! - Redraw the canvas, and focus rect - \param painter Painter -*/ -void QwtPlotCanvas::drawContents(QPainter *painter) -{ - if ( d_data->paintAttributes & PaintCached && d_data->cache - && d_data->cache->size() == contentsRect().size() ) - { - painter->drawPixmap(contentsRect().topLeft(), *d_data->cache); + if ( frameWidth() > 0 ) + drawBorder( &p ); + } + } + + painter.drawPixmap( 0, 0, *d_data->backingStore ); } else { - QwtPlot *plot = ((QwtPlot *)parent()); - const bool doAutoReplot = plot->autoReplot(); - plot->setAutoReplot(false); + if ( testAttribute(Qt::WA_StyledBackground ) ) + { + if ( testAttribute( Qt::WA_OpaquePaintEvent ) ) + { + qwtFillBackground( &painter, this ); + drawCanvas( &painter, true ); + } + else + { + drawCanvas( &painter, false ); + } + } + else + { + if ( testAttribute( Qt::WA_OpaquePaintEvent ) ) + { + if ( autoFillBackground() ) + qwtDrawBackground( &painter, this ); + } - drawCanvas(painter); + drawCanvas( &painter, false ); - plot->setAutoReplot(doAutoReplot); + if ( frameWidth() > 0 ) + drawBorder( &painter ); + } } if ( hasFocus() && focusIndicator() == CanvasFocusIndicator ) - drawFocusIndicator(painter); + drawFocusIndicator( &painter ); } -/*! - Draw the the canvas - - Paints all plot items to the contentsRect(), using QwtPlot::drawCanvas - and updates the paint cache. - - \param painter Painter - - \sa QwtPlot::drawCanvas(), setPaintAttributes(), testPaintAttributes() -*/ -void QwtPlotCanvas::drawCanvas(QPainter *painter) +void QwtPlotCanvas::drawCanvas( QPainter *painter, bool withBackground ) { - if ( !contentsRect().isValid() ) - return; + bool hackStyledBackground = false; - QBrush bgBrush; -#if QT_VERSION >= 0x040000 - bgBrush = palette().brush(backgroundRole()); -#else - QColorGroup::ColorRole role = - QPalette::backgroundRoleFromMode( backgroundMode() ); - bgBrush = colorGroup().brush( role ); -#endif - - if ( d_data->paintAttributes & PaintCached && d_data->cache ) + if ( withBackground && testAttribute( Qt::WA_StyledBackground ) + && testPaintAttribute( HackStyledBackground ) ) { - *d_data->cache = QPixmap(contentsRect().size()); + // Antialiasing rounded borders is done by + // inserting pixels with colors between the + // border color and the color on the canvas, + // When the border is painted before the plot items + // these colors are interpolated for the canvas + // and the plot items need to be clipped excluding + // the anialiased pixels. In situations, where + // the plot items fill the area at the rounded + // borders this is noticeable. + // The only way to avoid these annoying "artefacts" + // is to paint the border on top of the plot items. -#ifdef Q_WS_X11 -#if QT_VERSION >= 0x040000 - if ( d_data->cache->x11Info().screen() != x11Info().screen() ) - d_data->cache->x11SetScreen(x11Info().screen()); -#else - if ( d_data->cache->x11Screen() != x11Screen() ) - d_data->cache->x11SetScreen(x11Screen()); -#endif -#endif - - if ( d_data->paintAttributes & PaintPacked ) + if ( d_data->styleSheet.hasBorder && + !d_data->styleSheet.borderPath.isEmpty() ) { - QPainter bgPainter(d_data->cache); - bgPainter.setPen(Qt::NoPen); - - bgPainter.setBrush(bgBrush); - bgPainter.drawRect(d_data->cache->rect()); + // We have a border with at least one rounded corner + hackStyledBackground = true; } - else - d_data->cache->fill(this, d_data->cache->rect().topLeft()); + } - QPainter cachePainter(d_data->cache); - cachePainter.translate(-contentsRect().x(), - -contentsRect().y()); + if ( withBackground ) + { + painter->save(); - ((QwtPlot *)parent())->drawCanvas(&cachePainter); + if ( testAttribute( Qt::WA_StyledBackground ) ) + { + if ( hackStyledBackground ) + { + // paint background without border - cachePainter.end(); + painter->setPen( Qt::NoPen ); + painter->setBrush( d_data->styleSheet.background.brush ); + painter->setBrushOrigin( d_data->styleSheet.background.origin ); + painter->setClipPath( d_data->styleSheet.borderPath ); + painter->drawRect( contentsRect() ); + } + else + { + qwtDrawStyledBackground( this, painter ); + } + } + else if ( autoFillBackground() ) + { + painter->setPen( Qt::NoPen ); + painter->setBrush( palette().brush( backgroundRole() ) ); - painter->drawPixmap(contentsRect(), *d_data->cache); + if ( d_data->borderRadius > 0.0 ) + { + if ( frameWidth() > 0 ) + { + painter->setClipPath( borderPath( rect() ) ); + painter->drawRect( rect() ); + } + else + { + painter->setRenderHint( QPainter::Antialiasing, true ); + painter->drawPath( borderPath( rect() ) ); + } + } + else + { + painter->drawRect( contentsRect() ); + } + } + + painter->restore(); + } + + painter->save(); + + if ( !d_data->styleSheet.borderPath.isEmpty() ) + { + painter->setClipPath( + d_data->styleSheet.borderPath, Qt::IntersectClip ); } else { -#if QT_VERSION >= 0x040000 - if ( d_data->paintAttributes & PaintPacked ) -#endif - { - painter->save(); + if ( d_data->borderRadius > 0.0 ) + painter->setClipPath( borderPath( rect() ), Qt::IntersectClip ); + else + painter->setClipRect( contentsRect(), Qt::IntersectClip ); + } - painter->setPen(Qt::NoPen); - painter->setBrush(bgBrush); - painter->drawRect(contentsRect()); + plot()->drawCanvas( painter ); - painter->restore(); - } + painter->restore(); - ((QwtPlot *)parent())->drawCanvas(painter); + if ( withBackground && hackStyledBackground ) + { + // Now paint the border on top + QStyleOptionFrame opt; + opt.initFrom(this); + style()->drawPrimitive( QStyle::PE_Frame, &opt, painter, this); } } -/*! +/*! + Draw the border of the plot canvas + + \param painter Painter + \sa setBorderRadius(), QFrame::drawFrame() +*/ +void QwtPlotCanvas::drawBorder( QPainter *painter ) +{ + if ( d_data->borderRadius > 0 ) + { + if ( frameWidth() > 0 ) + { + QwtPainter::drawRoundedFrame( painter, QRectF( rect() ), + d_data->borderRadius, d_data->borderRadius, + palette(), frameWidth(), frameStyle() ); + } + } + else + { + drawFrame( painter ); + } +} + +/*! + Resize event + \param event Resize event +*/ +void QwtPlotCanvas::resizeEvent( QResizeEvent *event ) +{ + QFrame::resizeEvent( event ); + updateStyleSheetInfo(); +} + +/*! Draw the focus indication \param painter Painter */ -void QwtPlotCanvas::drawFocusIndicator(QPainter *painter) +void QwtPlotCanvas::drawFocusIndicator( QPainter *painter ) { const int margin = 1; QRect focusRect = contentsRect(); - focusRect.setRect(focusRect.x() + margin, focusRect.y() + margin, - focusRect.width() - 2 * margin, focusRect.height() - 2 * margin); + focusRect.setRect( focusRect.x() + margin, focusRect.y() + margin, + focusRect.width() - 2 * margin, focusRect.height() - 2 * margin ); - QwtPainter::drawFocusRect(painter, this, focusRect); -} - -void QwtPlotCanvas::setSystemBackground(bool on) -{ -#if QT_VERSION < 0x040000 - if ( backgroundMode() == Qt::NoBackground ) - { - if ( on ) - setBackgroundMode(Qt::PaletteBackground); - } - else - { - if ( !on ) - setBackgroundMode(Qt::NoBackground); - } -#else - if ( testAttribute(Qt::WA_NoSystemBackground) == on ) - setAttribute(Qt::WA_NoSystemBackground, !on); -#endif + QwtPainter::drawFocusRect( painter, this, focusRect ); } /*! @@ -397,26 +941,139 @@ void QwtPlotCanvas::setSystemBackground(bool on) */ void QwtPlotCanvas::replot() { - invalidatePaintCache(); + invalidateBackingStore(); - /* - In case of cached or packed painting the canvas - is repainted completely and doesn't need to be erased. - */ - const bool erase = - !testPaintAttribute(QwtPlotCanvas::PaintPacked) - && !testPaintAttribute(QwtPlotCanvas::PaintCached); - -#if QT_VERSION >= 0x040000 - const bool noBackgroundMode = testAttribute(Qt::WA_NoBackground); - if ( !erase && !noBackgroundMode ) - setAttribute(Qt::WA_NoBackground, true); - - repaint(contentsRect()); - - if ( !erase && !noBackgroundMode ) - setAttribute(Qt::WA_NoBackground, false); -#else - repaint(contentsRect(), erase); -#endif + if ( testPaintAttribute( QwtPlotCanvas::ImmediatePaint ) ) + repaint( contentsRect() ); + else + update( contentsRect() ); +} + +//! Update the cached informations about the current style sheet +void QwtPlotCanvas::updateStyleSheetInfo() +{ + if ( !testAttribute(Qt::WA_StyledBackground ) ) + return; + + QwtStyleSheetRecorder recorder( size() ); + + QPainter painter( &recorder ); + + QStyleOption opt; + opt.initFrom(this); + style()->drawPrimitive( QStyle::PE_Widget, &opt, &painter, this); + + painter.end(); + + d_data->styleSheet.hasBorder = !recorder.border.rectList.isEmpty(); + d_data->styleSheet.cornerRects = recorder.clipRects; + + if ( recorder.background.path.isEmpty() ) + { + if ( !recorder.border.rectList.isEmpty() ) + { + d_data->styleSheet.borderPath = + qwtCombinePathList( rect(), recorder.border.pathList ); + } + } + else + { + d_data->styleSheet.borderPath = recorder.background.path; + d_data->styleSheet.background.brush = recorder.background.brush; + d_data->styleSheet.background.origin = recorder.background.origin; + } +} + +/*! + Calculate the painter path for a styled or rounded border + + When the canvas has no styled background or rounded borders + the painter path is empty. + + \param rect Bounding rectangle of the canvas + \return Painter path, that can be used for clipping +*/ +QPainterPath QwtPlotCanvas::borderPath( const QRect &rect ) const +{ + if ( testAttribute(Qt::WA_StyledBackground ) ) + { + QwtStyleSheetRecorder recorder( rect.size() ); + + QPainter painter( &recorder ); + + QStyleOption opt; + opt.initFrom(this); + opt.rect = rect; + style()->drawPrimitive( QStyle::PE_Widget, &opt, &painter, this); + + painter.end(); + + if ( !recorder.background.path.isEmpty() ) + return recorder.background.path; + + if ( !recorder.border.rectList.isEmpty() ) + return qwtCombinePathList( rect, recorder.border.pathList ); + } + else if ( d_data->borderRadius > 0.0 ) + { + double fw2 = frameWidth() * 0.5; + QRectF r = QRectF(rect).adjusted( fw2, fw2, -fw2, -fw2 ); + + QPainterPath path; + path.addRoundedRect( r, d_data->borderRadius, d_data->borderRadius ); + return path; + } + + return QPainterPath(); +} + +/*! + Calculate a mask, that can be used to clip away the border frame + + \param size Size including the frame +*/ +QBitmap QwtPlotCanvas::borderMask( const QSize &size ) const +{ + const QRect r( 0, 0, size.width(), size.height() ); + + const QPainterPath path = borderPath( r ); + if ( path.isEmpty() ) + return QBitmap(); + + QImage image( size, QImage::Format_ARGB32_Premultiplied ); + image.fill( Qt::color0 ); + + QPainter painter( &image ); + painter.setClipPath( path ); + painter.fillRect( r, Qt::color1 ); + + // now erase the frame + + painter.setCompositionMode( QPainter::CompositionMode_DestinationOut ); + + if ( testAttribute(Qt::WA_StyledBackground ) ) + { + QStyleOptionFrame opt; + opt.initFrom(this); + opt.rect = r; + style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, this ); + } + else + { + if ( d_data->borderRadius > 0 && frameWidth() > 0 ) + { + painter.setPen( QPen( Qt::color1, frameWidth() ) ); + painter.setBrush( Qt::NoBrush ); + painter.setRenderHint( QPainter::Antialiasing, true ); + + painter.drawPath( path ); + } + } + + painter.end(); + + const QImage mask = image.createMaskFromColor( + QColor( Qt::color1 ).rgb(), Qt::MaskOutColor ); + + return QBitmap::fromImage( mask ); } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_canvas.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_canvas.h index 5e8e3bb24..740dfeaca 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_canvas.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_canvas.h @@ -2,26 +2,26 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - #ifndef QWT_PLOT_CANVAS_H #define QWT_PLOT_CANVAS_H +#include "qwt_global.h" #include #include -#include "qwt_global.h" +#include +#include class QwtPlot; class QPixmap; /*! - \brief Canvas of a QwtPlot. - \sa QwtPlot + \brief Canvas of a QwtPlot. + \sa QwtPlot */ class QWT_EXPORT QwtPlotCanvas : public QFrame { @@ -31,31 +31,72 @@ public: /*! \brief Paint attributes - - - PaintCached\n - Paint double buffered and reuse the content of the pixmap buffer - for some spontaneous repaints that happen when a plot gets unhidden, - deiconified or changes the focus. - Disabling the cache will improve the performance for - incremental paints (using QwtPlotCurve::draw). - - PaintPacked\n - Suppress system background repaints and paint it together with - the canvas contents. - Painting packed might avoid flickering for expensive repaints, - when there is a notable gap between painting the background - and the plot contents. + The default setting enables BackingStore and Opaque. - The default setting enables PaintCached and PaintPacked - - \sa setPaintAttribute(), testPaintAttribute(), paintCache() + \sa setPaintAttribute(), testPaintAttribute() */ enum PaintAttribute { - PaintCached = 1, - PaintPacked = 2 + /*! + \brief Paint double buffered reusing the content + of the pixmap buffer when possible. + + Using a backing store might improve the performance + significantly, when workin with widget overlays ( like rubberbands ). + Disabling the cache might improve the performance for + incremental paints (using QwtPlotDirectPainter ). + + \sa backingStore(), invalidateBackingStore() + */ + BackingStore = 1, + + /*! + \brief Try to fill the complete contents rectangle + of the plot canvas + + When using styled backgrounds Qt assumes, that the + canvas doesn't fill its area completely + ( f.e because of rounded borders ) and fills the area + below the canvas. When this is done with gradients it might + result in a serious performance bottleneck - depending on the size. + + When the Opaque attribute is enabled the canvas tries to + identify the gaps with some heuristics and to fill those only. + + \warning Will not work for semitransparent backgrounds + */ + Opaque = 2, + + /*! + \brief Try to improve painting of styled backgrounds + + QwtPlotCanvas supports the box model attributes for + customizing the layout with style sheets. Unfortunately + the design of Qt style sheets has no concept how to + handle backgrounds with rounded corners - beside of padding. + + When HackStyledBackground is enabled the plot canvas tries + to seperate the background from the background border + by reverse engeneering to paint the background before and + the border after the plot items. In this order the border + gets prefectly antialiased and you can avoid some pixel + artifacts in the corners. + */ + HackStyledBackground = 4, + + /*! + When ImmediatePaint is set replot() calls repaint() + instead of update(). + + \sa replot(), QWidget::repaint(), QWidget::update() + */ + ImmediatePaint = 8 }; + //! Paint attributes + typedef QFlags PaintAttributes; + /*! \brief Focus indicator @@ -81,39 +122,47 @@ public: ItemFocusIndicator }; - explicit QwtPlotCanvas(QwtPlot *); + explicit QwtPlotCanvas( QwtPlot * ); virtual ~QwtPlotCanvas(); QwtPlot *plot(); const QwtPlot *plot() const; - void setFocusIndicator(FocusIndicator); + void setFocusIndicator( FocusIndicator ); FocusIndicator focusIndicator() const; - void setPaintAttribute(PaintAttribute, bool on = true); - bool testPaintAttribute(PaintAttribute) const; + void setBorderRadius( double ); + double borderRadius() const; - QPixmap *paintCache(); - const QPixmap *paintCache() const; - void invalidatePaintCache(); + QPainterPath borderPath( const QRect &rect ) const; + QBitmap borderMask( const QSize & ) const; + + void setPaintAttribute( PaintAttribute, bool on = true ); + bool testPaintAttribute( PaintAttribute ) const; + + const QPixmap *backingStore() const; + void invalidateBackingStore(); void replot(); + virtual bool event( QEvent * ); + protected: - virtual void hideEvent(QHideEvent *); + virtual void paintEvent( QPaintEvent * ); + virtual void resizeEvent( QResizeEvent * ); - virtual void paintEvent(QPaintEvent *); + virtual void drawFocusIndicator( QPainter * ); + virtual void drawBorder( QPainter * ); - virtual void drawContents(QPainter *); - virtual void drawFocusIndicator(QPainter *); + void updateStyleSheetInfo(); - void drawCanvas(QPainter *painter = NULL); - -private: - void setSystemBackground(bool); +private: + void drawCanvas( QPainter *, bool withBackground ); class PrivateData; PrivateData *d_data; }; +Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotCanvas::PaintAttributes ) + #endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_curve.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_curve.cpp index 02492bef9..4111d744a 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_curve.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_curve.cpp @@ -7,195 +7,48 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -#include -#include -#include -#include "qwt_global.h" -#include "qwt_legend.h" -#include "qwt_legend_item.h" -#include "qwt_data.h" -#include "qwt_scale_map.h" -#include "qwt_double_rect.h" +#include "qwt_plot_curve.h" #include "qwt_math.h" #include "qwt_clipper.h" #include "qwt_painter.h" +#include "qwt_legend.h" +#include "qwt_legend_item.h" +#include "qwt_scale_map.h" #include "qwt_plot.h" #include "qwt_plot_canvas.h" #include "qwt_curve_fitter.h" #include "qwt_symbol.h" -#include "qwt_plot_curve.h" +#include +#include +#include +#include -#if QT_VERSION < 0x040000 -#include -#else -#include -#endif - -#if QT_VERSION >= 0x040000 - -#include -#include - -class QwtPlotCurvePaintHelper: public QObject +static int verifyRange( int size, int &i1, int &i2 ) { -public: - QwtPlotCurvePaintHelper(const QwtPlotCurve *curve, int from, int to): - _curve(curve), - _from(from), - _to(to) - { - } - - virtual bool eventFilter(QObject *, QEvent *event) - { - if ( event->type() == QEvent::Paint ) - { - _curve->draw(_from, _to); - return true; - } - return false; - } -private: - const QwtPlotCurve *_curve; - int _from; - int _to; -}; - -#endif // QT_VERSION >= 0x040000 - -// Creating and initializing a QPainter is an -// expensive operation. So we keep an painter -// open for situations, where we paint outside -// of paint events. This improves the performance -// of incremental painting like in the realtime -// example a lot. -// But it is not possible to have more than -// one QPainter open at the same time. So we -// need to close it before regular paint events -// are processed. - -class QwtGuardedPainter: public QObject -{ -public: - ~QwtGuardedPainter() - { - end(); - } - - QPainter *begin(QwtPlotCanvas *canvas) - { - _canvas = canvas; - - QMap::iterator it = _map.find(_canvas); - if ( it == _map.end() ) - { - QPainter *painter = new QPainter(_canvas); - painter->setClipping(true); - painter->setClipRect(_canvas->contentsRect()); - - it = _map.insert(_canvas, painter); - _canvas->installEventFilter(this); - } -#if QT_VERSION < 0x040000 - return it.data(); -#else - return it.value(); -#endif - } - - void end() - { - if ( _canvas ) - { - QMap::iterator it = _map.find(_canvas); - if ( it != _map.end() ) - { - _canvas->removeEventFilter(this); - -#if QT_VERSION < 0x040000 - delete it.data(); -#else - delete it.value(); -#endif - _map.erase(it); - } - } - } - - virtual bool eventFilter(QObject *, QEvent *event) - { - if ( event->type() == QEvent::Paint ) - end(); - - return false; - } - -private: -#if QT_VERSION < 0x040000 - QGuardedPtr _canvas; -#else - QPointer _canvas; -#endif - static QMap _map; -}; - -QMap QwtGuardedPainter::_map; - -static int verifyRange(int size, int &i1, int &i2) -{ - if (size < 1) + if ( size < 1 ) return 0; - i1 = qwtLim(i1, 0, size-1); - i2 = qwtLim(i2, 0, size-1); + i1 = qBound( 0, i1, size - 1 ); + i2 = qBound( 0, i2, size - 1 ); if ( i1 > i2 ) - qSwap(i1, i2); + qSwap( i1, i2 ); - return (i2 - i1 + 1); + return ( i2 - i1 + 1 ); } class QwtPlotCurve::PrivateData { public: - class PixelMatrix: private QBitArray - { - public: - PixelMatrix(const QRect& rect): - QBitArray(rect.width() * rect.height()), - _rect(rect) - { - fill(false); - } - - inline bool testPixel(const QPoint& pos) - { - if ( !_rect.contains(pos) ) - return false; - - const int idx = _rect.width() * (pos.y() - _rect.y()) + - (pos.x() - _rect.x()); - - const bool marked = testBit(idx); - if ( !marked ) - setBit(idx, true); - - return !marked; - } - - private: - QRect _rect; - }; - PrivateData(): - curveType(Yfx), - style(QwtPlotCurve::Lines), - reference(0.0), - attributes(0), - paintAttributes(0) + style( QwtPlotCurve::Lines ), + baseline( 0.0 ), + symbol( NULL ), + attributes( 0 ), + paintAttributes( QwtPlotCurve::ClipPolygons ), + legendAttributes( 0 ) { - symbol = new QwtSymbol(); - pen = QPen(Qt::black); + pen = QPen( Qt::black ); curveFitter = new QwtSplineCurveFitter; } @@ -205,45 +58,37 @@ public: delete curveFitter; } - QwtPlotCurve::CurveType curveType; QwtPlotCurve::CurveStyle style; - double reference; + double baseline; - QwtSymbol *symbol; + const QwtSymbol *symbol; QwtCurveFitter *curveFitter; QPen pen; QBrush brush; - int attributes; - int paintAttributes; + QwtPlotCurve::CurveAttributes attributes; + QwtPlotCurve::PaintAttributes paintAttributes; - QwtGuardedPainter guardedPainter; + QwtPlotCurve::LegendAttributes legendAttributes; }; -//! Constructor -QwtPlotCurve::QwtPlotCurve(): - QwtPlotItem(QwtText()) +/*! + Constructor + \param title Title of the curve +*/ +QwtPlotCurve::QwtPlotCurve( const QwtText &title ): + QwtPlotSeriesItem( title ) { init(); } /*! Constructor - \param title Title of the curve + \param title Title of the curve */ -QwtPlotCurve::QwtPlotCurve(const QwtText &title): - QwtPlotItem(title) -{ - init(); -} - -/*! - Constructor - \param title Title of the curve -*/ -QwtPlotCurve::QwtPlotCurve(const QString &title): - QwtPlotItem(QwtText(title)) +QwtPlotCurve::QwtPlotCurve( const QString &title ): + QwtPlotSeriesItem( QwtText( title ) ) { init(); } @@ -251,22 +96,19 @@ QwtPlotCurve::QwtPlotCurve(const QString &title): //! Destructor QwtPlotCurve::~QwtPlotCurve() { - delete d_xy; delete d_data; } -/*! - \brief Initialize data members -*/ +//! Initialize internal members void QwtPlotCurve::init() { - setItemAttribute(QwtPlotItem::Legend); - setItemAttribute(QwtPlotItem::AutoScale); + setItemAttribute( QwtPlotItem::Legend ); + setItemAttribute( QwtPlotItem::AutoScale ); d_data = new PrivateData; - d_xy = new QwtPolygonFData(QwtArray()); + d_series = new QwtPointSeriesData(); - setZ(20.0); + setZ( 20.0 ); } //! \return QwtPlotItem::Rtti_PlotCurve @@ -280,9 +122,9 @@ int QwtPlotCurve::rtti() const \param attribute Paint attribute \param on On/Off - /sa PaintAttribute, testPaintAttribute() + \sa testPaintAttribute() */ -void QwtPlotCurve::setPaintAttribute(PaintAttribute attribute, bool on) +void QwtPlotCurve::setPaintAttribute( PaintAttribute attribute, bool on ) { if ( on ) d_data->paintAttributes |= attribute; @@ -292,20 +134,44 @@ void QwtPlotCurve::setPaintAttribute(PaintAttribute attribute, bool on) /*! \brief Return the current paint attributes - \sa PaintAttribute, setPaintAttribute() + \sa setPaintAttribute() */ -bool QwtPlotCurve::testPaintAttribute(PaintAttribute attribute) const +bool QwtPlotCurve::testPaintAttribute( PaintAttribute attribute ) const { - return (d_data->paintAttributes & attribute); + return ( d_data->paintAttributes & attribute ); +} + +/*! + Specify an attribute how to draw the legend identifier + + \param attribute Attribute + \param on On/Off + /sa testLegendAttribute() +*/ +void QwtPlotCurve::setLegendAttribute( LegendAttribute attribute, bool on ) +{ + if ( on ) + d_data->legendAttributes |= attribute; + else + d_data->legendAttributes &= ~attribute; +} + +/*! + \brief Return the current paint attributes + \sa setLegendAttribute() +*/ +bool QwtPlotCurve::testLegendAttribute( LegendAttribute attribute ) const +{ + return ( d_data->legendAttributes & attribute ); } /*! Set the curve's drawing style \param style Curve style - \sa CurveStyle, style() + \sa style() */ -void QwtPlotCurve::setStyle(CurveStyle style) +void QwtPlotCurve::setStyle( CurveStyle style ) { if ( style != d_data->style ) { @@ -316,44 +182,45 @@ void QwtPlotCurve::setStyle(CurveStyle style) /*! Return the current style - \sa CurveStyle, setStyle() + \sa setStyle() */ -QwtPlotCurve::CurveStyle QwtPlotCurve::style() const -{ - return d_data->style; +QwtPlotCurve::CurveStyle QwtPlotCurve::style() const +{ + return d_data->style; } /*! - \brief Assign a symbol + Assign a symbol + \param symbol Symbol \sa symbol() */ -void QwtPlotCurve::setSymbol(const QwtSymbol &symbol ) +void QwtPlotCurve::setSymbol( const QwtSymbol *symbol ) { - delete d_data->symbol; - d_data->symbol = symbol.clone(); - itemChanged(); + if ( symbol != d_data->symbol ) + { + delete d_data->symbol; + d_data->symbol = symbol; + itemChanged(); + } } /*! - \brief Return the current symbol - \sa setSymbol() + \return Current symbol or NULL, when no symbol has been assigned + \sa setSymbol() */ -const QwtSymbol &QwtPlotCurve::symbol() const -{ - return *d_data->symbol; +const QwtSymbol *QwtPlotCurve::symbol() const +{ + return d_data->symbol; } /*! Assign a pen - The width of non cosmetic pens is scaled according to the resolution - of the paint device. - \param pen New pen - \sa pen(), brush(), QwtPainter::scaledPen() + \sa pen(), brush() */ -void QwtPlotCurve::setPen(const QPen &pen) +void QwtPlotCurve::setPen( const QPen &pen ) { if ( pen != d_data->pen ) { @@ -363,30 +230,30 @@ void QwtPlotCurve::setPen(const QPen &pen) } /*! - \brief Return the pen used to draw the lines - \sa setPen(), brush() + \return Pen used to draw the lines + \sa setPen(), brush() */ -const QPen& QwtPlotCurve::pen() const -{ - return d_data->pen; +const QPen& QwtPlotCurve::pen() const +{ + return d_data->pen; } /*! - \brief Assign a brush. + \brief Assign a brush. - In case of brush.style() != QBrush::NoBrush + In case of brush.style() != QBrush::NoBrush and style() != QwtPlotCurve::Sticks the area between the curve and the baseline will be filled. In case !brush.color().isValid() the area will be filled by pen.color(). The fill algorithm simply connects the first and the - last curve point to the baseline. So the curve data has to be sorted - (ascending or descending). + last curve point to the baseline. So the curve data has to be sorted + (ascending or descending). \param brush New brush \sa brush(), setBaseline(), baseline() */ -void QwtPlotCurve::setBrush(const QBrush &brush) +void QwtPlotCurve::setBrush( const QBrush &brush ) { if ( brush != d_data->brush ) { @@ -396,301 +263,97 @@ void QwtPlotCurve::setBrush(const QBrush &brush) } /*! - \brief Return the brush used to fill the area between lines and the baseline + \return Brush used to fill the area between lines and the baseline \sa setBrush(), setBaseline(), baseline() */ -const QBrush& QwtPlotCurve::brush() const +const QBrush& QwtPlotCurve::brush() const { return d_data->brush; } - /*! - Set data by copying x- and y-values from specified memory blocks. - Contrary to setCurveRawData(), this function makes a 'deep copy' of - the data. - - \param xData Pointer to x values - \param yData Pointer to y values - \param size Size of xData and yData - - \note Internally the data is stored in a QwtArrayData object -*/ -void QwtPlotCurve::setData(const double *xData, const double *yData, int size) -{ - delete d_xy; - d_xy = new QwtArrayData(xData, yData, size); - itemChanged(); -} - -/*! - Initialize data with x- and y-arrays (explicitly shared) - ( Builds an QwtArrayData object internally ) - - \param xData x data - \param yData y data - - \note Internally the data is stored in a QwtArrayData object -*/ -void QwtPlotCurve::setData(const QwtArray &xData, - const QwtArray &yData) -{ - delete d_xy; - d_xy = new QwtArrayData(xData, yData); - itemChanged(); -} - -/*! - Initialize data with an array of points (explicitly shared). - - \param data Data - \note Internally the data is stored in a QwtPolygonFData object -*/ -#if QT_VERSION < 0x040000 -void QwtPlotCurve::setData(const QwtArray &data) -#else -void QwtPlotCurve::setData(const QPolygonF &data) -#endif -{ - delete d_xy; - d_xy = new QwtPolygonFData(data); - itemChanged(); -} - -/*! - Initialize data with a pointer to QwtData. - - \param data Data - \sa QwtData::copy() -*/ -void QwtPlotCurve::setData(const QwtData &data) -{ - delete d_xy; - d_xy = data.copy(); - itemChanged(); -} - -/*! - \brief Initialize the data by pointing to memory blocks which are not managed - by QwtPlotCurve. - - setRawData is provided for efficiency. It is important to keep the pointers - during the lifetime of the underlying QwtCPointerData class. - - \param xData pointer to x data - \param yData pointer to y data - \param size size of x and y - - \note Internally the data is stored in a QwtCPointerData object -*/ -void QwtPlotCurve::setRawData(const double *xData, const double *yData, int size) -{ - delete d_xy; - d_xy = new QwtCPointerData(xData, yData, size); - itemChanged(); -} - -/*! - Returns the bounding rectangle of the curve data. If there is - no bounding rect, like for empty data the rectangle is invalid. - \sa QwtData::boundingRect(), QwtDoubleRect::isValid() -*/ - -QwtDoubleRect QwtPlotCurve::boundingRect() const -{ - if ( d_xy == NULL ) - return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid - - return d_xy->boundingRect(); -} - -/*! - \brief Draw the complete curve + Draw an interval of the curve \param painter Painter \param xMap Maps x-values into pixel coordinates. \param yMap Maps y-values into pixel coordinates. - - \sa drawCurve(), drawSymbols() -*/ -void QwtPlotCurve::draw(QPainter *painter, - const QwtScaleMap &xMap, const QwtScaleMap &yMap, - const QRect &) const -{ - draw(painter, xMap, yMap, 0, -1); -} - -/*! - \brief Draw a set of points of a curve. - - When observing an measurement while it is running, new points have to be - added to an existing curve. drawCurve can be used to display them avoiding - a complete redraw of the canvas. - - Setting plot()->canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); - will result in faster painting, if the paint engine of the canvas widget - supports this feature. - + \param canvasRect Contents rect of the canvas \param from Index of the first point to be painted \param to Index of the last point to be painted. If to < 0 the curve will be painted to its last point. - \sa drawCurve(), drawSymbols() -*/ -void QwtPlotCurve::draw(int from, int to) const -{ - if ( !plot() ) - return; - - QwtPlotCanvas *canvas = plot()->canvas(); - -#if QT_VERSION >= 0x040000 -#if 0 - if ( canvas->paintEngine()->type() == QPaintEngine::OpenGL ) - { - /* - OpenGL alway repaint the complete widget. - So for this operation OpenGL is one of the slowest - environments. - */ - canvas->repaint(); - return; - } -#endif - - if ( !canvas->testAttribute(Qt::WA_WState_InPaintEvent) && - !canvas->testAttribute(Qt::WA_PaintOutsidePaintEvent) ) - { - /* - We save curve and range in helper and call repaint. - The helper filters the Paint event, to repeat - the QwtPlotCurve::draw, but now from inside the paint - event. - */ - - QwtPlotCurvePaintHelper helper(this, from, to); - canvas->installEventFilter(&helper); - - const bool noSystemBackground = - canvas->testAttribute(Qt::WA_NoSystemBackground); - canvas->setAttribute(Qt::WA_NoSystemBackground, true); - canvas->repaint(); - canvas->setAttribute(Qt::WA_NoSystemBackground, noSystemBackground); - - return; - } -#endif - - const QwtScaleMap xMap = plot()->canvasMap(xAxis()); - const QwtScaleMap yMap = plot()->canvasMap(yAxis()); - - if ( canvas->testPaintAttribute(QwtPlotCanvas::PaintCached) && - canvas->paintCache() && !canvas->paintCache()->isNull() ) - { - QPainter cachePainter((QPixmap *)canvas->paintCache()); - cachePainter.translate(-canvas->contentsRect().x(), - -canvas->contentsRect().y()); - - draw(&cachePainter, xMap, yMap, from, to); - } - -#if QT_VERSION >= 0x040000 - if ( canvas->testAttribute(Qt::WA_WState_InPaintEvent) ) - { - QPainter painter(canvas); - - painter.setClipping(true); - painter.setClipRect(canvas->contentsRect()); - - draw(&painter, xMap, yMap, from, to); - } - else -#endif - { - QPainter *painter = d_data->guardedPainter.begin(canvas); - draw(painter, xMap, yMap, from, to); - } -} - -/*! - \brief Draw an interval of the curve - \param painter Painter - \param xMap maps x-values into pixel coordinates. - \param yMap maps y-values into pixel coordinates. - \param from index of the first point to be painted - \param to index of the last point to be painted. If to < 0 the - curve will be painted to its last point. - \sa drawCurve(), drawSymbols(), */ -void QwtPlotCurve::draw(QPainter *painter, - const QwtScaleMap &xMap, const QwtScaleMap &yMap, - int from, int to) const +void QwtPlotCurve::drawSeries( QPainter *painter, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const { if ( !painter || dataSize() <= 0 ) return; - if (to < 0) + if ( to < 0 ) to = dataSize() - 1; - if ( verifyRange(dataSize(), from, to) > 0 ) + if ( verifyRange( dataSize(), from, to ) > 0 ) { painter->save(); - painter->setPen(QwtPainter::scaledPen(d_data->pen)); + painter->setPen( d_data->pen ); /* - Qt 4.0.0 is slow when drawing lines, but it's even + Qt 4.0.0 is slow when drawing lines, but it's even slower when the painter has a brush. So we don't set the brush before we really need it. */ - drawCurve(painter, d_data->style, xMap, yMap, from, to); + drawCurve( painter, d_data->style, xMap, yMap, canvasRect, from, to ); painter->restore(); - if (d_data->symbol->style() != QwtSymbol::NoSymbol) + if ( d_data->symbol && + ( d_data->symbol->style() != QwtSymbol::NoSymbol ) ) { painter->save(); - drawSymbols(painter, *d_data->symbol, xMap, yMap, from, to); + drawSymbols( painter, *d_data->symbol, + xMap, yMap, canvasRect, from, to ); painter->restore(); } } } /*! - \brief Draw the line part (without symbols) of a curve interval. + \brief Draw the line part (without symbols) of a curve interval. \param painter Painter \param style curve style, see QwtPlotCurve::CurveStyle \param xMap x map \param yMap y map + \param canvasRect Contents rect of the canvas \param from index of the first point to be painted \param to index of the last point to be painted \sa draw(), drawDots(), drawLines(), drawSteps(), drawSticks() */ - -void QwtPlotCurve::drawCurve(QPainter *painter, int style, - const QwtScaleMap &xMap, const QwtScaleMap &yMap, - int from, int to) const +void QwtPlotCurve::drawCurve( QPainter *painter, int style, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const { - switch (style) + switch ( style ) { case Lines: - if ( testCurveAttribute(Fitted) ) + if ( testCurveAttribute( Fitted ) ) { - // we always need the complete + // we always need the complete // curve for fitting from = 0; to = dataSize() - 1; } - drawLines(painter, xMap, yMap, from, to); + drawLines( painter, xMap, yMap, canvasRect, from, to ); break; case Sticks: - drawSticks(painter, xMap, yMap, from, to); + drawSticks( painter, xMap, yMap, canvasRect, from, to ); break; case Steps: - drawSteps(painter, xMap, yMap, from, to); + drawSteps( painter, xMap, yMap, canvasRect, from, to ); break; case Dots: - drawDots(painter, xMap, yMap, from, to); + drawDots( painter, xMap, yMap, canvasRect, from, to ); break; case NoCurve: default: @@ -707,125 +370,60 @@ void QwtPlotCurve::drawCurve(QPainter *painter, int style, \param painter Painter \param xMap x map \param yMap y map + \param canvasRect Contents rect of the canvas \param from index of the first point to be painted \param to index of the last point to be painted - \sa setCurveAttribute(), setCurveFitter(), draw(), + \sa setCurveAttribute(), setCurveFitter(), draw(), drawLines(), drawDots(), drawSteps(), drawSticks() */ -void QwtPlotCurve::drawLines(QPainter *painter, - const QwtScaleMap &xMap, const QwtScaleMap &yMap, - int from, int to) const +void QwtPlotCurve::drawLines( QPainter *painter, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const { int size = to - from + 1; if ( size <= 0 ) return; - QwtPolygon polyline; - if ( ( d_data->attributes & Fitted ) && d_data->curveFitter ) + const bool doAlign = QwtPainter::roundingAlignment( painter ); + + QPolygonF polyline( size ); + + QPointF *points = polyline.data(); + for ( int i = from; i <= to; i++ ) { - // Transform x and y values to window coordinates - // to avoid a distinction between linear and - // logarithmic scales. + const QPointF sample = d_series->sample( i ); -#if QT_VERSION < 0x040000 - QwtArray points(size); -#else - QPolygonF points(size); -#endif - for (int i = from; i <= to; i++) + double x = xMap.transform( sample.x() ); + double y = yMap.transform( sample.y() ); + if ( doAlign ) { - QwtDoublePoint &p = points[i]; - p.setX( xMap.xTransform(x(i)) ); - p.setY( yMap.xTransform(y(i)) ); + x = qRound( x ); + y = qRound( y ); } - points = d_data->curveFitter->fitCurve(points); - size = points.size(); + points[i - from].rx() = x; + points[i - from].ry() = y; + } - if ( size == 0 ) - return; + if ( ( d_data->attributes & Fitted ) && d_data->curveFitter ) + polyline = d_data->curveFitter->fitCurve( polyline ); - // Round QwtDoublePoints to QPoints - // When Qwt support for Qt3 has been dropped (Qwt 6.x) - // we will use a doubles for painting and the following - // step will be obsolete. + if ( d_data->paintAttributes & ClipPolygons ) + { + qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF()); + const QPolygonF clipped = QwtClipper::clipPolygonF( + canvasRect.adjusted(-pw, -pw, pw, pw), polyline, false ); - polyline.resize(size); - - const QwtDoublePoint *p = points.data(); - QPoint *pl = polyline.data(); - if ( d_data->paintAttributes & PaintFiltered ) - { - - QPoint pp(qRound(p[0].x()), qRound(p[0].y())); - pl[0] = pp; - - int count = 1; - for (int i = 1; i < size; i++) - { - const QPoint pi(qRound(p[i].x()), qRound(p[i].y())); - if ( pi != pp ) - { - pl[count++] = pi; - pp = pi; - } - } - if ( count != size ) - polyline.resize(count); - } - else - { - for ( int i = 0; i < size; i++ ) - { - pl[i].setX( qRound(p[i].x()) ); - pl[i].setY( qRound(p[i].y()) ); - } - } + QwtPainter::drawPolyline( painter, clipped ); } else { - polyline.resize(size); - - if ( d_data->paintAttributes & PaintFiltered ) - { - QPoint pp( xMap.transform(x(from)), yMap.transform(y(from)) ); - polyline.setPoint(0, pp); - - int count = 1; - for (int i = from + 1; i <= to; i++) - { - const QPoint pi(xMap.transform(x(i)), yMap.transform(y(i))); - if ( pi != pp ) - { - polyline.setPoint(count, pi); - count++; - - pp = pi; - } - } - if ( count != size ) - polyline.resize(count); - } - else - { - for (int i = from; i <= to; i++) - { - int xi = xMap.transform(x(i)); - int yi = yMap.transform(y(i)); - - polyline.setPoint(i - from, xi, yi); - } - } + QwtPainter::drawPolyline( painter, polyline ); } - if ( d_data->paintAttributes & ClipPolygons ) - polyline = QwtClipper::clipPolygon(painter->window(), polyline); - - QwtPainter::drawPolyline(painter, polyline); - if ( d_data->brush.style() != Qt::NoBrush ) - fillCurve(painter, xMap, yMap, polyline); + fillCurve( painter, xMap, yMap, canvasRect, polyline ); } /*! @@ -834,28 +432,49 @@ void QwtPlotCurve::drawLines(QPainter *painter, \param painter Painter \param xMap x map \param yMap y map + \param canvasRect Contents rect of the canvas \param from index of the first point to be painted \param to index of the last point to be painted \sa draw(), drawCurve(), drawDots(), drawLines(), drawSteps() */ -void QwtPlotCurve::drawSticks(QPainter *painter, - const QwtScaleMap &xMap, const QwtScaleMap &yMap, - int from, int to) const +void QwtPlotCurve::drawSticks( QPainter *painter, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &, int from, int to ) const { - int x0 = xMap.transform(d_data->reference); - int y0 = yMap.transform(d_data->reference); + painter->save(); + painter->setRenderHint( QPainter::Antialiasing, false ); - for (int i = from; i <= to; i++) + const bool doAlign = QwtPainter::roundingAlignment( painter ); + + double x0 = xMap.transform( d_data->baseline ); + double y0 = yMap.transform( d_data->baseline ); + if ( doAlign ) { - const int xi = xMap.transform(x(i)); - const int yi = yMap.transform(y(i)); - - if (d_data->curveType == Xfy) - QwtPainter::drawLine(painter, x0, yi, xi, yi); - else - QwtPainter::drawLine(painter, xi, y0, xi, yi); + x0 = qRound( x0 ); + y0 = qRound( y0 ); } + + const Qt::Orientation o = orientation(); + + for ( int i = from; i <= to; i++ ) + { + const QPointF sample = d_series->sample( i ); + double xi = xMap.transform( sample.x() ); + double yi = yMap.transform( sample.y() ); + if ( doAlign ) + { + xi = qRound( xi ); + yi = qRound( yi ); + } + + if ( o == Qt::Horizontal ) + QwtPainter::drawLine( painter, x0, yi, xi, yi ); + else + QwtPainter::drawLine( painter, xi, y0, xi, yi ); + } + + painter->restore(); } /*! @@ -864,138 +483,124 @@ void QwtPlotCurve::drawSticks(QPainter *painter, \param painter Painter \param xMap x map \param yMap y map + \param canvasRect Contents rect of the canvas \param from index of the first point to be painted \param to index of the last point to be painted \sa draw(), drawCurve(), drawSticks(), drawLines(), drawSteps() */ -void QwtPlotCurve::drawDots(QPainter *painter, - const QwtScaleMap &xMap, const QwtScaleMap &yMap, - int from, int to) const +void QwtPlotCurve::drawDots( QPainter *painter, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const { - const QRect window = painter->window(); - if ( window.isEmpty() ) - return; - const bool doFill = d_data->brush.style() != Qt::NoBrush; + const bool doAlign = QwtPainter::roundingAlignment( painter ); - QwtPolygon polyline; + QPolygonF polyline; if ( doFill ) - polyline.resize(to - from + 1); + polyline.resize( to - from + 1 ); - if ( to > from && d_data->paintAttributes & PaintFiltered ) + QPointF *points = polyline.data(); + + for ( int i = from; i <= to; i++ ) { - if ( doFill ) + const QPointF sample = d_series->sample( i ); + double xi = xMap.transform( sample.x() ); + double yi = yMap.transform( sample.y() ); + if ( doAlign ) { - QPoint pp( xMap.transform(x(from)), yMap.transform(y(from)) ); - - QwtPainter::drawPoint(painter, pp.x(), pp.y()); - polyline.setPoint(0, pp); - - int count = 1; - for (int i = from + 1; i <= to; i++) - { - const QPoint pi(xMap.transform(x(i)), yMap.transform(y(i))); - if ( pi != pp ) - { - QwtPainter::drawPoint(painter, pi.x(), pi.y()); - - polyline.setPoint(count, pi); - count++; - - pp = pi; - } - } - if ( int(polyline.size()) != count ) - polyline.resize(count); + xi = qRound( xi ); + yi = qRound( yi ); } - else + + QwtPainter::drawPoint( painter, QPointF( xi, yi ) ); + + if ( doFill ) { - // if we don't need to fill, we can sort out - // duplicates independent from the order - - PrivateData::PixelMatrix pixelMatrix(window); - - for (int i = from; i <= to; i++) - { - const QPoint p( xMap.transform(x(i)), - yMap.transform(y(i)) ); - - if ( pixelMatrix.testPixel(p) ) - QwtPainter::drawPoint(painter, p.x(), p.y()); - } - } - } - else - { - for (int i = from; i <= to; i++) - { - const int xi = xMap.transform(x(i)); - const int yi = yMap.transform(y(i)); - QwtPainter::drawPoint(painter, xi, yi); - - if ( doFill ) - polyline.setPoint(i - from, xi, yi); + points[i - from].rx() = xi; + points[i - from].ry() = yi; } } if ( doFill ) - { - if ( d_data->paintAttributes & ClipPolygons ) - polyline = QwtClipper::clipPolygon(painter->window(), polyline); - - fillCurve(painter, xMap, yMap, polyline); - } + fillCurve( painter, xMap, yMap, canvasRect, polyline ); } /*! Draw step function - The direction of the steps depends on Inverted attribute. + The direction of the steps depends on Inverted attribute. \param painter Painter \param xMap x map \param yMap y map + \param canvasRect Contents rect of the canvas \param from index of the first point to be painted \param to index of the last point to be painted \sa CurveAttribute, setCurveAttribute(), draw(), drawCurve(), drawDots(), drawLines(), drawSticks() */ -void QwtPlotCurve::drawSteps(QPainter *painter, - const QwtScaleMap &xMap, const QwtScaleMap &yMap, - int from, int to) const +void QwtPlotCurve::drawSteps( QPainter *painter, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const { - QwtPolygon polyline(2 * (to - from) + 1); + const bool doAlign = QwtPainter::roundingAlignment( painter ); - bool inverted = d_data->curveType == Yfx; + QPolygonF polygon( 2 * ( to - from ) + 1 ); + QPointF *points = polygon.data(); + + bool inverted = orientation() == Qt::Vertical; if ( d_data->attributes & Inverted ) inverted = !inverted; - int i,ip; - for (i = from, ip = 0; i <= to; i++, ip += 2) + int i, ip; + for ( i = from, ip = 0; i <= to; i++, ip += 2 ) { - const int xi = xMap.transform(x(i)); - const int yi = yMap.transform(y(i)); + const QPointF sample = d_series->sample( i ); + double xi = xMap.transform( sample.x() ); + double yi = yMap.transform( sample.y() ); + if ( doAlign ) + { + xi = qRound( xi ); + yi = qRound( yi ); + } if ( ip > 0 ) { - if (inverted) - polyline.setPoint(ip - 1, polyline[ip-2].x(), yi); + const QPointF &p0 = points[ip - 2]; + QPointF &p = points[ip - 1]; + + if ( inverted ) + { + p.rx() = p0.x(); + p.ry() = yi; + } else - polyline.setPoint(ip - 1, xi, polyline[ip-2].y()); + { + p.rx() = xi; + p.ry() = p0.y(); + } } - polyline.setPoint(ip, xi, yi); + points[ip].rx() = xi; + points[ip].ry() = yi; } if ( d_data->paintAttributes & ClipPolygons ) - polyline = QwtClipper::clipPolygon(painter->window(), polyline); + { + const QPolygonF clipped = QwtClipper::clipPolygonF( + canvasRect, polygon, false ); - QwtPainter::drawPolyline(painter, polyline); + QwtPainter::drawPolyline( painter, clipped ); + } + else + { + QwtPainter::drawPolyline( painter, polygon ); + } if ( d_data->brush.style() != Qt::NoBrush ) - fillCurve(painter, xMap, yMap, polyline); + fillCurve( painter, xMap, yMap, canvasRect, polygon ); } @@ -1005,11 +610,11 @@ void QwtPlotCurve::drawSteps(QPainter *painter, \param attribute Curve attribute \param on On/Off - /sa CurveAttribute, testCurveAttribute(), setCurveFitter() + /sa testCurveAttribute(), setCurveFitter() */ -void QwtPlotCurve::setCurveAttribute(CurveAttribute attribute, bool on) +void QwtPlotCurve::setCurveAttribute( CurveAttribute attribute, bool on ) { - if ( bool(d_data->attributes & attribute) == on ) + if ( bool( d_data->attributes & attribute ) == on ) return; if ( on ) @@ -1022,44 +627,31 @@ void QwtPlotCurve::setCurveAttribute(CurveAttribute attribute, bool on) /*! \return true, if attribute is enabled - \sa CurveAttribute, setCurveAttribute() + \sa setCurveAttribute() */ -bool QwtPlotCurve::testCurveAttribute(CurveAttribute attribute) const -{ +bool QwtPlotCurve::testCurveAttribute( CurveAttribute attribute ) const +{ return d_data->attributes & attribute; } -/*! - Assign the curve type - - \param curveType Yfx or Xfy - \sa CurveType, curveType() -*/ -void QwtPlotCurve::setCurveType(CurveType curveType) -{ - if ( d_data->curveType != curveType ) - { - d_data->curveType = curveType; - itemChanged(); - } -} - -/*! - Return the curve type - \sa CurveType, setCurveType() -*/ -QwtPlotCurve::CurveType QwtPlotCurve::curveType() const -{ - return d_data->curveType; -} - /*! Assign a curve fitter - setCurveFitter(NULL) disables curve fitting. - \param curveFitter Curve fitter + The curve fitter "smooths" the curve points, when the Fitted + CurveAttribute is set. setCurveFitter(NULL) also disables curve fitting. + + The curve fitter operates on the translated points ( = widget coordinates) + to be functional for logarithmic scales. Obviously this is less performant + for fitting algorithms, that reduce the number of points. + + For situations, where curve fitting is used to improve the performance + of painting huge series of points it might be better to execute the fitter + on the curve points once and to cache the result in the QwtSeriesData object. + + \param curveFitter() Curve fitter + \sa Fitted */ -void QwtPlotCurve::setCurveFitter(QwtCurveFitter *curveFitter) +void QwtPlotCurve::setCurveFitter( QwtCurveFitter *curveFitter ) { delete d_data->curveFitter; d_data->curveFitter = curveFitter; @@ -1069,135 +661,191 @@ void QwtPlotCurve::setCurveFitter(QwtCurveFitter *curveFitter) /*! Get the curve fitter. If curve fitting is disabled NULL is returned. + \return Curve fitter + \sa setCurveFitter(), Fitted */ QwtCurveFitter *QwtPlotCurve::curveFitter() const { return d_data->curveFitter; } -/*! - Fill the area between the curve and the baseline with +/*! + Fill the area between the curve and the baseline with the curve brush \param painter Painter \param xMap x map \param yMap y map - \param pa Polygon + \param canvasRect Contents rect of the canvas + \param polygon Polygon - will be modified ! - \sa setBrush(), setBaseline(), setCurveType() + \sa setBrush(), setBaseline(), setStyle() */ -void QwtPlotCurve::fillCurve(QPainter *painter, +void QwtPlotCurve::fillCurve( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, - QwtPolygon &pa) const + const QRectF &canvasRect, QPolygonF &polygon ) const { if ( d_data->brush.style() == Qt::NoBrush ) return; - closePolyline(xMap, yMap, pa); - if ( pa.count() <= 2 ) // a line can't be filled + closePolyline( painter, xMap, yMap, polygon ); + if ( polygon.count() <= 2 ) // a line can't be filled return; - QBrush b = d_data->brush; - if ( !b.color().isValid() ) - b.setColor(d_data->pen.color()); + QBrush brush = d_data->brush; + if ( !brush.color().isValid() ) + brush.setColor( d_data->pen.color() ); + + if ( d_data->paintAttributes & ClipPolygons ) + polygon = QwtClipper::clipPolygonF( canvasRect, polygon, true ); painter->save(); - painter->setPen(QPen(Qt::NoPen)); - painter->setBrush(b); + painter->setPen( Qt::NoPen ); + painter->setBrush( brush ); - QwtPainter::drawPolygon(painter, pa); + QwtPainter::drawPolygon( painter, polygon ); painter->restore(); } /*! - \brief Complete a polygon to be a closed polygon - including the area between the original polygon - and the baseline. + \brief Complete a polygon to be a closed polygon including the + area between the original polygon and the baseline. + + \param painter Painter \param xMap X map \param yMap Y map - \param pa Polygon to be completed + \param polygon Polygon to be completed */ -void QwtPlotCurve::closePolyline( +void QwtPlotCurve::closePolyline( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, - QwtPolygon &pa) const + QPolygonF &polygon ) const { - const int sz = pa.size(); - if ( sz < 2 ) + if ( polygon.size() < 2 ) return; - pa.resize(sz + 2); + const bool doAlign = QwtPainter::roundingAlignment( painter ); - if ( d_data->curveType == QwtPlotCurve::Xfy ) + double baseline = d_data->baseline; + + if ( orientation() == Qt::Vertical ) { - pa.setPoint(sz, - xMap.transform(d_data->reference), pa.point(sz - 1).y()); - pa.setPoint(sz + 1, - xMap.transform(d_data->reference), pa.point(0).y()); + if ( yMap.transformation()->type() == QwtScaleTransformation::Log10 ) + { + if ( baseline < QwtScaleMap::LogMin ) + baseline = QwtScaleMap::LogMin; + } + + double refY = yMap.transform( baseline ); + if ( doAlign ) + refY = qRound( refY ); + + polygon += QPointF( polygon.last().x(), refY ); + polygon += QPointF( polygon.first().x(), refY ); } else { - pa.setPoint(sz, - pa.point(sz - 1).x(), yMap.transform(d_data->reference)); - pa.setPoint(pa.size() - 1, - pa.point(0).x(), yMap.transform(d_data->reference)); + if ( xMap.transformation()->type() == QwtScaleTransformation::Log10 ) + { + if ( baseline < QwtScaleMap::LogMin ) + baseline = QwtScaleMap::LogMin; + } + + double refX = xMap.transform( baseline ); + if ( doAlign ) + refX = qRound( refX ); + + polygon += QPointF( refX, polygon.last().y() ); + polygon += QPointF( refX, polygon.first().y() ); } } /*! - \brief Draw symbols + Draw symbols + \param painter Painter \param symbol Curve symbol \param xMap x map \param yMap y map - \param from index of the first point to be painted - \param to index of the last point to be painted + \param canvasRect Contents rect of the canvas + \param from Index of the first point to be painted + \param to Index of the last point to be painted - \sa setSymbol(), draw(), drawCurve() + \sa setSymbol(), drawSeries(), drawCurve() */ -void QwtPlotCurve::drawSymbols(QPainter *painter, const QwtSymbol &symbol, - const QwtScaleMap &xMap, const QwtScaleMap &yMap, - int from, int to) const +void QwtPlotCurve::drawSymbols( QPainter *painter, const QwtSymbol &symbol, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const { - painter->setBrush(symbol.brush()); - painter->setPen(QwtPainter::scaledPen(symbol.pen())); + const bool doAlign = QwtPainter::roundingAlignment( painter ); - const QwtMetricsMap &metricsMap = QwtPainter::metricsMap(); - - QRect rect; - rect.setSize(metricsMap.screenToLayout(symbol.size())); - - if ( to > from && d_data->paintAttributes & PaintFiltered ) + bool usePixmap = testPaintAttribute( CacheSymbols ); + if ( usePixmap && !doAlign ) { - const QRect window = painter->window(); - if ( window.isEmpty() ) - return; + // Don't use the pixmap, when the paint device + // could generate scalable vectors - PrivateData::PixelMatrix pixelMatrix(window); + usePixmap = false; + } - for (int i = from; i <= to; i++) + if ( usePixmap ) + { + QPixmap pm( symbol.boundingSize() ); + pm.fill( Qt::transparent ); + + const double pw2 = 0.5 * pm.width(); + const double ph2 = 0.5 * pm.height(); + + QPainter p( &pm ); + p.setRenderHints( painter->renderHints() ); + symbol.drawSymbol( &p, QPointF( pw2, ph2 ) ); + p.end(); + + for ( int i = from; i <= to; i++ ) { - const QPoint pi( xMap.transform(x(i)), - yMap.transform(y(i)) ); + const QPointF sample = d_series->sample( i ); - if ( pixelMatrix.testPixel(pi) ) + double xi = xMap.transform( sample.x() ); + double yi = yMap.transform( sample.y() ); + if ( doAlign ) { - rect.moveCenter(pi); - symbol.draw(painter, rect); + xi = qRound( xi ); + yi = qRound( yi ); + } + + if ( canvasRect.contains( xi, yi ) ) + { + const int left = qCeil( xi ) - pw2; + const int top = qCeil( yi ) - ph2; + + painter->drawPixmap( left, top, pm ); } } } else { - for (int i = from; i <= to; i++) - { - const int xi = xMap.transform(x(i)); - const int yi = yMap.transform(y(i)); + const int chunkSize = 500; - rect.moveCenter(QPoint(xi, yi)); - symbol.draw(painter, rect); + for ( int i = from; i <= to; i += chunkSize ) + { + const int n = qMin( chunkSize, to - i + 1 ); + + QPolygonF points; + for ( int j = 0; j < n; j++ ) + { + const QPointF sample = d_series->sample( i + j ); + + const double xi = xMap.transform( sample.x() ); + const double yi = yMap.transform( sample.y() ); + + if ( canvasRect.contains( xi, yi ) ) + points += QPointF( xi, yi ); + } + + if ( points.size() > 0 ) + symbol.drawSymbols( painter, points ); } } } @@ -1206,40 +854,33 @@ void QwtPlotCurve::drawSymbols(QPainter *painter, const QwtSymbol &symbol, \brief Set the value of the baseline The baseline is needed for filling the curve with a brush or - the Sticks drawing style. - The default value is 0.0. The interpretation - of the baseline depends on the CurveType. With QwtPlotCurve::Yfx, - the baseline is interpreted as a horizontal line at y = baseline(), - with QwtPlotCurve::Yfy, it is interpreted as a vertical line at - x = baseline(). - \param reference baseline - \sa baseline(), setBrush(), setStyle(), setCurveType() + the Sticks drawing style. + The interpretation of the baseline depends on the CurveType. + With QwtPlotCurve::Yfx, the baseline is interpreted as a horizontal line + at y = baseline(), with QwtPlotCurve::Yfy, it is interpreted as a vertical + line at x = baseline(). + + The default value is 0.0. + + \param value Value of the baseline + \sa baseline(), setBrush(), setStyle(), setStyle() */ -void QwtPlotCurve::setBaseline(double reference) +void QwtPlotCurve::setBaseline( double value ) { - if ( d_data->reference != reference ) + if ( d_data->baseline != value ) { - d_data->reference = reference; + d_data->baseline = value; itemChanged(); } } /*! - Return the value of the baseline - \sa setBaseline() + \return Value of the baseline + \sa setBaseline() */ -double QwtPlotCurve::baseline() const -{ - return d_data->reference; -} - -/*! - Return the size of the data arrays - \sa setData() -*/ -int QwtPlotCurve::dataSize() const +double QwtPlotCurve::baseline() const { - return d_xy->size(); + return d_data->baseline; } /*! @@ -1248,106 +889,236 @@ int QwtPlotCurve::dataSize() const \param pos Position, where to look for the closest curve point \param dist If dist != NULL, closestPoint() returns the distance between the position and the clostest curve point - \return Index of the closest curve point, or -1 if none can be found + \return Index of the closest curve point, or -1 if none can be found ( f.e when the curve has no points ) - \note closestPoint() implements a dumb algorithm, that iterates + \note closestPoint() implements a dumb algorithm, that iterates over all points */ -int QwtPlotCurve::closestPoint(const QPoint &pos, double *dist) const +int QwtPlotCurve::closestPoint( const QPoint &pos, double *dist ) const { if ( plot() == NULL || dataSize() <= 0 ) return -1; - const QwtScaleMap xMap = plot()->canvasMap(xAxis()); - const QwtScaleMap yMap = plot()->canvasMap(yAxis()); + const QwtScaleMap xMap = plot()->canvasMap( xAxis() ); + const QwtScaleMap yMap = plot()->canvasMap( yAxis() ); int index = -1; double dmin = 1.0e10; - for (int i=0; i < dataSize(); i++) + for ( uint i = 0; i < dataSize(); i++ ) { - const double cx = xMap.xTransform(x(i)) - pos.x(); - const double cy = yMap.xTransform(y(i)) - pos.y(); + const QPointF sample = d_series->sample( i ); - const double f = qwtSqr(cx) + qwtSqr(cy); - if (f < dmin) + const double cx = xMap.transform( sample.x() ) - pos.x(); + const double cy = yMap.transform( sample.y() ) - pos.y(); + + const double f = qwtSqr( cx ) + qwtSqr( cy ); + if ( f < dmin ) { index = i; dmin = f; } } if ( dist ) - *dist = sqrt(dmin); + *dist = qSqrt( dmin ); return index; } -//! Update the widget that represents the curve on the legend -void QwtPlotCurve::updateLegend(QwtLegend *legend) const +/*! + \brief Update the widget that represents the item on the legend + + \param legend Legend + \sa drawLegendIdentifier(), legendItem(), QwtPlotItem::Legend +*/ +void QwtPlotCurve::updateLegend( QwtLegend *legend ) const { - if ( !legend ) - return; - - QwtPlotItem::updateLegend(legend); - - QWidget *widget = legend->find(this); - if ( !widget || !widget->inherits("QwtLegendItem") ) - return; - - QwtLegendItem *legendItem = (QwtLegendItem *)widget; - -#if QT_VERSION < 0x040000 - const bool doUpdate = legendItem->isUpdatesEnabled(); -#else - const bool doUpdate = legendItem->updatesEnabled(); -#endif - legendItem->setUpdatesEnabled(false); - - const int policy = legend->displayPolicy(); - - if (policy == QwtLegend::FixedIdentifier) + if ( legend && testItemAttribute( QwtPlotItem::Legend ) + && ( d_data->legendAttributes & QwtPlotCurve::LegendShowSymbol ) + && d_data->symbol + && d_data->symbol->style() != QwtSymbol::NoSymbol ) { - int mode = legend->identifierMode(); - - if (mode & QwtLegendItem::ShowLine) - legendItem->setCurvePen(pen()); - - if (mode & QwtLegendItem::ShowSymbol) - legendItem->setSymbol(symbol()); - - if (mode & QwtLegendItem::ShowText) - legendItem->setText(title()); - else - legendItem->setText(QwtText()); - - legendItem->setIdentifierMode(mode); - } - else if (policy == QwtLegend::AutoIdentifier) - { - int mode = 0; - - if (QwtPlotCurve::NoCurve != style()) + QWidget *lgdItem = legend->find( this ); + if ( lgdItem == NULL ) { - legendItem->setCurvePen(pen()); - mode |= QwtLegendItem::ShowLine; + lgdItem = legendItem(); + if ( lgdItem ) + legend->insert( this, lgdItem ); } - if (QwtSymbol::NoSymbol != symbol().style()) + + QwtLegendItem *l = qobject_cast( lgdItem ); + if ( l ) { - legendItem->setSymbol(symbol()); - mode |= QwtLegendItem::ShowSymbol; + QSize sz = d_data->symbol->boundingSize(); + sz += QSize( 2, 2 ); // margin + + if ( d_data->legendAttributes & QwtPlotCurve::LegendShowLine ) + { + // Avoid, that the line is completely covered by the symbol + + int w = qCeil( 1.5 * sz.width() ); + if ( w % 2 ) + w++; + + sz.setWidth( qMax( 8, w ) ); + } + + l->setIdentifierSize( sz ); } - if ( !title().isEmpty() ) - { - legendItem->setText(title()); - mode |= QwtLegendItem::ShowText; - } - else - { - legendItem->setText(QwtText()); - } - legendItem->setIdentifierMode(mode); } - legendItem->setUpdatesEnabled(doUpdate); - legendItem->update(); + QwtPlotItem::updateLegend( legend ); } + +/*! + \brief Draw the identifier representing the curve on the legend + + \param painter Painter + \param rect Bounding rectangle for the identifier + + \sa setLegendAttribute(), QwtPlotItem::Legend +*/ +void QwtPlotCurve::drawLegendIdentifier( + QPainter *painter, const QRectF &rect ) const +{ + if ( rect.isEmpty() ) + return; + + const int dim = qMin( rect.width(), rect.height() ); + + QSize size( dim, dim ); + + QRectF r( 0, 0, size.width(), size.height() ); + r.moveCenter( rect.center() ); + + if ( d_data->legendAttributes == 0 ) + { + QBrush brush = d_data->brush; + if ( brush.style() == Qt::NoBrush ) + { + if ( style() != QwtPlotCurve::NoCurve ) + brush = QBrush( pen().color() ); + else if ( d_data->symbol && + ( d_data->symbol->style() != QwtSymbol::NoSymbol ) ) + { + brush = QBrush( d_data->symbol->pen().color() ); + } + } + if ( brush.style() != Qt::NoBrush ) + painter->fillRect( r, brush ); + } + if ( d_data->legendAttributes & QwtPlotCurve::LegendShowBrush ) + { + if ( d_data->brush.style() != Qt::NoBrush ) + painter->fillRect( r, d_data->brush ); + } + if ( d_data->legendAttributes & QwtPlotCurve::LegendShowLine ) + { + if ( pen() != Qt::NoPen ) + { + painter->setPen( pen() ); + QwtPainter::drawLine( painter, rect.left(), rect.center().y(), + rect.right() - 1.0, rect.center().y() ); + } + } + if ( d_data->legendAttributes & QwtPlotCurve::LegendShowSymbol ) + { + if ( d_data->symbol && + ( d_data->symbol->style() != QwtSymbol::NoSymbol ) ) + { + QSize symbolSize = d_data->symbol->boundingSize(); + symbolSize -= QSize( 2, 2 ); + + // scale the symbol size down if it doesn't fit into rect. + + double xRatio = 1.0; + if ( rect.width() < symbolSize.width() ) + xRatio = rect.width() / symbolSize.width(); + double yRatio = 1.0; + if ( rect.height() < symbolSize.height() ) + yRatio = rect.height() / symbolSize.height(); + + const double ratio = qMin( xRatio, yRatio ); + + painter->save(); + painter->scale( ratio, ratio ); + + d_data->symbol->drawSymbol( painter, rect.center() / ratio ); + + painter->restore(); + } + } +} + +/*! + Initialize data with an array of points (explicitly shared). + + \param samples Vector of points +*/ +void QwtPlotCurve::setSamples( const QVector &samples ) +{ + delete d_series; + d_series = new QwtPointSeriesData( samples ); + itemChanged(); +} + +#ifndef QWT_NO_COMPAT + +/*! + \brief Initialize the data by pointing to memory blocks which + are not managed by QwtPlotCurve. + + setRawSamples is provided for efficiency. + It is important to keep the pointers + during the lifetime of the underlying QwtCPointerData class. + + \param xData pointer to x data + \param yData pointer to y data + \param size size of x and y + + \sa QwtCPointerData +*/ +void QwtPlotCurve::setRawSamples( + const double *xData, const double *yData, int size ) +{ + delete d_series; + d_series = new QwtCPointerData( xData, yData, size ); + itemChanged(); +} + +/*! + Set data by copying x- and y-values from specified memory blocks. + Contrary to setRawSamples(), this function makes a 'deep copy' of + the data. + + \param xData pointer to x values + \param yData pointer to y values + \param size size of xData and yData + + \sa QwtPointArrayData +*/ +void QwtPlotCurve::setSamples( + const double *xData, const double *yData, int size ) +{ + delete d_series; + d_series = new QwtPointArrayData( xData, yData, size ); + itemChanged(); +} + +/*! + \brief Initialize data with x- and y-arrays (explicitly shared) + + \param xData x data + \param yData y data + + \sa QwtPointArrayData +*/ +void QwtPlotCurve::setSamples( const QVector &xData, + const QVector &yData ) +{ + delete d_series; + d_series = new QwtPointArrayData( xData, yData ); + itemChanged(); +} +#endif // !QWT_NO_COMPAT + diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_curve.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_curve.h index 3c0551495..fa11dab25 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_curve.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_curve.h @@ -10,15 +10,15 @@ #ifndef QWT_PLOT_CURVE_H #define QWT_PLOT_CURVE_H +#include "qwt_global.h" +#include "qwt_plot_seriesitem.h" +#include "qwt_series_data.h" +#include "qwt_text.h" #include #include -#include "qwt_global.h" -#include "qwt_plot_item.h" -#include "qwt_text.h" -#include "qwt_polygon.h" -#include "qwt_data.h" class QPainter; +class QPolygonF; class QwtScaleMap; class QwtSymbol; class QwtCurveFitter; @@ -27,20 +27,21 @@ class QwtCurveFitter; \brief A plot item, that represents a series of points A curve is the representation of a series of points in the x-y plane. - It supports different display styles, interpolation ( f.e. spline ) + It supports different display styles, interpolation ( f.e. spline ) and symbols. \par Usage
a) Assign curve properties
When a curve is created, it is configured to draw black solid lines - with in Lines style and no symbols. You can change this by calling + with in QwtPlotCurve::Lines style and no symbols. + You can change this by calling setPen(), setStyle() and setSymbol().
b) Connect/Assign data.
-
QwtPlotCurve gets its points using a QwtData object offering +
QwtPlotCurve gets its points using a QwtSeriesData object offering a bridge to the real storage of the points ( like QAbstractItemModel ). - There are several convenience classes derived from QwtData, that also store + There are several convenience classes derived from QwtSeriesData, that also store the points inside ( like QStandardItemModel ). QwtPlotCurve also offers - a couple of variations of setData(), that build QwtData objects from + a couple of variations of setSamples(), that build QwtSeriesData objects from arrays internally.
c) Attach the curve to a plot
See QwtPlotItem::attach() @@ -49,261 +50,270 @@ class QwtCurveFitter; \par Example: see examples/bode - \sa QwtPlot, QwtData, QwtSymbol, QwtScaleMap + \sa QwtPointSeriesData, QwtSymbol, QwtScaleMap */ -class QWT_EXPORT QwtPlotCurve: public QwtPlotItem +class QWT_EXPORT QwtPlotCurve: public QwtPlotSeriesItem { public: /*! - Curve type. - - - Yfx\n - Draws y as a function of x (the default). The - baseline is interpreted as a horizontal line - with y = baseline(). - - Xfy\n - Draws x as a function of y. The baseline is - interpreted as a vertical line with x = baseline(). - - The baseline is used for aligning the sticks, or - filling the curve with a brush. - - \sa setCurveType(), curveType(), baseline() brush() - */ - enum CurveType - { - Yfx, - Xfy - }; - - /*! - Curve styles. - - - NoCurve\n - Don't draw a curve. Note: This doesn't affect the symbols. - - Lines\n - Connect the points with straight lines. The lines might - be interpolated depending on the 'Fitted' attribute. Curve - fitting can be configured using setCurveFitter(). - - Sticks\n - Draw vertical(Yfx) or horizontal(Xfy) sticks from a baseline - which is defined by setBaseline(). - - Steps\n - Connect the points with a step function. The step function - is drawn from the left to the right or vice versa, - depending on the 'Inverted' attribute. - - Dots\n - Draw dots at the locations of the data points. Note: - This is different from a dotted line (see setPen()), and faster - as a curve in NoStyle style and a symbol painting a point. - - UserCurve\n - Styles >= UserCurve are reserved for derived - classes of QwtPlotCurve that overload drawCurve() with - additional application specific curve types. - + Curve styles. \sa setStyle(), style() */ enum CurveStyle { - NoCurve, + /*! + Don't draw a curve. Note: This doesn't affect the symbols. + */ + NoCurve = -1, + /*! + Connect the points with straight lines. The lines might + be interpolated depending on the 'Fitted' attribute. Curve + fitting can be configured using setCurveFitter(). + */ Lines, + + /*! + Draw vertical or horizontal sticks ( depending on the + orientation() ) from a baseline which is defined by setBaseline(). + */ Sticks, + + /*! + Connect the points with a step function. The step function + is drawn from the left to the right or vice versa, + depending on the QwtPlotCurve::Inverted attribute. + */ Steps, + + /*! + Draw dots at the locations of the data points. Note: + This is different from a dotted line (see setPen()), and faster + as a curve in QwtPlotCurve::NoStyle style and a symbol + painting a point. + */ Dots, + /*! + Styles >= QwtPlotCurve::UserCurve are reserved for derived + classes of QwtPlotCurve that overload drawCurve() with + additional application specific curve types. + */ UserCurve = 100 }; - /*! + /*! Attribute for drawing the curve - - - Fitted ( in combination with the Lines QwtPlotCurve::CurveStyle only )\n - A QwtCurveFitter tries to - interpolate/smooth the curve, before it is painted. - Note that curve fitting requires temorary memory - for calculating coefficients and additional points. - If painting in Fitted mode is slow it might be better - to fit the points, before they are passed to QwtPlotCurve. - - Inverted\n - For Steps only. Draws a step function - from the right to the left. - - \sa setCurveAttribute(), testCurveAttribute(), curveFitter() + \sa setCurveAttribute(), testCurveAttribute(), curveFitter() */ enum CurveAttribute { - Inverted = 1, - Fitted = 2 + /*! + For QwtPlotCurve::Steps only. + Draws a step function from the right to the left. + */ + Inverted = 0x01, + + /*! + Only in combination with QwtPlotCurve::Lines + A QwtCurveFitter tries to + interpolate/smooth the curve, before it is painted. + + \note Curve fitting requires temorary memory + for calculating coefficients and additional points. + If painting in QwtPlotCurve::Fitted mode is slow it might be better + to fit the points, before they are passed to QwtPlotCurve. + */ + Fitted = 0x02 }; - /*! + //! Curve attributes + typedef QFlags CurveAttributes; + + /*! + Attributes how to represent the curve on the legend + + \sa setLegendAttribute(), testLegendAttribute(), + drawLegendIdentifier() + */ + + enum LegendAttribute + { + /*! + QwtPlotCurve tries to find a color representing the curve + and paints a rectangle with it. + */ + LegendNoAttribute = 0x00, + + /*! + If the style() is not QwtPlotCurve::NoCurve a line + is painted with the curve pen(). + */ + LegendShowLine = 0x01, + + /*! + If the curve has a valid symbol it is painted. + */ + LegendShowSymbol = 0x02, + + /*! + If the curve has a brush a rectangle filled with the + curve brush() is painted. + */ + LegendShowBrush = 0x04 + }; + + //! Legend attributes + typedef QFlags LegendAttributes; + + /*! Attributes to modify the drawing algorithm. - - - PaintFiltered\n - Tries to reduce the data that has to be painted, by sorting out - duplicates, or paintings outside the visible area. Might have a - notable impact on curves with many close points. - Only a couple of very basic filtering algos are implemented. - - ClipPolygons\n - Clip polygons before painting them. In situations, where points - are far outside the visible area (f.e when zooming deep) this - might be a substantial improvement for the painting performance - ( especially on Windows ). - - The default is, that no paint attributes are enabled. + The default setting enables ClipPolygons \sa setPaintAttribute(), testPaintAttribute() */ enum PaintAttribute { - PaintFiltered = 1, - ClipPolygons = 2 + /*! + Clip polygons before painting them. In situations, where points + are far outside the visible area (f.e when zooming deep) this + might be a substantial improvement for the painting performance + */ + ClipPolygons = 0x01, + + /*! + Paint the symbol to a QPixmap and paint the pixmap + instead rendering the symbol for each point. The flag has + no effect, when the curve is not painted to the canvas + ( f.e when exporting the plot to a PDF document ). + */ + CacheSymbols = 0x02 }; - explicit QwtPlotCurve(); - explicit QwtPlotCurve(const QwtText &title); - explicit QwtPlotCurve(const QString &title); + //! Paint attributes + typedef QFlags PaintAttributes; + + explicit QwtPlotCurve( const QString &title = QString::null ); + explicit QwtPlotCurve( const QwtText &title ); virtual ~QwtPlotCurve(); virtual int rtti() const; - void setCurveType(CurveType); - CurveType curveType() const; + void setPaintAttribute( PaintAttribute, bool on = true ); + bool testPaintAttribute( PaintAttribute ) const; - void setPaintAttribute(PaintAttribute, bool on = true); - bool testPaintAttribute(PaintAttribute) const; + void setLegendAttribute( LegendAttribute, bool on = true ); + bool testLegendAttribute( LegendAttribute ) const; - void setRawData(const double *x, const double *y, int size); - void setData(const double *xData, const double *yData, int size); - void setData(const QwtArray &xData, const QwtArray &yData); -#if QT_VERSION < 0x040000 - void setData(const QwtArray &data); -#else - void setData(const QPolygonF &data); +#ifndef QWT_NO_COMPAT + void setRawSamples( const double *xData, const double *yData, int size ); + void setSamples( const double *xData, const double *yData, int size ); + void setSamples( const QVector &xData, const QVector &yData ); #endif - void setData(const QwtData &data); - - int closestPoint(const QPoint &pos, double *dist = NULL) const; + void setSamples( const QVector & ); - QwtData &data(); - const QwtData &data() const; + int closestPoint( const QPoint &pos, double *dist = NULL ) const; - int dataSize() const; - inline double x(int i) const; - inline double y(int i) const; + double minXValue() const; + double maxXValue() const; + double minYValue() const; + double maxYValue() const; - virtual QwtDoubleRect boundingRect() const; + void setCurveAttribute( CurveAttribute, bool on = true ); + bool testCurveAttribute( CurveAttribute ) const; - //! boundingRect().left() - inline double minXValue() const { return boundingRect().left(); } - //! boundingRect().right() - inline double maxXValue() const { return boundingRect().right(); } - //! boundingRect().top() - inline double minYValue() const { return boundingRect().top(); } - //! boundingRect().bottom() - inline double maxYValue() const { return boundingRect().bottom(); } - - void setCurveAttribute(CurveAttribute, bool on = true); - bool testCurveAttribute(CurveAttribute) const; - - void setPen(const QPen &); + void setPen( const QPen & ); const QPen &pen() const; - void setBrush(const QBrush &); + void setBrush( const QBrush & ); const QBrush &brush() const; - void setBaseline(double ref); + void setBaseline( double ref ); double baseline() const; - void setStyle(CurveStyle style); + void setStyle( CurveStyle style ); CurveStyle style() const; - void setSymbol(const QwtSymbol &s); - const QwtSymbol& symbol() const; + void setSymbol( const QwtSymbol *s ); + const QwtSymbol *symbol() const; - void setCurveFitter(QwtCurveFitter *); + void setCurveFitter( QwtCurveFitter * ); QwtCurveFitter *curveFitter() const; - virtual void draw(QPainter *p, + virtual void drawSeries( QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, - const QRect &) const; + const QRectF &canvasRect, int from, int to ) const; - virtual void draw(QPainter *p, - const QwtScaleMap &xMap, const QwtScaleMap &yMap, - int from, int to) const; - - void draw(int from, int to) const; - - virtual void updateLegend(QwtLegend *) const; + virtual void updateLegend( QwtLegend * ) const; + virtual void drawLegendIdentifier( QPainter *, const QRectF & ) const; protected: void init(); - virtual void drawCurve(QPainter *p, int style, + virtual void drawCurve( QPainter *p, int style, const QwtScaleMap &xMap, const QwtScaleMap &yMap, - int from, int to) const; + const QRectF &canvasRect, int from, int to ) const; - virtual void drawSymbols(QPainter *p, const QwtSymbol &, + virtual void drawSymbols( QPainter *p, const QwtSymbol &, const QwtScaleMap &xMap, const QwtScaleMap &yMap, - int from, int to) const; + const QRectF &canvasRect, int from, int to ) const; - void drawLines(QPainter *p, + void drawLines( QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, - int from, int to) const; - void drawSticks(QPainter *p, - const QwtScaleMap &xMap, const QwtScaleMap &yMap, - int from, int to) const; - void drawDots(QPainter *p, - const QwtScaleMap &xMap, const QwtScaleMap &yMap, - int from, int to) const; - void drawSteps(QPainter *p, - const QwtScaleMap &xMap, const QwtScaleMap &yMap, - int from, int to) const; + const QRectF &canvasRect, int from, int to ) const; - void fillCurve(QPainter *, - const QwtScaleMap &, const QwtScaleMap &, - QwtPolygon &) const; - void closePolyline(const QwtScaleMap &, const QwtScaleMap &, - QwtPolygon &) const; + void drawSticks( QPainter *p, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const; + + void drawDots( QPainter *p, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const; + + void drawSteps( QPainter *p, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const; + + virtual void fillCurve( QPainter *, + const QwtScaleMap &, const QwtScaleMap &, + const QRectF &canvasRect, QPolygonF & ) const; + + void closePolyline( QPainter *, + const QwtScaleMap &, const QwtScaleMap &, QPolygonF & ) const; private: - QwtData *d_xy; - class PrivateData; PrivateData *d_data; }; -//! \return the the curve data -inline QwtData &QwtPlotCurve::data() +//! boundingRect().left() +inline double QwtPlotCurve::minXValue() const { - return *d_xy; + return boundingRect().left(); } -//! \return the the curve data -inline const QwtData &QwtPlotCurve::data() const +//! boundingRect().right() +inline double QwtPlotCurve::maxXValue() const { - return *d_xy; + return boundingRect().right(); } -/*! - \param i index - \return x-value at position i -*/ -inline double QwtPlotCurve::x(int i) const -{ - return d_xy->x(i); +//! boundingRect().top() +inline double QwtPlotCurve::minYValue() const +{ + return boundingRect().top(); } -/*! - \param i index - \return y-value at position i -*/ -inline double QwtPlotCurve::y(int i) const -{ - return d_xy->y(i); +//! boundingRect().bottom() +inline double QwtPlotCurve::maxYValue() const +{ + return boundingRect().bottom(); } +Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotCurve::PaintAttributes ) +Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotCurve::LegendAttributes ) +Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotCurve::CurveAttributes ) + #endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_dict.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_dict.cpp index c592edd5d..f7000bc93 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_dict.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_dict.cpp @@ -7,86 +7,60 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - #include "qwt_plot_dict.h" class QwtPlotDict::PrivateData { public: -#if QT_VERSION < 0x040000 - class ItemList: public QValueList -#else class ItemList: public QList -#endif { public: - void insertItem(QwtPlotItem *item) + void insertItem( QwtPlotItem *item ) { if ( item == NULL ) return; - // Unfortunately there is no inSort operation - // for lists in Qt4. The implementation below - // is slow, but there shouldn't be many plot items. - -#ifdef __GNUC__ -#endif - -#if QT_VERSION < 0x040000 - QValueListIterator it; -#else - QList::Iterator it; -#endif - for ( it = begin(); it != end(); ++it ) - { - if ( *it == item ) - return; - - if ( (*it)->z() > item->z() ) - { - insert(it, item); - return; - } - } - append(item); + QList::iterator it = + qUpperBound( begin(), end(), item, LessZThan() ); + insert( it, item ); } - void removeItem(QwtPlotItem *item) + void removeItem( QwtPlotItem *item ) { if ( item == NULL ) return; - int i = 0; + QList::iterator it = + qLowerBound( begin(), end(), item, LessZThan() ); -#if QT_VERSION < 0x040000 - QValueListIterator it; -#else - QList::Iterator it; -#endif - for ( it = begin(); it != end(); ++it ) + for ( ; it != end(); ++it ) { if ( item == *it ) { -#if QT_VERSION < 0x040000 - remove(it); -#else - removeAt(i); -#endif - return; + erase( it ); + break; } - i++; } } + private: + class LessZThan + { + public: + inline bool operator()( const QwtPlotItem *item1, + const QwtPlotItem *item2 ) const + { + return item1->z() < item2->z(); + } + }; }; ItemList itemList; bool autoDelete; }; -/*! - Constructor +/*! + Constructor Auto deletion is enabled. \sa setAutoDelete(), attachItem() @@ -97,7 +71,7 @@ QwtPlotDict::QwtPlotDict() d_data->autoDelete = true; } -/*! +/*! Destructor If autoDelete is on, all attached items will be deleted @@ -105,7 +79,7 @@ QwtPlotDict::QwtPlotDict() */ QwtPlotDict::~QwtPlotDict() { - detachItems(QwtPlotItem::Rtti_PlotItem, d_data->autoDelete); + detachItems( QwtPlotItem::Rtti_PlotItem, d_data->autoDelete ); delete d_data; } @@ -117,7 +91,7 @@ QwtPlotDict::~QwtPlotDict() \sa autoDelete(), attachItem() */ -void QwtPlotDict::setAutoDelete(bool autoDelete) +void QwtPlotDict::setAutoDelete( bool autoDelete ) { d_data->autoDelete = autoDelete; } @@ -143,22 +117,22 @@ bool QwtPlotDict::autoDelete() const \sa setAutoDelete(), ~QwtPlotDict() */ -void QwtPlotDict::attachItem(QwtPlotItem *item, bool on) +void QwtPlotDict::attachItem( QwtPlotItem *item, bool on ) { if ( on ) - d_data->itemList.insertItem(item); + d_data->itemList.insertItem( item ); else - d_data->itemList.removeItem(item); + d_data->itemList.removeItem( item ); } /*! Detach items from the dictionary - \param rtti In case of QwtPlotItem::Rtti_PlotItem detach all items + \param rtti In case of QwtPlotItem::Rtti_PlotItem detach all items otherwise only those items of the type rtti. \param autoDelete If true, delete all detached items */ -void QwtPlotDict::detachItems(int rtti, bool autoDelete) +void QwtPlotDict::detachItems( int rtti, bool autoDelete ) { PrivateData::ItemList list = d_data->itemList; QwtPlotItemIterator it = list.begin(); @@ -170,20 +144,45 @@ void QwtPlotDict::detachItems(int rtti, bool autoDelete) if ( rtti == QwtPlotItem::Rtti_PlotItem || item->rtti() == rtti ) { - item->attach(NULL); + item->attach( NULL ); if ( autoDelete ) delete item; } } } -//! \brief A QwtPlotItemList of all attached plot items. -/// -/// Use caution when iterating these lists, as removing/detaching an item will -/// invalidate the iterator. Instead you can place pointers to objects to be -/// removed in a removal list, and traverse that list later. -//! \return List of all attached plot items. +/*! + \brief A QwtPlotItemList of all attached plot items. + + Use caution when iterating these lists, as removing/detaching an item will + invalidate the iterator. Instead you can place pointers to objects to be + removed in a removal list, and traverse that list later. + + \return List of all attached plot items. +*/ const QwtPlotItemList &QwtPlotDict::itemList() const { return d_data->itemList; } + +/*! + \return List of all attached plot items of a specific type. + \sa QwtPlotItem::rtti() +*/ +QwtPlotItemList QwtPlotDict::itemList( int rtti ) const +{ + if ( rtti == QwtPlotItem::Rtti_PlotItem ) + return d_data->itemList; + + QwtPlotItemList items; + + PrivateData::ItemList list = d_data->itemList; + for ( QwtPlotItemIterator it = list.begin(); it != list.end(); ++it ) + { + QwtPlotItem *item = *it; + if ( item->rtti() == rtti ) + items += item; + } + + return items; +} diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_dict.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_dict.h index 18a666f67..2a8ad69a1 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_dict.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_dict.h @@ -7,28 +7,18 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - /*! \file !*/ #ifndef QWT_PLOT_DICT #define QWT_PLOT_DICT #include "qwt_global.h" #include "qwt_plot_item.h" - -#if QT_VERSION < 0x040000 -#include -typedef QValueListConstIterator QwtPlotItemIterator; -/// \var typedef QValueList< QwtPlotItem *> QwtPlotItemList -/// \brief See QT 3.x assistant documentation for QValueList -typedef QValueList QwtPlotItemList; -#else #include -typedef QList::ConstIterator QwtPlotItemIterator; + /// \var typedef QList< QwtPlotItem *> QwtPlotItemList /// \brief See QT 4.x assistant documentation for QList typedef QList QwtPlotItemList; -#endif +typedef QList::ConstIterator QwtPlotItemIterator; /*! \brief A dictionary for plot items @@ -43,20 +33,21 @@ class QWT_EXPORT QwtPlotDict { public: explicit QwtPlotDict(); - ~QwtPlotDict(); + virtual ~QwtPlotDict(); - void setAutoDelete(bool); + void setAutoDelete( bool ); bool autoDelete() const; const QwtPlotItemList& itemList() const; + QwtPlotItemList itemList( int rtti ) const; - void detachItems(int rtti = QwtPlotItem::Rtti_PlotItem, - bool autoDelete = true); + void detachItems( int rtti = QwtPlotItem::Rtti_PlotItem, + bool autoDelete = true ); private: friend class QwtPlotItem; - void attachItem(QwtPlotItem *, bool); + void attachItem( QwtPlotItem *, bool ); class PrivateData; PrivateData *d_data; diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_directpainter.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_directpainter.cpp new file mode 100644 index 000000000..3cc69408c --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_directpainter.cpp @@ -0,0 +1,313 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#include "qwt_plot_directpainter.h" +#include "qwt_scale_map.h" +#include "qwt_plot.h" +#include "qwt_plot_canvas.h" +#include "qwt_plot_seriesitem.h" +#include +#include +#include +#include + +static inline void renderItem( + QPainter *painter, const QRect &canvasRect, + QwtPlotAbstractSeriesItem *seriesItem, int from, int to ) +{ + // A minor performance improvement is possible + // with caching the maps. TODO ... + + QwtPlot *plot = seriesItem->plot(); + const QwtScaleMap xMap = plot->canvasMap( seriesItem->xAxis() ); + const QwtScaleMap yMap = plot->canvasMap( seriesItem->yAxis() ); + + painter->setRenderHint( QPainter::Antialiasing, + seriesItem->testRenderHint( QwtPlotItem::RenderAntialiased ) ); + seriesItem->drawSeries( painter, xMap, yMap, canvasRect, from, to ); +} + +class QwtPlotDirectPainter::PrivateData +{ +public: + PrivateData(): + attributes( 0 ), + hasClipping(false), + seriesItem( NULL ) + { + } + + QwtPlotDirectPainter::Attributes attributes; + + bool hasClipping; + QRegion clipRegion; + + QPainter painter; + + QwtPlotAbstractSeriesItem *seriesItem; + int from; + int to; +}; + +//! Constructor +QwtPlotDirectPainter::QwtPlotDirectPainter( QObject *parent ): + QObject( parent ) +{ + d_data = new PrivateData; +} + +//! Destructor +QwtPlotDirectPainter::~QwtPlotDirectPainter() +{ + delete d_data; +} + +/*! + Change an attribute + + \param attribute Attribute to change + \param on On/Off + + \sa Attribute, testAttribute() +*/ +void QwtPlotDirectPainter::setAttribute( Attribute attribute, bool on ) +{ + if ( bool( d_data->attributes & attribute ) != on ) + { + if ( on ) + d_data->attributes |= attribute; + else + d_data->attributes &= ~attribute; + + if ( ( attribute == AtomicPainter ) && on ) + reset(); + } +} + +/*! + Check if a attribute is set. + + \param attribute Attribute to be tested + \sa Attribute, setAttribute() +*/ +bool QwtPlotDirectPainter::testAttribute( Attribute attribute ) const +{ + return d_data->attributes & attribute; +} + +/*! + En/Disables clipping + + \param enable Enables clipping is true, disable it otherwise + \sa hasClipping(), clipRegion(), setClipRegion() +*/ +void QwtPlotDirectPainter::setClipping( bool enable ) +{ + d_data->hasClipping = enable; +} + +/*! + \return true, when clipping is enabled + \sa setClipping(), clipRegion(), setClipRegion() +*/ +bool QwtPlotDirectPainter::hasClipping() const +{ + return d_data->hasClipping; +} + +/*! + \brief Assign a clip region and enable clipping + + Depending on the environment setting a proper clip region might improve + the performance heavily. F.e. on Qt embedded only the clipped part of + the backing store will be copied to a ( maybe unaccelerated ) frame buffer + device. + + \param region Clip region + \sa clipRegion(), hasClipping(), setClipping() +*/ +void QwtPlotDirectPainter::setClipRegion( const QRegion ®ion ) +{ + d_data->clipRegion = region; + d_data->hasClipping = true; +} + +/*! + \return Currently set clip region. + \sa setClipRegion(), setClipping(), hasClipping() +*/ +QRegion QwtPlotDirectPainter::clipRegion() const +{ + return d_data->clipRegion; +} + +/*! + \brief Draw a set of points of a seriesItem. + + When observing an measurement while it is running, new points have to be + added to an existing seriesItem. drawSeries can be used to display them avoiding + a complete redraw of the canvas. + + Setting plot()->canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); + will result in faster painting, if the paint engine of the canvas widget + supports this feature. + + \param seriesItem Item to be painted + \param from Index of the first point to be painted + \param to Index of the last point to be painted. If to < 0 the + series will be painted to its last point. +*/ +void QwtPlotDirectPainter::drawSeries( + QwtPlotAbstractSeriesItem *seriesItem, int from, int to ) +{ + if ( seriesItem == NULL || seriesItem->plot() == NULL ) + return; + + QwtPlotCanvas *canvas = seriesItem->plot()->canvas(); + const QRect canvasRect = canvas->contentsRect(); + + const bool hasBackingStore = + canvas->testPaintAttribute( QwtPlotCanvas::BackingStore ) + && canvas->backingStore() && !canvas->backingStore()->isNull(); + + if ( hasBackingStore ) + { + QPainter painter( const_cast( canvas->backingStore() ) ); + painter.translate( -canvasRect.x(), -canvasRect.y() ); + + if ( d_data->hasClipping ) + painter.setClipRegion( d_data->clipRegion ); + + renderItem( &painter, canvasRect, seriesItem, from, to ); + + if ( testAttribute( QwtPlotDirectPainter::FullRepaint ) ) + { + canvas->repaint(); + return; + } + } + + bool immediatePaint = true; + if ( !canvas->testAttribute( Qt::WA_WState_InPaintEvent ) && + !canvas->testAttribute( Qt::WA_PaintOutsidePaintEvent ) ) + { + immediatePaint = false; + } + + if ( immediatePaint ) + { + QwtPlotCanvas *canvas = seriesItem->plot()->canvas(); + if ( !d_data->painter.isActive() ) + { + reset(); + + d_data->painter.begin( canvas ); + canvas->installEventFilter( this ); + } + + if ( d_data->hasClipping ) + { + d_data->painter.setClipRegion( + QRegion( canvasRect ) & d_data->clipRegion ); + } + else + { + if ( !d_data->painter.hasClipping() ) + d_data->painter.setClipRect( canvasRect ); + } + + renderItem( &d_data->painter, canvasRect, seriesItem, from, to ); + + if ( d_data->attributes & QwtPlotDirectPainter::AtomicPainter ) + { + reset(); + } + else + { + if ( d_data->hasClipping ) + d_data->painter.setClipping( false ); + } + } + else + { + reset(); + + d_data->seriesItem = seriesItem; + d_data->from = from; + d_data->to = to; + + QRegion clipRegion = canvasRect; + if ( d_data->hasClipping ) + clipRegion &= d_data->clipRegion; + + canvas->installEventFilter( this ); + canvas->repaint(clipRegion); + canvas->removeEventFilter( this ); + + d_data->seriesItem = NULL; + } +} + +//! Close the internal QPainter +void QwtPlotDirectPainter::reset() +{ + if ( d_data->painter.isActive() ) + { + QWidget *w = ( QWidget * )d_data->painter.device(); + if ( w ) + w->removeEventFilter( this ); + + d_data->painter.end(); + } +} + +//! Event filter +bool QwtPlotDirectPainter::eventFilter( QObject *, QEvent *event ) +{ + if ( event->type() == QEvent::Paint ) + { + reset(); + + if ( d_data->seriesItem ) + { + const QPaintEvent *pe = static_cast< QPaintEvent *>( event ); + + QwtPlotCanvas *canvas = d_data->seriesItem->plot()->canvas(); + + QPainter painter( canvas ); + painter.setClipRegion( pe->region() ); + + bool copyCache = testAttribute( CopyBackingStore ) + && canvas->testPaintAttribute( QwtPlotCanvas::BackingStore ); + + if ( copyCache ) + { + // is something valid in the cache ? + copyCache = ( canvas->backingStore() != NULL ) + && !canvas->backingStore()->isNull(); + } + + if ( copyCache ) + { + painter.drawPixmap( + canvas->contentsRect().topLeft(), + *canvas->backingStore() ); + } + else + { + renderItem( &painter, canvas->contentsRect(), + d_data->seriesItem, d_data->from, d_data->to ); + } + + return true; // don't call QwtPlotCanvas::paintEvent() + } + } + + return false; +} diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_directpainter.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_directpainter.h new file mode 100644 index 000000000..318c115e0 --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_directpainter.h @@ -0,0 +1,100 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#ifndef QWT_PLOT_DIRECT_PAINTER_H +#define QWT_PLOT_DIRECT_PAINTER_H + +#include "qwt_global.h" +#include + +class QRegion; +class QwtPlotAbstractSeriesItem; + +/*! + \brief Painter object trying to paint incrementally + + Often applications want to display samples while they are + collected. When there are too many samples complete replots + will be expensive to be processed in a collection cycle. + + QwtPlotDirectPainter offers an API to paint + subsets ( f.e all additions points ) without erasing/repainting + the plot canvas. + + On certain environments it might be important to calculate a proper + clip region before painting. F.e. for Qt Embedded only the clipped part + of the backing store will be copied to a ( maybe unaccelerated ) + frame buffer. + + \warning Incremental painting will only help when no replot is triggered + by another operation ( like changing scales ) and nothing needs + to be erased. +*/ +class QWT_EXPORT QwtPlotDirectPainter: public QObject +{ +public: + /*! + \brief Paint attributes + \sa setAttribute(), testAttribute(), drawSeries() + */ + enum Attribute + { + /*! + Initializing a QPainter is an expensive operation. + When AtomicPainter is set each call of drawSeries() opens/closes + a temporary QPainter. Otherwise QwtPlotDirectPainter tries to + use the same QPainter as long as possible. + */ + AtomicPainter = 0x01, + + /*! + When FullRepaint is set the plot canvas is explicitely repainted + after the samples have been rendered. + */ + FullRepaint = 0x02, + + /*! + When QwtPlotCanvas::BackingStore is enabled the painter + has to paint to the backing store and the widget. In certain + situations/environments it might be faster to paint to + the backing store only and then copy the backingstore to the canvas. + This flag can also be useful for settings, where Qt fills the + the clip region with the widget background. + */ + CopyBackingStore = 0x04 + }; + + //! Paint attributes + typedef QFlags Attributes; + + QwtPlotDirectPainter( QObject *parent = NULL ); + virtual ~QwtPlotDirectPainter(); + + void setAttribute( Attribute, bool on ); + bool testAttribute( Attribute ) const; + + void setClipping( bool ); + bool hasClipping() const; + + void setClipRegion( const QRegion & ); + QRegion clipRegion() const; + + void drawSeries( QwtPlotAbstractSeriesItem *, int from, int to ); + void reset(); + + virtual bool eventFilter( QObject *, QEvent * ); + +private: + class PrivateData; + PrivateData *d_data; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotDirectPainter::Attributes ) + +#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_grid.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_grid.cpp index e0fdf0276..283ed01d5 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_grid.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_grid.cpp @@ -2,27 +2,28 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -#include -#include +#include "qwt_plot_grid.h" #include "qwt_painter.h" #include "qwt_text.h" #include "qwt_scale_map.h" #include "qwt_scale_div.h" -#include "qwt_plot_grid.h" +#include "qwt_math.h" +#include +#include class QwtPlotGrid::PrivateData { public: PrivateData(): - xEnabled(true), - yEnabled(true), - xMinEnabled(false), - yMinEnabled(false) + xEnabled( true ), + yEnabled( true ), + xMinEnabled( false ), + yMinEnabled( false ) { } @@ -40,10 +41,10 @@ public: //! Enables major grid, disables minor grid QwtPlotGrid::QwtPlotGrid(): - QwtPlotItem(QwtText("Grid")) + QwtPlotItem( QwtText( "Grid" ) ) { d_data = new PrivateData; - setZ(10.0); + setZ( 10.0 ); } //! Destructor @@ -65,7 +66,7 @@ int QwtPlotGrid::rtti() const \sa Minor gridlines can be enabled or disabled with enableXMin() */ -void QwtPlotGrid::enableX(bool tf) +void QwtPlotGrid::enableX( bool tf ) { if ( d_data->xEnabled != tf ) { @@ -79,11 +80,11 @@ void QwtPlotGrid::enableX(bool tf) \param tf Enable (true) or disable \sa Minor gridlines can be enabled or disabled with enableYMin() */ -void QwtPlotGrid::enableY(bool tf) +void QwtPlotGrid::enableY( bool tf ) { if ( d_data->yEnabled != tf ) { - d_data->yEnabled = tf; + d_data->yEnabled = tf; itemChanged(); } } @@ -93,7 +94,7 @@ void QwtPlotGrid::enableY(bool tf) \param tf Enable (true) or disable \sa enableX() */ -void QwtPlotGrid::enableXMin(bool tf) +void QwtPlotGrid::enableXMin( bool tf ) { if ( d_data->xMinEnabled != tf ) { @@ -107,7 +108,7 @@ void QwtPlotGrid::enableXMin(bool tf) \param tf Enable (true) or disable \sa enableY() */ -void QwtPlotGrid::enableYMin(bool tf) +void QwtPlotGrid::enableYMin( bool tf ) { if ( d_data->yMinEnabled != tf ) { @@ -121,7 +122,7 @@ void QwtPlotGrid::enableYMin(bool tf) \param scaleDiv Scale division */ -void QwtPlotGrid::setXDiv(const QwtScaleDiv &scaleDiv) +void QwtPlotGrid::setXDiv( const QwtScaleDiv &scaleDiv ) { if ( d_data->xScaleDiv != scaleDiv ) { @@ -135,11 +136,11 @@ void QwtPlotGrid::setXDiv(const QwtScaleDiv &scaleDiv) \param scaleDiv Scale division */ -void QwtPlotGrid::setYDiv(const QwtScaleDiv &scaleDiv) +void QwtPlotGrid::setYDiv( const QwtScaleDiv &scaleDiv ) { if ( d_data->yScaleDiv != scaleDiv ) { - d_data->yScaleDiv = scaleDiv; + d_data->yScaleDiv = scaleDiv; itemChanged(); } } @@ -147,13 +148,10 @@ void QwtPlotGrid::setYDiv(const QwtScaleDiv &scaleDiv) /*! Assign a pen for both major and minor gridlines - The width of non cosmetic pens is scaled according to the resolution - of the paint device. - \param pen Pen - \sa setMajPen(), setMinPen(), QwtPainter::scaledPen() + \sa setMajPen(), setMinPen() */ -void QwtPlotGrid::setPen(const QPen &pen) +void QwtPlotGrid::setPen( const QPen &pen ) { if ( d_data->majPen != pen || d_data->minPen != pen ) { @@ -166,13 +164,10 @@ void QwtPlotGrid::setPen(const QPen &pen) /*! Assign a pen for the major gridlines - The width of non cosmetic pens is scaled according to the resolution - of the paint device. - \param pen Pen - \sa majPen(), setMinPen(), setPen(), QwtPainter::scaledPen() + \sa majPen(), setMinPen(), setPen() */ -void QwtPlotGrid::setMajPen(const QPen &pen) +void QwtPlotGrid::setMajPen( const QPen &pen ) { if ( d_data->majPen != pen ) { @@ -184,93 +179,107 @@ void QwtPlotGrid::setMajPen(const QPen &pen) /*! Assign a pen for the minor gridlines - The width of non cosmetic pens is scaled according to the resolution - of the paint device. - \param pen Pen - \sa minPen(), setMajPen(), setPen(), QwtPainter::scaledPen() + \sa minPen(), setMajPen(), setPen() */ -void QwtPlotGrid::setMinPen(const QPen &pen) +void QwtPlotGrid::setMinPen( const QPen &pen ) { if ( d_data->minPen != pen ) { - d_data->minPen = pen; + d_data->minPen = pen; itemChanged(); } } /*! \brief Draw the grid - - The grid is drawn into the bounding rectangle such that + + The grid is drawn into the bounding rectangle such that gridlines begin and end at the rectangle's borders. The X and Y maps are used to map the scale divisions into the drawing region screen. \param painter Painter \param xMap X axis map - \param yMap Y axis + \param yMap Y axis \param canvasRect Contents rect of the plot canvas */ -void QwtPlotGrid::draw(QPainter *painter, +void QwtPlotGrid::draw( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, - const QRect &canvasRect) const + const QRectF &canvasRect ) const { // draw minor gridlines - painter->setPen(QwtPainter::scaledPen(d_data->minPen)); - - if (d_data->xEnabled && d_data->xMinEnabled) + QPen minPen = d_data->minPen; + minPen.setCapStyle( Qt::FlatCap ); + + painter->setPen( minPen ); + + if ( d_data->xEnabled && d_data->xMinEnabled ) { - drawLines(painter, canvasRect, Qt::Vertical, xMap, - d_data->xScaleDiv.ticks(QwtScaleDiv::MinorTick)); - drawLines(painter, canvasRect, Qt::Vertical, xMap, - d_data->xScaleDiv.ticks(QwtScaleDiv::MediumTick)); + drawLines( painter, canvasRect, Qt::Vertical, xMap, + d_data->xScaleDiv.ticks( QwtScaleDiv::MinorTick ) ); + drawLines( painter, canvasRect, Qt::Vertical, xMap, + d_data->xScaleDiv.ticks( QwtScaleDiv::MediumTick ) ); } - if (d_data->yEnabled && d_data->yMinEnabled) + if ( d_data->yEnabled && d_data->yMinEnabled ) { - drawLines(painter, canvasRect, Qt::Horizontal, yMap, - d_data->yScaleDiv.ticks(QwtScaleDiv::MinorTick)); - drawLines(painter, canvasRect, Qt::Horizontal, yMap, - d_data->yScaleDiv.ticks(QwtScaleDiv::MediumTick)); + drawLines( painter, canvasRect, Qt::Horizontal, yMap, + d_data->yScaleDiv.ticks( QwtScaleDiv::MinorTick ) ); + drawLines( painter, canvasRect, Qt::Horizontal, yMap, + d_data->yScaleDiv.ticks( QwtScaleDiv::MediumTick ) ); } // draw major gridlines - painter->setPen(QwtPainter::scaledPen(d_data->majPen)); - - if (d_data->xEnabled) + QPen majPen = d_data->majPen; + majPen.setCapStyle( Qt::FlatCap ); + + painter->setPen( majPen ); + + if ( d_data->xEnabled ) { - drawLines(painter, canvasRect, Qt::Vertical, xMap, - d_data->xScaleDiv.ticks(QwtScaleDiv::MajorTick)); + drawLines( painter, canvasRect, Qt::Vertical, xMap, + d_data->xScaleDiv.ticks( QwtScaleDiv::MajorTick ) ); } - if (d_data->yEnabled) + if ( d_data->yEnabled ) { - drawLines(painter, canvasRect, Qt::Horizontal, yMap, - d_data->yScaleDiv.ticks(QwtScaleDiv::MajorTick)); + drawLines( painter, canvasRect, Qt::Horizontal, yMap, + d_data->yScaleDiv.ticks( QwtScaleDiv::MajorTick ) ); } } -void QwtPlotGrid::drawLines(QPainter *painter, const QRect &canvasRect, - Qt::Orientation orientation, const QwtScaleMap &scaleMap, - const QwtValueList &values) const +void QwtPlotGrid::drawLines( QPainter *painter, const QRectF &canvasRect, + Qt::Orientation orientation, const QwtScaleMap &scaleMap, + const QList &values ) const { - const int x1 = canvasRect.left(); - const int x2 = canvasRect.right(); - const int y1 = canvasRect.top(); - const int y2 = canvasRect.bottom(); + const double x1 = canvasRect.left(); + const double x2 = canvasRect.right() - 1.0; + const double y1 = canvasRect.top(); + const double y2 = canvasRect.bottom() - 1.0; - for (uint i = 0; i < (uint)values.count(); i++) + const bool doAlign = QwtPainter::roundingAlignment( painter ); + + for ( int i = 0; i < values.count(); i++ ) { - const int value = scaleMap.transform(values[i]); + double value = scaleMap.transform( values[i] ); + if ( doAlign ) + value = qRound( value ); + if ( orientation == Qt::Horizontal ) { - if ((value >= y1) && (value <= y2)) - QwtPainter::drawLine(painter, x1, value, x2, value); + if ( qwtFuzzyGreaterOrEqual( value, y1 ) && + qwtFuzzyLessOrEqual( value, y2 ) ) + { + QwtPainter::drawLine( painter, x1, value, x2, value ); + } } else { - if ((value >= x1) && (value <= x2)) - QwtPainter::drawLine(painter, value, y1, value, y2); + if ( qwtFuzzyGreaterOrEqual( value, x1 ) && + qwtFuzzyLessOrEqual( value, x2 ) ) + { + QwtPainter::drawLine( painter, value, y1, value, y2 ); + } } } } @@ -279,69 +288,69 @@ void QwtPlotGrid::drawLines(QPainter *painter, const QRect &canvasRect, \return the pen for the major gridlines \sa setMajPen(), setMinPen(), setPen() */ -const QPen &QwtPlotGrid::majPen() const -{ - return d_data->majPen; +const QPen &QwtPlotGrid::majPen() const +{ + return d_data->majPen; } /*! \return the pen for the minor gridlines \sa setMinPen(), setMajPen(), setPen() */ -const QPen &QwtPlotGrid::minPen() const -{ - return d_data->minPen; +const QPen &QwtPlotGrid::minPen() const +{ + return d_data->minPen; } - + /*! \return true if vertical gridlines are enabled \sa enableX() */ bool QwtPlotGrid::xEnabled() const -{ - return d_data->xEnabled; +{ + return d_data->xEnabled; } /*! \return true if minor vertical gridlines are enabled \sa enableXMin() */ -bool QwtPlotGrid::xMinEnabled() const -{ - return d_data->xMinEnabled; +bool QwtPlotGrid::xMinEnabled() const +{ + return d_data->xMinEnabled; } /*! \return true if horizontal gridlines are enabled \sa enableY() */ -bool QwtPlotGrid::yEnabled() const -{ - return d_data->yEnabled; +bool QwtPlotGrid::yEnabled() const +{ + return d_data->yEnabled; } /*! \return true if minor horizontal gridlines are enabled \sa enableYMin() */ -bool QwtPlotGrid::yMinEnabled() const +bool QwtPlotGrid::yMinEnabled() const { - return d_data->yMinEnabled; + return d_data->yMinEnabled; } - + /*! \return the scale division of the x axis */ -const QwtScaleDiv &QwtPlotGrid::xScaleDiv() const -{ - return d_data->xScaleDiv; +const QwtScaleDiv &QwtPlotGrid::xScaleDiv() const +{ + return d_data->xScaleDiv; } /*! \return the scale division of the y axis */ -const QwtScaleDiv &QwtPlotGrid::yScaleDiv() const -{ - return d_data->yScaleDiv; +const QwtScaleDiv &QwtPlotGrid::yScaleDiv() const +{ + return d_data->yScaleDiv; } - + /*! Update the grid to changes of the axes scale division @@ -350,9 +359,9 @@ const QwtScaleDiv &QwtPlotGrid::yScaleDiv() const \sa QwtPlot::updateAxes() */ -void QwtPlotGrid::updateScaleDiv(const QwtScaleDiv& xScaleDiv, - const QwtScaleDiv& yScaleDiv) +void QwtPlotGrid::updateScaleDiv( const QwtScaleDiv& xScaleDiv, + const QwtScaleDiv& yScaleDiv ) { - setXDiv(xScaleDiv); - setYDiv(yScaleDiv); + setXDiv( xScaleDiv ); + setYDiv( yScaleDiv ); } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_grid.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_grid.h index 4b9d2cdf9..969239809 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_grid.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_grid.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -39,43 +39,43 @@ public: virtual int rtti() const; - void enableX(bool tf); + void enableX( bool tf ); bool xEnabled() const; - void enableY(bool tf); + void enableY( bool tf ); bool yEnabled() const; - void enableXMin(bool tf); + void enableXMin( bool tf ); bool xMinEnabled() const; - void enableYMin(bool tf); + void enableYMin( bool tf ); bool yMinEnabled() const; - void setXDiv(const QwtScaleDiv &sx); + void setXDiv( const QwtScaleDiv &sx ); const QwtScaleDiv &xScaleDiv() const; - void setYDiv(const QwtScaleDiv &sy); + void setYDiv( const QwtScaleDiv &sy ); const QwtScaleDiv &yScaleDiv() const; - void setPen(const QPen &p); + void setPen( const QPen &p ); - void setMajPen(const QPen &p); + void setMajPen( const QPen &p ); const QPen& majPen() const; - void setMinPen(const QPen &p); + void setMinPen( const QPen &p ); const QPen& minPen() const; - virtual void draw(QPainter *p, + virtual void draw( QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, - const QRect &rect) const; + const QRectF &rect ) const; - virtual void updateScaleDiv(const QwtScaleDiv &xMap, - const QwtScaleDiv &yMap); + virtual void updateScaleDiv( + const QwtScaleDiv &xMap, const QwtScaleDiv &yMap ); private: - void drawLines(QPainter *painter, const QRect &, - Qt::Orientation orientation, const QwtScaleMap &, - const QwtValueList &) const; + void drawLines( QPainter *painter, const QRectF &, + Qt::Orientation orientation, const QwtScaleMap &, + const QList & ) const; class PrivateData; PrivateData *d_data; diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_histogram.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_histogram.cpp new file mode 100644 index 000000000..1bd972c8e --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_histogram.cpp @@ -0,0 +1,648 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#include "qwt_plot_histogram.h" +#include "qwt_plot.h" +#include "qwt_legend.h" +#include "qwt_legend_item.h" +#include "qwt_painter.h" +#include "qwt_column_symbol.h" +#include "qwt_scale_map.h" +#include +#include + +static inline bool isCombinable( const QwtInterval &d1, + const QwtInterval &d2 ) +{ + if ( d1.isValid() && d2.isValid() ) + { + if ( d1.maxValue() == d2.minValue() ) + { + if ( !( d1.borderFlags() & QwtInterval::ExcludeMaximum + && d2.borderFlags() & QwtInterval::ExcludeMinimum ) ) + { + return true; + } + } + } + + return false; +} + +class QwtPlotHistogram::PrivateData +{ +public: + PrivateData(): + baseline( 0.0 ), + style( Columns ), + symbol( NULL ) + { + } + + ~PrivateData() + { + delete symbol; + } + + double baseline; + + QPen pen; + QBrush brush; + QwtPlotHistogram::HistogramStyle style; + const QwtColumnSymbol *symbol; +}; + +/*! + Constructor + \param title Title of the histogram. +*/ + +QwtPlotHistogram::QwtPlotHistogram( const QwtText &title ): + QwtPlotSeriesItem( title ) +{ + init(); +} + +/*! + Constructor + \param title Title of the histogram. +*/ +QwtPlotHistogram::QwtPlotHistogram( const QString &title ): + QwtPlotSeriesItem( title ) +{ + init(); +} + +//! Destructor +QwtPlotHistogram::~QwtPlotHistogram() +{ + delete d_data; +} + +//! Initialize data members +void QwtPlotHistogram::init() +{ + d_data = new PrivateData(); + d_series = new QwtIntervalSeriesData(); + + setItemAttribute( QwtPlotItem::AutoScale, true ); + setItemAttribute( QwtPlotItem::Legend, true ); + + setZ( 20.0 ); +} + +/*! + Set the histogram's drawing style + + \param style Histogram style + \sa HistogramStyle, style() +*/ +void QwtPlotHistogram::setStyle( HistogramStyle style ) +{ + if ( style != d_data->style ) + { + d_data->style = style; + itemChanged(); + } +} + +/*! + Return the current style + \sa HistogramStyle, setStyle() +*/ +QwtPlotHistogram::HistogramStyle QwtPlotHistogram::style() const +{ + return d_data->style; +} + +/*! + Assign a pen, that is used in a style() depending way. + + \param pen New pen + \sa pen(), brush() +*/ +void QwtPlotHistogram::setPen( const QPen &pen ) +{ + if ( pen != d_data->pen ) + { + d_data->pen = pen; + itemChanged(); + } +} + +/*! + \return Pen used in a style() depending way. + \sa setPen(), brush() +*/ +const QPen &QwtPlotHistogram::pen() const +{ + return d_data->pen; +} + +/*! + Assign a brush, that is used in a style() depending way. + + \param brush New brush + \sa pen(), brush() +*/ +void QwtPlotHistogram::setBrush( const QBrush &brush ) +{ + if ( brush != d_data->brush ) + { + d_data->brush = brush; + itemChanged(); + } +} + +/*! + \return Brush used in a style() depending way. + \sa setPen(), brush() +*/ +const QBrush &QwtPlotHistogram::brush() const +{ + return d_data->brush; +} + +/*! + \brief Assign a symbol + + In Column style an optional symbol can be assigned, that is responsible + for displaying the rectangle that is defined by the interval and + the distance between baseline() and value. When no symbol has been + defined the area is displayed as plain rectangle using pen() and brush(). + + \sa style(), symbol(), drawColumn(), pen(), brush() + + \note In applications, where different intervals need to be displayed + in a different way ( f.e different colors or even using differnt symbols) + it is recommended to overload drawColumn(). +*/ +void QwtPlotHistogram::setSymbol( const QwtColumnSymbol *symbol ) +{ + if ( symbol != d_data->symbol ) + { + delete d_data->symbol; + d_data->symbol = symbol; + itemChanged(); + } +} + +/*! + \return Current symbol or NULL, when no symbol has been assigned + \sa setSymbol() +*/ +const QwtColumnSymbol *QwtPlotHistogram::symbol() const +{ + return d_data->symbol; +} + +/*! + \brief Set the value of the baseline + + Each column representing an QwtIntervalSample is defined by its + interval and the interval between baseline and the value of the sample. + + The default value of the baseline is 0.0. + + \param value Value of the baseline + \sa baseline() +*/ +void QwtPlotHistogram::setBaseline( double value ) +{ + if ( d_data->baseline != value ) + { + d_data->baseline = value; + itemChanged(); + } +} + +/*! + \return Value of the baseline + \sa setBaseline() +*/ +double QwtPlotHistogram::baseline() const +{ + return d_data->baseline; +} + +/*! + \return Bounding rectangle of all samples. + For an empty series the rectangle is invalid. +*/ +QRectF QwtPlotHistogram::boundingRect() const +{ + QRectF rect = d_series->boundingRect(); + if ( !rect.isValid() ) + return rect; + + if ( orientation() == Qt::Horizontal ) + { + rect = QRectF( rect.y(), rect.x(), + rect.height(), rect.width() ); + + if ( rect.left() > d_data->baseline ) + rect.setLeft( d_data->baseline ); + else if ( rect.right() < d_data->baseline ) + rect.setRight( d_data->baseline ); + } + else + { + if ( rect.bottom() < d_data->baseline ) + rect.setBottom( d_data->baseline ); + else if ( rect.top() > d_data->baseline ) + rect.setTop( d_data->baseline ); + } + + return rect; +} + +//! \return QwtPlotItem::Rtti_PlotHistogram +int QwtPlotHistogram::rtti() const +{ + return QwtPlotItem::Rtti_PlotHistogram; +} + +/*! + Initialize data with an array of samples. + \param samples Vector of points +*/ +void QwtPlotHistogram::setSamples( + const QVector &samples ) +{ + delete d_series; + d_series = new QwtIntervalSeriesData( samples ); + itemChanged(); +} + +/*! + Draw a subset of the histogram samples + + \param painter Painter + \param xMap Maps x-values into pixel coordinates. + \param yMap Maps y-values into pixel coordinates. + \param canvasRect Contents rect of the canvas + \param from Index of the first sample to be painted + \param to Index of the last sample to be painted. If to < 0 the + series will be painted to its last sample. + + \sa drawOutline(), drawLines(), drawColumns +*/ +void QwtPlotHistogram::drawSeries( QPainter *painter, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &, int from, int to ) const +{ + if ( !painter || dataSize() <= 0 ) + return; + + if ( to < 0 ) + to = dataSize() - 1; + + switch ( d_data->style ) + { + case Outline: + drawOutline( painter, xMap, yMap, from, to ); + break; + case Lines: + drawLines( painter, xMap, yMap, from, to ); + break; + case Columns: + drawColumns( painter, xMap, yMap, from, to ); + break; + default: + break; + } +} + +/*! + Draw a histogram in Outline style() + + \param painter Painter + \param xMap Maps x-values into pixel coordinates. + \param yMap Maps y-values into pixel coordinates. + \param from Index of the first sample to be painted + \param to Index of the last sample to be painted. If to < 0 the + histogram will be painted to its last point. + + \sa setStyle(), style() + \warning The outline style requires, that the intervals are in increasing + order and not overlapping. +*/ +void QwtPlotHistogram::drawOutline( QPainter *painter, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + int from, int to ) const +{ + const bool doAlign = QwtPainter::roundingAlignment( painter ); + + double v0 = ( orientation() == Qt::Horizontal ) ? + xMap.transform( baseline() ) : yMap.transform( baseline() ); + if ( doAlign ) + v0 = qRound( v0 ); + + QwtIntervalSample previous; + + QPolygonF polygon; + for ( int i = from; i <= to; i++ ) + { + const QwtIntervalSample sample = d_series->sample( i ); + + if ( !sample.interval.isValid() ) + { + flushPolygon( painter, v0, polygon ); + previous = sample; + continue; + } + + if ( previous.interval.isValid() ) + { + if ( !isCombinable( previous.interval, sample.interval ) ) + flushPolygon( painter, v0, polygon ); + } + + if ( orientation() == Qt::Vertical ) + { + double x1 = xMap.transform( sample.interval.minValue() ); + double x2 = xMap.transform( sample.interval.maxValue() ); + double y = yMap.transform( sample.value ); + if ( doAlign ) + { + x1 = qRound( x1 ); + x2 = qRound( x2 ); + y = qRound( y ); + } + + if ( polygon.size() == 0 ) + polygon += QPointF( x1, v0 ); + + polygon += QPointF( x1, y ); + polygon += QPointF( x2, y ); + } + else + { + double y1 = yMap.transform( sample.interval.minValue() ); + double y2 = yMap.transform( sample.interval.maxValue() ); + double x = xMap.transform( sample.value ); + if ( doAlign ) + { + y1 = qRound( y1 ); + y2 = qRound( y2 ); + x = qRound( x ); + } + + if ( polygon.size() == 0 ) + polygon += QPointF( v0, y1 ); + + polygon += QPointF( x, y1 ); + polygon += QPointF( x, y2 ); + } + previous = sample; + } + + flushPolygon( painter, v0, polygon ); +} + +/*! + Draw a histogram in Columns style() + + \param painter Painter + \param xMap Maps x-values into pixel coordinates. + \param yMap Maps y-values into pixel coordinates. + \param from Index of the first sample to be painted + \param to Index of the last sample to be painted. If to < 0 the + histogram will be painted to its last point. + + \sa setStyle(), style(), setSymbol(), drawColumn() +*/ +void QwtPlotHistogram::drawColumns( QPainter *painter, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + int from, int to ) const +{ + painter->setPen( d_data->pen ); + painter->setBrush( d_data->brush ); + + for ( int i = from; i <= to; i++ ) + { + const QwtIntervalSample sample = d_series->sample( i ); + if ( !sample.interval.isNull() ) + { + const QwtColumnRect rect = columnRect( sample, xMap, yMap ); + drawColumn( painter, rect, sample ); + } + } +} + +/*! + Draw a histogram in Lines style() + + \param painter Painter + \param xMap Maps x-values into pixel coordinates. + \param yMap Maps y-values into pixel coordinates. + \param from Index of the first sample to be painted + \param to Index of the last sample to be painted. If to < 0 the + histogram will be painted to its last point. + + \sa setStyle(), style(), setPen() +*/ +void QwtPlotHistogram::drawLines( QPainter *painter, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + int from, int to ) const +{ + const bool doAlign = QwtPainter::roundingAlignment( painter ); + + painter->setPen( d_data->pen ); + painter->setBrush( Qt::NoBrush ); + + for ( int i = from; i <= to; i++ ) + { + const QwtIntervalSample sample = d_series->sample( i ); + if ( !sample.interval.isNull() ) + { + const QwtColumnRect rect = columnRect( sample, xMap, yMap ); + + QRectF r = rect.toRect(); + if ( doAlign ) + { + r.setLeft( qRound( r.left() ) ); + r.setRight( qRound( r.right() ) ); + r.setTop( qRound( r.top() ) ); + r.setBottom( qRound( r.bottom() ) ); + } + + switch ( rect.direction ) + { + case QwtColumnRect::LeftToRight: + { + QwtPainter::drawLine( painter, + r.topRight(), r.bottomRight() ); + break; + } + case QwtColumnRect::RightToLeft: + { + QwtPainter::drawLine( painter, + r.topLeft(), r.bottomLeft() ); + break; + } + case QwtColumnRect::TopToBottom: + { + QwtPainter::drawLine( painter, + r.bottomRight(), r.bottomLeft() ); + break; + } + case QwtColumnRect::BottomToTop: + { + QwtPainter::drawLine( painter, + r.topRight(), r.topLeft() ); + break; + } + } + } + } +} + +//! Internal, used by the Outline style. +void QwtPlotHistogram::flushPolygon( QPainter *painter, + double baseLine, QPolygonF &polygon ) const +{ + if ( polygon.size() == 0 ) + return; + + if ( orientation() == Qt::Horizontal ) + polygon += QPointF( baseLine, polygon.last().y() ); + else + polygon += QPointF( polygon.last().x(), baseLine ); + + if ( d_data->brush.style() != Qt::NoBrush ) + { + painter->setPen( Qt::NoPen ); + painter->setBrush( d_data->brush ); + + if ( orientation() == Qt::Horizontal ) + { + polygon += QPointF( polygon.last().x(), baseLine ); + polygon += QPointF( polygon.first().x(), baseLine ); + } + else + { + polygon += QPointF( baseLine, polygon.last().y() ); + polygon += QPointF( baseLine, polygon.first().y() ); + } + QwtPainter::drawPolygon( painter, polygon ); + polygon.resize( polygon.size() - 2 ); + } + if ( d_data->pen.style() != Qt::NoPen ) + { + painter->setBrush( Qt::NoBrush ); + painter->setPen( d_data->pen ); + QwtPainter::drawPolyline( painter, polygon ); + } + polygon.clear(); +} + +/*! + Calculate the area that is covered by a sample + + \param sample Sample + \param xMap Maps x-values into pixel coordinates. + \param yMap Maps y-values into pixel coordinates. + + \return Rectangle, that is covered by a sample +*/ +QwtColumnRect QwtPlotHistogram::columnRect( const QwtIntervalSample &sample, + const QwtScaleMap &xMap, const QwtScaleMap &yMap ) const +{ + QwtColumnRect rect; + + const QwtInterval &iv = sample.interval; + if ( !iv.isValid() ) + return rect; + + if ( orientation() == Qt::Horizontal ) + { + const double x0 = xMap.transform( baseline() ); + const double x = xMap.transform( sample.value ); + const double y1 = yMap.transform( iv.minValue() ); + const double y2 = yMap.transform( iv.maxValue() ); + + rect.hInterval.setInterval( x0, x ); + rect.vInterval.setInterval( y1, y2, iv.borderFlags() ); + rect.direction = ( x < x0 ) ? QwtColumnRect::RightToLeft : + QwtColumnRect::LeftToRight; + } + else + { + const double x1 = xMap.transform( iv.minValue() ); + const double x2 = xMap.transform( iv.maxValue() ); + const double y0 = yMap.transform( baseline() ); + const double y = yMap.transform( sample.value ); + + rect.hInterval.setInterval( x1, x2, iv.borderFlags() ); + rect.vInterval.setInterval( y0, y ); + rect.direction = ( y < y0 ) ? QwtColumnRect::BottomToTop : + QwtColumnRect::TopToBottom; + } + + return rect; +} + +/*! + Draw a column for a sample in Columns style(). + + When a symbol() has been set the symbol is used otherwise the + column is displayed as plain rectangle using pen() and brush(). + + \param painter Painter + \param rect Rectangle where to paint the column in paint device coordinates + \param sample Sample to be displayed + + \note In applications, where different intervals need to be displayed + in a different way ( f.e different colors or even using differnt symbols) + it is recommended to overload drawColumn(). +*/ +void QwtPlotHistogram::drawColumn( QPainter *painter, + const QwtColumnRect &rect, const QwtIntervalSample &sample ) const +{ + Q_UNUSED( sample ); + + if ( d_data->symbol && + ( d_data->symbol->style() != QwtColumnSymbol::NoStyle ) ) + { + d_data->symbol->draw( painter, rect ); + } + else + { + QRectF r = rect.toRect(); + if ( QwtPainter::roundingAlignment( painter ) ) + { + r.setLeft( qRound( r.left() ) ); + r.setRight( qRound( r.right() ) ); + r.setTop( qRound( r.top() ) ); + r.setBottom( qRound( r.bottom() ) ); + } + + QwtPainter::drawRect( painter, r ); + } +} + +/*! + Draw a plain rectangle without pen using the brush() as identifier + + \param painter Painter + \param rect Bounding rectangle for the identifier +*/ +void QwtPlotHistogram::drawLegendIdentifier( + QPainter *painter, const QRectF &rect ) const +{ + const double dim = qMin( rect.width(), rect.height() ); + + QSizeF size( dim, dim ); + + QRectF r( 0, 0, size.width(), size.height() ); + r.moveCenter( rect.center() ); + + painter->fillRect( r, d_data->brush ); +} diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_histogram.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_histogram.h new file mode 100644 index 000000000..3f88042c0 --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_histogram.h @@ -0,0 +1,134 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#ifndef QWT_PLOT_HISTOGRAM_H +#define QWT_PLOT_HISTOGRAM_H + +#include "qwt_global.h" +#include "qwt_plot_seriesitem.h" +#include "qwt_column_symbol.h" +#include +#include + +class QwtIntervalData; +class QString; +class QPolygonF; + +/*! + \brief QwtPlotHistogram represents a series of samples, where an interval + is associated with a value ( \f$y = f([x1,x2])\f$ ). + + The representation depends on the style() and an optional symbol() + that is displayed for each interval. + + \note The term "histogram" is used in a different way in the areas of + digital image processing and statistics. Wikipedia introduces the + terms "image histogram" and "color histogram" to avoid confusions. + While "image histograms" can be displayed by a QwtPlotCurve there + is no applicable plot item for a "color histogram" yet. +*/ + +class QWT_EXPORT QwtPlotHistogram: public QwtPlotSeriesItem +{ +public: + /*! + Histogram styles. + The default style is QwtPlotHistogram::Columns. + + \sa setStyle(), style(), setSymbol(), symbol(), setBaseline() + */ + enum HistogramStyle + { + /*! + Draw an outline around the area, that is build by all intervals + using the pen() and fill it with the brush(). The outline style + requires, that the intervals are in increasing order and + not overlapping. + */ + Outline, + + /*! + Draw a column for each interval. When a symbol() has been set + the symbol is used otherwise the column is displayed as + plain rectangle using pen() and brush(). + */ + Columns, + + /*! + Draw a simple line using the pen() for each interval. + */ + Lines, + + /*! + Styles >= UserStyle are reserved for derived + classes that overload drawSeries() with + additional application specific ways to display a histogram. + */ + UserStyle = 100 + }; + + explicit QwtPlotHistogram( const QString &title = QString::null ); + explicit QwtPlotHistogram( const QwtText &title ); + virtual ~QwtPlotHistogram(); + + virtual int rtti() const; + + void setPen( const QPen & ); + const QPen &pen() const; + + void setBrush( const QBrush & ); + const QBrush &brush() const; + + void setSamples( const QVector & ); + + void setBaseline( double reference ); + double baseline() const; + + void setStyle( HistogramStyle style ); + HistogramStyle style() const; + + void setSymbol( const QwtColumnSymbol * ); + const QwtColumnSymbol *symbol() const; + + virtual void drawSeries( QPainter *p, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const; + + virtual QRectF boundingRect() const; + + virtual void drawLegendIdentifier( QPainter *, const QRectF & ) const; + +protected: + virtual QwtColumnRect columnRect( const QwtIntervalSample &, + const QwtScaleMap &, const QwtScaleMap & ) const; + + virtual void drawColumn( QPainter *, const QwtColumnRect &, + const QwtIntervalSample & ) const; + + void drawColumns( QPainter *, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + int from, int to ) const; + + void drawOutline( QPainter *, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + int from, int to ) const; + + void drawLines( QPainter *, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + int from, int to ) const; + +private: + void init(); + void flushPolygon( QPainter *, double baseLine, QPolygonF & ) const; + + class PrivateData; + PrivateData *d_data; +}; + +#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_intervalcurve.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_intervalcurve.cpp new file mode 100644 index 000000000..5fe3b5437 --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_intervalcurve.cpp @@ -0,0 +1,547 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#include "qwt_plot_intervalcurve.h" +#include "qwt_interval_symbol.h" +#include "qwt_scale_map.h" +#include "qwt_clipper.h" +#include "qwt_painter.h" + +#include + +static inline bool qwtIsHSampleInside( const QwtIntervalSample &sample, + double xMin, double xMax, double yMin, double yMax ) +{ + const double y = sample.value; + const double x1 = sample.interval.minValue(); + const double x2 = sample.interval.maxValue(); + + const bool isOffScreen = ( y < yMin ) || ( y > yMax ) + || ( x1 < xMin && x2 < xMin ) || ( x1 > yMax && x2 > xMax ); + + return !isOffScreen; +} + +static inline bool qwtIsVSampleInside( const QwtIntervalSample &sample, + double xMin, double xMax, double yMin, double yMax ) +{ + const double x = sample.value; + const double y1 = sample.interval.minValue(); + const double y2 = sample.interval.maxValue(); + + const bool isOffScreen = ( x < xMin ) || ( x > xMax ) + || ( y1 < yMin && y2 < yMin ) || ( y1 > yMax && y2 > yMax ); + + return !isOffScreen; +} + +class QwtPlotIntervalCurve::PrivateData +{ +public: + PrivateData(): + style( Tube ), + symbol( NULL ), + pen( Qt::black ), + brush( Qt::white ) + { + paintAttributes = QwtPlotIntervalCurve::ClipPolygons; + paintAttributes |= QwtPlotIntervalCurve::ClipSymbol; + + pen.setCapStyle( Qt::FlatCap ); + } + + ~PrivateData() + { + delete symbol; + } + + CurveStyle style; + const QwtIntervalSymbol *symbol; + + QPen pen; + QBrush brush; + + QwtPlotIntervalCurve::PaintAttributes paintAttributes; +}; + +/*! + Constructor + \param title Title of the curve +*/ +QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QwtText &title ): + QwtPlotSeriesItem( title ) +{ + init(); +} + +/*! + Constructor + \param title Title of the curve +*/ +QwtPlotIntervalCurve::QwtPlotIntervalCurve( const QString &title ): + QwtPlotSeriesItem( QwtText( title ) ) +{ + init(); +} + +//! Destructor +QwtPlotIntervalCurve::~QwtPlotIntervalCurve() +{ + delete d_data; +} + +//! Initialize internal members +void QwtPlotIntervalCurve::init() +{ + setItemAttribute( QwtPlotItem::Legend, true ); + setItemAttribute( QwtPlotItem::AutoScale, true ); + + d_data = new PrivateData; + d_series = new QwtIntervalSeriesData(); + + setZ( 19.0 ); +} + +//! \return QwtPlotItem::Rtti_PlotIntervalCurve +int QwtPlotIntervalCurve::rtti() const +{ + return QwtPlotIntervalCurve::Rtti_PlotIntervalCurve; +} + +/*! + Specify an attribute how to draw the curve + + \param attribute Paint attribute + \param on On/Off + \sa testPaintAttribute() +*/ +void QwtPlotIntervalCurve::setPaintAttribute( + PaintAttribute attribute, bool on ) +{ + if ( on ) + d_data->paintAttributes |= attribute; + else + d_data->paintAttributes &= ~attribute; +} + +/*! + \brief Return the current paint attributes + \sa PaintAttribute, setPaintAttribute() +*/ +bool QwtPlotIntervalCurve::testPaintAttribute( + PaintAttribute attribute ) const +{ + return ( d_data->paintAttributes & attribute ); +} + +/*! + Initialize data with an array of samples. + \param samples Vector of samples +*/ +void QwtPlotIntervalCurve::setSamples( + const QVector &samples ) +{ + delete d_series; + d_series = new QwtIntervalSeriesData( samples ); + itemChanged(); +} + +/*! + Set the curve's drawing style + + \param style Curve style + \sa CurveStyle, style() +*/ +void QwtPlotIntervalCurve::setStyle( CurveStyle style ) +{ + if ( style != d_data->style ) + { + d_data->style = style; + itemChanged(); + } +} + +/*! + \brief Return the current style + \sa setStyle() +*/ +QwtPlotIntervalCurve::CurveStyle QwtPlotIntervalCurve::style() const +{ + return d_data->style; +} + +/*! + Assign a symbol. + + \param symbol Symbol + \sa symbol() +*/ +void QwtPlotIntervalCurve::setSymbol( const QwtIntervalSymbol *symbol ) +{ + if ( symbol != d_data->symbol ) + { + delete d_data->symbol; + d_data->symbol = symbol; + itemChanged(); + } +} + +/*! + \return Current symbol or NULL, when no symbol has been assigned + \sa setSymbol() +*/ +const QwtIntervalSymbol *QwtPlotIntervalCurve::symbol() const +{ + return d_data->symbol; +} + +/*! + \brief Assign a pen + \param pen New pen + \sa pen(), brush() +*/ +void QwtPlotIntervalCurve::setPen( const QPen &pen ) +{ + if ( pen != d_data->pen ) + { + d_data->pen = pen; + itemChanged(); + } +} + +/*! + \brief Return the pen used to draw the lines + \sa setPen(), brush() +*/ +const QPen& QwtPlotIntervalCurve::pen() const +{ + return d_data->pen; +} + +/*! + Assign a brush. + + The brush is used to fill the area in Tube style(). + + \param brush Brush + \sa brush(), pen(), setStyle(), CurveStyle +*/ +void QwtPlotIntervalCurve::setBrush( const QBrush &brush ) +{ + if ( brush != d_data->brush ) + { + d_data->brush = brush; + itemChanged(); + } +} + +/*! + \return Brush used to fill the area in Tube style() + \sa setBrush(), setStyle(), CurveStyle +*/ +const QBrush& QwtPlotIntervalCurve::brush() const +{ + return d_data->brush; +} + +/*! + \return Bounding rectangle of all samples. + For an empty series the rectangle is invalid. +*/ +QRectF QwtPlotIntervalCurve::boundingRect() const +{ + QRectF rect = QwtPlotSeriesItem::boundingRect(); + if ( rect.isValid() && orientation() == Qt::Vertical ) + rect.setRect( rect.y(), rect.x(), rect.height(), rect.width() ); + + return rect; +} + +/*! + Draw a subset of the samples + + \param painter Painter + \param xMap Maps x-values into pixel coordinates. + \param yMap Maps y-values into pixel coordinates. + \param canvasRect Contents rect of the canvas + \param from Index of the first sample to be painted + \param to Index of the last sample to be painted. If to < 0 the + series will be painted to its last sample. + + \sa drawTube(), drawSymbols() +*/ +void QwtPlotIntervalCurve::drawSeries( QPainter *painter, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const +{ + if ( to < 0 ) + to = dataSize() - 1; + + if ( from < 0 ) + from = 0; + + if ( from > to ) + return; + + switch ( d_data->style ) + { + case Tube: + drawTube( painter, xMap, yMap, canvasRect, from, to ); + break; + + case NoCurve: + default: + break; + } + + if ( d_data->symbol && + ( d_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) ) + { + drawSymbols( painter, *d_data->symbol, + xMap, yMap, canvasRect, from, to ); + } +} + +/*! + Draw a tube + + Builds 2 curves from the upper and lower limits of the intervals + and draws them with the pen(). The area between the curves is + filled with the brush(). + + \param painter Painter + \param xMap Maps x-values into pixel coordinates. + \param yMap Maps y-values into pixel coordinates. + \param canvasRect Contents rect of the canvas + \param from Index of the first sample to be painted + \param to Index of the last sample to be painted. If to < 0 the + series will be painted to its last sample. + + \sa drawSeries(), drawSymbols() +*/ +void QwtPlotIntervalCurve::drawTube( QPainter *painter, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const +{ + const bool doAlign = QwtPainter::roundingAlignment( painter ); + + painter->save(); + + const size_t size = to - from + 1; + QPolygonF polygon( 2 * size ); + QPointF *points = polygon.data(); + + for ( uint i = 0; i < size; i++ ) + { + QPointF &minValue = points[i]; + QPointF &maxValue = points[2 * size - 1 - i]; + + const QwtIntervalSample intervalSample = sample( from + i ); + if ( orientation() == Qt::Vertical ) + { + double x = xMap.transform( intervalSample.value ); + double y1 = yMap.transform( intervalSample.interval.minValue() ); + double y2 = yMap.transform( intervalSample.interval.maxValue() ); + if ( doAlign ) + { + x = qRound( x ); + y1 = qRound( y1 ); + y2 = qRound( y2 ); + } + + minValue.rx() = x; + minValue.ry() = y1; + maxValue.rx() = x; + maxValue.ry() = y2; + } + else + { + double y = yMap.transform( intervalSample.value ); + double x1 = xMap.transform( intervalSample.interval.minValue() ); + double x2 = xMap.transform( intervalSample.interval.maxValue() ); + if ( doAlign ) + { + y = qRound( y ); + x1 = qRound( x1 ); + x2 = qRound( x2 ); + } + + minValue.rx() = x1; + minValue.ry() = y; + maxValue.rx() = x2; + maxValue.ry() = y; + } + } + + if ( d_data->brush.style() != Qt::NoBrush ) + { + painter->setPen( QPen( Qt::NoPen ) ); + painter->setBrush( d_data->brush ); + + if ( d_data->paintAttributes & ClipPolygons ) + { + const qreal m = 1.0; + const QPolygonF p = QwtClipper::clipPolygonF( + canvasRect.adjusted(-m, -m, m, m), polygon, true ); + + QwtPainter::drawPolygon( painter, p ); + } + else + { + QwtPainter::drawPolygon( painter, polygon ); + } + } + + if ( d_data->pen.style() != Qt::NoPen ) + { + painter->setPen( d_data->pen ); + painter->setBrush( Qt::NoBrush ); + + if ( d_data->paintAttributes & ClipPolygons ) + { + qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF()); + const QRectF clipRect = canvasRect.adjusted(-pw, -pw, pw, pw); + + QPolygonF p; + + p.resize( size ); + qMemCopy( p.data(), points, size * sizeof( QPointF ) ); + p = QwtClipper::clipPolygonF( canvasRect, p ); + QwtPainter::drawPolyline( painter, p ); + + p.resize( size ); + qMemCopy( p.data(), points + size, size * sizeof( QPointF ) ); + p = QwtClipper::clipPolygonF( canvasRect, p ); + QwtPainter::drawPolyline( painter, p ); + } + else + { + QwtPainter::drawPolyline( painter, points, size ); + QwtPainter::drawPolyline( painter, points + size, size ); + } + } + + painter->restore(); +} + +/*! + Draw symbols for a subset of the samples + + \param painter Painter + \param symbol Interval symbol + \param xMap x map + \param yMap y map + \param canvasRect Contents rect of the canvas + \param from Index of the first sample to be painted + \param to Index of the last sample to be painted + + \sa setSymbol(), drawSeries(), drawTube() +*/ +void QwtPlotIntervalCurve::drawSymbols( + QPainter *painter, const QwtIntervalSymbol &symbol, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const +{ + painter->save(); + + QPen pen = symbol.pen(); + pen.setCapStyle( Qt::FlatCap ); + + painter->setPen( pen ); + painter->setBrush( symbol.brush() ); + + const QRectF &tr = QwtScaleMap::invTransform( xMap, yMap, canvasRect); + + const double xMin = tr.left(); + const double xMax = tr.right(); + const double yMin = tr.top(); + const double yMax = tr.bottom(); + + const bool doClip = d_data->paintAttributes & ClipPolygons; + + for ( int i = from; i <= to; i++ ) + { + const QwtIntervalSample s = sample( i ); + + if ( orientation() == Qt::Vertical ) + { + if ( !doClip || qwtIsVSampleInside( s, xMin, xMax, yMin, yMax ) ) + { + const double x = xMap.transform( s.value ); + const double y1 = yMap.transform( s.interval.minValue() ); + const double y2 = yMap.transform( s.interval.maxValue() ); + + symbol.draw( painter, orientation(), + QPointF( x, y1 ), QPointF( x, y2 ) ); + } + } + else + { + if ( !doClip || qwtIsHSampleInside( s, xMin, xMax, yMin, yMax ) ) + { + const double y = yMap.transform( s.value ); + const double x1 = xMap.transform( s.interval.minValue() ); + const double x2 = xMap.transform( s.interval.maxValue() ); + + symbol.draw( painter, orientation(), + QPointF( x1, y ), QPointF( x2, y ) ); + } + } + } + + painter->restore(); +} + +/*! + In case of Tibe stale() a plain rectangle is painted without a pen filled + the brush(). If a symbol is assigned it is painted cebtered into rect. + + \param painter Painter + \param rect Bounding rectangle for the identifier +*/ + +void QwtPlotIntervalCurve::drawLegendIdentifier( + QPainter *painter, const QRectF &rect ) const +{ + const double dim = qMin( rect.width(), rect.height() ); + + QSizeF size( dim, dim ); + + QRectF r( 0, 0, size.width(), size.height() ); + r.moveCenter( rect.center() ); + + if ( d_data->style == Tube ) + { + painter->fillRect( r, d_data->brush ); + } + + if ( d_data->symbol && + ( d_data->symbol->style() != QwtIntervalSymbol::NoSymbol ) ) + { + QPen pen = d_data->symbol->pen(); + pen.setWidthF( pen.widthF() ); + pen.setCapStyle( Qt::FlatCap ); + + painter->setPen( pen ); + painter->setBrush( d_data->symbol->brush() ); + + if ( orientation() == Qt::Vertical ) + { + d_data->symbol->draw( painter, orientation(), + QPointF( r.center().x(), r.top() ), + QPointF( r.center().x(), r.bottom() - 1 ) ); + } + else + { + d_data->symbol->draw( painter, orientation(), + QPointF( r.left(), r.center().y() ), + QPointF( r.right() - 1, r.center().y() ) ); + } + } +} diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_intervalcurve.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_intervalcurve.h new file mode 100644 index 000000000..b63f44ea4 --- /dev/null +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_intervalcurve.h @@ -0,0 +1,130 @@ +/* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** + * Qwt Widget Library + * Copyright (C) 1997 Josef Wilgen + * Copyright (C) 2002 Uwe Rathmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the Qwt License, Version 1.0 + *****************************************************************************/ + +#ifndef QWT_PLOT_INTERVAL_CURVE_H +#define QWT_PLOT_INTERVAL_CURVE_H + +#include "qwt_global.h" +#include "qwt_plot_seriesitem.h" +#include "qwt_series_data.h" + +class QwtIntervalSymbol; + +/*! + \brief QwtPlotIntervalCurve represents a series of samples, where each value + is associated with an interval ( \f$[y1,y2] = f(x)\f$ ). + + The representation depends on the style() and an optional symbol() + that is displayed for each interval. QwtPlotIntervalCurve might be used + to disply error bars or the area between 2 curves. +*/ + +class QWT_EXPORT QwtPlotIntervalCurve: public QwtPlotSeriesItem +{ +public: + /*! + \brief Curve styles. + The default setting is QwtPlotIntervalCurve::Tube. + + \sa setStyle(), style() + */ + + enum CurveStyle + { + /*! + Don't draw a curve. Note: This doesn't affect the symbols. + */ + NoCurve, + + /*! + Build 2 curves from the upper and lower limits of the intervals + and draw them with the pen(). The area between the curves is + filled with the brush(). + */ + Tube, + + /*! + Styles >= QwtPlotIntervalCurve::UserCurve are reserved for derived + classes that overload drawSeries() with + additional application specific curve types. + */ + UserCurve = 100 + }; + + /*! + Attributes to modify the drawing algorithm. + \sa setPaintAttribute(), testPaintAttribute() + */ + enum PaintAttribute + { + /*! + Clip polygons before painting them. In situations, where points + are far outside the visible area (f.e when zooming deep) this + might be a substantial improvement for the painting performance. + */ + ClipPolygons = 0x01, + + //! Check if a symbol is on the plot canvas before painting it. + ClipSymbol = 0x02 + }; + + //! Paint attributes + typedef QFlags PaintAttributes; + + explicit QwtPlotIntervalCurve( const QString &title = QString::null ); + explicit QwtPlotIntervalCurve( const QwtText &title ); + + virtual ~QwtPlotIntervalCurve(); + + virtual int rtti() const; + + void setPaintAttribute( PaintAttribute, bool on = true ); + bool testPaintAttribute( PaintAttribute ) const; + + void setSamples( const QVector & ); + + void setPen( const QPen & ); + const QPen &pen() const; + + void setBrush( const QBrush & ); + const QBrush &brush() const; + + void setStyle( CurveStyle style ); + CurveStyle style() const; + + void setSymbol( const QwtIntervalSymbol * ); + const QwtIntervalSymbol *symbol() const; + + virtual void drawSeries( QPainter *p, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const; + + virtual QRectF boundingRect() const; + virtual void drawLegendIdentifier( QPainter *, const QRectF & ) const; + +protected: + + void init(); + + virtual void drawTube( QPainter *, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const; + + virtual void drawSymbols( QPainter *, const QwtIntervalSymbol &, + const QwtScaleMap &xMap, const QwtScaleMap &yMap, + const QRectF &canvasRect, int from, int to ) const; + +private: + class PrivateData; + PrivateData *d_data; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotIntervalCurve::PaintAttributes ) + +#endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_item.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_item.cpp index 091df45e0..cbbfb99af 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_item.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_item.cpp @@ -2,40 +2,38 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ +#include "qwt_plot_item.h" #include "qwt_text.h" #include "qwt_plot.h" #include "qwt_legend.h" #include "qwt_legend_item.h" -#include "qwt_plot_item.h" +#include "qwt_scale_div.h" +#include class QwtPlotItem::PrivateData { public: PrivateData(): - plot(NULL), - isVisible(true), - attributes(0), -#if QT_VERSION >= 0x040000 - renderHints(0), -#endif - z(0.0), - xAxis(QwtPlot::xBottom), - yAxis(QwtPlot::yLeft) + plot( NULL ), + isVisible( true ), + attributes( 0 ), + renderHints( 0 ), + z( 0.0 ), + xAxis( QwtPlot::xBottom ), + yAxis( QwtPlot::yLeft ) { } mutable QwtPlot *plot; bool isVisible; - int attributes; -#if QT_VERSION >= 0x040000 - int renderHints; -#endif + QwtPlotItem::ItemAttributes attributes; + QwtPlotItem::RenderHints renderHints; double z; int xAxis; @@ -44,11 +42,11 @@ public: QwtText title; }; -/*! +/*! Constructor \param title Title of the item */ -QwtPlotItem::QwtPlotItem(const QwtText &title) +QwtPlotItem::QwtPlotItem( const QwtText &title ) { d_data = new PrivateData; d_data->title = title; @@ -57,11 +55,11 @@ QwtPlotItem::QwtPlotItem(const QwtText &title) //! Destroy the QwtPlotItem QwtPlotItem::~QwtPlotItem() { - attach(NULL); + attach( NULL ); delete d_data; } -/*! +/*! \brief Attach the item to a plot. This method will attach a QwtPlotItem to the QwtPlot argument. It will first @@ -70,9 +68,9 @@ QwtPlotItem::~QwtPlotItem() was attached to. \param plot Plot widget - \sa QwtPlotItem::detach() + \sa detach() */ -void QwtPlotItem::attach(QwtPlot *plot) +void QwtPlotItem::attach( QwtPlot *plot ) { if ( plot == d_data->plot ) return; @@ -82,13 +80,9 @@ void QwtPlotItem::attach(QwtPlot *plot) if ( d_data->plot ) { if ( d_data->plot->legend() ) - { - QWidget *legendItem = d_data->plot->legend()->find(this); - if ( legendItem ) - delete legendItem; - } + d_data->plot->legend()->remove( this ); - d_data->plot->attachItem(this, false); + d_data->plot->attachItem( this, false ); if ( d_data->plot->autoReplot() ) d_data->plot->update(); @@ -100,20 +94,32 @@ void QwtPlotItem::attach(QwtPlot *plot) { // insert the item into the current plot - d_data->plot->attachItem(this, true); + d_data->plot->attachItem( this, true ); itemChanged(); } } -/*! +/*! + \brief This method detaches a QwtPlotItem from any + QwtPlot it has been associated with. + + detach() is equivalent to calling attach( NULL ) + \sa attach() +*/ +void QwtPlotItem::detach() +{ + attach( NULL ); +} + +/*! Return rtti for the specific class represented. QwtPlotItem is simply a virtual interface class, and base classes will implement this method with specific rtti values so a user can differentiate them. - The rtti value is useful for environments, where the + The rtti value is useful for environments, where the runtime type information is disabled and it is not possible to do a dynamic_cast<...>. - + \return rtti value \sa RttiValues */ @@ -123,9 +129,9 @@ int QwtPlotItem::rtti() const } //! Return attached plot -QwtPlot *QwtPlotItem::plot() const -{ - return d_data->plot; +QwtPlot *QwtPlotItem::plot() const +{ + return d_data->plot; } /*! @@ -133,9 +139,9 @@ QwtPlot *QwtPlotItem::plot() const \return setZ(), QwtPlotDict::itemList() */ -double QwtPlotItem::z() const -{ - return d_data->z; +double QwtPlotItem::z() const +{ + return d_data->z; } /*! @@ -146,43 +152,44 @@ double QwtPlotItem::z() const \param z Z-value \sa z(), QwtPlotDict::itemList() */ -void QwtPlotItem::setZ(double z) -{ +void QwtPlotItem::setZ( double z ) +{ if ( d_data->z != z ) { - d_data->z = z; + if ( d_data->plot ) // update the z order + d_data->plot->attachItem( this, false ); + + d_data->z = z; + if ( d_data->plot ) - { - // update the z order - d_data->plot->attachItem(this, false); - d_data->plot->attachItem(this, true); - } + d_data->plot->attachItem( this, true ); + itemChanged(); } } -/*! +/*! Set a new title \param title Title - \sa title() -*/ -void QwtPlotItem::setTitle(const QString &title) + \sa title() +*/ +void QwtPlotItem::setTitle( const QString &title ) { - setTitle(QwtText(title)); + setTitle( QwtText( title ) ); } -/*! +/*! Set a new title \param title Title - \sa title() -*/ -void QwtPlotItem::setTitle(const QwtText &title) + \sa title() +*/ +void QwtPlotItem::setTitle( const QwtText &title ) { if ( d_data->title != title ) { - d_data->title = title; + d_data->title = title; itemChanged(); } } @@ -198,15 +205,15 @@ const QwtText &QwtPlotItem::title() const /*! Toggle an item attribute - + \param attribute Attribute type \param on true/false \sa testItemAttribute(), ItemAttribute */ -void QwtPlotItem::setItemAttribute(ItemAttribute attribute, bool on) +void QwtPlotItem::setItemAttribute( ItemAttribute attribute, bool on ) { - if ( bool(d_data->attributes & attribute) != on ) + if ( bool( d_data->attributes & attribute ) != on ) { if ( on ) d_data->attributes |= attribute; @@ -224,24 +231,22 @@ void QwtPlotItem::setItemAttribute(ItemAttribute attribute, bool on) \return true/false \sa setItemAttribute(), ItemAttribute */ -bool QwtPlotItem::testItemAttribute(ItemAttribute attribute) const +bool QwtPlotItem::testItemAttribute( ItemAttribute attribute ) const { - return d_data->attributes & attribute; + return ( d_data->attributes & attribute ); } -#if QT_VERSION >= 0x040000 - /*! Toggle an render hint - + \param hint Render hint \param on true/false \sa testRenderHint(), RenderHint */ -void QwtPlotItem::setRenderHint(RenderHint hint, bool on) +void QwtPlotItem::setRenderHint( RenderHint hint, bool on ) { - if ( ((d_data->renderHints & hint) != 0) != on ) + if ( ( ( d_data->renderHints & hint ) != 0 ) != on ) { if ( on ) d_data->renderHints |= hint; @@ -259,51 +264,49 @@ void QwtPlotItem::setRenderHint(RenderHint hint, bool on) \return true/false \sa setRenderHint(), RenderHint */ -bool QwtPlotItem::testRenderHint(RenderHint hint) const +bool QwtPlotItem::testRenderHint( RenderHint hint ) const { - return (d_data->renderHints & hint); + return ( d_data->renderHints & hint ); } -#endif - //! Show the item void QwtPlotItem::show() { - setVisible(true); + setVisible( true ); } //! Hide the item void QwtPlotItem::hide() { - setVisible(false); + setVisible( false ); } -/*! +/*! Show/Hide the item \param on Show if true, otherwise hide \sa isVisible(), show(), hide() */ -void QwtPlotItem::setVisible(bool on) -{ +void QwtPlotItem::setVisible( bool on ) +{ if ( on != d_data->isVisible ) { - d_data->isVisible = on; - itemChanged(); + d_data->isVisible = on; + itemChanged(); } } -/*! +/*! \return true if visible \sa setVisible(), show(), hide() */ bool QwtPlotItem::isVisible() const -{ - return d_data->isVisible; +{ + return d_data->isVisible; } -/*! - Update the legend and call QwtPlot::autoRefresh for the +/*! + Update the legend and call QwtPlot::autoRefresh for the parent plot. \sa updateLegend() @@ -313,13 +316,13 @@ void QwtPlotItem::itemChanged() if ( d_data->plot ) { if ( d_data->plot->legend() ) - updateLegend(d_data->plot->legend()); + updateLegend( d_data->plot->legend() ); d_data->plot->autoRefresh(); } } -/*! +/*! Set X and Y axis The item will painted according to the coordinates its Axes. @@ -329,76 +332,76 @@ void QwtPlotItem::itemChanged() \sa setXAxis(), setYAxis(), xAxis(), yAxis() */ -void QwtPlotItem::setAxis(int xAxis, int yAxis) +void QwtPlotItem::setAxes( int xAxis, int yAxis ) { - if (xAxis == QwtPlot::xBottom || xAxis == QwtPlot::xTop ) - d_data->xAxis = xAxis; + if ( xAxis == QwtPlot::xBottom || xAxis == QwtPlot::xTop ) + d_data->xAxis = xAxis; - if (yAxis == QwtPlot::yLeft || yAxis == QwtPlot::yRight ) - d_data->yAxis = yAxis; + if ( yAxis == QwtPlot::yLeft || yAxis == QwtPlot::yRight ) + d_data->yAxis = yAxis; - itemChanged(); + itemChanged(); } -/*! +/*! Set the X axis The item will painted according to the coordinates its Axes. \param axis X Axis - \sa setAxis(), setYAxis(), xAxis() + \sa setAxes(), setYAxis(), xAxis() */ -void QwtPlotItem::setXAxis(int axis) +void QwtPlotItem::setXAxis( int axis ) { - if (axis == QwtPlot::xBottom || axis == QwtPlot::xTop ) + if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop ) { - d_data->xAxis = axis; - itemChanged(); + d_data->xAxis = axis; + itemChanged(); } } -/*! +/*! Set the Y axis The item will painted according to the coordinates its Axes. \param axis Y Axis - \sa setAxis(), setXAxis(), yAxis() + \sa setAxes(), setXAxis(), yAxis() */ -void QwtPlotItem::setYAxis(int axis) +void QwtPlotItem::setYAxis( int axis ) { - if (axis == QwtPlot::yLeft || axis == QwtPlot::yRight ) + if ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight ) { - d_data->yAxis = axis; - itemChanged(); + d_data->yAxis = axis; + itemChanged(); } } //! Return xAxis -int QwtPlotItem::xAxis() const -{ - return d_data->xAxis; +int QwtPlotItem::xAxis() const +{ + return d_data->xAxis; } //! Return yAxis -int QwtPlotItem::yAxis() const -{ - return d_data->yAxis; +int QwtPlotItem::yAxis() const +{ + return d_data->yAxis; } /*! - \return An invalid bounding rect: QwtDoubleRect(1.0, 1.0, -2.0, -2.0) + \return An invalid bounding rect: QRectF(1.0, 1.0, -2.0, -2.0) */ -QwtDoubleRect QwtPlotItem::boundingRect() const +QRectF QwtPlotItem::boundingRect() const { - return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid + return QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid } /*! \brief Allocate the widget that represents the item on the legend - The default implementation is made for QwtPlotCurve and returns a - QwtLegendItem(), but an item could be represented by any type of widget, + The default implementation returns a QwtLegendItem(), but an item + could be represented by any type of widget, by overloading legendItem() and updateLegend(). \return QwtLegendItem() @@ -406,7 +409,15 @@ QwtDoubleRect QwtPlotItem::boundingRect() const */ QWidget *QwtPlotItem::legendItem() const { - return new QwtLegendItem; + QwtLegendItem *item = new QwtLegendItem; + if ( d_data->plot ) + { + QObject::connect( item, SIGNAL( clicked() ), + d_data->plot, SLOT( legendItemClicked() ) ); + QObject::connect( item, SIGNAL( checked( bool ) ), + d_data->plot, SLOT( legendItemChecked( bool ) ) ); + } + return item; } /*! @@ -414,54 +425,67 @@ QWidget *QwtPlotItem::legendItem() const updateLegend() is called from itemChanged() to adopt the widget representing the item on the legend to its new configuration. - - The default implementation is made for QwtPlotCurve and updates a - QwtLegendItem(), but an item could be represented by any type of widget, + + The default implementation updates a QwtLegendItem(), + but an item could be represented by any type of widget, by overloading legendItem() and updateLegend(). \param legend Legend \sa legendItem(), itemChanged(), QwtLegend() */ -void QwtPlotItem::updateLegend(QwtLegend *legend) const +void QwtPlotItem::updateLegend( QwtLegend *legend ) const { - if ( !legend ) + if ( legend == NULL ) return; - QWidget *lgdItem = legend->find(this); - if ( testItemAttribute(QwtPlotItem::Legend) ) + QWidget *lgdItem = legend->find( this ); + if ( testItemAttribute( QwtPlotItem::Legend ) ) { if ( lgdItem == NULL ) { lgdItem = legendItem(); if ( lgdItem ) - { - if ( lgdItem->inherits("QwtLegendItem") ) - { - QwtLegendItem *label = (QwtLegendItem *)lgdItem; - label->setItemMode(legend->itemMode()); - - if ( d_data->plot ) - { - QObject::connect(label, SIGNAL(clicked()), - d_data->plot, SLOT(legendItemClicked())); - QObject::connect(label, SIGNAL(checked(bool)), - d_data->plot, SLOT(legendItemChecked(bool))); - } - } - legend->insert(this, lgdItem); - } + legend->insert( this, lgdItem ); } - if ( lgdItem && lgdItem->inherits("QwtLegendItem") ) + + QwtLegendItem *label = qobject_cast( lgdItem ); + if ( label ) { - QwtLegendItem* label = (QwtLegendItem*)lgdItem; - if ( label ) - label->setText(d_data->title); + // paint the identifier + const QSize sz = label->identifierSize(); + + QPixmap identifier( sz.width(), sz.height() ); + identifier.fill( Qt::transparent ); + + QPainter painter( &identifier ); + painter.setRenderHint( QPainter::Antialiasing, + testRenderHint( QwtPlotItem::RenderAntialiased ) ); + drawLegendIdentifier( &painter, + QRect( 0, 0, sz.width(), sz.height() ) ); + painter.end(); + + const bool doUpdate = label->updatesEnabled(); + if ( doUpdate ) + label->setUpdatesEnabled( false ); + + label->setText( title() ); + label->setIdentifier( identifier ); + label->setItemMode( legend->itemMode() ); + + if ( doUpdate ) + label->setUpdatesEnabled( true ); + + label->update(); } } else { - delete lgdItem; + if ( lgdItem ) + { + lgdItem->hide(); + lgdItem->deleteLater(); + } } } @@ -478,9 +502,11 @@ void QwtPlotItem::updateLegend(QwtLegend *legend) const \sa QwtPlot::updateAxes() */ -void QwtPlotItem::updateScaleDiv(const QwtScaleDiv &, - const QwtScaleDiv &) -{ +void QwtPlotItem::updateScaleDiv( const QwtScaleDiv &xScaleDiv, + const QwtScaleDiv &yScaleDiv ) +{ + Q_UNUSED( xScaleDiv ); + Q_UNUSED( yScaleDiv ); } /*! @@ -489,12 +515,12 @@ void QwtPlotItem::updateScaleDiv(const QwtScaleDiv &, \param xMap X map \param yMap X map - \return Bounding rect of the scale maps + \return Bounding scale rect of the scale maps, normalized */ -QwtDoubleRect QwtPlotItem::scaleRect(const QwtScaleMap &xMap, - const QwtScaleMap &yMap) const +QRectF QwtPlotItem::scaleRect( const QwtScaleMap &xMap, + const QwtScaleMap &yMap ) const { - return QwtDoubleRect(xMap.s1(), yMap.s1(), + return QRectF( xMap.s1(), yMap.s1(), xMap.sDist(), yMap.sDist() ); } @@ -504,61 +530,13 @@ QwtDoubleRect QwtPlotItem::scaleRect(const QwtScaleMap &xMap, \param xMap X map \param yMap X map - \return Bounding rect of the scale maps + \return Bounding paint rect of the scale maps, normalized */ -QRect QwtPlotItem::paintRect(const QwtScaleMap &xMap, - const QwtScaleMap &yMap) const +QRectF QwtPlotItem::paintRect( const QwtScaleMap &xMap, + const QwtScaleMap &yMap ) const { - const QRect rect( qRound(xMap.p1()), qRound(yMap.p1()), - qRound(xMap.pDist()), qRound(yMap.pDist()) ); + const QRectF rect( xMap.p1(), yMap.p1(), + xMap.pDist(), yMap.pDist() ); return rect; } - -/*! - Transform a rectangle - - \param xMap X map - \param yMap Y map - \param rect Rectangle in scale coordinates - \return Rectangle in paint coordinates - - \sa invTransform() -*/ -QRect QwtPlotItem::transform(const QwtScaleMap &xMap, - const QwtScaleMap &yMap, const QwtDoubleRect& rect) const -{ - int x1 = qRound(xMap.transform(rect.left())); - int x2 = qRound(xMap.transform(rect.right())); - int y1 = qRound(yMap.transform(rect.top())); - int y2 = qRound(yMap.transform(rect.bottom())); - - if ( x2 < x1 ) - qSwap(x1, x2); - if ( y2 < y1 ) - qSwap(y1, y2); - - return QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1); -} - -/*! - Transform a rectangle from paint to scale coordinates - - \param xMap X map - \param yMap Y map - \param rect Rectangle in paint coordinates - \return Rectangle in scale coordinates - \sa transform() -*/ -QwtDoubleRect QwtPlotItem::invTransform(const QwtScaleMap &xMap, - const QwtScaleMap &yMap, const QRect& rect) const -{ - const double x1 = xMap.invTransform(rect.left()); - const double x2 = xMap.invTransform(rect.right()); - const double y1 = yMap.invTransform(rect.top()); - const double y2 = yMap.invTransform(rect.bottom()); - - const QwtDoubleRect r(x1, y1, x2 - x1, y2 - y1); - - return r.normalized(); -} diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_item.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_item.h index 227c226c9..3f8f82e1c 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_item.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_item.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -13,10 +13,9 @@ #include "qwt_global.h" #include "qwt_legend_itemmanager.h" #include "qwt_text.h" -#include "qwt_double_rect.h" +#include class QString; -class QRect; class QPainter; class QWidget; class QwtPlot; @@ -54,10 +53,10 @@ class QwtScaleDiv; into autoscaling or has an entry on the legnd. Before misusing the existing item classes it might be better to - implement a new type of plot item + implement a new type of plot item ( don't implement a watermark as spectrogram ). - Deriving a new type of QwtPlotItem primarily means to implement - the YourPlotItem::draw() method. + Deriving a new type of QwtPlotItem primarily means to implement + the YourPlotItem::draw() method. \sa The cpuplot example shows the implementation of additional plot items. */ @@ -67,18 +66,20 @@ class QWT_EXPORT QwtPlotItem: public QwtLegendItemManager public: /*! \brief Runtime type information - + RttiValues is used to cast plot items, without having to enable runtime type information of the compiler. */ enum RttiValues - { + { Rtti_PlotItem = 0, Rtti_PlotGrid, Rtti_PlotScale, Rtti_PlotMarker, Rtti_PlotCurve, + Rtti_PlotSpectroCurve, + Rtti_PlotIntervalCurve, Rtti_PlotHistogram, Rtti_PlotSpectrogram, Rtti_PlotSVG, @@ -88,73 +89,67 @@ public: /*! Plot Item Attributes - - - Legend\n - The item is represented on the legend. - - AutoScale \n - The boundingRect() of the item is included in the - autoscaling calculation. - \sa setItemAttribute(), testItemAttribute() */ enum ItemAttribute { - Legend = 1, - AutoScale = 2 + //! The item is represented on the legend. + Legend = 0x01, + + /*! + The boundingRect() of the item is included in the + autoscaling calculation. + */ + AutoScale = 0x02 }; -#if QT_VERSION >= 0x040000 + //! Plot Item Attributes + typedef QFlags ItemAttributes; + //! Render hints enum RenderHint { + //! Enable antialiasing RenderAntialiased = 1 }; -#endif - explicit QwtPlotItem(const QwtText &title = QwtText()); + //! Render hints + typedef QFlags RenderHints; + + explicit QwtPlotItem( const QwtText &title = QwtText() ); virtual ~QwtPlotItem(); - void attach(QwtPlot *plot); - - /*! - \brief This method detaches a QwtPlotItem from any QwtPlot it has been - associated with. - - detach() is equivalent to calling attach( NULL ) - \sa attach( QwtPlot* plot ) - */ - void detach() { attach(NULL); } + void attach( QwtPlot *plot ); + void detach(); QwtPlot *plot() const; - - void setTitle(const QString &title); - void setTitle(const QwtText &title); + + void setTitle( const QString &title ); + void setTitle( const QwtText &title ); const QwtText &title() const; virtual int rtti() const; - void setItemAttribute(ItemAttribute, bool on = true); - bool testItemAttribute(ItemAttribute) const; + void setItemAttribute( ItemAttribute, bool on = true ); + bool testItemAttribute( ItemAttribute ) const; -#if QT_VERSION >= 0x040000 - void setRenderHint(RenderHint, bool on = true); - bool testRenderHint(RenderHint) const; -#endif + void setRenderHint( RenderHint, bool on = true ); + bool testRenderHint( RenderHint ) const; - double z() const; - void setZ(double z); + double z() const; + void setZ( double z ); void show(); void hide(); - virtual void setVisible(bool); + virtual void setVisible( bool ); bool isVisible () const; - void setAxis(int xAxis, int yAxis); + void setAxes( int xAxis, int yAxis ); - void setXAxis(int axis); + void setXAxis( int axis ); int xAxis() const; - void setYAxis(int axis); + void setYAxis( int axis ); int yAxis() const; virtual void itemChanged(); @@ -167,25 +162,20 @@ public: \param yMap Maps y-values into pixel coordinates. \param canvasRect Contents rect of the canvas in painter coordinates */ - virtual void draw(QPainter *painter, + virtual void draw( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, - const QRect &canvasRect) const = 0; + const QRectF &canvasRect ) const = 0; - virtual QwtDoubleRect boundingRect() const; + virtual QRectF boundingRect() const; - virtual void updateLegend(QwtLegend *) const; - virtual void updateScaleDiv(const QwtScaleDiv&, - const QwtScaleDiv&); + virtual void updateLegend( QwtLegend * ) const; + virtual void updateScaleDiv( + const QwtScaleDiv&, const QwtScaleDiv& ); virtual QWidget *legendItem() const; - QwtDoubleRect scaleRect(const QwtScaleMap &, const QwtScaleMap &) const; - QRect paintRect(const QwtScaleMap &, const QwtScaleMap &) const; - - QRect transform(const QwtScaleMap &, const QwtScaleMap &, - const QwtDoubleRect&) const; - QwtDoubleRect invTransform(const QwtScaleMap &, const QwtScaleMap &, - const QRect&) const; + QRectF scaleRect( const QwtScaleMap &, const QwtScaleMap & ) const; + QRectF paintRect( const QwtScaleMap &, const QwtScaleMap & ) const; private: // Disabled copy constructor and operator= @@ -195,5 +185,8 @@ private: class PrivateData; PrivateData *d_data; }; - + +Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotItem::ItemAttributes ) +Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotItem::RenderHints ) + #endif diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_layout.cpp b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_layout.cpp index 567544c89..9ad2db61c 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_layout.cpp +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_layout.cpp @@ -7,20 +7,19 @@ * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ -// vim: expandtab - -#include +#include "qwt_plot_layout.h" #include "qwt_text.h" #include "qwt_text_label.h" #include "qwt_plot_canvas.h" #include "qwt_scale_widget.h" #include "qwt_legend.h" -#include "qwt_plot_layout.h" +#include +#include class QwtPlotLayout::LayoutData { public: - void init(const QwtPlot *, const QRect &rect); + void init( const QwtPlot *, const QRectF &rect ); struct t_legendData { @@ -29,7 +28,7 @@ public: int hScrollBarHeight; QSize hint; } legend; - + struct t_titleData { QwtText text; @@ -44,7 +43,7 @@ public: int start; int end; int baseLineOffset; - int tickOffset; + int tickOffset; int dimWithoutTitle; } scale[QwtPlot::axisCnt]; @@ -58,54 +57,54 @@ public: Extract all layout relevant data from the plot components */ -void QwtPlotLayout::LayoutData::init(const QwtPlot *plot, const QRect &rect) +void QwtPlotLayout::LayoutData::init( const QwtPlot *plot, const QRectF &rect ) { // legend - if ( plot->plotLayout()->legendPosition() != QwtPlot::ExternalLegend + if ( plot->plotLayout()->legendPosition() != QwtPlot::ExternalLegend && plot->legend() ) { legend.frameWidth = plot->legend()->frameWidth(); - legend.vScrollBarWidth = + legend.vScrollBarWidth = plot->legend()->verticalScrollBar()->sizeHint().width(); - legend.hScrollBarHeight = + legend.hScrollBarHeight = plot->legend()->horizontalScrollBar()->sizeHint().height(); const QSize hint = plot->legend()->sizeHint(); - int w = qwtMin(hint.width(), rect.width()); - int h = plot->legend()->heightForWidth(w); + int w = qMin( hint.width(), qFloor( rect.width() ) ); + int h = plot->legend()->heightForWidth( w ); if ( h == 0 ) h = hint.height(); if ( h > rect.height() ) w += legend.vScrollBarWidth; - legend.hint = QSize(w, h); + legend.hint = QSize( w, h ); } - // title + // title title.frameWidth = 0; title.text = QwtText(); - if (plot->titleLabel() ) + if ( plot->titleLabel() ) { const QwtTextLabel *label = plot->titleLabel(); - title.text = label->text(); - if ( !(title.text.testPaintAttribute(QwtText::PaintUsingTextFont)) ) - title.text.setFont(label->font()); - + title.text = label->text(); + if ( !( title.text.testPaintAttribute( QwtText::PaintUsingTextFont ) ) ) + title.text.setFont( label->font() ); + title.frameWidth = plot->titleLabel()->frameWidth(); } - // scales + // scales - for (int axis = 0; axis < QwtPlot::axisCnt; axis++ ) + for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { - if ( plot->axisEnabled(axis) ) + if ( plot->axisEnabled( axis ) ) { - const QwtScaleWidget *scaleWidget = plot->axisWidget(axis); + const QwtScaleWidget *scaleWidget = plot->axisWidget( axis ); scale[axis].isEnabled = true; @@ -119,19 +118,19 @@ void QwtPlotLayout::LayoutData::init(const QwtPlot *plot, const QRect &rect) scale[axis].baseLineOffset = scaleWidget->margin(); scale[axis].tickOffset = scaleWidget->margin(); if ( scaleWidget->scaleDraw()->hasComponent( - QwtAbstractScaleDraw::Ticks) ) + QwtAbstractScaleDraw::Ticks ) ) { - scale[axis].tickOffset += - (int)scaleWidget->scaleDraw()->majTickLength(); + scale[axis].tickOffset += + scaleWidget->scaleDraw()->maxTickLength(); } scale[axis].dimWithoutTitle = scaleWidget->dimForLength( - QWIDGETSIZE_MAX, scale[axis].scaleFont); + QWIDGETSIZE_MAX, scale[axis].scaleFont ); if ( !scaleWidget->title().isEmpty() ) { - scale[axis].dimWithoutTitle -= - scaleWidget->titleHeightForWidth(QWIDGETSIZE_MAX); + scale[axis].dimWithoutTitle -= + scaleWidget->titleHeightForWidth( QWIDGETSIZE_MAX ); } } else @@ -145,7 +144,7 @@ void QwtPlotLayout::LayoutData::init(const QwtPlot *plot, const QRect &rect) } } - // canvas + // canvas canvas.frameWidth = plot->canvas()->frameWidth(); } @@ -154,22 +153,20 @@ class QwtPlotLayout::PrivateData { public: PrivateData(): - margin(0), - spacing(5), - alignCanvasToScales(false) + spacing( 5 ), + alignCanvasToScales( false ) { } - QRect titleRect; - QRect legendRect; - QRect scaleRect[QwtPlot::axisCnt]; - QRect canvasRect; + QRectF titleRect; + QRectF legendRect; + QRectF scaleRect[QwtPlot::axisCnt]; + QRectF canvasRect; QwtPlotLayout::LayoutData layoutData; QwtPlot::LegendPosition legendPos; double legendRatio; - unsigned int margin; unsigned int spacing; unsigned int canvasMargin[QwtPlot::axisCnt]; bool alignCanvasToScales; @@ -183,8 +180,8 @@ QwtPlotLayout::QwtPlotLayout() { d_data = new PrivateData; - setLegendPosition(QwtPlot::BottomLegend); - setCanvasMargin(4); + setLegendPosition( QwtPlot::BottomLegend ); + setCanvasMargin( 4 ); invalidate(); } @@ -195,51 +192,27 @@ QwtPlotLayout::~QwtPlotLayout() delete d_data; } -/*! - Change the margin of the plot. The margin is the space - around all components. - - \param margin new margin - \sa margin(), setSpacing(), - QwtPlot::setMargin() -*/ -void QwtPlotLayout::setMargin(int margin) -{ - if ( margin < 0 ) - margin = 0; - d_data->margin = margin; -} - -/*! - \return margin - \sa setMargin(), spacing(), QwtPlot::margin() -*/ -int QwtPlotLayout::margin() const -{ - return d_data->margin; -} - /*! Change a margin of the canvas. The margin is the space above/below the scale ticks. A negative margin will be set to -1, excluding the borders of the scales. - + \param margin New margin - \param axis One of QwtPlot::Axis. Specifies where the position of the margin. + \param axis One of QwtPlot::Axis. Specifies where the position of the margin. -1 means margin at all borders. - \sa canvasMargin() + \sa canvasMargin() \warning The margin will have no effect when alignCanvasToScales is true */ -void QwtPlotLayout::setCanvasMargin(int margin, int axis) +void QwtPlotLayout::setCanvasMargin( int margin, int axis ) { if ( margin < -1 ) margin = -1; if ( axis == -1 ) { - for (axis = 0; axis < QwtPlot::axisCnt; axis++) + for ( axis = 0; axis < QwtPlot::axisCnt; axis++ ) d_data->canvasMargin[axis] = margin; } else if ( axis >= 0 && axis < QwtPlot::axisCnt ) @@ -250,7 +223,7 @@ void QwtPlotLayout::setCanvasMargin(int margin, int axis) \return Margin around the scale tick borders \sa setCanvasMargin() */ -int QwtPlotLayout::canvasMargin(int axis) const +int QwtPlotLayout::canvasMargin( int axis ) const { if ( axis < 0 || axis >= QwtPlot::axisCnt ) return 0; @@ -265,12 +238,12 @@ int QwtPlotLayout::canvasMargin(int axis) const \param alignCanvasToScales New align-canvas-to-axis-scales setting - \sa setCanvasMargin() + \sa setCanvasMargin() \note In this context the term 'scale' means the backbone of a scale. - \warning In case of alignCanvasToScales == true canvasMargin will have + \warning In case of alignCanvasToScales == true canvasMargin will have no effect */ -void QwtPlotLayout::setAlignCanvasToScales(bool alignCanvasToScales) +void QwtPlotLayout::setAlignCanvasToScales( bool alignCanvasToScales ) { d_data->alignCanvasToScales = alignCanvasToScales; } @@ -281,7 +254,7 @@ void QwtPlotLayout::setAlignCanvasToScales(bool alignCanvasToScales) - align with the axis scale ends to control its size. \return align-canvas-to-axis-scales setting - \sa setAlignCanvasToScales, setCanvasMargin() + \sa setAlignCanvasToScales, setCanvasMargin() \note In this context the term 'scale' means the backbone of a scale. */ bool QwtPlotLayout::alignCanvasToScales() const @@ -292,18 +265,18 @@ bool QwtPlotLayout::alignCanvasToScales() const /*! Change the spacing of the plot. The spacing is the distance between the plot components. - + \param spacing new spacing - \sa setMargin(), spacing() + \sa setMargin(), spacing() */ -void QwtPlotLayout::setSpacing(int spacing) +void QwtPlotLayout::setSpacing( int spacing ) { - d_data->spacing = qwtMax(0, spacing); + d_data->spacing = qMax( 0, spacing ); } /*! \return spacing - \sa margin(), setSpacing() + \sa margin(), setSpacing() */ int QwtPlotLayout::spacing() const { @@ -312,23 +285,23 @@ int QwtPlotLayout::spacing() const /*! \brief Specify the position of the legend - \param pos The legend's position. - \param ratio Ratio between legend and the bounding rect + \param pos The legend's position. + \param ratio Ratio between legend and the bounding rect of title, canvas and axes. The legend will be shrinked if it would need more space than the given ratio. The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0 it will be reset to the default ratio. - The default vertical/horizontal ratio is 0.33/0.5. - + The default vertical/horizontal ratio is 0.33/0.5. + \sa QwtPlot::setLegendPosition() */ -void QwtPlotLayout::setLegendPosition(QwtPlot::LegendPosition pos, double ratio) +void QwtPlotLayout::setLegendPosition( QwtPlot::LegendPosition pos, double ratio ) { if ( ratio > 1.0 ) ratio = 1.0; - switch(pos) + switch ( pos ) { case QwtPlot::TopLegend: case QwtPlot::BottomLegend: @@ -354,15 +327,15 @@ void QwtPlotLayout::setLegendPosition(QwtPlot::LegendPosition pos, double ratio) /*! \brief Specify the position of the legend - \param pos The legend's position. Valid values are - \c QwtPlot::LeftLegend, \c QwtPlot::RightLegend, + \param pos The legend's position. Valid values are + \c QwtPlot::LeftLegend, \c QwtPlot::RightLegend, \c QwtPlot::TopLegend, \c QwtPlot::BottomLegend. - + \sa QwtPlot::setLegendPosition() */ -void QwtPlotLayout::setLegendPosition(QwtPlot::LegendPosition pos) +void QwtPlotLayout::setLegendPosition( QwtPlot::LegendPosition pos ) { - setLegendPosition(pos, 0.0); + setLegendPosition( pos, 0.0 ); } /*! @@ -377,16 +350,16 @@ QwtPlot::LegendPosition QwtPlotLayout::legendPosition() const /*! Specify the relative size of the legend in the plot - \param ratio Ratio between legend and the bounding rect + \param ratio Ratio between legend and the bounding rect of title, canvas and axes. The legend will be shrinked if it would need more space than the given ratio. The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0 it will be reset to the default ratio. - The default vertical/horizontal ratio is 0.33/0.5. + The default vertical/horizontal ratio is 0.33/0.5. */ -void QwtPlotLayout::setLegendRatio(double ratio) +void QwtPlotLayout::setLegendRatio( double ratio ) { - setLegendPosition(legendPosition(), ratio); + setLegendPosition( legendPosition(), ratio ); } /*! @@ -403,7 +376,7 @@ double QwtPlotLayout::legendRatio() const \sa activate(), invalidate() */ -const QRect &QwtPlotLayout::titleRect() const +const QRectF &QwtPlotLayout::titleRect() const { return d_data->titleRect; } @@ -413,7 +386,7 @@ const QRect &QwtPlotLayout::titleRect() const \sa activate(), invalidate() */ -const QRect &QwtPlotLayout::legendRect() const +const QRectF &QwtPlotLayout::legendRect() const { return d_data->legendRect; } @@ -424,11 +397,11 @@ const QRect &QwtPlotLayout::legendRect() const \sa activate(), invalidate() */ -const QRect &QwtPlotLayout::scaleRect(int axis) const +const QRectF &QwtPlotLayout::scaleRect( int axis ) const { if ( axis < 0 || axis >= QwtPlot::axisCnt ) { - static QRect dummyRect; + static QRectF dummyRect; return dummyRect; } return d_data->scaleRect[axis]; @@ -439,28 +412,28 @@ const QRect &QwtPlotLayout::scaleRect(int axis) const \sa activate(), invalidate() */ -const QRect &QwtPlotLayout::canvasRect() const +const QRectF &QwtPlotLayout::canvasRect() const { return d_data->canvasRect; } /*! - Invalidate the geometry of all components. + Invalidate the geometry of all components. \sa activate() */ void QwtPlotLayout::invalidate() { d_data->titleRect = d_data->legendRect = d_data->canvasRect = QRect(); - for (int axis = 0; axis < QwtPlot::axisCnt; axis++ ) + for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) d_data->scaleRect[axis] = QRect(); } -/*! +/*! \brief Return a minimum size hint \sa QwtPlot::minimumSizeHint() */ -QSize QwtPlotLayout::minimumSizeHint(const QwtPlot *plot) const +QSize QwtPlotLayout::minimumSizeHint( const QwtPlot *plot ) const { class ScaleData { @@ -482,32 +455,32 @@ QSize QwtPlotLayout::minimumSizeHint(const QwtPlot *plot) const int axis; for ( axis = 0; axis < QwtPlot::axisCnt; axis++ ) { - if ( plot->axisEnabled(axis) ) + if ( plot->axisEnabled( axis ) ) { - const QwtScaleWidget *scl = plot->axisWidget(axis); + const QwtScaleWidget *scl = plot->axisWidget( axis ); ScaleData &sd = scaleData[axis]; const QSize hint = scl->minimumSizeHint(); - sd.w = hint.width(); - sd.h = hint.height(); - scl->getBorderDistHint(sd.minLeft, sd.minRight); + sd.w = hint.width(); + sd.h = hint.height(); + scl->getBorderDistHint( sd.minLeft, sd.minRight ); sd.tickOffset = scl->margin(); - if ( scl->scaleDraw()->hasComponent(QwtAbstractScaleDraw::Ticks) ) - sd.tickOffset += scl->scaleDraw()->majTickLength(); + if ( scl->scaleDraw()->hasComponent( QwtAbstractScaleDraw::Ticks ) ) + sd.tickOffset += scl->scaleDraw()->maxTickLength(); } canvasBorder[axis] = plot->canvas()->frameWidth() + d_data->canvasMargin[axis] + 1; - + } for ( axis = 0; axis < QwtPlot::axisCnt; axis++ ) { ScaleData &sd = scaleData[axis]; - if ( sd.w && (axis == QwtPlot::xBottom || axis == QwtPlot::xTop) ) + if ( sd.w && ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop ) ) { - if ( (sd.minLeft > canvasBorder[QwtPlot::yLeft]) + if ( ( sd.minLeft > canvasBorder[QwtPlot::yLeft] ) && scaleData[QwtPlot::yLeft].w ) { int shiftLeft = sd.minLeft - canvasBorder[QwtPlot::yLeft]; @@ -516,7 +489,7 @@ QSize QwtPlotLayout::minimumSizeHint(const QwtPlot *plot) const sd.w -= shiftLeft; } - if ( (sd.minRight > canvasBorder[QwtPlot::yRight]) + if ( ( sd.minRight > canvasBorder[QwtPlot::yRight] ) && scaleData[QwtPlot::yRight].w ) { int shiftRight = sd.minRight - canvasBorder[QwtPlot::yRight]; @@ -527,9 +500,9 @@ QSize QwtPlotLayout::minimumSizeHint(const QwtPlot *plot) const } } - if ( sd.h && (axis == QwtPlot::yLeft || axis == QwtPlot::yRight) ) + if ( sd.h && ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight ) ) { - if ( (sd.minLeft > canvasBorder[QwtPlot::xBottom]) && + if ( ( sd.minLeft > canvasBorder[QwtPlot::xBottom] ) && scaleData[QwtPlot::xBottom].h ) { int shiftBottom = sd.minLeft - canvasBorder[QwtPlot::xBottom]; @@ -538,7 +511,7 @@ QSize QwtPlotLayout::minimumSizeHint(const QwtPlot *plot) const sd.h -= shiftBottom; } - if ( (sd.minLeft > canvasBorder[QwtPlot::xTop]) && + if ( ( sd.minLeft > canvasBorder[QwtPlot::xTop] ) && scaleData[QwtPlot::xTop].h ) { int shiftTop = sd.minRight - canvasBorder[QwtPlot::xTop]; @@ -554,31 +527,31 @@ QSize QwtPlotLayout::minimumSizeHint(const QwtPlot *plot) const const QSize minCanvasSize = canvas->minimumSize(); int w = scaleData[QwtPlot::yLeft].w + scaleData[QwtPlot::yRight].w; - int cw = qwtMax(scaleData[QwtPlot::xBottom].w, scaleData[QwtPlot::xTop].w) - + 2 * (canvas->frameWidth() + 1); - w += qwtMax(cw, minCanvasSize.width()); + int cw = qMax( scaleData[QwtPlot::xBottom].w, scaleData[QwtPlot::xTop].w ) + + 2 * ( canvas->frameWidth() + 1 ); + w += qMax( cw, minCanvasSize.width() ); int h = scaleData[QwtPlot::xBottom].h + scaleData[QwtPlot::xTop].h; - int ch = qwtMax(scaleData[QwtPlot::yLeft].h, scaleData[QwtPlot::yRight].h) - + 2 * (canvas->frameWidth() + 1); - h += qwtMax(ch, minCanvasSize.height()); + int ch = qMax( scaleData[QwtPlot::yLeft].h, scaleData[QwtPlot::yRight].h ) + + 2 * ( canvas->frameWidth() + 1 ); + h += qMax( ch, minCanvasSize.height() ); const QwtTextLabel *title = plot->titleLabel(); - if (title && !title->text().isEmpty()) + if ( title && !title->text().isEmpty() ) { - // If only QwtPlot::yLeft or QwtPlot::yRight is showing, + // If only QwtPlot::yLeft or QwtPlot::yRight is showing, // we center on the plot canvas. - const bool centerOnCanvas = !(plot->axisEnabled(QwtPlot::yLeft) - && plot->axisEnabled(QwtPlot::yRight)); + const bool centerOnCanvas = !( plot->axisEnabled( QwtPlot::yLeft ) + && plot->axisEnabled( QwtPlot::yRight ) ); int titleW = w; if ( centerOnCanvas ) { - titleW -= scaleData[QwtPlot::yLeft].w + titleW -= scaleData[QwtPlot::yLeft].w + scaleData[QwtPlot::yRight].w; } - int titleH = title->heightForWidth(titleW); + int titleH = title->heightForWidth( titleW ); if ( titleH > titleW ) // Compensate for a long title { w = titleW = titleH; @@ -588,7 +561,7 @@ QSize QwtPlotLayout::minimumSizeHint(const QwtPlot *plot) const + scaleData[QwtPlot::yRight].w; } - titleH = title->heightForWidth(titleW); + titleH = title->heightForWidth( titleW ); } h += titleH + d_data->spacing; } @@ -599,11 +572,11 @@ QSize QwtPlotLayout::minimumSizeHint(const QwtPlot *plot) const if ( d_data->legendPos != QwtPlot::ExternalLegend && legend && !legend->isEmpty() ) { - if ( d_data->legendPos == QwtPlot::LeftLegend + if ( d_data->legendPos == QwtPlot::LeftLegend || d_data->legendPos == QwtPlot::RightLegend ) { int legendW = legend->sizeHint().width(); - int legendH = legend->heightForWidth(legendW); + int legendH = legend->heightForWidth( legendW ); if ( legend->frameWidth() > 0 ) w += d_data->spacing; @@ -612,28 +585,25 @@ QSize QwtPlotLayout::minimumSizeHint(const QwtPlot *plot) const legendW += legend->verticalScrollBar()->sizeHint().height(); if ( d_data->legendRatio < 1.0 ) - legendW = qwtMin(legendW, int(w / (1.0 - d_data->legendRatio))); + legendW = qMin( legendW, int( w / ( 1.0 - d_data->legendRatio ) ) ); - w += legendW; + w += legendW + d_data->spacing; } else // QwtPlot::Top, QwtPlot::Bottom { - int legendW = qwtMin(legend->sizeHint().width(), w); - int legendH = legend->heightForWidth(legendW); + int legendW = qMin( legend->sizeHint().width(), w ); + int legendH = legend->heightForWidth( legendW ); if ( legend->frameWidth() > 0 ) h += d_data->spacing; if ( d_data->legendRatio < 1.0 ) - legendH = qwtMin(legendH, int(h / (1.0 - d_data->legendRatio))); - - h += legendH; + legendH = qMin( legendH, int( h / ( 1.0 - d_data->legendRatio ) ) ); + + h += legendH + d_data->spacing; } } - w += 2 * d_data->margin; - h += 2 * d_data->margin; - return QSize( w, h ); } @@ -645,26 +615,26 @@ QSize QwtPlotLayout::minimumSizeHint(const QwtPlot *plot) const \sa Options */ -QRect QwtPlotLayout::layoutLegend(int options, - const QRect &rect) const +QRectF QwtPlotLayout::layoutLegend( Options options, + const QRectF &rect ) const { - const QSize hint(d_data->layoutData.legend.hint); + const QSize hint( d_data->layoutData.legend.hint ); int dim; - if ( d_data->legendPos == QwtPlot::LeftLegend + if ( d_data->legendPos == QwtPlot::LeftLegend || d_data->legendPos == QwtPlot::RightLegend ) { // We don't allow vertical legends to take more than // half of the available space. - dim = qwtMin(hint.width(), int(rect.width() * d_data->legendRatio)); + dim = qMin( hint.width(), int( rect.width() * d_data->legendRatio ) ); - if ( !(options & IgnoreScrollbars) ) + if ( !( options & IgnoreScrollbars ) ) { if ( hint.height() > rect.height() ) { // The legend will need additional - // space for the vertical scrollbar. + // space for the vertical scrollbar. dim += d_data->layoutData.legend.vScrollBarWidth; } @@ -672,26 +642,26 @@ QRect QwtPlotLayout::layoutLegend(int options, } else { - dim = qwtMin(hint.height(), int(rect.height() * d_data->legendRatio)); - dim = qwtMax(dim, d_data->layoutData.legend.hScrollBarHeight); + dim = qMin( hint.height(), int( rect.height() * d_data->legendRatio ) ); + dim = qMax( dim, d_data->layoutData.legend.hScrollBarHeight ); } - QRect legendRect = rect; - switch(d_data->legendPos) + QRectF legendRect = rect; + switch ( d_data->legendPos ) { case QwtPlot::LeftLegend: - legendRect.setWidth(dim); + legendRect.setWidth( dim ); break; case QwtPlot::RightLegend: - legendRect.setX(rect.right() - dim + 1); - legendRect.setWidth(dim); + legendRect.setX( rect.right() - dim ); + legendRect.setWidth( dim ); break; case QwtPlot::TopLegend: - legendRect.setHeight(dim); + legendRect.setHeight( dim ); break; case QwtPlot::BottomLegend: - legendRect.setY(rect.bottom() - dim + 1); - legendRect.setHeight(dim); + legendRect.setY( rect.bottom() - dim ); + legendRect.setHeight( dim ); break; case QwtPlot::ExternalLegend: break; @@ -706,26 +676,26 @@ QRect QwtPlotLayout::layoutLegend(int options, \param legendRect Maximum geometry for the legend \return Geometry for the aligned legend */ -QRect QwtPlotLayout::alignLegend(const QRect &canvasRect, - const QRect &legendRect) const +QRectF QwtPlotLayout::alignLegend( const QRectF &canvasRect, + const QRectF &legendRect ) const { - QRect alignedRect = legendRect; + QRectF alignedRect = legendRect; - if ( d_data->legendPos == QwtPlot::BottomLegend + if ( d_data->legendPos == QwtPlot::BottomLegend || d_data->legendPos == QwtPlot::TopLegend ) { if ( d_data->layoutData.legend.hint.width() < canvasRect.width() ) { - alignedRect.setX(canvasRect.x()); - alignedRect.setWidth(canvasRect.width()); + alignedRect.setX( canvasRect.x() ); + alignedRect.setWidth( canvasRect.width() ); } } else { if ( d_data->layoutData.legend.hint.height() < canvasRect.height() ) { - alignedRect.setY(canvasRect.y()); - alignedRect.setHeight(canvasRect.height()); + alignedRect.setY( canvasRect.y() ); + alignedRect.setHeight( canvasRect.height() ); } } @@ -743,25 +713,25 @@ QRect QwtPlotLayout::alignLegend(const QRect &canvasRect, \sa Options */ -void QwtPlotLayout::expandLineBreaks(int options, const QRect &rect, - int &dimTitle, int dimAxis[QwtPlot::axisCnt]) const +void QwtPlotLayout::expandLineBreaks( int options, const QRectF &rect, + int &dimTitle, int dimAxis[QwtPlot::axisCnt] ) const { dimTitle = 0; for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) dimAxis[axis] = 0; int backboneOffset[QwtPlot::axisCnt]; - for (int axis = 0; axis < QwtPlot::axisCnt; axis++ ) + for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { backboneOffset[axis] = 0; if ( !d_data->alignCanvasToScales ) backboneOffset[axis] += d_data->canvasMargin[axis]; - if ( !(options & IgnoreFrames) ) + if ( !( options & IgnoreFrames ) ) backboneOffset[axis] += d_data->layoutData.canvas.frameWidth; } bool done = false; - while (!done) + while ( !done ) { done = true; @@ -781,11 +751,11 @@ void QwtPlotLayout::expandLineBreaks(int options, const QRect &rect, != d_data->layoutData.scale[QwtPlot::yRight].isEnabled ) { // center to the canvas - w -= dimAxis[QwtPlot::yLeft] + dimAxis[QwtPlot::yRight]; + w -= dimAxis[QwtPlot::yLeft] + dimAxis[QwtPlot::yRight]; } - int d = d_data->layoutData.title.text.heightForWidth(w); - if ( !(options & IgnoreFrames) ) + int d = qCeil( d_data->layoutData.title.text.heightForWidth( w ) ); + if ( !( options & IgnoreFrames ) ) d += 2 * d_data->layoutData.title.frameWidth; if ( d > dimTitle ) @@ -797,29 +767,29 @@ void QwtPlotLayout::expandLineBreaks(int options, const QRect &rect, for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { - const struct LayoutData::t_scaleData &scaleData = + const struct LayoutData::t_scaleData &scaleData = d_data->layoutData.scale[axis]; - if (scaleData.isEnabled) + if ( scaleData.isEnabled ) { int length; if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom ) { - length = rect.width() - dimAxis[QwtPlot::yLeft] + length = rect.width() - dimAxis[QwtPlot::yLeft] - dimAxis[QwtPlot::yRight]; length -= scaleData.start + scaleData.end; if ( dimAxis[QwtPlot::yRight] > 0 ) length -= 1; - length += qwtMin(dimAxis[QwtPlot::yLeft], - scaleData.start - backboneOffset[QwtPlot::yLeft]); - length += qwtMin(dimAxis[QwtPlot::yRight], - scaleData.end - backboneOffset[QwtPlot::yRight]); + length += qMin( dimAxis[QwtPlot::yLeft], + scaleData.start - backboneOffset[QwtPlot::yLeft] ); + length += qMin( dimAxis[QwtPlot::yRight], + scaleData.end - backboneOffset[QwtPlot::yRight] ); } else // QwtPlot::yLeft, QwtPlot::yRight { - length = rect.height() - dimAxis[QwtPlot::xTop] + length = rect.height() - dimAxis[QwtPlot::xTop] - dimAxis[QwtPlot::xBottom]; length -= scaleData.start + scaleData.end; length -= 1; @@ -831,15 +801,15 @@ void QwtPlotLayout::expandLineBreaks(int options, const QRect &rect, if ( dimAxis[QwtPlot::xBottom] > 0 ) { - length += qwtMin( - d_data->layoutData.scale[QwtPlot::xBottom].tickOffset, - scaleData.start - backboneOffset[QwtPlot::xBottom]); + length += qMin( + d_data->layoutData.scale[QwtPlot::xBottom].tickOffset, + scaleData.start - backboneOffset[QwtPlot::xBottom] ); } if ( dimAxis[QwtPlot::xTop] > 0 ) { - length += qwtMin( - d_data->layoutData.scale[QwtPlot::xTop].tickOffset, - scaleData.end - backboneOffset[QwtPlot::xTop]); + length += qMin( + d_data->layoutData.scale[QwtPlot::xTop].tickOffset, + scaleData.end - backboneOffset[QwtPlot::xTop] ); } if ( dimTitle > 0 ) @@ -849,7 +819,7 @@ void QwtPlotLayout::expandLineBreaks(int options, const QRect &rect, int d = scaleData.dimWithoutTitle; if ( !scaleData.scaleWidget->title().isEmpty() ) { - d += scaleData.scaleWidget->titleHeightForWidth(length); + d += scaleData.scaleWidget->titleHeightForWidth( length ); } @@ -870,22 +840,20 @@ void QwtPlotLayout::expandLineBreaks(int options, const QRect &rect, \sa Options */ -void QwtPlotLayout::alignScales(int options, - QRect &canvasRect, QRect scaleRect[QwtPlot::axisCnt]) const +void QwtPlotLayout::alignScales( int options, + QRectF &canvasRect, QRectF scaleRect[QwtPlot::axisCnt] ) const { - int axis; - int backboneOffset[QwtPlot::axisCnt]; - for (axis = 0; axis < QwtPlot::axisCnt; axis++ ) + for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { backboneOffset[axis] = 0; if ( !d_data->alignCanvasToScales ) backboneOffset[axis] += d_data->canvasMargin[axis]; - if ( !(options & IgnoreFrames) ) + if ( !( options & IgnoreFrames ) ) backboneOffset[axis] += d_data->layoutData.canvas.frameWidth; } - for (axis = 0; axis < QwtPlot::axisCnt; axis++ ) + for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { if ( !scaleRect[axis].isValid() ) continue; @@ -893,104 +861,156 @@ void QwtPlotLayout::alignScales(int options, const int startDist = d_data->layoutData.scale[axis].start; const int endDist = d_data->layoutData.scale[axis].end; - QRect &axisRect = scaleRect[axis]; + QRectF &axisRect = scaleRect[axis]; if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom ) { - const int leftOffset = + const QRectF &leftScaleRect = scaleRect[QwtPlot::yLeft]; + const int leftOffset = backboneOffset[QwtPlot::yLeft] - startDist; - if ( scaleRect[QwtPlot::yLeft].isValid() ) + if ( leftScaleRect.isValid() ) { - int minLeft = scaleRect[QwtPlot::yLeft].left(); - int left = axisRect.left() + leftOffset; - axisRect.setLeft(qwtMax(left, minLeft)); + const int dx = leftOffset + leftScaleRect.width(); + if ( d_data->alignCanvasToScales && dx < 0 ) + { + /* + The axis needs more space than the width + of the left scale. + */ + canvasRect.setLeft( qMax( canvasRect.left(), + axisRect.left() - dx ) ); + } + else + { + const double minLeft = leftScaleRect.left(); + const double left = axisRect.left() + leftOffset; + axisRect.setLeft( qMax( left, minLeft ) ); + } } else { if ( d_data->alignCanvasToScales && leftOffset < 0 ) { - canvasRect.setLeft(qwtMax(canvasRect.left(), - axisRect.left() - leftOffset)); + canvasRect.setLeft( qMax( canvasRect.left(), + axisRect.left() - leftOffset ) ); } else { if ( leftOffset > 0 ) - axisRect.setLeft(axisRect.left() + leftOffset); + axisRect.setLeft( axisRect.left() + leftOffset ); } } - const int rightOffset = + const QRectF &rightScaleRect = scaleRect[QwtPlot::yRight]; + const int rightOffset = backboneOffset[QwtPlot::yRight] - endDist + 1; - if ( scaleRect[QwtPlot::yRight].isValid() ) + if ( rightScaleRect.isValid() ) { - int maxRight = scaleRect[QwtPlot::yRight].right(); - int right = axisRect.right() - rightOffset; - axisRect.setRight(qwtMin(right, maxRight)); + const int dx = rightOffset + rightScaleRect.width(); + if ( d_data->alignCanvasToScales && dx < 0 ) + { + /* + The axis needs more space than the width + of the right scale. + */ + canvasRect.setRight( qMin( canvasRect.right(), + axisRect.right() + dx ) ); + } + + const double maxRight = rightScaleRect.right(); + const double right = axisRect.right() - rightOffset; + axisRect.setRight( qMin( right, maxRight ) ); } else { if ( d_data->alignCanvasToScales && rightOffset < 0 ) { - canvasRect.setRight( qwtMin(canvasRect.right(), - axisRect.right() + rightOffset) ); + canvasRect.setRight( qMin( canvasRect.right(), + axisRect.right() + rightOffset ) ); } else { if ( rightOffset > 0 ) - axisRect.setRight(axisRect.right() - rightOffset); + axisRect.setRight( axisRect.right() - rightOffset ); } } } else // QwtPlot::yLeft, QwtPlot::yRight { - const int bottomOffset = + const QRectF &bottomScaleRect = scaleRect[QwtPlot::xBottom]; + const int bottomOffset = backboneOffset[QwtPlot::xBottom] - endDist + 1; - if ( scaleRect[QwtPlot::xBottom].isValid() ) + if ( bottomScaleRect.isValid() ) { - int maxBottom = scaleRect[QwtPlot::xBottom].top() + - d_data->layoutData.scale[QwtPlot::xBottom].tickOffset; - - int bottom = axisRect.bottom() - bottomOffset; - axisRect.setBottom(qwtMin(bottom, maxBottom)); + const int dy = bottomOffset + bottomScaleRect.height(); + if ( d_data->alignCanvasToScales && dy < 0 ) + { + /* + The axis needs more space than the height + of the bottom scale. + */ + canvasRect.setBottom( qMin( canvasRect.bottom(), + axisRect.bottom() + dy ) ); + } + else + { + const double maxBottom = bottomScaleRect.top() + + d_data->layoutData.scale[QwtPlot::xBottom].tickOffset; + const double bottom = axisRect.bottom() - bottomOffset; + axisRect.setBottom( qMin( bottom, maxBottom ) ); + } } else { if ( d_data->alignCanvasToScales && bottomOffset < 0 ) { - canvasRect.setBottom(qwtMin(canvasRect.bottom(), - axisRect.bottom() + bottomOffset)); + canvasRect.setBottom( qMin( canvasRect.bottom(), + axisRect.bottom() + bottomOffset ) ); } else { if ( bottomOffset > 0 ) - axisRect.setBottom(axisRect.bottom() - bottomOffset); + axisRect.setBottom( axisRect.bottom() - bottomOffset ); } } - + + const QRectF &topScaleRect = scaleRect[QwtPlot::xTop]; const int topOffset = backboneOffset[QwtPlot::xTop] - startDist; - if ( scaleRect[QwtPlot::xTop].isValid() ) + if ( topScaleRect.isValid() ) { - int minTop = scaleRect[QwtPlot::xTop].bottom() - - d_data->layoutData.scale[QwtPlot::xTop].tickOffset; - - int top = axisRect.top() + topOffset; - axisRect.setTop(qwtMax(top, minTop)); + const int dy = topOffset + topScaleRect.height(); + if ( d_data->alignCanvasToScales && dy < 0 ) + { + /* + The axis needs more space than the height + of the top scale. + */ + canvasRect.setTop( qMax( canvasRect.top(), + axisRect.top() - dy ) ); + } + else + { + const double minTop = topScaleRect.bottom() - + d_data->layoutData.scale[QwtPlot::xTop].tickOffset; + const double top = axisRect.top() + topOffset; + axisRect.setTop( qMax( top, minTop ) ); + } } else { if ( d_data->alignCanvasToScales && topOffset < 0 ) { - canvasRect.setTop(qwtMax(canvasRect.top(), - axisRect.top() - topOffset)); + canvasRect.setTop( qMax( canvasRect.top(), + axisRect.top() - topOffset ) ); } else { if ( topOffset > 0 ) - axisRect.setTop(axisRect.top() + topOffset); + axisRect.setTop( axisRect.top() + topOffset ); } } } @@ -1004,109 +1024,93 @@ void QwtPlotLayout::alignScales(int options, */ int fw = 0; - if ( !(options & IgnoreFrames) ) + if ( !( options & IgnoreFrames ) ) fw = d_data->layoutData.canvas.frameWidth; - if ( scaleRect[QwtPlot::xBottom].isValid() && - scaleRect[QwtPlot::xTop].isValid() ) + for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { - for ( int axis = QwtPlot::xBottom; axis <= QwtPlot::xTop; axis++ ) + if ( !scaleRect[axis].isValid() ) + continue; + + if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop ) { - scaleRect[axis].setLeft(canvasRect.left() + fw - - d_data->layoutData.scale[axis].start); - scaleRect[axis].setRight(canvasRect.right() - fw - 1 - + d_data->layoutData.scale[axis].end); + scaleRect[axis].setLeft( canvasRect.left() + fw + - d_data->layoutData.scale[axis].start ); + scaleRect[axis].setRight( canvasRect.right() - fw - 1 + + d_data->layoutData.scale[axis].end ); + } + else + { + scaleRect[axis].setTop( canvasRect.top() + fw + - d_data->layoutData.scale[axis].start ); + scaleRect[axis].setBottom( canvasRect.bottom() - fw - 1 + + d_data->layoutData.scale[axis].end ); } } - if ( scaleRect[QwtPlot::yLeft].isValid() && - scaleRect[QwtPlot::yRight].isValid() ) - { - for ( int axis = QwtPlot::yLeft; axis <= QwtPlot::yRight; axis++ ) - { - scaleRect[axis].setTop(canvasRect.top() + fw - - d_data->layoutData.scale[axis].start); - scaleRect[axis].setBottom(canvasRect.bottom() - fw - 1 - + d_data->layoutData.scale[axis].end); - } - } + if ( scaleRect[QwtPlot::xTop].isValid() ) + scaleRect[QwtPlot::xTop].setBottom( canvasRect.top() ); + if ( scaleRect[QwtPlot::xBottom].isValid() ) + scaleRect[QwtPlot::xBottom].setTop( canvasRect.bottom() ); + if ( scaleRect[QwtPlot::yLeft].isValid() ) + scaleRect[QwtPlot::yLeft].setRight( canvasRect.left() ); + if ( scaleRect[QwtPlot::yRight].isValid() ) + scaleRect[QwtPlot::yRight].setLeft( canvasRect.right() ); } } /*! - \brief Recalculate the geometry of all components. + \brief Recalculate the geometry of all components. \param plot Plot to be layout \param plotRect Rect where to place the components - \param options Options + \param options Layout options - \sa invalidate(), Options, titleRect(), + \sa invalidate(), titleRect(), legendRect(), scaleRect(), canvasRect() */ -void QwtPlotLayout::activate(const QwtPlot *plot, - const QRect &plotRect, int options) +void QwtPlotLayout::activate( const QwtPlot *plot, + const QRectF &plotRect, Options options ) { invalidate(); - QRect rect(plotRect); // undistributed rest of the plot rect - - if ( !(options & IgnoreMargin) ) - { - // subtract the margin - - rect.setRect( - rect.x() + d_data->margin, - rect.y() + d_data->margin, - rect.width() - 2 * d_data->margin, - rect.height() - 2 * d_data->margin - ); - } + QRectF rect( plotRect ); // undistributed rest of the plot rect // We extract all layout relevant data from the widgets, // filter them through pfilter and save them to d_data->layoutData. - d_data->layoutData.init(plot, rect); + d_data->layoutData.init( plot, rect ); - if (!(options & IgnoreLegend) + if ( !( options & IgnoreLegend ) && d_data->legendPos != QwtPlot::ExternalLegend && plot->legend() && !plot->legend()->isEmpty() ) { - d_data->legendRect = layoutLegend(options, rect); + d_data->legendRect = layoutLegend( options, rect ); // subtract d_data->legendRect from rect - const QRegion region(rect); - rect = region.subtract(d_data->legendRect).boundingRect(); + const QRegion region( rect.toRect() ); + rect = region.subtract( d_data->legendRect.toRect() ).boundingRect(); - if ( d_data->layoutData.legend.frameWidth && - !(options & IgnoreFrames ) ) + switch ( d_data->legendPos ) { - // In case of a frame we have to insert a spacing. - // Otherwise the leading of the font separates - // legend and scale/canvas - - switch(d_data->legendPos) - { - case QwtPlot::LeftLegend: - rect.setLeft(rect.left() + d_data->spacing); - break; - case QwtPlot::RightLegend: - rect.setRight(rect.right() - d_data->spacing); - break; - case QwtPlot::TopLegend: - rect.setTop(rect.top() + d_data->spacing); - break; - case QwtPlot::BottomLegend: - rect.setBottom(rect.bottom() - d_data->spacing); - break; - case QwtPlot::ExternalLegend: - break; // suppress compiler warning - } + case QwtPlot::LeftLegend: + rect.setLeft( rect.left() + d_data->spacing ); + break; + case QwtPlot::RightLegend: + rect.setRight( rect.right() - d_data->spacing ); + break; + case QwtPlot::TopLegend: + rect.setTop( rect.top() + d_data->spacing ); + break; + case QwtPlot::BottomLegend: + rect.setBottom( rect.bottom() - d_data->spacing ); + break; + case QwtPlot::ExternalLegend: + break; // suppress compiler warning } } -#ifdef __GNUC__ -#endif /* +---+-----------+---+ | Title | @@ -1125,17 +1129,17 @@ void QwtPlotLayout::activate(const QwtPlot *plot, // axes and title include text labels. The height of each // label depends on its line breaks, that depend on the width // for the label. A line break in a horizontal text will reduce - // the available width for vertical texts and vice versa. + // the available width for vertical texts and vice versa. // expandLineBreaks finds the height/width for title and axes // including all line breaks. int dimTitle, dimAxes[QwtPlot::axisCnt]; - expandLineBreaks(options, rect, dimTitle, dimAxes); + expandLineBreaks( options, rect, dimTitle, dimAxes ); - if (dimTitle > 0 ) + if ( dimTitle > 0 ) { - d_data->titleRect = QRect(rect.x(), rect.y(), - rect.width(), dimTitle); + d_data->titleRect = QRect( rect.x(), rect.y(), + rect.width(), dimTitle ); if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled != d_data->layoutData.scale[QwtPlot::yRight].isEnabled ) @@ -1143,20 +1147,20 @@ void QwtPlotLayout::activate(const QwtPlot *plot, // if only one of the y axes is missing we align // the title centered to the canvas - d_data->titleRect.setX(rect.x() + dimAxes[QwtPlot::yLeft]); - d_data->titleRect.setWidth(rect.width() - - dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight]); + d_data->titleRect.setX( rect.x() + dimAxes[QwtPlot::yLeft] ); + d_data->titleRect.setWidth( rect.width() + - dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight] ); } - // subtract title - rect.setTop(rect.top() + dimTitle + d_data->spacing); + // subtract title + rect.setTop( rect.top() + dimTitle + d_data->spacing ); } d_data->canvasRect.setRect( rect.x() + dimAxes[QwtPlot::yLeft], rect.y() + dimAxes[QwtPlot::xTop], rect.width() - dimAxes[QwtPlot::yRight] - dimAxes[QwtPlot::yLeft], - rect.height() - dimAxes[QwtPlot::xBottom] - dimAxes[QwtPlot::xTop]); + rect.height() - dimAxes[QwtPlot::xBottom] - dimAxes[QwtPlot::xTop] ); for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ ) { @@ -1165,33 +1169,29 @@ void QwtPlotLayout::activate(const QwtPlot *plot, if ( dimAxes[axis] ) { int dim = dimAxes[axis]; - QRect &scaleRect = d_data->scaleRect[axis]; + QRectF &scaleRect = d_data->scaleRect[axis]; scaleRect = d_data->canvasRect; - switch(axis) + switch ( axis ) { case QwtPlot::yLeft: - scaleRect.setX(d_data->canvasRect.left() - dim); - scaleRect.setWidth(dim); + scaleRect.setX( d_data->canvasRect.left() - dim ); + scaleRect.setWidth( dim ); break; case QwtPlot::yRight: - scaleRect.setX(d_data->canvasRect.right() + 1); - scaleRect.setWidth(dim); + scaleRect.setX( d_data->canvasRect.right() ); + scaleRect.setWidth( dim ); break; case QwtPlot::xBottom: - scaleRect.setY(d_data->canvasRect.bottom() + 1); - scaleRect.setHeight(dim); + scaleRect.setY( d_data->canvasRect.bottom() ); + scaleRect.setHeight( dim ); break; case QwtPlot::xTop: - scaleRect.setY(d_data->canvasRect.top() - dim); - scaleRect.setHeight(dim); + scaleRect.setY( d_data->canvasRect.top() - dim ); + scaleRect.setHeight( dim ); break; } -#if QT_VERSION < 0x040000 - scaleRect = scaleRect.normalize(); -#else scaleRect = scaleRect.normalized(); -#endif } } @@ -1214,14 +1214,14 @@ void QwtPlotLayout::activate(const QwtPlot *plot, // be aligned to the canvas. So we try to use the empty // corners to extend the axes, so that the label texts // left/right of the min/max ticks are moved into them. - - alignScales(options, d_data->canvasRect, d_data->scaleRect); - if (!d_data->legendRect.isEmpty() ) + alignScales( options, d_data->canvasRect, d_data->scaleRect ); + + if ( !d_data->legendRect.isEmpty() ) { // We prefer to align the legend to the canvas - not to // the complete plot - if possible. - d_data->legendRect = alignLegend(d_data->canvasRect, d_data->legendRect); + d_data->legendRect = alignLegend( d_data->canvasRect, d_data->legendRect ); } } diff --git a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_layout.h b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_layout.h index cdc6603ff..6073768d0 100644 --- a/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_layout.h +++ b/ground/openpilotgcs/src/libs/qwt/src/qwt_plot_layout.h @@ -2,7 +2,7 @@ * Qwt Widget Library * Copyright (C) 1997 Josef Wilgen * Copyright (C) 2002 Uwe Rathmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the Qwt License, Version 1.0 *****************************************************************************/ @@ -26,78 +26,73 @@ class QWT_EXPORT QwtPlotLayout public: /*! Options to configure the plot layout engine - - - AlignScales\n - Unused - - IgnoreScrollbars\n - Ignore the dimension of the scrollbars. There are no - scrollbars, when the plot is rendered to a paint device - (QwtPlot::print() ). - - IgnoreFrames\n - Ignore all frames. QwtPlot::print() doesn't paint them. - - IgnoreMargin\n - Ignore the margin(). - - IgnoreLegend\n - Ignore the legend. - - \sa activate() + \sa activate(), QwtPlotRenderer */ - enum Options + enum Option { - AlignScales = 1, - IgnoreScrollbars = 2, - IgnoreFrames = 4, - IgnoreMargin = 8, - IgnoreLegend = 16 + //! Unused + AlignScales = 0x01, + + /*! + Ignore the dimension of the scrollbars. There are no + scrollbars, when the plot is not rendered to widgets. + */ + IgnoreScrollbars = 0x02, + + //! Ignore all frames. + IgnoreFrames = 0x04, + + //! Ignore the legend. + IgnoreLegend = 0x08 }; + //! Layout options + typedef QFlags