Signals | Public Member Functions

BaseQueryModel Class Reference

This is the base model used by the Factory for showing data. More...

#include <basequerymodel.h>

Inheritance diagram for BaseQueryModel:
Inheritance graph
[legend]
Collaboration diagram for BaseQueryModel:
Collaboration graph
[legend]

List of all members.

Signals

void signal_treeItemDropped (int db_tree_id)
void signal_treeItemDropped (TreeItem *item)

Public Member Functions

 BaseQueryModel (QObject *parent=0)
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
void setBuilderView (BuilderView *view)
BuilderViewbuilderView ()
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
QStringList mimeTypes () const
Qt::DropActions supportedDropActions () const
Qt::ItemFlags flags (const QModelIndex &index) const

Detailed Description

This is the base model used by the Factory for showing data.

Todo:
Fix the BuilderView reference hack. Model may not know anything about the view and all should go through the model. So header should "save" its data into the model through BaseQueryModel::setHeaderData();

Constructor & Destructor Documentation

BaseQueryModel::BaseQueryModel ( QObject parent = 0  ) 

                                                        : SqlQueryModel(parent), view(0)
{
    setDependency("tbl_sensor_channel_data");

#ifdef DEBUG_DEFAULTQUERY
    setQuery(Database::execStatic("SELECT * FROM "
             "(SELECT sens_chan_data_timestamp AS timestamp, sens_chan_data_data AS sensdata1 FROM tbl_sensor_channel_data WHERE tree_id = 1 AND sens_chan_data_timestamp < '2009-06-19') AS subquery0 "
             "  FULL OUTER JOIN "
             "(SELECT sens_chan_data_timestamp AS timestamp, sens_chan_data_data AS sensdata3 FROM tbl_sensor_channel_data WHERE tree_id = 2 AND sens_chan_data_timestamp < '2009-06-19') AS subquery2 "
             "  USING (timestamp) "));
#endif //DEBUG_DEFAULTQUERY
};


Member Function Documentation

BuilderView * BaseQueryModel::builderView (  ) 

{
    return view;
}

bool BaseQueryModel::dropMimeData ( const QMimeData data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex parent 
)

{
    qDebug() << "Item drop tried on: column: " << column << " row: " << row << " parent: " << parent;
    if (action == Qt::IgnoreAction) return true;
    if (!(data->hasFormat("appobj/treeitem.pointer"))) return false;

    if (data->hasFormat("appobj/treeitem.pointer")){
        QByteArray encodedData = data->data("appobj/treeitem.pointer");
        QDataStream stream(&encodedData, QIODevice::ReadOnly);
        while (!stream.atEnd()) {
            qint64 p;
            stream >> p;
            TreeItem *droppedTreeItem = reinterpret_cast<TreeItem*>(p);
            droppedTrees.insert(parent.column(), droppedTreeItem);
            //qDebug() << "Dropped treepointer: " << droppedTreeItem;
            foreach(QVariant id, droppedTreeItem->getDataRecursively(TreeItem::TreeItemId)) {
                if (id.toInt() != -1) emit signal_treeItemDropped(id.toInt());
                if (id.toInt() != -1) emit signal_treeItemDropped(droppedTreeItem->find(id.toInt()));
            }
        }
        return true;
    }

    return false;
}

Qt::ItemFlags BaseQueryModel::flags ( const QModelIndex index  )  const

{
    Qt::ItemFlags defaultFlags = SqlQueryModel::flags(index); //selectable and enabled
    return defaultFlags | Qt::ItemIsDropEnabled;
}

QVariant BaseQueryModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const

{
    if (orientation == Qt::Horizontal && role == GlobalEnum::BuilderHeaderDataUnitSymbolRole){
        Q_ASSERT(view);
        Q_ASSERT(view->dataHeader());
        // Very hackisch!!!
        return view->dataHeader()->data(section-1 /* -1 = Hack again */, role);
    }
    else
        return SqlQueryModel::headerData(section, orientation, role);
}

QStringList BaseQueryModel::mimeTypes (  )  const

{
    return QStringList() << "appobj/treeitem.pointer";
}

void BaseQueryModel::setBuilderView ( BuilderView view  ) 

Referenced by Factory::Factory().

{
    this->view = view;
}

void BaseQueryModel::signal_treeItemDropped ( TreeItem item  )  [signal]
void BaseQueryModel::signal_treeItemDropped ( int  db_tree_id  )  [signal]

Referenced by dropMimeData().

Qt::DropActions BaseQueryModel::supportedDropActions (  )  const

{
    return Qt::CopyAction | Qt::MoveAction;
}


The documentation for this class was generated from the following files: