Skip to content

Instantly share code, notes, and snippets.

@Superlokkus
Last active September 7, 2015 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Superlokkus/a994d42534beca9ed5c6 to your computer and use it in GitHub Desktop.
Save Superlokkus/a994d42534beca9ed5c6 to your computer and use it in GitHub Desktop.
void Wt::WAbstractItemModel::sort
/*! @file directory.h
To be compiled first with the odb compiler
Copyright Markus Klemm markus@markusklemm.net
im Auftrag für RHe Microsystems GmbH
*/
#ifndef DIRECTORY_H
#define DIRECTORY_H
#include <string>
#include <ctime>
#include <memory>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/uuid/uuid.hpp>
#include <odb/core.hxx>
#include <boost/optional.hpp>
#include "file_type.h"
#include "file.h"
namespace MDDB_Service {
namespace MDDB_Web{
class file;
class file_type;
#pragma db object table("directories") session pointer(std::shared_ptr<directory>)
class directory
{
public:
#pragma db column("directory_id") type("uniqueidentifier") id not_null
boost::uuids::uuid directory_id;
#pragma db column("full_path") type("nvarchar(512)") not_null
std::wstring full_path;
#pragma db column("file_type") not_null
std::shared_ptr<file_type> file_type;
#pragma db column("active") type("bit") not_null
bool active;
#pragma db column("added") type("datetime2") not_null
boost::posix_time::ptime added;
#pragma db column("added_by") type("varchar(32)") not_null
std::string added_by;
#pragma db inverse(directory)
std::vector<std::shared_ptr<file>> files;
directory() : active(true)
{}
bool operator<(const directory &d) const{
return this->directory_id < d.directory_id;
}
bool operator==(const directory &d) const{
return this->directory_id == d.directory_id;
}
};
}
}
#endif
void sort(int column, Wt::SortOrder order = Wt::AscendingOrder){
this->layoutAboutToBeChanged().emit();
odb::query<directory> query("ORDER BY");
switch (column){
case 0:
query += odb::query<directory>::full_path; //no operator "+=" matches these operands operand types are: odb::query<MDDB_Service::MDDB_Web::directory, odb::mssql::query_base> += const odb::mssql::query_column<std::wstring, odb::mssql::id_nstring> / C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const odb::query_columns<T,id_mssql,odb::access::object_traits_impl<MDDB_Service::MDDB_Web::directory,id_mssql>>::full_path_type_'
break;
case 1:
query += odb::query<directory>::active; //no error
break;
case 2:
default:
query += odb::query<directory>::added; //no operator "+=" matches these operands operand types are: odb::query<MDDB_Service::MDDB_Web::directory, odb::mssql::query_base> += const odb::mssql::query_column<boost::posix_time::ptime, odb::mssql::id_datetime> / binary '+=' : no operator found which takes a left-hand operand of type 'odb::query<MDDB_Service::MDDB_Web::directory,odb::mssql::query_base>'
break;
}
switch (order){
case Wt::DescendingOrder:
query += "DESC";
break;
default:
query += "ASC";
break;
}
change_query(query);
this->layoutChanged().emit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment