1 /*************************************************************************** 2 namedobject.h: adds naming features to objects... 3 ------------------- 4 begin : May 29, 2008 5 copyright : (C) 2008 C. Barth Netterfield 6 email : netterfield@astro.utoronto.ca 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 // name system: see object names devel doc for intended behavior 18 19 20 #ifndef NAMEDOBJECT_H 21 #define NAMEDOBJECT_H 22 23 #include <QString> 24 #include <QXmlStreamWriter> 25 #include <QFont> 26 #include "kst_export.h" 27 28 namespace Kst { 29 30 // short name index variables 31 KSTCORE_EXPORT extern int _vectornum; // vectors 32 KSTCORE_EXPORT extern int _pluginnum; // plugins 33 KSTCORE_EXPORT extern int _csdnum; // csd 34 KSTCORE_EXPORT extern int _curvecnum; // curves 35 KSTCORE_EXPORT extern int _equationnum; // equations 36 KSTCORE_EXPORT extern int _histogramnum; // histograms 37 KSTCORE_EXPORT extern int _imagenum; // images 38 KSTCORE_EXPORT extern int _psdnum; // psd 39 KSTCORE_EXPORT extern int _scalarnum; // scalars 40 KSTCORE_EXPORT extern int _stringnum; // text string 41 KSTCORE_EXPORT extern int _matrixnum; // matrix 42 KSTCORE_EXPORT extern int _plotnum; // plot item 43 KSTCORE_EXPORT extern int _legendnum; // legend 44 KSTCORE_EXPORT extern int _viewitemnum; // view item (drawable) 45 KSTCORE_EXPORT extern int _datasourcenum; // datasource 46 47 KSTCORE_EXPORT extern int max_vectornum; // vectors 48 KSTCORE_EXPORT extern int max_pluginnum; // plugins 49 KSTCORE_EXPORT extern int max_csdnum; // csd 50 KSTCORE_EXPORT extern int max_curvenum; // curves 51 KSTCORE_EXPORT extern int max_equationnum; // equations 52 KSTCORE_EXPORT extern int max_histogramnum; // histograms 53 KSTCORE_EXPORT extern int max_imagenum; // images 54 KSTCORE_EXPORT extern int max_psdnum; // psd 55 KSTCORE_EXPORT extern int max_scalarnum; // scalars 56 KSTCORE_EXPORT extern int max_stringnum; // string 57 KSTCORE_EXPORT extern int max_matrixnum; // matrix 58 KSTCORE_EXPORT extern int max_plotnum; // plot item 59 KSTCORE_EXPORT extern int max_legendnum; // legend 60 KSTCORE_EXPORT extern int max_viewitemnum; // view item 61 KSTCORE_EXPORT extern int max_datasourcenum; // datasource 62 63 struct SizeCache { 64 int nameWidthPixels; 65 int fontSize; 66 QString name; 67 }; 68 69 KSTCORE_EXPORT void resetNameIndexes(); 70 71 class KSTCORE_EXPORT NamedObject 72 { 73 public: 74 NamedObject(); 75 virtual ~NamedObject(); 76 77 enum ShortNameIndex { 78 VECTORNUM = 0x0001, 79 PLUGINNUM = 0x0002, 80 CSDNUM = 0x0004, 81 CURVENUM = 0x0008, 82 EQUATIONNUM = 0x0010, 83 HISTOGRAMNUM = 0x0020, 84 IMAGENUM = 0x0040, 85 PSDNUM = 0x0080, 86 SCALARNUM = 0x0100, 87 STRINGNUM = 0x0200, 88 MATRIXNUM = 0x0400, 89 PLOTNUM = 0x0800, 90 LEGENDNUM = 0x1000, 91 VIEWITEMNUM = 0x2000, 92 DATASOURCENUM= 0x4000 93 }; 94 95 // name system: see object names devel doc 96 QString Name() const; // eg GYRO1 (V1) 97 QString CleanedName() const; // all \_ replaced with _ 98 QString descriptiveName() const; // eg GYRO1: automatic or manual 99 QString shortName() const; // eg V1: always automatically generated 100 QString lengthLimitedName(int length = 20) const; // Name, but with descriptiveName truncated 101 QString sizeLimitedName(const QFont&font,const int&width) const; // Name, shrunk to fit in width with font 102 QString sizeLimitedName(const QWidget *widget) const; // Name, shrunk to fit in widget 103 virtual QString descriptionTip() const = 0; // description for tooltips 104 void setDescriptiveName(QString new_name); // auto if new_name.isEmpty() 105 bool descriptiveNameIsManual() const; 106 static void processShortNameIndexAttributes(QXmlStreamAttributes &attrs); 107 108 // Reset all name indexes. Should only be used by ObjectStore when clearing the store entirely. 109 static void resetNameIndex(); 110 111 protected: 112 virtual QString _automaticDescriptiveName() const= 0; 113 virtual void _initializeShortName() = 0; 114 QString _manualDescriptiveName; 115 QString _shortName; 116 virtual void saveNameInfo(QXmlStreamWriter &s, unsigned I = 0xffff); 117 118 // object indices used for saving/resorting shortnames 119 int _initial_vectornum; // vectors 120 int _initial_pluginnum; // plugins 121 int _initial_csdnum; // csd 122 int _initial_curvenum; // curves 123 int _initial_equationnum; // equations 124 int _initial_histogramnum; // histograms 125 int _initial_imagenum; // images 126 int _initial_psdnum; // psd 127 int _initial_scalarnum; // scalars 128 int _initial_stringnum; // text string 129 int _initial_matrixnum; // matrix 130 131 int _initial_plotnum; // plot item 132 int _initial_legendnum; // legend 133 int _initial_viewitemnum; // view item 134 int _initial_datasourcenum; // datasource 135 private: 136 SizeCache *_sizeCache; 137 }; 138 139 KSTCORE_EXPORT bool shortNameLessThan(NamedObject *n1, NamedObject *n2); 140 141 } 142 #endif 143