File indexing completed on 2024-06-02 04:34:50

0001 /***************************************************************************
0002                  namedobject.h: adds naming features to objects...
0003                              -------------------
0004     begin                : May 29, 2008
0005     copyright            : (C) 2008 C. Barth Netterfield
0006     email                : netterfield@astro.utoronto.ca
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 // name system: see object names devel doc for intended behavior
0018 
0019 
0020 #ifndef NAMEDOBJECT_H
0021 #define NAMEDOBJECT_H
0022 
0023 #include <QString>
0024 #include <QXmlStreamWriter>
0025 #include <QFont>
0026 #include "kst_export.h"
0027 
0028 namespace Kst {
0029 
0030 // short name index variables
0031 KSTCORE_EXPORT extern int _vectornum; // vectors
0032 KSTCORE_EXPORT extern int _pluginnum; // plugins
0033 KSTCORE_EXPORT extern int _csdnum; // csd
0034 KSTCORE_EXPORT extern int _curvecnum; // curves
0035 KSTCORE_EXPORT extern int _equationnum; // equations
0036 KSTCORE_EXPORT extern int _histogramnum; // histograms
0037 KSTCORE_EXPORT extern int _imagenum; // images
0038 KSTCORE_EXPORT extern int _psdnum; // psd
0039 KSTCORE_EXPORT extern int _scalarnum; // scalars
0040 KSTCORE_EXPORT extern int _stringnum; // text string
0041 KSTCORE_EXPORT extern int _matrixnum; // matrix
0042 KSTCORE_EXPORT extern int _plotnum; // plot item
0043 KSTCORE_EXPORT extern int _legendnum; // legend
0044 KSTCORE_EXPORT extern int _viewitemnum; // view item (drawable)
0045 KSTCORE_EXPORT extern int _datasourcenum; // datasource
0046 
0047 KSTCORE_EXPORT extern int max_vectornum; // vectors
0048 KSTCORE_EXPORT extern int max_pluginnum; // plugins
0049 KSTCORE_EXPORT extern int max_csdnum; // csd
0050 KSTCORE_EXPORT extern int max_curvenum; // curves
0051 KSTCORE_EXPORT extern int max_equationnum; // equations
0052 KSTCORE_EXPORT extern int max_histogramnum; // histograms
0053 KSTCORE_EXPORT extern int max_imagenum; // images
0054 KSTCORE_EXPORT extern int max_psdnum; // psd
0055 KSTCORE_EXPORT extern int max_scalarnum; // scalars
0056 KSTCORE_EXPORT extern int max_stringnum; // string
0057 KSTCORE_EXPORT extern int max_matrixnum; // matrix
0058 KSTCORE_EXPORT extern int max_plotnum; // plot item
0059 KSTCORE_EXPORT extern int max_legendnum; // legend
0060 KSTCORE_EXPORT extern int max_viewitemnum; // view item
0061 KSTCORE_EXPORT extern int max_datasourcenum; // datasource
0062 
0063 struct SizeCache {
0064     int nameWidthPixels;
0065     int fontSize;
0066     QString name;
0067 };
0068 
0069 KSTCORE_EXPORT void resetNameIndexes();
0070 
0071 class KSTCORE_EXPORT NamedObject 
0072 {
0073 public: 
0074      NamedObject();
0075      virtual ~NamedObject();
0076 
0077      enum ShortNameIndex {
0078       VECTORNUM    = 0x0001,
0079       PLUGINNUM    = 0x0002,
0080       CSDNUM       = 0x0004,
0081       CURVENUM     = 0x0008,
0082       EQUATIONNUM  = 0x0010,
0083       HISTOGRAMNUM = 0x0020,
0084       IMAGENUM     = 0x0040,
0085       PSDNUM       = 0x0080,
0086       SCALARNUM    = 0x0100,
0087       STRINGNUM    = 0x0200,
0088       MATRIXNUM    = 0x0400,
0089       PLOTNUM      = 0x0800,
0090       LEGENDNUM    = 0x1000,
0091       VIEWITEMNUM  = 0x2000,
0092       DATASOURCENUM= 0x4000
0093     };
0094 
0095     // name system: see object names devel doc
0096     QString Name() const; // eg GYRO1 (V1)
0097     QString CleanedName() const; // all \_ replaced with _
0098     QString descriptiveName() const; // eg GYRO1: automatic or manual
0099     QString shortName() const; // eg V1: always automatically generated
0100     QString lengthLimitedName(int length = 20) const; // Name, but with descriptiveName truncated
0101     QString sizeLimitedName(const QFont&font,const int&width) const; // Name, shrunk to fit in width with font
0102     QString sizeLimitedName(const QWidget *widget) const; // Name, shrunk to fit in widget
0103     virtual QString descriptionTip() const = 0; // description for tooltips
0104     void setDescriptiveName(QString new_name); // auto if new_name.isEmpty()
0105     bool descriptiveNameIsManual() const;
0106     static void processShortNameIndexAttributes(QXmlStreamAttributes &attrs);
0107 
0108     // Reset all name indexes.  Should only be used by ObjectStore when clearing the store entirely.
0109     static void resetNameIndex();
0110 
0111   protected:
0112     virtual QString _automaticDescriptiveName() const= 0;
0113     virtual void _initializeShortName() = 0;
0114     QString _manualDescriptiveName;
0115     QString _shortName;
0116     virtual void saveNameInfo(QXmlStreamWriter &s, unsigned I = 0xffff);
0117 
0118     // object indices used for saving/resorting shortnames
0119     int _initial_vectornum; // vectors
0120     int _initial_pluginnum; // plugins
0121     int _initial_csdnum; // csd
0122     int _initial_curvenum; // curves
0123     int _initial_equationnum; // equations
0124     int _initial_histogramnum; // histograms
0125     int _initial_imagenum; // images
0126     int _initial_psdnum; // psd
0127     int _initial_scalarnum; // scalars
0128     int _initial_stringnum; // text string
0129     int _initial_matrixnum; // matrix
0130 
0131     int _initial_plotnum; // plot item
0132     int _initial_legendnum; // legend
0133     int _initial_viewitemnum; // view item
0134     int _initial_datasourcenum; // datasource
0135   private:
0136     SizeCache *_sizeCache;
0137 };
0138 
0139 KSTCORE_EXPORT bool shortNameLessThan(NamedObject *n1, NamedObject *n2);
0140 
0141 }
0142 #endif