Commit 32104088 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Merge branch 'master' into chouquette_sound_workflow

Conflicts:
	src/Workflow/MainWorkflow.cpp
	src/Workflow/TrackHandler.cpp
parents 9f0de1f0 3acd0490
Hacking on VLMC
---------------
Thanks
------
Most parts of this guide are taken from the Amarok coding rules.
This C++ FAQ is a life saver in many situations, so you want to keep it handy:
http://www.parashift.com/c++-faq-lite/
Formatting
----------
* Spaces, not tabs
* Indentation is 4 spaces
* No trailing spaces
* Lines should be limited to 90 characters
* Spaces between brackets and argument functions
* Spaces before and after operators
* For pointer and reference variable declarations put a space between the type
and the * or & and no space before the variable name.
* For if, else, while and similar statements put the brackets on the next line,
although brackets are not needed for single statements.
* Function and class definitions have their brackets on separate lines
* A function implementation's return type is on its own line.
* A return keyword must be used without parenthesis.
* CamelCase.{cpp,h} style file names.
* Qt 4 includes a foreach keyword which makes it very easy to iterate over all
elements of a container.
Example:
| bool
| MyClass::myMethod( QStringList list, const QString &name )
| {
| if( list.isEmpty() )
| return false;
|
| /*
| Define the temporary variable like this to restrict its scope
| when you do not need it outside the loop. Let the compiler
| optimise it.
| */
| foreach( const QString &string, list )
| debug() << "Current string is " << string;
| }
The program astyle can be used to automatically format source code, which can
be useful for badly formatted 3rd party patches.
Use it like this to get (approximately) VLMC formatting style:
"astyle -s4 -b -p -U -D -o source.cpp"
Class, Function, Enums & Variable Naming
---------------------------------
* Use CamelCase for everything.
* Local variables should start out with a lowercase letter.
* Class names are capitalized
* Prefix class member variables with m_, ex. m_tracksView.
* Prefix static member variables with s_, ex s_instance
* Functions are named in the Qt style. It's like Java's, without the "get"
prefix.
* A getter is variable()
* If it's a getter for a boolean, prefix with 'is', so isCondition()
* A setter is setVariable( arg ).
Best Practices
--------------
* Focus on code portability
* Focus on code readability
* Do not overload an operator without a valid justification
* For each overloaded operator, there must be an equivalent method
* Do not use reinterpret_cast without a valid justification
* Do not write functions and/or methods of more than 100 lines
Includes
--------
Header includes should be listed in the following order:
- Own Header
- VLMC includes
- Qt includes
They should also be sorted alphabetically, for ease of locating them. A small
comment if applicable is also helpful.
Includes in a header file should be kept to the absolute minimum, as to keep
compile times low. This can be achieved by using "forward declarations"
instead of includes, like "class QListView;". Forward declarations work for
pointers and const references.
In vim you can sort headers automatically by marking the block, and then
doing ":sort".
Example:
| #include "MySuperWidget.h"
|
| #include "Timeline.h"
| #include "TracksRuler.h"
| #include "TracksView.h"
|
| #include <QGraphicsView>
| #include <QWidget>
Comments
--------
Comment your code. Don't comment what the code does, comment on the purpose of
the code. It's good for others reading your code, and ultimately it's good for
you too. Every method must be commented (in Doxygen format), including
potential return value and potential parameters.
For headers, use the Doxygen syntax. See: http://www.stack.nl/~dimitri/doxygen/
Header Formatting
-----------------
General rules apply here. Please keep header function definitions aligned
nicely, if possible. It helps greatly when looking through the code. Sorted
methods, either by name or by their function (ie, group all related methods
together) is great too. Access levels should be sorted in this order:
public, protected, private.
Example:
| #ifndef TRACKSCONTROLS_H
| #define TRACKSCONTROLS_H
|
| class TracksControls : public QScrollArea
| {
| Q_OBJECT
|
| public:
| TracksControls( QWidget *parent = 0 );
| ~TracksControls() {};
|
| public slots:
| void addVideoTrack( GraphicsTrack *track );
| void addAudioTrack( GraphicsTrack *track );
| void clear();
|
| private:
| QWidget *m_centralWidget;
| QWidget *m_separator;
| QVBoxLayout *m_layout;
| };
|
| #endif // TRACKSCONTROLS_H
0 vs NULL
---------
0 and NULL are the same in C++. However, NULL is expected to be used with
pointers, therefore, it improves code clarity.
To summarize:
* You shall use NULL when dealing with pointers.
* You must not use NULL when dealing with something that's not a pointer.
Const Correctness
-----------------
Try to keep your code const correct. Declare methods const if they don't mutate
the object, and use const variables. It improves safety, and also makes it
easier to understand the code.
In case of a pointer/reference to a const value, you must put the const at the
beginning of the line.
See: http://www.parashift.com/c++-faq-lite/const-correctness.html
Example:
| bool
| MyClass::isValidFile( const QString &path ) const
| {
| const bool valid = QFile::exist( path );
|
| return valid;
| }
Casts
-----
Prefer C++ casts instead of the traditionnals C casts.
Wrong:
| void
| MyClass::clicked( QAbstractButton *button )
| {
| QPushButton *pButton = (QPushButton*)button;
|
| pButton->setFlat( true );
| }
Correct:
| void
| MyClass::clicked( QAbstractButton *button )
| {
| QPushButton *pButton = static_cast<QPushButton *>( button );
|
| pButton->setFlat( true );
| }
Commenting Out Code
-------------------
Don't keep commented out code. It just causes confusion and makes the source
harder to read. Remember, the last revision before your change is always
availabe in Git. Hence no need for leaving cruft in the source.
Wrong:
| myWidget->show();
| //myWidget->rise(); //what is this good for?
Correct:
| myWidget->show();
Internationalization (i18n)
---------------------------
Each translatable string should be enclosed within a tr().
Wrong:
| myPushButton->setText( "Click me!" );
Correct:
| myPushButton->setText( tr( "Click me!" ) );
Read more on: http://doc.trolltech.com/i18n-source-translation.html
VLMC also supports retranslation of the entire GUI at runtime. You should
subscribe to QEvent::LanguageChange to be notified of a language change and
update the GUI accordingly.
Example:
| void
| MyWidget::changeEvent( QEvent *e )
| {
| QFrame::changeEvent( e );
| switch( e->type() )
| {
| case QEvent::LanguageChange:
| ui.retranslateUi( this );
| break;
| default:
| break;
| }
| }
Embedding UI Class
------------------
Use simple aggregation to embed a Qt UI into your class.
Example:
| #include "ui_MyWidget.h"
|
| class MyWidget : public QFrame
| {
| Q_OBJECT
|
| public:
| MyWidget( QWidget *parent = 0 );
| ~MyWidget() {};
|
| protected:
| virtual void changeEvent( QEvent *e );
|
| private:
| Ui::MyWidget ui;
| };
Debugging
---------
Debug is not printed out on the console by default. However, everything is
written to a log file. This can be changed by setting -v, -vv, and
--logfile=[output_file]
Don't ever ever ever let some debugs such as "i am here", "ptr == 0xDEADB33F".
Just let what's required. (ie: a media loaded, the render has started.... )
Copyright
---------
To comply with the GPL, add your name, email address & the year to the top of
any file that you edit. If you bring in code or files from elsewhere, make sure
its GPL-compatible and to put the authors name, email & copyright year to the
top of those files.
Please note that it is not sufficient to write a pointer to the license (like a
URL). The complete license header needs to be written everytime.
Thanks, now have fun!
-- the VLMC developers
This diff is collapsed.
Requirements:
-------------
- doxygen
- graphviz
Generate the documentation:
---------------------------
Run doxygen from the doc/ directory:
# doxygen
The documentation will be generated into the html/ directory.
......@@ -23,14 +23,51 @@
#ifndef PROJECTSETTINGSDEFAULT_H
#define PROJECTSETTINGSDEFAULT_H
#include <QString>
/**
* \class ProjectSettingsDefault
*
* \brief Static class for loading default parameters
* for the project
*/
class ProjectSettingsDefault
{
public:
/**
* \brief load all the project defaults parameters
* \param part the settings part in wich the default values will
* be loaded
*/
static void load( const QString& part );
private:
/**
* \brief will load the project Audio related values.
* \param part the settings part in wich the audio default
* values will be loaded
*/
static void loadAudioDefaults( const QString& part );
/**
* \brief will load the project Video related values.
* \param part the settings part in wich the audio default
* values will be loaded
*/
static void loadVideoDefaults( const QString& part );
/**
* \brief will load the Project global values.
* \param part the settings part in wich the project default
* values will be loaded
*/
static void loadProjectDefaults( const QString& part );
private:
......
......@@ -39,8 +39,3 @@ const QVariant& SettingValue::get() const
{
return m_val;
}
QVariant& SettingValue::get()
{
return m_val;
}
......@@ -26,18 +26,42 @@
#include <QObject>
#include <QVariant>
/**
* 'class SettingValue
*
* \brief represent a setting value
*
*/
class SettingValue : public QObject
{
Q_OBJECT
Q_DISABLE_COPY( SettingValue );
public:
SettingValue( const QVariant& val );
/**
* \brief setter for the m_val member
* \param val the value wich will be affected to m_val
*/
void set( const QVariant& val );
/**
* \brief getter for the m_val member
*/
const QVariant& get() const;
QVariant& get();
private:
/**
* \brief the QVariant containingthe value of the settings
*/
QVariant m_val;
signals:
/**
* \brief This signal is emmited while the m_val
* member have been modified
*/
void changed( const QVariant& );
};
......
......@@ -20,6 +20,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "SettingsManager.h"
#include "VLMCSettingsDefault.h"
#include "ProjectSettingsDefault.h"
#include <QHash>
#include <QDomElement>
#include <QDomNamedNodeMap>
......@@ -29,9 +34,7 @@
#include <QReadLocker>
#include <QTextStream>
#include "SettingsManager.h"
#include "VLMCSettingsDefault.h"
#include "ProjectSettingsDefault.h"
bool SettingsManager::m_defaultLoaded = false;
......@@ -44,22 +47,6 @@ SettingsManager::~SettingsManager()
{
}
//void SettingsManager::setValues( const QString& part, SettingsPart::ConfigPair values )
//{
// if ( !m_tempData.contains( part ) )
// addNewSettingsPart( part );
// m_globalLock.lockForRead();
// SettingsPart* sett = m_tempData[part];
// m_globalLock.unlock();
// SettingsPart::ConfigPair::iterator it = values.begin();
// SettingsPart::ConfigPair::iterator end = values.end();
//
// QWriteLocker lock( &sett->m_lock );
// for ( ; it != end; ++it )
// sett->m_data.insert( it.key(), it.value() );
// return ;
//}
void SettingsManager::setValue( const QString& part , const QString& key, const QVariant& value )
{
m_globalLock.lockForRead();
......@@ -213,10 +200,13 @@ void SettingsManager::flush()
void SettingsManager::loadDefaultsSettings()
{
VLMCSettingsDefault::load( "default" );
VLMCSettingsDefault::load( "VLMC" );
ProjectSettingsDefault::load( "default" );
ProjectSettingsDefault::load( "project" );
if ( !SettingsManager::m_defaultLoaded )
{
VLMCSettingsDefault::load( "default" );
VLMCSettingsDefault::load( "VLMC" );
ProjectSettingsDefault::load( "default" );
ProjectSettingsDefault::load( "project" );
}
}
SettingsManager* SettingsManager::getInstance()
......
......@@ -23,24 +23,49 @@
#ifndef SETTINGSMANAGER_H
#define SETTINGSMANAGER_H
#include "SettingValue.h"
#include "QSingleton.hpp"
#include <QObject>
#include <QVector>
#include <QHash>
#include <QReadWriteLock>
#include <QString>
#include <QVariant>
#include <QDomDocument>
#include "SettingValue.h"
#include "QSingleton.hpp"
class QDomDocument;
class QDomElement;
class QString;
/**
* \struct SettingsPart
* \brief Represent a part of the Settings.
*
* This is used to group different settings, and to be able to easily
* save or load just a part of all the settings used by the application.
*/
struct SettingsPart
{
typedef QHash<QString, SettingValue*> ConfigPair;
SettingsPart() {}
/**
* \brief the HashList containing the settings
*/
ConfigPair m_data;
/**
* \brief The ReadWriteLock used for when we need to read / write the settingsPart.
*/
QReadWriteLock m_lock;
/**
* \brief This flag is used when the SettingsPart is
* a readOnly Part.
*/
bool m_rdOnly;
private:
......@@ -48,6 +73,10 @@ struct SettingsPart
SettingsPart& operator =( const SettingsPart& );
};
/**
* \class SettingsManager
* \brief Will manage everything related to the settings.
*/
class SettingsManager : public QObject, public QSingleton<SettingsManager>
{
......@@ -56,28 +85,143 @@ class SettingsManager : public QObject, public QSingleton<SettingsManager>
friend class QSingleton<SettingsManager>;
public:
// void setValues( const QString& part, SettingsPart::ConfigPair );
/**
* \brief Set a value to an existing or a new SettingValue
*
* If the SettingsPart part does not exist, it will be created
* \sa commit()
* \param part the part in wich the value will be set
* \param key the key of the setting
* \param value the value of the setting
*/
void setValue( const QString& part, const QString& key, const QVariant& value );
/**
* \brief get a settings value for a given name
*
* if the settings is not in part, return the default value
* for this setting
* \param part the part where the settings is stored
* \param key the setting's name
* \return the settingPart named part
* \warning if part does not exist, return a NULL pointer
*/
const SettingValue* getValue( const QString& part, const QString& key ) const;
/**
* \brief getter for a settingsPart
* \param part the name of the part we wish to get
* \return The settingsPart named part
* \warning returns a NULL pointer if the SettingsPart part does not exist
*/
const SettingsPart* getConfigPart( const QString& part ) const;
/**
* \brief save a settingPart into a DomDocument
*
* This will only save one part, to save all the preferences, you have to call
* this method with all the name of the existing SettingsPart
* \param part The part to save
* \param xmlfile The QDomDocument used to create new QDomElements
* \param root The root Element of the xml file in wich the project will be saved.
*/
void saveSettings( const QString& part, QDomDocument& xmlfile, QDomElement& root );
/**
* \brief load a Settings part from a QDomElement
*
* after all settings contained in the donElement have been loaded, this method will emit the
* settingsLoaded() signal
* \param part the Settings part to Load. The settings part must exist in order to be loaded
* \param settings the QDomElement containing the settingPart to load.
*/
void loadSettings( const QString& part, const QDomElement& settings );
/**
* \brief add a new SettingsPart
* \param name the name of the SettingPart that need to be created
*
* The SettingsPart is not created if name is already used by another
* SettingsPart
*/
void addNewSettingsPart( const QString& name );
/**
* \brief commit all change made into the settingManager
*
* This will commit all the settings modified with the SetValue method
* that have been stored in a temporary Hashlist to the settingManager HashList.
* It allow us to discard all the modified settings that have been modified. like when the user
* press the cancel button wile configuring the project settings via the project wizard
* \sa flush()
*/
void commit();
/**
* \brief clean the temporary value stored in the SettingsManager
*
* this method allow the user to cancel all the modifications made to the settingsManager
* between two calls of the commit method.
* this method is also called at the end of the commit method
*/
void flush();
/**
* \brief Will load the default value of the application and the project settings
*
* the defaults are only loaded once
*/
static void loadDefaultsSettings();
/**
* \brief Return the only available instance of the settingsManager
*/
static SettingsManager* getInstance();
private:
SettingsManager( QObject* parent = 0 );
~SettingsManager();
/**
* \brief the HashList containing the SettingsPart available
*/
QHash<QString, SettingsPart*> m_data;