Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

District search criteria #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
*.la
*.a
/oxygen/
/build/
35 changes: 35 additions & 0 deletions src/interface/AbstractDistrictQuery.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/****************************************************************************
**
**
** Authors : don-vip
** Project : Housing
** FileName : AbstractDistrictQuery.cpp
** Date : 2015-09-05T23:26:14
** License : GPL3
** Home Page : https://github.com/don-vip/housing
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to this repo url please.

** Comment : An application to search for rent / purchase of appartment / house.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This package is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "AbstractDistrictQuery.h"

AbstractDistrictQuery::AbstractDistrictQuery( QObject* parent )
: QObject( parent )
{
}

AbstractDistrictQuery::~AbstractDistrictQuery()
{
}
52 changes: 52 additions & 0 deletions src/interface/AbstractDistrictQuery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/****************************************************************************
**
**
** Authors : don-vip
** Project : Housing
** FileName : AbstractDistrictQuery.h
** Date : 2015-09-05T23:26:14
** License : GPL3
** Home Page : https://github.com/don-vip/housing
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Url

** Comment : An application to search for rent / purchase of appartment / house.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This package is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef ABSTRACTDISTRICTQUERY_H
#define ABSTRACTDISTRICTQUERY_H

#include <QObject>

#include "District.h"

class AbstractDistrictQuery : public QObject
{
Q_OBJECT

public:
AbstractDistrictQuery( QObject* parent = 0 );
virtual ~AbstractDistrictQuery();

virtual void setMinimumSearchLength( int length ) = 0;
virtual int minimumSearchLength() const = 0;

public slots:
virtual void search( const QString& text ) = 0;

signals:
void districtsReceived( const District::List& districts );
void error( const QString& error );
};

#endif // ABSTRACTDISTRICTQUERY_H
2 changes: 2 additions & 0 deletions src/interface/AbstractHousingDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ QVariant AbstractHousingDriver::RequestProperties::toVariant() const
map[ "features" ] = int( features );
map[ "inputs" ] = variantInputs;
map[ "cities" ] = City::listToVariant( cities );
map[ "districts" ] = District::listToVariant( districts );
map[ "ignored" ] = variantIgnored;
map[ "bookmarked" ] = variantBookmarked;

Expand Down Expand Up @@ -108,6 +109,7 @@ void AbstractHousingDriver::RequestProperties::fromVariant( const QVariant& vari
}

cities = City::variantToList( map.value( "cities" ) );
districts = District::variantToList( map.value( "districts" ) );

ignoredIdSet.clear();

Expand Down
4 changes: 4 additions & 0 deletions src/interface/AbstractHousingDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@

#include "Announcement.h"
#include "City.h"
#include "District.h"

class AbstractCityQuery;
class AbstractDistrictQuery;

class AbstractHousingDriver : public QObject
{
Expand Down Expand Up @@ -138,6 +140,7 @@ class AbstractHousingDriver : public QObject
SearchFeatures features;
QHash<SearchInput, QVariant> inputs;
City::List cities;
District::List districts;
QSet<int> ignoredIdSet;
QSet<int> bookmarkedIdSet;

Expand Down Expand Up @@ -205,6 +208,7 @@ class AbstractHousingDriver : public QObject
virtual AbstractHousingDriver::SearchFeatures supportedSearchFeatures() const = 0;

virtual AbstractCityQuery* cityQuery() const = 0;
virtual AbstractDistrictQuery* districtQuery() const = 0;
virtual QMap<QString, QString> roomsInputs() const = 0;
virtual QMap<QString, QString> bedroomsInputs() const = 0;
virtual bool isOwnUrl( const QUrl& url ) const = 0;
Expand Down
176 changes: 176 additions & 0 deletions src/interface/District.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/****************************************************************************
**
**
** Authors : don-vip
** Project : Housing
** FileName : District.cpp
** Date : 2015-09-05T23:44:14
** License : GPL3
** Home Page : https://github.com/don-vip/housing
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Url

** Comment : An application to search for rent / purchase of appartment / house.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This package is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "District.h"

#include <QSharedData>
#include <QString>

class DistrictData : public QSharedData {
public:
QString label;
QString value;
QString valuesup;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the meaning of valueSup ?

QString code;

public:
DistrictData() {
}

DistrictData( const DistrictData& other )
: QSharedData( other ),
label( other.label ),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align members to the Q of QSharedData

value( other.value ),
valuesup( other.valuesup ),
code( other.code )
{
}

~DistrictData() {
}
};

District::District( const QVariant& variant )
: d( new DistrictData )
{
if ( !variant.isNull() ) {
fromVariant( variant );
}
}

District::District( const District& other )
: d( other.d )
{
}

District::District( const QString& label, const QString& value, const QString& code, const QString& valuesup )
: d( new DistrictData )
{
d->label = label;
d->value = value;
d->valuesup = valuesup;
d->code = code;
}

District::~District()
{
}

District& District::operator=( const District& other )
{
if ( this != &other ) {
d = other.d;
}

return *this;
}

bool District::operator==( const District& other ) const
{
return d->value == other.d->value && d->valuesup == other.d->valuesup;
}

bool District::operator<( const District& other ) const
{
return d->label.compare( other.d->label ) < 0;
}

bool District::isNull() const
{
return d->label.isEmpty() &&
d->value.isEmpty() &&
d->valuesup.isEmpty() &&
d->code.isEmpty()
;
}

QString District::label() const
{
return d->label;
}

QString District::value() const
{
return d->value;
}

QString District::valuesup() const
{
return d->valuesup;
}

QString District::code() const
{
return d->code;
}

QVariant District::toVariant() const
{
QVariantMap map;
map[ "label" ] = d->label;
map[ "value" ] = d->value;
map[ "valuesup" ] = d->valuesup;
map[ "code" ] = d->code;
return map;
}

void District::fromVariant( const QVariant& variant )
{
if ( !variant.type() == QVariant::Map ) {
return;
}

const QVariantMap map = variant.toMap();
d->label = map.value( "label" ).toString();
d->value = map.value( "value" ).toString();
d->valuesup = map.value( "valuesup" ).toString();
d->code = map.value( "code" ).toString();
}

QVariant District::listToVariant( const District::List& districts )
{
QVariantList list;

foreach ( const District& district, districts ) {
list << district.toVariant();
}

return list;
}

District::List District::variantToList( const QVariant& variant )
{
District::List list;

if ( variant.type() == QVariant::List ) {
const QVariantList districts = variant.toList();

foreach ( const QVariant& district, districts ) {
list << District( district );
}
}

return list;
}
65 changes: 65 additions & 0 deletions src/interface/District.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/****************************************************************************
**
**
** Authors : don-vip
** Project : Housing
** FileName : District.h
** Date : 2015-09-05T23:44:14
** License : GPL3
** Home Page : https://github.com/don-vip/housing
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Url

** Comment : An application to search for rent / purchase of appartment / house.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This package is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef DISTRICT_H
#define DISTRICT_H

#include <QSharedDataPointer>
#include <QList>
#include <QVariant>

class DistrictData;

class District
{
public:
typedef QList<District> List;

District( const QVariant& variant = QVariant() );
District( const District& other );
District( const QString& label, const QString& value, const QString& code, const QString& valuesup );
virtual ~District();

virtual District& operator=( const District& other );
virtual bool operator==( const District& other ) const;
virtual bool operator<( const District& other ) const;

bool isNull() const;
QString label() const;
QString value() const;
QString valuesup() const;
QString code() const;

QVariant toVariant() const;
void fromVariant( const QVariant& variant );

static QVariant listToVariant( const District::List& districts );
static District::List variantToList( const QVariant& variant );

private:
QSharedDataPointer<DistrictData> d;
};

#endif // DISTRICT_H
Loading