Skip to content

Commit

Permalink
Merge pull request #5 from LaTruelle/pythonqt-interface
Browse files Browse the repository at this point in the history
Refactoring, building interface
  • Loading branch information
LaTruelle committed Nov 2, 2015
2 parents d83acd1 + 9f2637b commit 12917b8
Show file tree
Hide file tree
Showing 89 changed files with 4,766 additions and 6,114 deletions.
35 changes: 35 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -4
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Linux
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
Standard: Cpp11
TabWidth: 4
UseTab: Never
...
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ set(PATAGUI_SOURCES
src/notification.cc
src/identity-proxy-model.cc
src/song-item-delegate.cc
src/make-songbook-process.cc
src/find-replace-dialog.cc
src/search-widget.cc
src/variant-factory.cc
src/variant-manager.cc
src/import-dialog.cc
src/conflict-dialog.cc
src/diff_match_patch/diff_match_patch.cpp
src/patacrep.cc
)

# header (moc)
Expand Down Expand Up @@ -81,13 +81,13 @@ set(PATAGUI_QT_HEADER
src/notification.hh
src/identity-proxy-model.hh
src/song-item-delegate.hh
src/make-songbook-process.hh
src/find-replace-dialog.hh
src/search-widget.hh
src/variant-factory.hh
src/variant-manager.hh
src/import-dialog.hh
src/conflict-dialog.hh
src/patacrep.hh
)

# uis
Expand Down
103 changes: 45 additions & 58 deletions src/chord-list-model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,55 +24,49 @@

#include <QDebug>

CChordListModel::CChordListModel(QObject *parent)
: QAbstractListModel(parent)
, m_columnCount(0)
, m_rowCount(0)
ChordListModel::ChordListModel(QObject *parent)
: QAbstractListModel(parent), m_columnCount(0), m_rowCount(0)
{
m_fixedColumnCount = false;
m_fixedRowCount = false;
}

CChordListModel::~CChordListModel()
ChordListModel::~ChordListModel()
{
foreach (CChord* chord, m_data)
foreach (Chord *chord, m_data)
delete chord;
m_data.clear();
}

int CChordListModel::columnCount(const QModelIndex &) const
int ChordListModel::columnCount(const QModelIndex &) const
{
return m_columnCount;
}

void CChordListModel::setColumnCount(int value)
void ChordListModel::setColumnCount(int value)
{
emit(layoutAboutToBeChanged());
m_fixedColumnCount = true;
m_columnCount = value;
emit(layoutChanged());
}

int CChordListModel::rowCount(const QModelIndex &) const
{
return m_rowCount;
}
int ChordListModel::rowCount(const QModelIndex &) const { return m_rowCount; }

void CChordListModel::setRowCount(int value)
void ChordListModel::setRowCount(int value)
{
emit(layoutAboutToBeChanged());
m_fixedRowCount = true;
m_rowCount = value;
emit(layoutChanged());
}

QVariant CChordListModel::data(const QModelIndex &index, int role) const
QVariant ChordListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || m_data.size()==0)
if (!index.isValid() || m_data.size() == 0)
return QVariant();

switch (role)
{
switch (role) {
case Qt::DisplayRole:
return m_data[positionFromIndex(index)]->toString();
case Qt::DecorationRole:
Expand All @@ -90,16 +84,16 @@ QVariant CChordListModel::data(const QModelIndex &index, int role) const
}
}

bool CChordListModel::setData(const QModelIndex & index, const QVariant & value, int role)
bool ChordListModel::setData(const QModelIndex &index, const QVariant &value,
int role)
{
Q_UNUSED(role);

if (!index.isValid())
return false;

CChord *chord = new CChord(value.toString());
if (chord->isValid())
{
Chord *chord = new Chord(value.toString());
if (chord->isValid()) {
int pos = positionFromIndex(index);
delete m_data[pos];
m_data[pos] = chord;
Expand All @@ -110,20 +104,20 @@ bool CChordListModel::setData(const QModelIndex & index, const QVariant & value,
return false;
}

void CChordListModel::insertItem(const QModelIndex & index, const QString & value)
void ChordListModel::insertItem(const QModelIndex &index, const QString &value)
{
setColumnCount(columnCount() + 1);
m_fixedColumnCount = false;
int pos = index.column() < 0 ? columnCount()-1 : index.column();
int pos = index.column() < 0 ? columnCount() - 1 : index.column();

CChord *chord = new CChord(value);
Chord *chord = new Chord(value);
if (chord->isValid())
m_data.insert(pos, chord);
else
delete chord;
}

void CChordListModel::removeItem(const QModelIndex & index)
void ChordListModel::removeItem(const QModelIndex &index)
{
int pos = positionFromIndex(index);
delete m_data[pos];
Expand All @@ -133,23 +127,20 @@ void CChordListModel::removeItem(const QModelIndex & index)
int col = indexFromPosition(m_data.size()).column();

// dynamically reduce the QListModel
if (rowCount() > row +1)
{
if (rowCount() > row + 1) {
setRowCount(row + 1);
m_fixedRowCount = false;
}
if (columnCount() > col +1)
{
if (columnCount() > col + 1) {
setColumnCount(col + 1);
m_fixedColumnCount = false;
}
}

void CChordListModel::addItem(const QString & value)
void ChordListModel::addItem(const QString &value)
{
CChord * chord = new CChord(value);
if (!chord->isValid())
{
Chord *chord = new Chord(value);
if (!chord->isValid()) {
delete chord;
return;
}
Expand All @@ -160,55 +151,51 @@ void CChordListModel::addItem(const QString & value)
int col = indexFromPosition(m_data.size()).column();

// dynamically expand the QListModel
if (rowCount() < row +1)
{
if (rowCount() < row + 1) {
setRowCount(row + 1);
m_fixedRowCount = false;
}
if (columnCount() < col +1)
{
if (columnCount() < col + 1) {
setColumnCount(col + 1);
m_fixedColumnCount = false;
}
}

QModelIndex CChordListModel::indexFromPosition(int position)
QModelIndex ChordListModel::indexFromPosition(int position)
{
int row = 1, col = 1;
if (m_fixedColumnCount)
{
row = (position-1)/columnCount();
col = (position-1)%columnCount();
if (m_fixedColumnCount) {
row = (position - 1) / columnCount();
col = (position - 1) % columnCount();
}
if (m_fixedRowCount)
{
row = (position-1)%rowCount();
col = (position-1)/rowCount();
if (m_fixedRowCount) {
row = (position - 1) % rowCount();
col = (position - 1) / rowCount();
}
return QAbstractListModel::createIndex(row, col);
}

int CChordListModel::positionFromIndex(const QModelIndex & index) const
int ChordListModel::positionFromIndex(const QModelIndex &index) const
{
return columnCount() * index.row() + index.column();
}

CChord * CChordListModel::getChord(const QModelIndex & index) const
Chord *ChordListModel::getChord(const QModelIndex &index) const
{
return m_data[positionFromIndex(index)];
}

Qt::DropActions CChordListModel::supportedDropActions() const
Qt::DropActions ChordListModel::supportedDropActions() const
{
return Qt::CopyAction | Qt::MoveAction;
}

Qt::DropActions CChordListModel::supportedDragActions() const
Qt::DropActions ChordListModel::supportedDragActions() const
{
return Qt::CopyAction | Qt::MoveAction;
}

Qt::ItemFlags CChordListModel::flags(const QModelIndex &index) const
Qt::ItemFlags ChordListModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index);

Expand All @@ -218,14 +205,14 @@ Qt::ItemFlags CChordListModel::flags(const QModelIndex &index) const
return Qt::ItemIsDropEnabled | defaultFlags;
}

QStringList CChordListModel::mimeTypes() const
QStringList ChordListModel::mimeTypes() const
{
QStringList types;
types << "text/plain";
return types;
}

QMimeData * CChordListModel::mimeData(const QModelIndexList &indexes) const
QMimeData *ChordListModel::mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeData = new QMimeData();
foreach (const QModelIndex &index, indexes)
Expand All @@ -235,8 +222,9 @@ QMimeData * CChordListModel::mimeData(const QModelIndexList &indexes) const
return mimeData;
}

bool CChordListModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent)
bool ChordListModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column,
const QModelIndex &parent)
{
if (action == Qt::IgnoreAction)
return true;
Expand All @@ -257,9 +245,8 @@ bool CChordListModel::dropMimeData(const QMimeData *data, Qt::DropAction action,

QString newItem = data->text();
insertItem(index(0, beginColumn), newItem);
for(int j=0; j<columnCount(); ++j)
if (m_data[j]->toString() == newItem && j != beginColumn)
{
for (int j = 0; j < columnCount(); ++j)
if (m_data[j]->toString() == newItem && j != beginColumn) {
removeItem(index(0, j));
return true;
}
Expand Down
Loading

0 comments on commit 12917b8

Please sign in to comment.