Yeah I was thinking of making MyView a friend class to QWidget to gain access to its private variables. The urnTree is made from a class that is a sublcass of AbstractItemModel so it is a custom class and the class that has access to it called UrnTab is a subclass of QWidget. I didn't really think it would be possible to do what I am trying to do but I thought I would ask and find out .
Here is the 'parent' class that has the private members I am talking about in it:
#ifndef URNTAB_H
#define URNTAB_H
#include <QWidget>
#include <QFile>
#include <QHash>
#include <QModelIndex>
#include "UrnInfo.h"
class TreeModel;
class MyView;
class UrnInfoDialog;
{
Q_OBJECT
public:
//...
public slots:
//...
private slots:
//...
private:
TreeModel *urnTree;
MyView *view;
//...
QHash<int, GlobalUrnInfo> urnData;
//....
};
#ifndef URNTAB_H
#define URNTAB_H
#include <QWidget>
#include <QFile>
#include <QHash>
#include <QModelIndex>
#include "UrnInfo.h"
class TreeModel;
class MyView;
class UrnInfoDialog;
class QSplitter;
class UrnTab : public QWidget
{
Q_OBJECT
public:
UrnTab(QFile &inFile, QWidget *parent = 0);
//...
public slots:
//...
private slots:
//...
private:
TreeModel *urnTree;
MyView *view;
//...
QHash<int, GlobalUrnInfo> urnData;
//....
};
To copy to clipboard, switch view to plain text mode
Obviously I want MyView to have access to urnTree and urnData since in the UrnTab constructor I do view = new MyView(this) where 'this' is the UrnTab object. I hope that clears up what I am trying to do.
Thanks again for any help!
Added after 1 54 minutes:
Ok so I need to redirect this question because I just realized that I don't necessarily need access to urnTree and urnData, what I need is access to a public function called updateParent(QModelIndex) inside of UrnTab. I haven't used a ton of polymorphism in awhile so I am kinda rusty on how to go about doing this. Basically I want MyView to be able to call this function inside of the dropEvent. I believe there is a way to do this but I am starting to run into OOP principles I haven't used in awhile and I am not sure if I am forgetting something or its plan not possible.
Here is the example of the call:
{
QPoint position
= event
->pos
();
// call updateParent(curIndex) function in UrnTab which is the parent object to MyView
// MyView is built inside of the UrnTab constructor with UrnTab as its parent object i.e. MyView *view = new MyView(this) where 'this' is UrnTab
}
void MyView::dropEvent(QDropEvent *event)
{
QPoint position = event->pos();
QModelIndex curIndex = this->indexAt(position);
// call updateParent(curIndex) function in UrnTab which is the parent object to MyView
// MyView is built inside of the UrnTab constructor with UrnTab as its parent object i.e. MyView *view = new MyView(this) where 'this' is UrnTab
}
To copy to clipboard, switch view to plain text mode
Bookmarks