make compile with -pedantic and use foreach in some places
This commit is contained in:
@ -17,7 +17,7 @@ if(PLAIN_KEYS)
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-deprecated-declarations")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -Wno-deprecated-declarations")
|
||||
|
||||
if(NOT(CMAKE_BUILD_TYPE STREQUAL "Debug"))
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "event.h"
|
||||
|
||||
//this should be initialized by main.cpp as soon as the program starts.
|
||||
Display* display;
|
||||
Display* display = 0;
|
||||
|
||||
//actually creates an XWindows event :)
|
||||
void sendevent( xevent e ) {
|
||||
|
@ -43,7 +43,7 @@ void FlashButton::flash()
|
||||
}
|
||||
|
||||
|
||||
FlashRadioArray::FlashRadioArray( int count, QString names[], bool horizontal, QWidget* parent)
|
||||
FlashRadioArray::FlashRadioArray( const QStringList &names, bool horizontal, QWidget* parent)
|
||||
:QWidget( parent )
|
||||
{
|
||||
if (horizontal) {
|
||||
@ -55,19 +55,23 @@ FlashRadioArray::FlashRadioArray( int count, QString names[], bool horizontal, Q
|
||||
LMain->setMargin(5);
|
||||
LMain->setSpacing(5);
|
||||
}
|
||||
|
||||
// TODO: fix memleak
|
||||
int count = names.size();
|
||||
int i = 0;
|
||||
Buttons = new FlashButton*[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
Buttons[i] = new FlashButton( names[i], this, "" );
|
||||
foreach (const QString &name, names) {
|
||||
Buttons[i] = new FlashButton( name, this, "" );
|
||||
//when any of the buttons is clicked, it calls the same function on this.
|
||||
connect( Buttons[i], SIGNAL( clicked() ), this, SLOT( clicked() ));
|
||||
LMain->addWidget(Buttons[i]);
|
||||
++i;
|
||||
}
|
||||
|
||||
Count = count;
|
||||
State = 0;
|
||||
Buttons[0]->setDown( true );
|
||||
if (count > 0) {
|
||||
Buttons[0]->setDown( true );
|
||||
}
|
||||
}
|
||||
|
||||
int FlashRadioArray::getState()
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <QPushButton>
|
||||
#include <QPalette>
|
||||
#include <QBoxLayout>
|
||||
#include <QStringList>
|
||||
|
||||
|
||||
//A QPushButton that can flash a color
|
||||
@ -50,7 +51,7 @@ class FlashRadioArray : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FlashRadioArray( int count, QString names[], bool horizontal, QWidget* parent);
|
||||
FlashRadioArray( const QStringList &names, bool horizontal, QWidget* parent);
|
||||
//returns an integer returning the currently selected button.
|
||||
//First button is 0.
|
||||
int getState();
|
||||
|
@ -212,7 +212,7 @@ void JoySlider::mousePressEvent( QMouseEvent* e )
|
||||
else if (throttle >= 0 && abs( xpt - pointFor( XZone, false )) < 5) result = DRAG_XZ;
|
||||
else if (throttle >= 0 && abs( xpt - pointFor( DeadZone, false )) < 5) result = DRAG_DZ;
|
||||
dragging = result;
|
||||
};
|
||||
}
|
||||
|
||||
void JoySlider::mouseReleaseEvent( QMouseEvent* )
|
||||
{
|
||||
|
@ -157,7 +157,7 @@ void LayoutManager::save() {
|
||||
//if it's good, start writing the file
|
||||
if (file.open(QIODevice::WriteOnly)) {
|
||||
QTextStream stream( &file );
|
||||
stream << "# "NAME" Layout File\n\n";
|
||||
stream << "# " NAME " Layout File\n\n";
|
||||
QHashIterator<int, JoyPad*> it (joypads);
|
||||
while (it.hasNext())
|
||||
{
|
||||
|
@ -38,23 +38,14 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) {
|
||||
//produce a list of names for the FlashRadioArray
|
||||
//this is only necesary since joystick devices need not always be
|
||||
//contiguous
|
||||
int padcount = available.count();
|
||||
QString names[padcount];
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
QHashIterator<int, JoyPad*> it( available );
|
||||
while (it.hasNext())
|
||||
{
|
||||
it.next();
|
||||
names[i] = it.value()->getName();
|
||||
connect(this, SIGNAL(focusStateChanged(bool)), it.value(), SLOT(focusChange(bool)));
|
||||
++i;
|
||||
}
|
||||
} while (0);
|
||||
QStringList names;
|
||||
foreach (JoyPad *joypad, available) {
|
||||
names.append(joypad->getName());
|
||||
connect(this, SIGNAL(focusStateChanged(bool)), joypad, SLOT(focusChange(bool)));
|
||||
}
|
||||
|
||||
//flash radio array
|
||||
JoyButtons = new FlashRadioArray(padcount, names, true, this );
|
||||
JoyButtons = new FlashRadioArray(names, true, this );
|
||||
LMain->addWidget( JoyButtons );
|
||||
|
||||
//we have a WidgetStack to represent the multiple joypads
|
||||
@ -63,20 +54,15 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) {
|
||||
LMain->addWidget(PadStack);
|
||||
|
||||
//go through each of the available joysticks
|
||||
i = 0; // i is the current index into PadStack
|
||||
do
|
||||
{
|
||||
QHashIterator<int, JoyPad*> it(available);
|
||||
while (it.hasNext())
|
||||
{
|
||||
it.next();
|
||||
//add a new JoyPadWidget to the stack
|
||||
PadStack->insertWidget( i,it.value()->widget(PadStack,i) );
|
||||
//every time it "flashes", flash the associated tab.
|
||||
connect( PadStack->widget(i), SIGNAL( flashed( int ) ), JoyButtons, SLOT( flash( int )));
|
||||
++i;
|
||||
}
|
||||
} while (0);
|
||||
// i is the current index into PadStack
|
||||
int i = 0;
|
||||
foreach (JoyPad *joypad, available) {
|
||||
//add a new JoyPadWidget to the stack
|
||||
PadStack->insertWidget( i, joypad->widget(PadStack,i) );
|
||||
//every time it "flashes", flash the associated tab.
|
||||
connect( PadStack->widget(i), SIGNAL( flashed( int ) ), JoyButtons, SLOT( flash( int )));
|
||||
++i;
|
||||
}
|
||||
//whenever a new tab is selected, raise the appropriate JoyPadWidget
|
||||
connect( JoyButtons, SIGNAL( changed( int ) ), PadStack, SLOT( setCurrentIndex( int )));
|
||||
|
||||
@ -118,21 +104,12 @@ void LayoutEdit::updateLayoutList() {
|
||||
void LayoutEdit::updateJoypadWidgets() {
|
||||
int indexOfFlashRadio = LMain->indexOf(JoyButtons);
|
||||
FlashRadioArray *newJoyButtons;
|
||||
int padcount = available.count();
|
||||
QString names[padcount];
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
QHashIterator<int, JoyPad*> it( available );
|
||||
while (it.hasNext())
|
||||
{
|
||||
it.next();
|
||||
names[i] = it.value()->getName();
|
||||
++i;
|
||||
}
|
||||
} while (0);
|
||||
QStringList names;
|
||||
foreach (JoyPad *joypad, available) {
|
||||
names.append(joypad->getName());
|
||||
}
|
||||
|
||||
newJoyButtons = new FlashRadioArray(padcount, names, true, this );
|
||||
newJoyButtons = new FlashRadioArray( names, true, this );
|
||||
LMain->insertWidget(indexOfFlashRadio, newJoyButtons);
|
||||
LMain->removeWidget(JoyButtons);
|
||||
FlashRadioArray* oldJoyButtons = JoyButtons;
|
||||
@ -143,20 +120,14 @@ void LayoutEdit::updateJoypadWidgets() {
|
||||
for(int i = 0; i<numberOfJoypads; i++) {
|
||||
PadStack->removeWidget(PadStack->widget(0));
|
||||
}
|
||||
i = 0;
|
||||
do
|
||||
{
|
||||
QHashIterator<int, JoyPad*> it(available);
|
||||
while (it.hasNext())
|
||||
{
|
||||
it.next();
|
||||
//add a new JoyPadWidget to the stack
|
||||
PadStack->insertWidget( i,it.value()->widget(PadStack,i) );
|
||||
//every time it "flashes", flash the associated tab.
|
||||
connect( PadStack->widget(i), SIGNAL( flashed( int ) ), JoyButtons, SLOT( flash( int )));
|
||||
++i;
|
||||
}
|
||||
} while (0);
|
||||
int i = 0;
|
||||
foreach (JoyPad *joypad, available) {
|
||||
//add a new JoyPadWidget to the stack
|
||||
PadStack->insertWidget( i, joypad->widget(PadStack,i) );
|
||||
//every time it "flashes", flash the associated tab.
|
||||
connect( PadStack->widget(i), SIGNAL( flashed( int ) ), JoyButtons, SLOT( flash( int )));
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutEdit::closeEvent(QCloseEvent *event) {
|
||||
@ -169,12 +140,9 @@ void LayoutEdit::appFocusChanged(QWidget *old, QWidget *now) {
|
||||
emit focusStateChanged(false);
|
||||
} else if(old!=NULL && now==NULL) {
|
||||
emit focusStateChanged(true);
|
||||
QHashIterator<int, JoyPad*> it( available );
|
||||
while (it.hasNext())
|
||||
{
|
||||
foreach (JoyPad *joypad, available) {
|
||||
debug_mesg("iterating and releasing\n");
|
||||
it.next();
|
||||
it.value()->release();
|
||||
joypad->release();
|
||||
}
|
||||
debug_mesg("done releasing!\n");
|
||||
}
|
||||
|
@ -1,80 +0,0 @@
|
||||
########################################
|
||||
# #
|
||||
# QMake project file for QJoyPad #
|
||||
# #
|
||||
########################################
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
##### Setup Targets #####
|
||||
|
||||
icons.path = $$INSTALL_PREFIX/share/pixmaps/qjoypad
|
||||
icons.conf_path = $$PREFIX/share/pixmaps/qjoypad
|
||||
icons.extra = cp ../icons/* $${icons.path}; cd $${icons.path}; ln -sf gamepad4-24x24.png icon24.png; ln -sf gamepad3-64x64.png icon64.png; chmod -R a+r $${icons.path}
|
||||
|
||||
doc.path = $$INSTALL_PREFIX/share/doc/qjoypad4
|
||||
doc.extra = cp ../README.txt ../LICENSE.txt $${doc.path}
|
||||
target.path = $$INSTALL_PREFIX/bin
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
##### Setup Compile #####
|
||||
|
||||
DEFINES += DEVDIR='\\\"$$DEVDIR\\\"'
|
||||
DEFINES += ICON24='\\\"$${icons.conf_path}/icon24.png\\\"'
|
||||
DEFINES += ICON64='\\\"$${icons.conf_path}/icon64.png\\\"'
|
||||
|
||||
TEMPLATE = app
|
||||
INCLUDEPATH += .
|
||||
QMAKE_LIBS += -lXtst -lX11
|
||||
QMAKE_CXXFLAGS += -Werror -Wno-deprecated-declarations
|
||||
|
||||
# Input
|
||||
HEADERS += axis.h \
|
||||
axis_edit.h \
|
||||
axisw.h \
|
||||
button.h \
|
||||
button_edit.h \
|
||||
buttonw.h \
|
||||
constant.h \
|
||||
device.h \
|
||||
error.h \
|
||||
event.h \
|
||||
flash.h \
|
||||
icon.h \
|
||||
joypad.h \
|
||||
joypadw.h \
|
||||
joyslider.h \
|
||||
keycode.h \
|
||||
layout.h \
|
||||
getkey.h \
|
||||
layout_edit.h \
|
||||
quickset.h
|
||||
SOURCES += axis.cpp \
|
||||
axis_edit.cpp \
|
||||
axisw.cpp \
|
||||
button.cpp \
|
||||
button_edit.cpp \
|
||||
buttonw.cpp \
|
||||
event.cpp \
|
||||
flash.cpp \
|
||||
icon.cpp \
|
||||
joypad.cpp \
|
||||
joypadw.cpp \
|
||||
joyslider.cpp \
|
||||
keycode.cpp \
|
||||
layout.cpp \
|
||||
layout_edit.cpp \
|
||||
main.cpp \
|
||||
quickset.cpp \
|
||||
getkey.cpp
|
||||
|
||||
|
||||
##### Install #####
|
||||
|
||||
INSTALLS += target icons doc
|
Reference in New Issue
Block a user