Skip to content

Commit

Permalink
Merge pull request #3 from Brewtarget/develop
Browse files Browse the repository at this point in the history
update
  • Loading branch information
rhoob committed Sep 2, 2016
2 parents 0609e55 + 277091e commit e0cbf22
Show file tree
Hide file tree
Showing 36 changed files with 381 additions and 941 deletions.
13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROJECT(brewtarget)
CMAKE_MINIMUM_REQUIRED( VERSION 2.8.8 )
CMAKE_POLICY( VERSION 2.8.11 )
CMAKE_MINIMUM_REQUIRED( VERSION 3.0 )
CMAKE_POLICY( VERSION 3.0 )

# Creates a Makefile.
# NOTE: cmake . -DCMAKE_INSTALL_PREFIX=/tmp/blah && make DESTDIR=/foo
Expand Down Expand Up @@ -70,6 +70,11 @@ SET( MACOSX_BUNDLE_ICON_FILE "BrewtargetIcon.icns" )
SET( MACOSX_BUNDLE_COPYRIGHT "GPLv3" )

#==============================Compile flags===================================

# Enable and enforce c++11 standards, so that we may lambda
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED_ON)

IF( NOT ${NO_MESSING_WITH_FLAGS} )
IF( CMAKE_COMPILER_IS_GNUCXX )
SET( CMAKE_CXX_FLAGS_RELEASE "-Wall -ansi -pedantic -Wno-long-long -O2" )
Expand Down Expand Up @@ -99,6 +104,8 @@ IF( APPLE AND NOT CMAKE_OSX_ARCHITECTURES )
#SET( CMAKE_OSX_ARCHITECTURES ppc i386 ppc64 x86_64 ) # Build universal binary.
ENDIF()

ADD_DEFINITIONS("-std=c++11")

#============================Directories=======================================
SET(ROOTDIR "${CMAKE_CURRENT_SOURCE_DIR}")
SET(SRCDIR "${ROOTDIR}/src")
Expand Down Expand Up @@ -641,3 +648,5 @@ ELSE()
MESSAGE( STATUS "Building Brewtarget." )
ADD_SUBDIRECTORY(${SRCDIR})
ENDIF()


Binary file modified data/default_db.sqlite
Binary file not shown.
80 changes: 67 additions & 13 deletions src/BeerXMLElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,90 @@
#include "database.h"

BeerXMLElement::BeerXMLElement()
: QObject(0), _key(-1), _table(Brewtarget::NOTABLE)
: QObject(0),
_key(-1),
_table(Brewtarget::NOTABLE),
_folder(QString()),
_name(QString()),
_display(QVariant()),
_deleted(QVariant())
{
_valid = true;
}

BeerXMLElement::BeerXMLElement(BeerXMLElement const& other)
: QObject(0), _key(other._key), _table(other._table)
: QObject(0),
_key(other._key),
_table(other._table),
_folder(QString()),
_name(QString()),
_display(QVariant()),
_deleted(QVariant())
{
_valid = true;
}

bool BeerXMLElement::deleted() const { return get("deleted").toBool(); }
bool BeerXMLElement::display() const { return get("display").toBool(); }
bool BeerXMLElement::deleted() const
{

if ( ! _deleted.isValid() )
_deleted = get("deleted");

return _deleted.toBool();
}

bool BeerXMLElement::display() const
{
if ( ! _display.isValid() )
_display = get("display");

return _display.toBool();
}

// Sigh. New databases, more complexity
void BeerXMLElement::setDeleted(bool var) {
void BeerXMLElement::setDeleted(const bool var)
{
set("deleted", "deleted", var ? Brewtarget::dbTrue() : Brewtarget::dbFalse());
_deleted = var;
}
void BeerXMLElement::setDisplay(bool var) {

void BeerXMLElement::setDisplay(bool var)
{
set("display", "display", var ? Brewtarget::dbTrue() : Brewtarget::dbFalse());
_display = var;
}

QString BeerXMLElement::folder() const { return get("folder").toString(); }
void BeerXMLElement::setFolder(QString var, bool signal)
QString BeerXMLElement::folder() const
{
if ( _folder.isEmpty() )
_folder = get("folder").toString();

return _folder;
}

void BeerXMLElement::setFolder(const QString var, bool signal)
{
set( "folder", "folder", var );
_folder = var;
if ( signal )
emit changedFolder(var);
}

QString BeerXMLElement::name() const
{
if ( _name.isEmpty() )
_name = get("name").toString();

return _name;
}

void BeerXMLElement::setName(const QString var)
{
set( "name", "name", var );
_name = var;
emit changedName(var);
}

int BeerXMLElement::key() const { return _key; }

Brewtarget::DBTable BeerXMLElement::table() const{ return _table; }
Expand Down Expand Up @@ -151,7 +205,7 @@ QDate BeerXMLElement::getDate( QDomText const& textNode )
ok = ret.isValid();
}

if ( !ok )
if ( !ok )
Brewtarget::logE(QString("BeerXMLElement::getDate: %1 is not an ISO date-time. Line %2").arg(text).arg(textNode.lineNumber()) );

return ret;
Expand All @@ -162,8 +216,8 @@ QDate BeerXMLElement::getDate( QDomText const& textNode )
QDateTime BeerXMLElement::getDateTime(QString const& str)
{
QDateTime temp;
if ( str != "" && (temp = QDateTime::fromString(str, Qt::ISODate)).isValid() )

if ( str != "" && (temp = QDateTime::fromString(str, Qt::ISODate)).isValid() )
return temp;
else
return QDateTime::currentDateTime();
Expand Down Expand Up @@ -197,7 +251,7 @@ void BeerXMLElement::set( const char* prop_name, const char* col_name, QVariant
if (prop_name != NULL && col_name != NULL) {
// Get the meta property.
int ndx = metaObject()->indexOfProperty(prop_name);

// Should schedule an update of the appropriate entry in table,
// then use prop to emit its notification signal.
Database::instance().updateEntry( _table, _key, col_name, value, metaObject()->property(ndx), this, notify );
Expand All @@ -213,7 +267,7 @@ void BeerXMLElement::setInventory( const char* prop_name, const char* col_name,
{
// Get the meta property.
int ndx = metaObject()->indexOfProperty(prop_name);

int invkey = Database::instance().getInventoryID(_table, _key);
Brewtarget::DBTable invtable = Database::instance().getInventoryTable(_table);
if(invkey == 0){ //no inventory row in the database so lets make one
Expand Down
48 changes: 29 additions & 19 deletions src/BeerXMLElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,37 @@ class BeerXMLElement : public QObject
{
Q_OBJECT
Q_CLASSINFO("version","1")

friend class Database;
public:
BeerXMLElement();
BeerXMLElement( BeerXMLElement const& other );

// Everything that inherits from BeerXML has delete, display and a folder
Q_PROPERTY( bool deleted READ deleted WRITE setDeleted )
Q_PROPERTY( bool display READ display WRITE setDisplay )
// Everything that inherits from BeerXML has a name, delete, display and a folder
Q_PROPERTY( QString name READ name WRITE setName )
Q_PROPERTY( bool deleted READ deleted WRITE setDeleted )
Q_PROPERTY( bool display READ display WRITE setDisplay )
Q_PROPERTY( QString folder READ folder WRITE setFolder )

Q_PROPERTY( int key READ key )
Q_PROPERTY( Brewtarget::DBTable table READ table )

//! Convenience method to determine if we are deleted or displayed
bool deleted() const;
bool display() const;
//! Access to the folder attribute.
QString folder() const;
//! Access to the name attribute.
QString name() const;

//! And ways to set those flags
void setDeleted(bool var);
void setDisplay(bool var);
void setDeleted(const bool var);
void setDisplay(const bool var);
//! and a way to set the folder
virtual void setFolder(QString var, bool signal=true);
virtual void setFolder(const QString var, bool signal=true);

//!
void setName(const QString var);

//! \returns our key in the table we are stored in.
int key() const;
Expand All @@ -90,7 +96,7 @@ class BeerXMLElement : public QObject
QMetaProperty metaProperty(const char* name) const;
//! Convenience method to get a meta property by name.
QMetaProperty metaProperty(QString const& name) const;

// Some static helpers to convert to/from text.
static double getDouble( const QDomText& textNode );
static bool getBool( const QDomText& textNode );
Expand All @@ -106,14 +112,14 @@ class BeerXMLElement : public QObject
static QString text(int val);
//! Convert the date to string in Qt::ISODate format for storage NOT display.
static QString text(QDate const& val);

//! Use this to pass pointers around in QVariants.
static inline QVariant qVariantFromPtr( BeerXMLElement* ptr )
{
uintptr_t addr = reinterpret_cast<uintptr_t>(ptr);
return QVariant::fromValue<uintptr_t>(addr);
}

static inline BeerXMLElement* extractPtr( QVariant ptrVal )
{
uintptr_t addr = ptrVal.value<uintptr_t>();
Expand All @@ -122,7 +128,7 @@ class BeerXMLElement : public QObject

bool isValid();
void invalidate();

signals:
/*!
* Passes the meta property that has changed about this object.
Expand All @@ -131,9 +137,10 @@ class BeerXMLElement : public QObject
*/
void changed(QMetaProperty, QVariant value = QVariant());
void changedFolder(QString);

void changedName(QString);

protected:

//! The key of this ingredient in its table.
int _key;
//! The table where this ingredient is stored.
Expand All @@ -149,24 +156,27 @@ class BeerXMLElement : public QObject
* 2) Call the NOTIFY method associated with \c prop_name if \c notify == true.
*/
void set( const char* prop_name, const char* col_name, QVariant const& value, bool notify = true );

/*!
* \param col_name - The database column of the attribute we want to get.
* Returns the value of the attribute specified by key/table/col_name.
*/
QVariant get( const char* col_name ) const;

void setInventory( const char* prop_name, const char* col_name, QVariant const& value, bool notify = true );
QVariant getInventory( const char* col_name ) const;




private:
/*!
* \param valid - Indicates if the beerXML element was valid. There is a problem with importing invalid
* XML. I'm hoping this helps fix it
*/
bool _valid;
mutable QString _folder;
mutable QString _name;
mutable QVariant _display;
mutable QVariant _deleted;

};


Expand Down
1 change: 1 addition & 0 deletions src/BtDatePopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ BtDatePopup::BtDatePopup(QWidget* parent) : QDialog(parent, Qt::Popup)
calendar = new QCalendarWidget(widget);
calendar->setObjectName(QString("btDatePopup_calendar"));
calendar->setNavigationBarVisible(true);
calendar->setSelectedDate(QDate::currentDate());


buttonbox = new QDialogButtonBox(widget);
Expand Down
Loading

0 comments on commit e0cbf22

Please sign in to comment.