PDA

View Full Version : QtPieMenu problem



MarkoSan
23rd May 2009, 12:24
Hello, I've created pie menu using QtPieMenu. Data shown in pei menu is loaded from database dynamically and every button gets its id then (from database). Now, how do I check which button was pressed in piemenu, I need this data. Please help!

aamer4yu
23rd May 2009, 12:49
What signals you get on clicked ?
You can however always check the sender(), cast it to the known class, and use the id to recognise which button was clicked :)

MarkoSan
23rd May 2009, 12:56
From the pie menu docs, I saw there is activeted(int i) signal, but I cannot catch it, been trying for 2 days now:

connect(this,
SIGNAL(activated(int)),
this,
SLOT(languageChanged(int)));simply does not work and I do not know why.

aamer4yu
23rd May 2009, 17:44
How are you connecting the signal ? Can we see the code ?

MarkoSan
23rd May 2009, 17:50
Ok, here is header file:

/*
* CLangSelectorMenu.h
*
* Created on: 21.5.2009
* Author: markofr
*/

#ifndef CLANGSELECTORMENU_H_
#define CLANGSELECTORMENU_H_

// qt includes
#include <QtCore/QString>
#include <QtGui/QWidget>
#include <QtCore/QList>
#include <QtSql/QSqlQuery>
#include <QtGui/QIcon>
#include <QtGui/QPixmap>
#include <QtGui/QMessageBox> // debug purposes

// custom includes
#include "src/qtpiemenu/qtpiemenu.h"
#include "globals.h"
#include "CDatabaseFoundation.h"

// database table declaration
typedef struct
{
quint32 iLangId; // language id
QString strName; // language name
QString strTranslatorFilePath; // language translator file path
QString strPicPath; // language picture path
QString strCurrency; // language curreny abbervavtion
} langStruct;

class CLangSelectorMenu : public QtPieMenu
{
Q_OBJECT

public:
CLangSelectorMenu(const QString& strText,
QWidget* pParent=0,
const char* pName=0,
quint16 iInnerRadius=60,
quint16 iOuterRadius=200);
~CLangSelectorMenu();

inline QList<langStruct> languages() const
{ return m_listLanguages; };
inline QSqlQuery* languageQuery() const
{ return m_pLanguageQuery; };
inline CDatabaseFoundation* databaseConnector() const
{ return m_pDatabaseConnector; };
inline quint32 currentLanguage() const
{ return m_iCurrentLanguage; };
inline void setCurrentLanguage(const quint32& iNewLanguage)
{ m_iCurrentLanguage=iNewLanguage; };

private:
QList<langStruct> m_listLanguages; // list of languages
QSqlQuery* m_pLanguageQuery; // language sql query
CDatabaseFoundation* m_pDatabaseConnector; // database connector
quint32 m_iCurrentLanguage; // current language id

private:
void fetchLanguages(); // gets languages from database
void createLangQuery(); // creates query object
void setupMenu(); // setups language menu according to database
void showString(const QString& strToShow); // debug method

private slots:
void ignoreAction();
void languageChanged(int i);

signals:
void activated(int i);
};

#endif /* CLANGSELECTORMENU_H_ */ and here is its implementation:
/*
* CLangSelectorMenu.cpp
*
* Created on: 21.5.2009
* Author: markofr
*/

#include "CLangSelectorMenu.h"

CLangSelectorMenu::CLangSelectorMenu(const QString& strText,
QWidget* pParent,
const char* pName,
quint16 iInnerRadius,
quint16 iOuterRadius)
: QtPieMenu(strText,
pParent,
pName,
static_cast<uint>(iInnerRadius),
static_cast<uint>(iOuterRadius))
{
m_pDatabaseConnector=CDatabaseFoundation::getInsta nce(strdbType, strdbHost, strDatabaseName, strdbUserName, strdbPassword);
Q_CHECK_PTR(m_pDatabaseConnector); // checks creation

setCurrentLanguage(1); // test purposes
createLangQuery(); // creates query object
fetchLanguages(); // creates language list
setupMenu(); // sets up menu
connect(this,
SIGNAL(activated(int)),
this,
SLOT(languageChanged(int)));
}

CLangSelectorMenu::~CLangSelectorMenu()
{
}

void CLangSelectorMenu::fetchLanguages()
{
langStruct tempRecord;

languageQuery()->exec("SELECT * FROM erosystem.language WHERE InUse=TRUE;"); // executes mysql query
if(languageQuery()->isActive())
{
// query active, no errors
while(languageQuery()->next())
{
// fetch records
tempRecord.iLangId=languageQuery()->value(iLanguageFieldID).toInt();
tempRecord.strCurrency=languageQuery()->value(iLanguageFieldCurrency).toString();
tempRecord.strName=languageQuery()->value(iLanguageFieldLName).toString();
tempRecord.strPicPath=languageQuery()->value(iLanguageFieldFlagPath).toString();
tempRecord.strTranslatorFilePath=languageQuery()->value(iLanguageFieldTranPath).toString();
//languages().append(tempRecord); // adds record to list
m_listLanguages.append(tempRecord); // adds record to list
}
}
else
{
// query not active, error handler
showString(tr("Query not active.")); // shows error
}
}

void CLangSelectorMenu::createLangQuery()
{
m_pLanguageQuery=new QSqlQuery(databaseConnector()->m_Database); // creates language query
Q_CHECK_PTR(m_pLanguageQuery); // checks creation
}

void CLangSelectorMenu::setupMenu()
{
//showString("m_listLanguages.size():"+QString::number(m_listLanguages.size())); // debug
for(int iIndex=0; iIndex<m_listLanguages.size(); iIndex++)
{
//showString("Pic path:"+m_listLanguages.at(iIndex).strPicPath); // debug
insertItem(QIcon(QPixmap(m_listLanguages.at(iIndex ).strPicPath)),
QString(m_listLanguages.at(iIndex).strName),
this,
SLOT(ignoreAction())); // inserts flag
}
}

void CLangSelectorMenu::ignoreAction()
{
showString("Language changed."); // debug
}

void CLangSelectorMenu::showString(const QString& strToShow)
{
QMessageBox tempBox;
tempBox.setText(strToShow);
tempBox.exec();
}

void CLangSelectorMenu::languageChanged(int i)
{
showString(QString::number(i)); // debug
}