Class: MxxRu::Cpp::Qt4

Inherits:
AbstractGenerator show all
Defined in:
lib/mxx_ru/cpp/qt4details.rb

Overview

Files generator for Qt4 class.

Main features:

  • building of moc-files using moc tool. Generation from source and header files is supported.

  • building header files from ui-files using uic-compiler.

Generated source files automatically added into cpp_source list of target.

Local list defines is supported.

If only pointer to the target passed into contructor, default list of defines is used. If it’s required to change default list, new list should be passed through a second argument:

generator( MxxRu::Cpp::Qt4.new( self, [ "QT_DEPRECATED_WARNINGS" ] ) )

Constant Summary collapse

DEFAULT_DEFINES =

Default list of defines. QT_DLL

[ 'QT_DLL', 'QT_THREAD_SUPPORT' ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a_target, a_defines = DEFAULT_DEFINES) ⇒ Qt4

Constructor.



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/mxx_ru/cpp/qt4details.rb', line 229

def initialize( a_target, a_defines = DEFAULT_DEFINES )
  @moc_name = "moc"
  @uic_name = "uic"
  @rcc_name = "rcc"
  @cpp_ext = ".cpp"
  @hpp_ext = ".h"
  @moc_ext = ".moc"
  @moc_result_subdir = nil
  @uic_result_subdir = nil
  @qrc_result_subdir = nil
  @lupdate_name = 'lupdate'
  @lupdate_options = [ '-noobsolete', '-silent' ]

  # If uic_result_subdir not nil than we must add
  # uic_result_subdir into
  # target include_path. But must do this only one time.
  @uic_result_subdir_include_paths = Set.new

  @qt_h2moc_files = []
  @qt_cpp2moc_files = []
  @qt_ui_files = []
  @qt_qrc2cpp_files = []
  @qt_qrc2rcc_files = []
  @qt_ts_files = []

  defines_to_set = a_defines.flatten
  defines_to_set.each { |d| a_target.define( d ) }

  @target = a_target

  # QtCore must be used.
  use_module Qt4Modules::QT_CORE
end

Instance Attribute Details

#cpp_extObject

File extension for source files generated. Used in both moc and uic tools. Default: .cpp



154
155
156
# File 'lib/mxx_ru/cpp/qt4details.rb', line 154

def cpp_ext
  @cpp_ext
end

#hpp_extObject

File extension for header files generated. Used in uic tool. Default: .h



159
160
161
# File 'lib/mxx_ru/cpp/qt4details.rb', line 159

def hpp_ext
  @hpp_ext
end

#lupdate_nameObject

Name of lupdate tool.

Default value: lupdate.



223
224
225
# File 'lib/mxx_ru/cpp/qt4details.rb', line 223

def lupdate_name
  @lupdate_name
end

#lupdate_optionsObject

List of options for lupdate utility.

Default value: [ ‘-noobsolete’, ‘-silent’ ]



217
218
219
# File 'lib/mxx_ru/cpp/qt4details.rb', line 217

def lupdate_options
  @lupdate_options
end

#moc_extObject

File extension for moc files generated. Used in moc tool. Default: .moc



164
165
166
# File 'lib/mxx_ru/cpp/qt4details.rb', line 164

def moc_ext
  @moc_ext
end

#moc_nameObject

moc tool executable Default: moc



141
142
143
# File 'lib/mxx_ru/cpp/qt4details.rb', line 141

def moc_name
  @moc_name
end

#moc_result_subdirObject

Subfolder name where moc generated files would be located. If nil, generated files would be in the same folder where source files were. Default: nil



170
171
172
# File 'lib/mxx_ru/cpp/qt4details.rb', line 170

def moc_result_subdir
  @moc_result_subdir
end

#qrc_result_subdirObject

Subfolder name where results of rcc invokation must be placed. If nil, generated files would be in the same folder where source qrc files were. Used only for qrc2cpp translation.



181
182
183
# File 'lib/mxx_ru/cpp/qt4details.rb', line 181

def qrc_result_subdir
  @qrc_result_subdir
end

#qt_cpp2moc_filesObject (readonly)

Files list for generating moc files from source files.

More exact: a.cpp -> a.moc.



192
193
194
# File 'lib/mxx_ru/cpp/qt4details.rb', line 192

def qt_cpp2moc_files
  @qt_cpp2moc_files
end

#qt_h2moc_filesObject (readonly)

Files list for generating moc files from header files.

More exact: a.hpp -> moc_a.cpp. moc_a.cpp file is added to cpp_source list of a target.



187
188
189
# File 'lib/mxx_ru/cpp/qt4details.rb', line 187

def qt_h2moc_files
  @qt_h2moc_files
end

#qt_qrc2cpp_filesObject (readonly)

Files list for generating source files from qrc files.

More exact: a.qrc -> qrc_a.cpp



202
203
204
# File 'lib/mxx_ru/cpp/qt4details.rb', line 202

def qt_qrc2cpp_files
  @qt_qrc2cpp_files
end

#qt_qrc2rcc_filesObject (readonly)

Files list for generating binary resource files from qrc files.

More exact: a.qrc -> a.rcc



207
208
209
# File 'lib/mxx_ru/cpp/qt4details.rb', line 207

def qt_qrc2rcc_files
  @qt_qrc2rcc_files
end

#qt_ts_filesObject (readonly)

File list for translations.



211
212
213
# File 'lib/mxx_ru/cpp/qt4details.rb', line 211

def qt_ts_files
  @qt_ts_files
end

#qt_ui_filesObject (readonly)

Files list for generating header files from ui files.

More exact: a.ui -> ui_a.hpp



197
198
199
# File 'lib/mxx_ru/cpp/qt4details.rb', line 197

def qt_ui_files
  @qt_ui_files
end

#rcc_nameObject

rcc tool executable Default: rcc.



149
150
151
# File 'lib/mxx_ru/cpp/qt4details.rb', line 149

def rcc_name
  @rcc_name
end

#targetObject (readonly)

Target, generator is created for.



226
227
228
# File 'lib/mxx_ru/cpp/qt4details.rb', line 226

def target
  @target
end

#uic_nameObject

uic tool executable Default: uic.



145
146
147
# File 'lib/mxx_ru/cpp/qt4details.rb', line 145

def uic_name
  @uic_name
end

#uic_result_subdirObject

Subfolder name where results of uic invokation must be placed. If nil, generated files would be in the same folder where source ui files were.



175
176
177
# File 'lib/mxx_ru/cpp/qt4details.rb', line 175

def uic_result_subdir
  @uic_result_subdir
end

Instance Method Details

#build(a_target) ⇒ Object

Perform files generation.



324
325
326
327
328
329
330
331
# File 'lib/mxx_ru/cpp/qt4details.rb', line 324

def build( a_target )
  build_from_ui( a_target )
  build_from_qrc2cpp( a_target )
  build_from_qrc2rcc( a_target )
  build_from_h( a_target )
  build_from_cpp( a_target )
  build_translations( a_target )
end

#clean(a_target) ⇒ Object

Perform generated files cleanup.



334
335
336
337
338
339
340
# File 'lib/mxx_ru/cpp/qt4details.rb', line 334

def clean( a_target )
  clean_from_ui( a_target )
  clean_from_qrc2cpp( a_target )
  clean_from_qrc2rcc( a_target )
  clean_from_h( a_target )
  clean_from_cpp( a_target )
end

#cpp2moc(a_file) ⇒ Object

Add a file for cpp to moc generation.



269
270
271
# File 'lib/mxx_ru/cpp/qt4details.rb', line 269

def cpp2moc( a_file )
  @qt_cpp2moc_files << @target.create_full_src_file_name( a_file )
end

#h2moc(a_file) ⇒ Object

Add a file for hpp to moc generation.



264
265
266
# File 'lib/mxx_ru/cpp/qt4details.rb', line 264

def h2moc( a_file )
  @qt_h2moc_files << @target.create_full_src_file_name( a_file )
end

#lib_qtmainObject

Add qtmain component for target.



343
344
345
346
# File 'lib/mxx_ru/cpp/qt4details.rb', line 343

def lib_qtmain
  @target.lib 'qtmain'
  self
end

#qrc2cpp(a_file) ⇒ Object

Add a file for qrc to cpp generation.



288
289
290
291
# File 'lib/mxx_ru/cpp/qt4details.rb', line 288

def qrc2cpp( a_file )
  full_file_name = @target.create_full_src_file_name( a_file )
  @qt_qrc2cpp_files << full_file_name
end

#qrc2rcc(a_file) ⇒ Object

Add a file for qrc to rcc generation.



294
295
296
297
# File 'lib/mxx_ru/cpp/qt4details.rb', line 294

def qrc2rcc( a_file )
  full_file_name = @target.create_full_src_file_name( a_file )
  @qt_qrc2rcc_files << full_file_name
end

#ts(a_name) ⇒ Object

Add translation file.

a_file – name of .ts-file.



319
320
321
# File 'lib/mxx_ru/cpp/qt4details.rb', line 319

def ts( a_name )
  @qt_ts_files << a_name
end

#ui(a_file) ⇒ Object

Add a file for ui to hpp generation.



274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/mxx_ru/cpp/qt4details.rb', line 274

def ui( a_file )
  full_file_name = @target.create_full_src_file_name( a_file )
  @qt_ui_files << full_file_name
  if @uic_result_subdir
    uic_result_path = make_uic_result_path_for( full_file_name )

    if !@uic_result_subdir_include_paths.member?( uic_result_path )
      @target.include_path( uic_result_path )
      @uic_result_subdir_include_paths.add( uic_result_path )
    end
  end
end

#use_module(a_module) ⇒ Object

Add a Qt4 module to target.

a_module – an instance of Qt4Modules::ModuleDescription.



302
303
304
305
# File 'lib/mxx_ru/cpp/qt4details.rb', line 302

def use_module( a_module )
  @target.define a_module.define
  @target.lib make_library_name( a_module.library )
end

#use_modules(*a_modules) ⇒ Object

Add some Qt4 modules to target.

a_modules – an enumeration of Qt4Modules::ModuleDescription instances.



311
312
313
# File 'lib/mxx_ru/cpp/qt4details.rb', line 311

def use_modules( *a_modules )
  a_modules.each { |m| use_module( m ) }
end