File indexing completed on 2024-07-14 07:17:25

0001 /*
0002     SPDX-FileCopyrightText: 2010 Akarsh Simha <akarsh.simha@kdemail.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "skycomponent.h"
0010 
0011 #include <QPen>
0012 
0013 /**
0014  * @class TargetListComponent
0015  * @short Highlights objects present in certain lists by drawing "target" symbols around them.
0016  *
0017  * To represent lists of specific objects on the skymap (eg: A star
0018  * hopping route, or a list of planned observation targets), one would
0019  * typically like to draw over the skymap, a bunch of symbols
0020  * highlighting the locations of these objects. This class manages
0021  * drawing of such lists. Along with the list, we also associate a pen
0022  * to use to represent objects from that list. Once this class is made
0023  * aware of a list to plot (which is stored somewhere else), it does
0024  * so when called from the SkyMapComposite. The class may be supplied
0025  * with pointers to two methods that tell it whether to draw symbols /
0026  * labels or not. Disabling symbol drawing is equivalent to disabling
0027  * the list. If the pointers are nullptr, the symbols are always drawn,
0028  * but the labels are not drawn.
0029  *
0030  * @note This does not inherit from ListComponent because it is not
0031  * necessary. ListComponent has extra methods like objectNearest(),
0032  * which we don't want. Also, ListComponent maintains its own list,
0033  * whereas this class merely holds a pointer to a list that's
0034  * manipulated from elsewhere.
0035  */
0036 
0037 class TargetListComponent : public SkyComponent
0038 {
0039   public:
0040     /**
0041      * @short Default constructor.
0042      */
0043     explicit TargetListComponent(SkyComposite *parent);
0044 
0045     /**
0046      * @short Constructor that sets up this target list
0047      */
0048     TargetListComponent(SkyComposite *parent, QList<SkyObject *> *objectList, QPen _pen,
0049                         bool (*optionDrawSymbols)(void) = nullptr, bool (*optionDrawLabels)(void) = nullptr);
0050 
0051     ~TargetListComponent() override;
0052 
0053     /**
0054      * @short Draw this component by iterating over the list.
0055      *
0056      * @note This method does not bother refreshing the coordinates of
0057      * the objects on the list. So this must be called only after the
0058      * objects are drawn in a given draw cycle.
0059      */
0060     void draw(SkyPainter *skyp) override;
0061 
0062     // FIXME: Maybe we should make these member objects private / protected?
0063     /// Pointer to list of objects to draw
0064     std::unique_ptr<SkyObjectList> list;
0065     /// Pointer to list of objects to draw
0066     QList<QSharedPointer<SkyObject>> list2;
0067     /// Pen to use to draw
0068     QPen pen;
0069 
0070     /**
0071      * @short Pointer to static method that tells us whether to draw this list or not
0072      * @note If the pointer is nullptr, the list is drawn nevertheless
0073      */
0074     bool (*drawSymbols)(void);
0075 
0076     /**
0077      * @short Pointer to static method that tells us whether to draw labels for this list or not
0078      * @note If the pointer is nullptr, labels are not drawn
0079      */
0080     bool (*drawLabels)(void);
0081 };