Developer documentation | Axl-2.5.1

axlInspectorObjectFactory.cpp
Go to the documentation of this file.
1 /* axlInspectorObjectFactory.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Julien Wintz, Inria.
5  * Created: mar. mars 29 12:35:33 2011 (+0200)
6  * Version: $Id$
7  * Last-Updated: Wed Apr 20 14:03:24 2011 (+0200)
8  * By: Julien Wintz
9  * Update #: 20
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
21 
22 // /////////////////////////////////////////////////////////////////
23 //
24 // /////////////////////////////////////////////////////////////////
25 
27 {
29 }
30 
32 {
33 
34 }
35 
37 {
39 }
40 
42 {
44 }
45 
46 void axlInspectorObjectInterface::setData(dtkAbstractData *data)
47 {
48  qDebug()<<"axlInspectorObjectInterface::setData : Default implementation";
49 }
50 
51 
52 void axlInspectorObjectInterface::initComboBoxShaderValue(QComboBox *comboBoxShader, QLineEdit *lineEditShader)
53 {
54  if(comboBoxShader) {
55 
56  QStringList filters;
57  filters << "*.vs";
58 
59  // First add item of axlShader.qrc, then find shader from shader path
60  QDir dirShader( ":axlShader/shader/");
61  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
62 
63  dirShader.setNameFilters(filters);
64 
65  QFileInfoList list = dirShader.entryInfoList();
66  // for (int i = 0; i < list.size(); ++i) {
67  // d->comboBoxShader->addItem(list.at(i).fileName());
68  // }
69 
70  QSettings settings("inria", "dtk");
71  QString defaultPath;
72  settings.beginGroup("shader");
73  QString defaultPathShader = settings.value("path", defaultPath).toString();
74  defaultPathShader.append("/");
75 
76  QDir defaultDirShader(defaultPathShader);
77  defaultDirShader.setNameFilters(filters);
78  QFileInfoList list2 = defaultDirShader.entryInfoList();
79 
80  list.append(list2);
81 
82  QStringList items;
83 
84  for (int i = 0; i < list.size(); ++i) {
85  if(!items.contains(list.at(i).fileName()))
86  items << list.at(i).fileName();
87  }
88 
89  qSort(items.begin(), items.end(), caseInsensitiveLessThan);
90  int indInitShader = -1;
91  int indCurrentShader = -1;
92 
93  foreach(QString item, items) {
94  indCurrentShader++;
95  comboBoxShader->addItem(item);
96 
97  QFileInfo currentFileInfo(lineEditShader->text());
98 
99  if(currentFileInfo.exists())
100  {
101  if(item == currentFileInfo.fileName())
102  indInitShader =indCurrentShader;
103  }
104  }
105 
106  //init the value from the lineEditShader.
107  if(indInitShader != -1)
108  comboBoxShader->setCurrentIndex(indInitShader);
109  }
110 }
111 
112 
113 QString axlInspectorObjectInterface::filePath(const QString& shader)
114 {
115 
116  // First add item of axlShader.qrc, then find shader from shader path
117  QDir dirShader( ":axlShader/shader/");
118  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
119 
120  QFileInfo currentFile(dirShader, shader);
121  if(!currentFile.exists())
122  {
123  QSettings settings("inria", "dtk");
124  QString defaultPath;
125  settings.beginGroup("shader");
126  QString defaultPathShader = settings.value("path", defaultPath).toString();
127  defaultPathShader.append("/");
128 
129  QDir defaultDirShader(defaultPathShader);
130  currentFile = QFileInfo(defaultDirShader, shader);
131 
132  }
133  return currentFile.absoluteFilePath();
134 }
135 
136 // /////////////////////////////////////////////////////////////////
137 //
138 // /////////////////////////////////////////////////////////////////
139 
140 class axlInspectorObjectFactoryPrivate
141 {
142 public:
144 };
145 
147 {
148  if(!s_instance)
150 
151  return s_instance;
152 }
153 
154 bool axlInspectorObjectFactory::registerInspectorObject(const QString& interface_name, axlInspectorObjectCreator func)
155 {
156  if(!d->creators.contains(interface_name))
157  d->creators.insert(interface_name, func);
158 
159  return true;
160 }
161 
163 {
164  if(!d->creators.contains(interface_name))
165  return NULL;
166 
167  return d->creators[interface_name]();
168 }
169 
170 
171 
172 axlInspectorObjectFactory::axlInspectorObjectFactory(void) : QObject(), d(new axlInspectorObjectFactoryPrivate)
173 {
174 
175 }
176 
177 axlInspectorObjectFactory::~axlInspectorObjectFactory(void)
178 {
179  delete d;
180 
181  d = NULL;
182 }
183 
bool registerInspectorObject(const QString &interface_name, axlInspectorObjectCreator func)
axlInspectorObjectInterface * create(const QString &interface_name)
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
static axlInspectorObjectFactory * instance(void)
virtual void setData(dtkAbstractData *data)
void setObjectFactorySingleton(axlInspectorObjectFactory *objectFactorySingleton)
static axlInspectorObjectFactory * s_instance
QHash< QString, axlInspectorObjectCreator > axlInspectorObjectCreatorHash
void initComboBoxShaderValue(QComboBox *comboBoxShader, QLineEdit *lineEditShader)
axlInspectorObjectFactory * objectFactorySingleton(void)
axlInspectorObjectFactory * m_objectFactorySingleton
QString filePath(const QString &shader)